home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 3 / 3067 / xkal2xremind.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-15  |  2.8 KB  |  126 lines

  1. /*
  2.  *    xkal2xremind.c : Prints weekly or one-shot reminders in xremind
  3.  *        format, minus 5 minutes from the scheduled time. Output
  4.  *        to given file or ~/.xremind.
  5.  *
  6.  *    George Ferguson, ferguson@cs.rochester.edu,  19 Feb 1991.
  7.  *
  8.  *    $Id: xkal2xremind.c,v 1.2 91/03/13 13:31:51 ferguson Exp $
  9.  *
  10.  */
  11. #ifndef lint
  12. static char rcs_id[] = "$Id: xkal2xremind.c,v 1.2 91/03/13 13:31:51 ferguson Exp $";
  13. #endif
  14. #include <stdio.h>
  15. #include <X11/Intrinsic.h>
  16. #include "app-resources.h"
  17. #include "db.h"
  18. #include "date-strings.h"
  19. extern char *getenv();
  20. extern int errno;
  21.  
  22. /*
  23.  * Functions declared in this file
  24.  */
  25. int main();
  26. static void syntax();
  27.  
  28. /*
  29.  * Data declared in this file
  30.  */
  31. char *program;
  32. AppResources appResources;
  33. int appointsChanged = False;        /* need this for linkage */
  34.  
  35. /*    -    -    -    -    -    -    -    -    */
  36.  
  37. int
  38. main(argc, argv)
  39. int argc;
  40. char **argv;
  41. {
  42.     FILE *fp;
  43.     char *s,output[1024];        /* how big shall we be? */
  44.     int dow,err;
  45.     Yearrec *yp;
  46.     Monrec *mp;
  47.     Dayrec *dp;
  48.     Msgrec *xp;
  49.  
  50.     program = *argv;
  51.     XtToolkitInitialize();    /* gotta have this, although no display */
  52.     getResources(&argc,argv);
  53.     if (argc == 2) {
  54.     strcpy(output,argv[1]);
  55.     } else if (argc == 1) {
  56.     strcpy(output,"");
  57.     if ((s=getenv("HOME")) != NULL) {
  58.         strcpy(output,s);
  59.         strcat(output,"/");
  60.     }
  61.     strcat(output,".xremind");
  62.     } else {
  63.     exit(1);
  64.     }
  65.     initDb();
  66.     initDateStrings();
  67.     if (appResources.systemAppoints && *appResources.systemAppoints)
  68.     readDb(appResources.systemAppoints,True);
  69.     if (appResources.personalAppoints && *appResources.personalAppoints)
  70.     readDb(appResources.personalAppoints,False);
  71.     appResources.outputFormat = "%n%/%d%/%Y%w %t ";
  72.     if (strcmp(output,"-") == 0) {
  73.     fp = stdout;
  74.     } else if ((fp=fopen(output,"w")) == NULL) {
  75.     err = errno;
  76.     fprintf(stderr,"%s: ",program);
  77.     errno = err;
  78.     perror(output);
  79.     exit(1);
  80.     }
  81.     for (dow = 0; dow < 8; dow++)
  82.       for (yp = Db[dow]; yp != NULL; yp = yp->next)
  83.     for (mp = yp->mons; mp != NULL; mp = mp->next)
  84.         for (dp = mp->days; dp != NULL; dp = dp->next)
  85.         for (xp = dp->msgs; xp != NULL; xp = xp->next)
  86.             if (((!dow && xp->year && xp->month && xp->day) ||
  87.                  (dow && !xp->year && !xp->month && !xp->day)) &&
  88.             xp->hour != -1) {
  89.             if (xp->hour == 0) {
  90.                 xp->mins = 55;
  91.                 xp->hour = 23;
  92.             } else if (xp->mins == -1) {
  93.                 xp->mins = 55;
  94.                 xp->hour -= 1;
  95.             } else if (xp->mins < 5) {
  96.                 xp->mins = 55 + xp->mins;
  97.                 xp->hour -= 1;
  98.             } else {
  99.                 xp->mins -= 5;
  100.             }
  101.             writeAppoint(fp,xp);
  102.             }
  103.     fclose(fp);
  104.     exit(0);
  105. }
  106.  
  107. #ifdef USE_ALERT
  108. /*
  109.  * alert() : This function is defined so that db.c will link happily,
  110.  *    although it will never be called since xkal2xremind runs in non-
  111.  *    interactive mode.
  112.  */
  113. /*VARARGS*/
  114. void
  115. alert()
  116. {
  117.     /* notused */
  118. }
  119. #endif
  120.  
  121. static void
  122. syntax()
  123. {
  124.     fprintf(stderr,"usage: %s [file]  (default is ~/.xremind)\n",program);
  125. }
  126.