1: #define MAINLINE 2: #include "parms.h" 3: #include "structs.h" 4: 5: #ifdef RCSIDENT 6: static char rcsid[] = "$Header: main.c,v 1.7.0.1 85/03/08 10:40:05 notes Rel $"; 7: #endif RCSIDENT 8: 9: /* 10: * this main program will take in a notefile name, and 11: * then proceed to handle all of the processing for it. This includes 12: * calling all of the appropriate routines. It should stay in the 13: * package pretty much as is. It may not be the master routine, but 14: * it will be the chief 'driver' while within a particular note. 15: * 16: * Original author: Rob Kolstad Winter, 1980. 17: * Modifications: Ray Essick June, 1981. 18: * Modified more: Ray Essick May, 1982. 19: * 20: * 21: */ 22: 23: 24: static int seqon = NOSEQ; /* sequencer mode */ 25: 26: main (argc, argv) 27: char **argv; 28: { 29: 30: int i; 31: char *p, 32: *q, 33: *calledas; 34: int autoseq = 0; /* if autoseq */ 35: int notesargs = 0; /* count nf's */ 36: int nfsdone; 37: struct nflist_f *nfptr; 38: char bufstdout[BUFSIZ]; /* buffer for speed */ 39: 40: setbuf (stdout, bufstdout); /* buffer it */ 41: startup (argc, argv); /* common init */ 42: 43: if (globuid == Anonuid) 44: { 45: fprintf (stderr, "Sorry, you have the wrong uid (%d) to use notesfiles.\n", 46: globuid); 47: fprintf (stderr, "Consult your local system guru for more help\n"); 48: exit (BAD); 49: } 50: if ((calledas = rindex (argv[0], '/')) != 0) /* get invoking name */ 51: calledas++; 52: else 53: calledas = argv[0]; /* no slash */ 54: if (strcmp (calledas, "notes") && *calledas != '=') /* autoseq entry */ 55: { 56: autoseq++; /* is autoseq */ 57: setseq (NORMSEQ); /* turn on */ 58: } 59: 60: /* 61: * grab some variables from the environment 62: */ 63: if ((p = getenv ("SHELL")) != 0) 64: hisshell = p; /* his shell */ 65: if ((p = getenv ("NFED")) != 0) 66: hised = p; /* and his editor */ 67: else 68: if ((p = getenv ("EDITOR")) != 0) /* try this name */ 69: hised = p; /* his editor */ 70: 71: /* 72: * Scan the command line now to pluck options and 73: * notesfile specifications 74: */ 75: 76: if (*calledas == '=' && calledas[1] != '\0' && argc == 1)/* a =xxx case */ 77: { 78: expand (&calledas[1]); /* nf name */ 79: notesargs++; 80: } 81: 82: for (i = 1; i < argc; i++) 83: { 84: if (argv[i][0] == '-') /* option */ 85: { 86: switch (argv[i][1]) 87: { 88: case 's': /* sequencer */ 89: case 'x': /* extended sequencer */ 90: case 'i': /* index sequencer */ 91: case 'n': /* no sequencer */ 92: expand (argv[i]); /* change mode */ 93: break; 94: 95: case 't': /* term type */ 96: if (++i == argc) 97: { 98: fprintf (stderr, "-t must be followed by terminal type\n"); 99: exit (BAD); 100: } 101: histty = argv[i]; 102: break; 103: 104: case 'f': /* -f file option */ 105: if (++i == argc) /* see if there is one */ 106: { 107: fprintf (stderr, "-f must be followed by a file name\n"); 108: exit (BAD); 109: } 110: readrc (argv[i]); /* load the file */ 111: notesargs++; /* supplied args */ 112: break; 113: 114: case 'a': /* alternate sequencer */ 115: if (++i == argc) /* supplied name? */ 116: { 117: fprintf (stderr, "-a requires a name\n"); 118: exit (BAD); 119: } 120: else 121: { 122: struct auth_f whoami; 123: getname (&whoami, 0); /* grab real name */ 124: sprintf (Seqname, "%s:%s", whoami.aname, argv[i]); 125: } 126: break; 127: 128: case 'o': /* zero date */ 129: if (++i == argc) /* give a date? */ 130: { 131: fprintf (stderr, "-o requires a date\n"); 132: exit (BAD); 133: } 134: else 135: { 136: struct when_f ztime; 137: 138: switch (parsetime (argv[i], &ztime)) 139: { 140: case 0: /* ok */ 141: Basetime = ztime; /* store it */ 142: setseq (USERSEQ); /* readonly */ 143: break; 144: case -1: /* no good */ 145: fprintf (stderr, "%s: unable to parse time `%s'\n", 146: Invokedas, argv[i]); 147: exit (BAD); 148: case -2: /* in future */ 149: fprintf (stderr, "%s: parsed date (%s) is in the future\n", 150: Invokedas, argv[i]); 151: exit (BAD); 152: } 153: } 154: break; 155: 156: default: 157: fprintf (stderr, "Bad switch: `%c'\n", argv[i][1]); 158: } 159: } 160: else /* is a notesfile */ 161: { 162: expand (argv[i]); /* add it to list */ 163: notesargs++; /* supplied args */ 164: } 165: } 166: 167: /* 168: * now, check some things and let it fly 169: */ 170: 171: if (autoseq) /* grab sequencer */ 172: { 173: if ((q = getenv ("NFSEQ")) != NULL) /* grab NFSEQ */ 174: { 175: expand (q); 176: } 177: else 178: { 179: char rcbuf[WDLEN]; 180: sprintf (rcbuf, "%s/%s/%s", Mstdir, UTILITY, SEQFILE); 181: if (readrc (rcbuf) != 0) /* system list */ 182: expand (DFLTSEQ); /* give him default */ 183: } 184: } 185: 186: if (!autoseq && !notesargs) /* wants a list */ 187: { 188: usage (); 189: } 190: 191: intflag = 0; /* none yet */ 192: catchem (); /* catch interupts */ 193: ttystrt (); /* CBREAK mode */ 194: 195: nfsdone = 0; /* count groups */ 196: while ((nfptr = nextgroup ()) != (struct nflist_f *) NULL) 197: { 198: switch (control (nfptr -> nf_name, (int) nfptr -> nf_seqmode)) 199: { 200: case QUITFAST: /* leave now */ 201: case QUITUPD: /* likewise */ 202: goto leaving; 203: 204: case QUITBAD: /* err in name or nf */ 205: case QUITNEX: /* no nf there */ 206: case (-1): /* "normal" return */ 207: default: 208: break; 209: } 210: nfsdone++; /* count the ones done */ 211: } 212: if (nfsdone == 0) /* check if did any */ 213: { 214: ttystop (); /* turn it off */ 215: printf ("No notesfiles processed\n"); 216: fflush (stdout); 217: exit (GOOD); 218: } 219: 220: leaving: /* get out of here */ 221: at (0, 1); /* at bottom LHS */ 222: putc ('\n', stdout); 223: ttystop (); /* back to normal */ 224: exit (GOOD); 225: } 226: 227: /* 228: * tell him how to invoke the program 229: */ 230: 231: usage () 232: { 233: char cmdline[CMDLEN]; /* build a command */ 234: char *command; 235: fprintf (stderr, 236: "Usage: %s [-s] [-t ttytype] [-f file] [-a seqname] topic [...]\n", 237: Invokedas); 238: fprintf (stderr, "Hit <return> to continue\n"); /* ponder this */ 239: getc (stderr); /* thanks to harpo!ber 4/30/82 */ 240: if ((command = getenv ("PAGER")) == NULL) /* overridden? */ 241: command = PAGER; /* assign default */ 242: #ifndef FASTFORK 243: sprintf (cmdline, "%s < %s/%s/%s", command, Mstdir, UTILITY, AVAILHLP); 244: dounix (cmdline, 1, 0); /* print the list */ 245: #else 246: sprintf (cmdline, "%s/%s/%s", Mstdir, UTILITY, AVAILHLP); 247: dounix (1, 0, command, cmdline, 0, 0, 0); 248: #endif 249: exit (BAD); 250: }