home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / bbs / may94 / os20 / util / recall.lha / Recall / Source / Recall.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-05  |  8.9 KB  |  356 lines

  1. /*
  2.  *    File:                    Recall.c
  3.  *    Description:    Runs through a project of events set by it's preferences
  4.  *                                and displays them.
  5.  *    Version:            2.2
  6.  *    Author:                Ketil Hunn
  7.  *    Mail:                    ketil@lyr.dhmolde.no
  8.  *                                hunn@dhmolde.no
  9.  *
  10.  *    Copyright © 1993-1994 Ketil Hunn.  Please read the document for further
  11.  *    information and copyrights.
  12.  *
  13.  *    In order to list the source-files included in this package properly,
  14.  *    the TAB size should be set at 2.
  15.  *
  16.  */
  17.  
  18. #define    TEXTBUFFERSIZE    2500
  19.  
  20. #include <libraries/locale.h>
  21. #include <clib/locale_protos.h>
  22. #include <pragmas/locale_pragmas.h>
  23. #include <dos/dostags.h>
  24.  
  25. #define  CATCOMP_NUMBERS
  26. #include "Recall_locale.h"
  27.  
  28. #define REQUESTER_TYPE    0
  29. #define    MYALERT_TYPE        1
  30. #define    EXECUTE_TYPE        2
  31.  
  32. #define    ALWAYS                    0
  33. #define    DAILY                        1
  34. #define    NEVER                        2
  35.  
  36. #define CALC_YEARS            0
  37. #define CALC_DAYS                1
  38.  
  39. #define GROUP_STAMP            -1
  40. #define ACK_STAMP                -2
  41.  
  42. //#include <stdio.h>
  43. #include <clib/alib_stdio_protos.h>
  44. #include <exec/types.h>
  45. #include <libraries/reqtools.h>
  46. #include <intuition/intuition.h>
  47. #include <exec/alerts.h>
  48. #include <dos/datetime.h>
  49. #include <exec/memory.h>
  50.  
  51. #include <clib/exec_protos.h>
  52. #include <proto/exec.h>
  53. #include <clib/intuition_protos.h>
  54. #include <proto/dos.h>
  55. #include <proto/reqtools.h>
  56.  
  57. /* PROTOTYPES */
  58. STRPTR __asm GetString(register __a0 struct LocaleInfo *li,
  59.                        register __d0 LONG stringNum);
  60. char *CatSingleEventTexts(struct EventNode *eventnode, char *text);
  61. char *CatGroupEventsTexts(struct List *list, short type, char *text);
  62. long ShowRequest(char *text, char *button, char *params);
  63.  
  64.  
  65. struct Library                *IntuitionBase,    *IFFParseBase,    *LocaleBase,
  66.                                             *UtilityBase;
  67. struct Device                    *TimerBase;
  68. struct ReqToolsBase     *ReqToolsBase=NULL;
  69. struct List                        *list=NULL;
  70. struct LocaleInfo            li;
  71. ULONG                                    datenow, timenow;
  72. char                                    title[25];
  73.  
  74. #include "Version.h"
  75. #include "MyEZRequest().h"
  76. #include "MyAlert().h"
  77. #include "Config20b.h"
  78. #include "CalcField.h"
  79. #include "CheckDateTime.h"
  80. #include "execute().h"
  81.  
  82. char const                        *version=VERSTR;
  83.  
  84. int main(int argc, char *argv[])
  85. {
  86.     struct timerequest    timereq, *tr=&timereq;
  87.     struct Node                    *node;
  88.     struct EventNode        *eventnode;
  89.     char                                *text, button[40]="  OK  ";
  90.     long                                retvalue_event, retvalue_alert, retvalue_exec;
  91.     char                                filename[FNSIZE];
  92.     short                                save=0;
  93.  
  94.     if(IntuitionBase=OpenLibrary("intuition.library", LIBVER))
  95.     {
  96.         if(IFFParseBase=OpenLibrary("iffparse.library", LIBVER))
  97.         {
  98.             if(UtilityBase=OpenLibrary("utility.library", LIBVER))
  99.             {
  100.                 if(!(OpenDevice("timer.device", UNIT_VBLANK, (struct IORequest *)tr, 0)))
  101.                 {
  102.                     TimerBase=tr->tr_node.io_Device;
  103.                     if(list=AllocMem(sizeof(struct List),MEMF_CLEAR))
  104.                     {
  105.                         NewList(list);
  106.  
  107.                         li.li_Catalog=NULL;
  108.                         if(LocaleBase=OpenLibrary("locale.library", 38))
  109.                         {
  110.                             li.li_LocaleBase = LocaleBase;
  111.                             li.li_Catalog    = OpenCatalogA(NULL,"Recall/Recall.catalog",NULL);
  112.                         }
  113.  
  114.                         datenow=NewMakeDate(NULL);
  115.                         timenow=NewMakeTime(NULL);
  116.                         {
  117.                             struct DateTime dt;
  118.                             char date[16];
  119.  
  120.                             DateStamp(&dt.dat_Stamp);
  121.                             dt.dat_Format    =4;
  122.                             dt.dat_Flags    =NULL;
  123.                             dt.dat_StrDay    =NULL;
  124.                             dt.dat_StrDate=date;
  125.                             dt.dat_StrTime=NULL;
  126.                             DateToStr(&dt);
  127.  
  128.                             strcpy(title, PROGNAME " " VERSION "  ");
  129.                             strcat(title, date);
  130.                         }
  131.  
  132.                         if(argc>1)
  133.                         {
  134.                             strcpy(filename, argv[1]);
  135.                             shellopen=TRUE;
  136.                         }
  137.                         else
  138.                             strcpy(filename, PREFSFILE);
  139.  
  140.                         if(ReadIFF(list, filename))
  141.                         {
  142.                             /* do not open reqtools.library if not needed */
  143.                             if(config.usereqtools)
  144.                                 ReqToolsBase=    (struct ReqToolsBase *)OpenLibrary
  145.                                                             (REQTOOLSNAME, REQTOOLSVERSION);
  146.  
  147.                             // Run through the list and mark all events that will be displayed
  148.                             for(every_node)
  149.                             {
  150.                                 eventnode=(struct EventNode *)node;
  151.                                 if(eventnode->show!=NEVER & eventnode->datestamp!=datenow)
  152.                                     if(eventnode->datestamp==ACK_STAMP)
  153.                                         eventnode->display=TRUE;
  154.                                     else if(CheckDateTime(eventnode)==TRUE)
  155.                                         eventnode->display=TRUE;
  156.                             }
  157.  
  158.                             /* add a Postpone-button to the requester */
  159.                             if(config.putoff)
  160.                                 strcat(button, GetString(&li, MSG_PUTOFF));
  161.  
  162.                             /* add a cancel-button to the requester */
  163.                             if(config.ack_events)
  164.                                 strcat(button, GetString(&li, MSG_CANCEL));
  165.  
  166.                             if(text=AllocMem(TEXTBUFFERSIZE, MEMF_CLEAR))
  167.                             {
  168.                                 for(every_node)
  169.                                 {
  170.                                     strcpy(text, "");
  171.                                     eventnode=(struct EventNode *)node;
  172.                                     if(eventnode->display==TRUE)
  173.                                     {
  174.                                         if(config.groupevents)
  175.                                             CatGroupEventsTexts(list, eventnode->type, text);
  176.                                         else
  177.                                             CatSingleEventTexts(eventnode, text);
  178.  
  179.                                         if(strlen(text))
  180.                                         {
  181.                                             if(config.flashscreen)
  182.                                                 DisplayBeep(NULL);    
  183.  
  184.                                             switch(eventnode->type)
  185.                                             {
  186.                                                 case REQUESTER_TYPE:
  187.                                                         retvalue_event=ShowRequest(text, button ,"");
  188.                                                     break;
  189.  
  190.                                                 case MYALERT_TYPE:
  191.                                                     if(config.ack_alerts)
  192.                                                     {
  193.                                                         strcat(text, GetString(&li, MSG_ALERTCONFIRM));
  194.                                                         retvalue_alert=MyAlert(RECOVERY_ALERT, text);
  195.                                                     }
  196.                                                     else
  197.                                                     {
  198.                                                         retvalue_alert=1;
  199.                                                         MyAlert(RECOVERY_ALERT, text);
  200.                                                     }
  201.                                                     break;
  202.     
  203.                                                 case EXECUTE_TYPE:
  204.                                                     if(config.ask_before_execute)
  205.                                                     {
  206.                                                         if(1==(retvalue_exec=ShowRequest(
  207.                                                                                                     GetString(&li, MSG_EXECUTEEVENT),
  208.                                                                                                     button,
  209.                                                                                                     text)))
  210.                                                             execute(text);
  211.                                                     }
  212.                                                     else
  213.                                                     {
  214.                                                         retvalue_exec=1;
  215.                                                         execute(text);
  216.                                                     }
  217.                                                     break;
  218.                                             }
  219.                                         }
  220.                                         eventnode->display=TRUE;
  221.                                      }
  222.                                     if(eventnode->datestamp==GROUP_STAMP | eventnode->display==TRUE)
  223.                                     {
  224.                                         eventnode->display=FALSE;
  225.                                         eventnode->datestamp=0;
  226.                                         switch(eventnode->type)
  227.                                         {
  228.                                             case REQUESTER_TYPE:
  229.                                                 if((retvalue_event==0 & config.ack_events) |
  230.                                                     (retvalue_event==1 & eventnode->show==DAILY))
  231.                                                 {
  232.                                                     eventnode->datestamp=datenow;
  233.                                                     save|=1;
  234.                                                 }
  235.                                                 else if(retvalue_event==2)
  236.                                                 {
  237.                                                     eventnode->datestamp=ACK_STAMP;
  238.                                                     save|=1;
  239.                                                 }
  240.                                                 break;
  241.                                             case MYALERT_TYPE:
  242.                                                 if(retvalue_alert==0)
  243.                                                 {
  244.                                                     eventnode->datestamp=datenow;
  245.                                                     save|=1;
  246.                                                 }
  247.                                                 break;
  248.                                             case EXECUTE_TYPE:
  249.                                                 if(retvalue_exec==0 |
  250.                                                     (retvalue_exec==1 & eventnode->show==DAILY))
  251.                                                 {
  252.                                                     eventnode->datestamp=datenow;
  253.                                                     save|=1;
  254.                                                 }
  255.                                                 else if(retvalue_exec==2)
  256.                                                 {
  257.                                                     eventnode->datestamp=ACK_STAMP;
  258.                                                     save|=1;
  259.                                                 }
  260.                                                 break;
  261.                                         }
  262.                                     }
  263.                                 }
  264.                                 FreeMem(text, TEXTBUFFERSIZE);
  265.                                 if(save)
  266.                                     WriteIFF(list, filename);
  267.                             }
  268.                             if(ReqToolsBase)
  269.                                 CloseLibrary((struct Library *)ReqToolsBase);
  270.                         }
  271.                         FreeEventList(list);
  272.                         FreeMem(list, sizeof(struct List));
  273.  
  274.                         if(LocaleBase)
  275.                         {
  276.                             CloseCatalog(li.li_Catalog);
  277.                             CloseLibrary(LocaleBase);
  278.                         }
  279.                     }
  280.                     CloseDevice((struct IORequest *)tr);
  281.                 }
  282.                 CloseLibrary(UtilityBase);
  283.             }
  284.             CloseLibrary(IFFParseBase);
  285.         }
  286.         CloseLibrary(IntuitionBase);
  287.     }
  288.     exit(0);
  289. }
  290.  
  291. char *CatSingleEventTexts(struct EventNode *eventnode, char *text)
  292. {
  293.     struct List *list=eventnode->textlist;
  294.     struct Node *node;
  295.  
  296.     eventnode->display=FALSE;
  297.     if(config.groupevents)
  298.         eventnode->datestamp=GROUP_STAMP;
  299.     for(every_node)
  300.     {
  301.         strcat(text, node->ln_Name);
  302.         if(node!=list->lh_TailPred)
  303.             strcat(text, "\n");
  304.     }
  305.     return CalcField(eventnode, text);
  306. }
  307.  
  308. char *CatGroupEventsTexts(struct List *list, short type, char *text)
  309. {
  310.     struct Node *node;
  311.     struct EventNode *eventnode;
  312.     char   *tmp;
  313.     BOOL   newline=FALSE;
  314.  
  315.     if(tmp=AllocMem(TEXTBUFFERSIZE, MEMF_CLEAR))
  316.     {
  317.         for(every_node)
  318.         {
  319.             eventnode=(struct EventNode *)node;
  320.             if(eventnode->type==type & eventnode->display==TRUE)
  321.             {
  322.                 if(!newline)
  323.                     newline=TRUE;
  324.                 else
  325.                     strcat(text, "\n");
  326.                 strcpy(tmp, "");
  327.                 strcat(text, CatSingleEventTexts(eventnode, tmp));
  328.             }
  329.         }
  330.         FreeMem(tmp, TEXTBUFFERSIZE);
  331.     }
  332.     return text;
  333. }
  334.  
  335. long ShowRequest(char *text, char *button, char *params)
  336. {
  337.     long val;
  338.     ULONG normaltag[]={    RTEZ_ReqTitle, (ULONG)(title),
  339.                                             TAG_END};
  340.     ULONG centretag[]={    RTEZ_ReqTitle,(ULONG)(title),
  341.                                             RT_ReqPos, REQPOS_CENTERSCR,
  342.                                             TAG_END};
  343.  
  344.     if(config.usereqtools==TRUE & ReqToolsBase!=NULL)
  345.         if(config.centrerequesters)
  346.             val=rtEZRequest(text, button, NULL,
  347.                                                                 (struct TagItem *)centretag, params);
  348.         else
  349.             val=rtEZRequest(text, button, NULL,
  350.                                                                 (struct TagItem *)normaltag, params);
  351.     else
  352.         val=MyEZRequest(title, text, button, params);
  353.  
  354.     return val;
  355. }
  356.