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

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