home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
misc
/
volume17
/
remind
/
part03
/
init.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-02-19
|
6KB
|
238 lines
#include <stdio.h>
#ifndef UNIX
#include <stdlib.h>
#endif
#include <string.h>
#include "defines.h"
#include "globals.h"
#include "protos.h"
#define PATCHLEVEL 0
static char DPMsg[] = "Debug and Purge options conflict - Purge chosen.\n";
static char DPCMsg[] = "Calendar overrides Debug and Purge options.\n";
static char NMsg[] = "Next overrides Calendar, Debug and Purge options.\n";
/***************************************************************/
/* */
/* void initialize(int argc, char *argv[]) */
/* */
/* Reads command line options, sets appropriate flags */
/* and FileName. Also exits with error if invoked */
/* incorrectly. */
/* */
/***************************************************************/
#ifdef __STDC__
void initialize(int argc, char *argv[])
#else
void initialize(argc, argv)
int argc;
char *argv[];
#endif
{
int i;
char *s;
int d, m, y, t;
Token tok;
Debug = 0;
Purge = 0;
Verbose = 0;
IgOnce = 0;
IgRun = 0;
Calendar = 0;
Next = 0;
PrintAts = 1;
QueueAts = 1;
CalWidth = 10;
SimpleCalendar = 0;
if(argc == 1) {
fprintf(stderr, "\nREMIND 2.3 Patch Level %d (C) 1990, 1991 by David Skoll.\n\n", PATCHLEVEL);
#ifdef UNIX
fprintf(stderr, "Usage: remind [-n | -d | -p | -c# [-w# | -s]] [-voraq] filename [date]\n\n");
#else
fprintf(stderr, "Usage: remind [-n | -d | -p | -c# [-w# | -s]] [-vor] filename [date]\n\n");
#endif
fprintf(stderr, "-n Output next occurrence of reminders in simple format\n");
fprintf(stderr, "-d Debug reminder file\n-p Purge reminder file\n");
fprintf(stderr, "-c# Produce calendar for # months\n");
fprintf(stderr, "-w# Make calendar # columns wide\n");
fprintf(stderr, "-s Produce simple calendar listing (used with -c)\n");
fprintf(stderr, "-v Verbose messages\n-o Ignore ONCE directives\n");
fprintf(stderr, "-r Ignore RUN directives\n");
#ifdef UNIX
fprintf(stderr, "-a Do not trigger current AT reminders in foreground\n");
fprintf(stderr, "-q Do not queue current AT reminders\n\n");
#endif
exit(1);
}
i = 1;
s = argv[i];
/* Process options */
while (*s == '-') {
while (*++s) {
switch(upper(*s)) {
case 'N': Next = 1;
if (Calendar || Debug || Purge) {
Calendar = Debug = Purge = 0;
fprintf(stderr, NMsg);
}
break;
case 'P': Purge = 1;
if (Next) {
Calendar = Debug = Purge = 0;
fprintf(stderr, NMsg);
}
if (Calendar) {
Debug = Purge = 0;
fprintf(stderr, DPCMsg);
}
if (Debug) {
Debug = 0;
fprintf(stderr, DPMsg);
}
break;
case 'D': Debug = 1;
if (Next) {
Calendar = Debug = Purge = 0;
fprintf(stderr, NMsg);
}
if (Calendar) {
Debug = Purge = 0;
fprintf(stderr, DPCMsg);
}
if (Purge) {
Debug = 0;
fprintf(stderr, DPMsg);
}
break;
case 'C': Calendar = 1;
if (Next) {
Calendar = Debug = Purge = 0;
fprintf(stderr, NMsg);
}
if (Debug || Purge) {
Debug = Purge = 0;
fprintf(stderr, DPCMsg);
}
t = atoi(s + 1);
if (t > 0 && t <= 12) Calendar = t;
/* Skip remaining chars on this option */
while (*++s) ;
s--;
break;
case 'W': CalWidth = (atoi(s+1)-9)/7;
if (CalWidth < 10) CalWidth = 10;
if (CalWidth > 40) CalWidth = 40;
while (*++s) ;
s--;
break;
case 'S': SimpleCalendar = 1; break;
case 'V': Verbose = 1; break;
case 'O': IgOnce = 1; break;
case 'R': IgRun = 1; break;
#ifdef UNIX
case 'A': PrintAts = 0; break;
case 'Q': QueueAts = 0; break;
#endif
default: fprintf(stderr, "Unknown option '%c' ignored.\n", *s);
}
}
i++;
if (i >= argc) {
fprintf(stderr, "Missing filename - type 'remind' for usage information.\n");
exit(1);
}
s = argv[i];
}
/* Set FileName */
strcpy(FileName, argv[i++]);
/* Get date, if supplied */
if (i < argc) {
*WorkBuf = 0;
while (i < argc) {
strcat(WorkBuf, argv[i++]);
strcat(WorkBuf, " ");
}
/* Parse the date */
d = m = y = -1;
tok.type = Unknown_t;
s = WorkBuf;
while (tok.type != Eol_t) {
tok = ParseToken(&s);
switch(tok.type) {
case Eol_t: break;
case Year_t: if (y == -1)
y = tok.val;
else {
fprintf(stderr, "Year specified twice!\n");
exit(1);
}
break;
case Month_t: if (m == -1)
m = tok.val;
else {
fprintf(stderr, "Month specified twice!\n");
exit(1);
}
break;
case Day_t: if (d == -1)
d = tok.val;
else {
fprintf(stderr, "Day specified twice!\n");
exit(1);
}
break;
default: fprintf(stderr, "Illegal token %s on command line.\n", tok.str);
exit(1);
}
}
if (d == -1 || m == -1 || y == -1) {
fprintf(stderr, "Date on command line must be fully specified.\n");
exit(1);
}
if (CheckDate(d, m, y)) {
fprintf(stderr, "Illegal date on command line.\n");
exit(1);
}
CurDay = d;
CurMon = m;
CurYear = y;
JulianToday = Julian(d, m, y);
}
OpenFile(FileName);
if (Debug) {
FromJulian(LastRun, &d, &m, &y);
#ifndef UNIX
fprintf(stderr, "\nFile %s last modified on %s, %d %s, %d\n", FileName,
#else
fprintf(stderr, "\nFile %s last accessed on %s, %d %s, %d\n", FileName,
#endif
DayName[LastRun % 7], d, MonthName[m], y);
}
return;
}