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