home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1421 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  4.6 KB

  1. From: rogers@sud509.ed.ray.com (Andrew Rogers)
  2. Newsgroups: comp.lang.postscript,alt.sources
  3. Subject: Pcal: postscript/c calendar printer (VMS version)
  4. Message-ID: <1355@sud509.ed.ray.com>
  5. Date: 5 Jun 90 16:08:46 GMT
  6.  
  7. In article <1340@sud509.ed.ray.com> rogers@sud509.RAY.COM I wrote:
  8. >(PS: send Email if you'd like a VMS version of this...)
  9.  
  10. Well, I guess I underestimated how many requests I'd get for this... so I'm
  11. posting the VMS version (actually the changes required to adapt the version
  12. I posted earlier to VMS) below.  The changes visible to the user are:
  13.  
  14.     1) Default calendar file is SYS$LOGIN:CALENDAR.DAT
  15.  
  16.     2) Automatically writes to an output file, CALENDAR.PS; added -o
  17.        option to override the default file name
  18.  
  19. The changes visible only to the programmer are:
  20.  
  21.     3) Eliminated use of getopt() to parse command line.  There may be
  22.        some minor variations in functionality introduced by this.
  23.  
  24. The following code replaces main() in the Unix version previously posted:
  25.  
  26. Andrew W. Rogers
  27.  
  28. --------------------------- cut here ----------------------------
  29. /*
  30.  * VMS version of pcal.c main module
  31.  *
  32.  * Adapted by Andrew W. Rogers
  33.  */
  34.  
  35. main(argc, argv)
  36. int argc;
  37. char **argv;
  38. {
  39.  
  40. #define EXIT_SUCCESS 1
  41. #define EXIT_FAILURE 3
  42.  
  43. #define GETARG(arg) if ((parg = *++opt ? opt : \
  44.             (*(argv+1) && **(argv+1) != '-' ? *++argv : NULL) ) \
  45.             != NULL) arg = parg; else
  46.  
  47. #define DOHEADER(phdr) for(ap = phdr; *ap; ap++) PRT("%s\n", *ap);
  48.  
  49.     register struct tm *lt;
  50.     register char **ap;
  51.     register char *cp;
  52.     char *cfile = NULL;
  53.     char *opt, *pnum, *parg;
  54.     char cbuf[80];
  55.     long t;
  56.     int errflg = 0;
  57.     int nocal = 0;
  58.     int sat = 0;
  59.      char *titlefont = "Times-Bold";
  60.      char *dayfont = "Times-Bold";
  61.     char *outfile = "CALENDAR.PS";
  62.      int rotate = 90;
  63.      int month = 0;
  64.     char doyear = 0;
  65.     char *trnlog();
  66.  
  67.      while (!errflg && *++argv) {
  68.  
  69.         if (**argv != '-') {
  70.             errflg = 1;
  71.             break;
  72.             }
  73.  
  74.         opt = (*argv) + 1;
  75.         switch (*opt) {
  76.  
  77.          case 'd':        /* Alternate day name/number font */
  78.              GETARG(dayfont);
  79.              break;
  80.  
  81.         case 'e':        /* Empty calendar */
  82.             nocal++;
  83.             cfile = NULL;
  84.             break;
  85.  
  86.         case 'f':        /* Alternate calendar file name */
  87.             GETARG(cfile);
  88.             nocal = 0;
  89.             break;
  90.  
  91.         case 'm':        /* Month */
  92.             pnum = NULL;
  93.             GETARG(pnum);
  94.             month = pnum ? atoi(pnum) : 0;
  95.             if (!month) doyear = 1;
  96.             break;
  97.  
  98.         case 'o':        /* Alternate output file name */
  99.             GETARG(outfile);
  100.             break;
  101.  
  102.          case 'r':        /* Portrait */
  103.              rotate = 0;
  104.              break;
  105.  
  106.         case 's':        /* Saturdays in black */
  107.             sat++;
  108.             break;
  109.  
  110.          case 't':        /* Alternate title font */
  111.              GETARG(titlefont);
  112.              break;
  113.  
  114.         case 'y':        /* Year */
  115.             pnum = NULL;
  116.             GETARG(pnum);
  117.             year = pnum ? atoi(pnum) : 0;
  118.             if (year != 0 && year < 1900) year = year % 100 + 1900;
  119.             break;
  120.  
  121.         default:
  122.             errflg = 1;
  123.             break;
  124.         }
  125.         }
  126.  
  127.     if (errflg) {
  128.         FPR(stderr,
  129.     "Usage: pcal [ -r ] [ -s ] [ -e | -f <cal> ] [ -m month] [ -y <year> ]\n");
  130.         FPR(stderr, 
  131.     "\t\t[ -t <title font> ] [ -d <day font> ] [-o <output file>]\n");
  132.         exit(EXIT_FAILURE);
  133.     }
  134.     t = time((long *)0);
  135.     lt = localtime(&t);
  136.  
  137.     if (!month && !doyear)
  138.         month = lt->tm_mon + 1;
  139.     if (!year)
  140.         year = lt->tm_year + 1900;
  141.  
  142.     if (outfile && freopen(outfile, "w", stdout) == (FILE *) NULL) {
  143.         FPR(stderr, "pcal: can't open file: %s\n", outfile);
  144.         exit(EXIT_FAILURE);
  145.         }
  146.  
  147.     /*
  148.      * In case we don't encounter any year data in the
  149.      * calendar file, assume the current year.
  150.      */
  151.     cyear = year;
  152.  
  153.     /*
  154.      * Open a supplied calendar file (if any)
  155.      */
  156.     if (cfile != NULL) {
  157.         if ((cfp = fopen(cfile, "r")) == NULL) {
  158.             FPR(stderr, "pcal: can't open file: %s\n", cfile);
  159.             exit(EXIT_FAILURE);
  160.         }
  161.     }
  162.     /*
  163.      * Else see if a calendar file exists in the home directory
  164.      */
  165.     else if (nocal == 0 && (cp = trnlog("SYS$LOGIN")) != NULL) {
  166.         (void)strcpy(cbuf, cp);
  167.         (void)strcat(cbuf, "CALENDAR.DAT");
  168.         cfp = fopen(cbuf, "r");
  169.     }
  170.  
  171.     /*
  172.      * Write out PostScript prolog
  173.      */
  174.      PRT("%%!\n");
  175.      PRT("/titlefont /%s def\n/dayfont /%s def\n", titlefont, dayfont);
  176.  
  177.     DOHEADER(header_1);
  178.     if (!sat)
  179.         DOHEADER(header_2);
  180.     DOHEADER(header_3);
  181.  
  182.      PRT("\t%d rotate\n", rotate);
  183.      if (rotate)
  184.          PRT("\t50 -120 translate\n");
  185.      else
  186.          PRT("\t0.75 0.75 scale\n\t50 460 translate\n");
  187.  
  188.     DOHEADER(header_4);
  189.  
  190.     if (month)
  191.         pmonth(month);
  192.     else
  193.         for (month = 1; month <= 12; month++)
  194.             pmonth(month);
  195.  
  196.     FPR(stderr, "Output is in file %s\n", outfile);
  197.     exit(EXIT_SUCCESS);
  198. }
  199.  
  200. #include <ssdef.h>
  201. #include <descrip.h>
  202.  
  203. char *trnlog(logname)    /* look up logical name */
  204.     char *logname;
  205. {
  206. static char trnbuf[81];
  207.  
  208. $DESCRIPTOR(src, logname);
  209. $DESCRIPTOR(dst, trnbuf);
  210. short len;
  211. int ret;
  212.  
  213. src.dsc$w_length  = strlen(logname);
  214. ret = LIB$SYS_TRNLOG(&src, &len, &dst);
  215. if (ret != SS$_NORMAL)
  216.     len = 0;
  217. trnbuf[len] = '\0';
  218. return trnbuf;
  219. }
  220.