home *** CD-ROM | disk | FTP | other *** search
- From: rogers@sud509.ed.ray.com (Andrew Rogers)
- Newsgroups: comp.lang.postscript,alt.sources
- Subject: Pcal: postscript/c calendar printer (VMS version)
- Message-ID: <1355@sud509.ed.ray.com>
- Date: 5 Jun 90 16:08:46 GMT
-
- In article <1340@sud509.ed.ray.com> rogers@sud509.RAY.COM I wrote:
- >(PS: send Email if you'd like a VMS version of this...)
-
- Well, I guess I underestimated how many requests I'd get for this... so I'm
- posting the VMS version (actually the changes required to adapt the version
- I posted earlier to VMS) below. The changes visible to the user are:
-
- 1) Default calendar file is SYS$LOGIN:CALENDAR.DAT
-
- 2) Automatically writes to an output file, CALENDAR.PS; added -o
- option to override the default file name
-
- The changes visible only to the programmer are:
-
- 3) Eliminated use of getopt() to parse command line. There may be
- some minor variations in functionality introduced by this.
-
- The following code replaces main() in the Unix version previously posted:
-
- Andrew W. Rogers
-
- --------------------------- cut here ----------------------------
- /*
- * VMS version of pcal.c main module
- *
- * Adapted by Andrew W. Rogers
- */
-
- main(argc, argv)
- int argc;
- char **argv;
- {
-
- #define EXIT_SUCCESS 1
- #define EXIT_FAILURE 3
-
- #define GETARG(arg) if ((parg = *++opt ? opt : \
- (*(argv+1) && **(argv+1) != '-' ? *++argv : NULL) ) \
- != NULL) arg = parg; else
-
- #define DOHEADER(phdr) for(ap = phdr; *ap; ap++) PRT("%s\n", *ap);
-
- register struct tm *lt;
- register char **ap;
- register char *cp;
- char *cfile = NULL;
- char *opt, *pnum, *parg;
- char cbuf[80];
- long t;
- int errflg = 0;
- int nocal = 0;
- int sat = 0;
- char *titlefont = "Times-Bold";
- char *dayfont = "Times-Bold";
- char *outfile = "CALENDAR.PS";
- int rotate = 90;
- int month = 0;
- char doyear = 0;
- char *trnlog();
-
- while (!errflg && *++argv) {
-
- if (**argv != '-') {
- errflg = 1;
- break;
- }
-
- opt = (*argv) + 1;
- switch (*opt) {
-
- case 'd': /* Alternate day name/number font */
- GETARG(dayfont);
- break;
-
- case 'e': /* Empty calendar */
- nocal++;
- cfile = NULL;
- break;
-
- case 'f': /* Alternate calendar file name */
- GETARG(cfile);
- nocal = 0;
- break;
-
- case 'm': /* Month */
- pnum = NULL;
- GETARG(pnum);
- month = pnum ? atoi(pnum) : 0;
- if (!month) doyear = 1;
- break;
-
- case 'o': /* Alternate output file name */
- GETARG(outfile);
- break;
-
- case 'r': /* Portrait */
- rotate = 0;
- break;
-
- case 's': /* Saturdays in black */
- sat++;
- break;
-
- case 't': /* Alternate title font */
- GETARG(titlefont);
- break;
-
- case 'y': /* Year */
- pnum = NULL;
- GETARG(pnum);
- year = pnum ? atoi(pnum) : 0;
- if (year != 0 && year < 1900) year = year % 100 + 1900;
- break;
-
- default:
- errflg = 1;
- break;
- }
- }
-
- if (errflg) {
- FPR(stderr,
- "Usage: pcal [ -r ] [ -s ] [ -e | -f <cal> ] [ -m month] [ -y <year> ]\n");
- FPR(stderr,
- "\t\t[ -t <title font> ] [ -d <day font> ] [-o <output file>]\n");
- exit(EXIT_FAILURE);
- }
- t = time((long *)0);
- lt = localtime(&t);
-
- if (!month && !doyear)
- month = lt->tm_mon + 1;
- if (!year)
- year = lt->tm_year + 1900;
-
- if (outfile && freopen(outfile, "w", stdout) == (FILE *) NULL) {
- FPR(stderr, "pcal: can't open file: %s\n", outfile);
- exit(EXIT_FAILURE);
- }
-
- /*
- * In case we don't encounter any year data in the
- * calendar file, assume the current year.
- */
- cyear = year;
-
- /*
- * Open a supplied calendar file (if any)
- */
- if (cfile != NULL) {
- if ((cfp = fopen(cfile, "r")) == NULL) {
- FPR(stderr, "pcal: can't open file: %s\n", cfile);
- exit(EXIT_FAILURE);
- }
- }
- /*
- * Else see if a calendar file exists in the home directory
- */
- else if (nocal == 0 && (cp = trnlog("SYS$LOGIN")) != NULL) {
- (void)strcpy(cbuf, cp);
- (void)strcat(cbuf, "CALENDAR.DAT");
- cfp = fopen(cbuf, "r");
- }
-
- /*
- * Write out PostScript prolog
- */
- PRT("%%!\n");
- PRT("/titlefont /%s def\n/dayfont /%s def\n", titlefont, dayfont);
-
- DOHEADER(header_1);
- if (!sat)
- DOHEADER(header_2);
- DOHEADER(header_3);
-
- PRT("\t%d rotate\n", rotate);
- if (rotate)
- PRT("\t50 -120 translate\n");
- else
- PRT("\t0.75 0.75 scale\n\t50 460 translate\n");
-
- DOHEADER(header_4);
-
- if (month)
- pmonth(month);
- else
- for (month = 1; month <= 12; month++)
- pmonth(month);
-
- FPR(stderr, "Output is in file %s\n", outfile);
- exit(EXIT_SUCCESS);
- }
-
- #include <ssdef.h>
- #include <descrip.h>
-
- char *trnlog(logname) /* look up logical name */
- char *logname;
- {
- static char trnbuf[81];
-
- $DESCRIPTOR(src, logname);
- $DESCRIPTOR(dst, trnbuf);
- short len;
- int ret;
-
- src.dsc$w_length = strlen(logname);
- ret = LIB$SYS_TRNLOG(&src, &len, &dst);
- if (ret != SS$_NORMAL)
- len = 0;
- trnbuf[len] = '\0';
- return trnbuf;
- }
-