|
|
1.1 ! root 1: /* library:option3.c 1.10 */ ! 2: #include "sccsid.h" ! 3: VERSION(@(#)library:option3.c 1.10) ! 4: ! 5: /****************** option3.c *****************************/ ! 6: ! 7: /* This routine accepts bulletin subscriptions. ! 8: * ! 9: */ ! 10: ! 11: #include <stdio.h> ! 12: #include <ctype.h> ! 13: #include <signal.h> ! 14: ! 15: option3(logfile, argc, argv) ! 16: FILE *logfile; ! 17: int argc; ! 18: char *argv[]; ! 19: { ! 20: int firsttime = 1; /* initialize to indicate first time through */ ! 21: int i, numreq=0; ! 22: long day; ! 23: char *dateptr, *ctime(), *ptr; ! 24: char instr[512], response[5000], *strchr(); ! 25: FILE *helpfile, *sendfile, *popen(); ! 26: extern char *Cmd, *whereto, libcntl[], pan[], req_name[]; ! 27: ! 28: /* get the date - note used only in the log */ ! 29: time(&day); ! 30: dateptr = ctime(&day); ! 31: ! 32: while (1) { /* continue until user is done */ ! 33: if (!argc) { ! 34: if (firsttime) { ! 35: printf("Enter your subscriptions in the form:\n (un)subscribe to <bulletin name>\n"); ! 36: firsttime = 0; ! 37: } ! 38: /* get the subscription */ ! 39: printf("Enter subscription"); ! 40: printf(" (exit with a period):"); ! 41: if (fgets(instr, 512, stdin) == NULL) break; ! 42: if (*instr == '.') break; ! 43: if ((ptr = strchr(instr, '\n')) != NULL) *ptr = '\0'; ! 44: } ! 45: /* special handling in the case of parameters passed */ ! 46: else { ! 47: *instr = '\0'; ! 48: for (i=0; i<argc; i++) { ! 49: if (*instr) strcat(instr, " "); ! 50: strcat(instr, argv[i]); ! 51: } ! 52: } ! 53: uppercase(instr); ! 54: /* check for help request */ ! 55: if ((*instr == '?') || (*instr == 'H')) { ! 56: sprintf(instr, "%s/option3.help", WHERE); ! 57: if ((helpfile = fopen(instr, "r")) == NULL) { ! 58: printf("Sorry. Help statement unavailable!\n"); ! 59: continue; ! 60: } ! 61: while (fgets(instr, 250, helpfile) != NULL) ! 62: fputs(instr, stdout); ! 63: fclose(helpfile); ! 64: if (argc) break; ! 65: continue; ! 66: } ! 67: if (strlen(instr) > 0) { ! 68: if ((strncmp(instr, "UNSUB", 5) != 0) && (strncmp(instr, "SUB", 3) != 0) ) { ! 69: printf("Illegal entry - a subscription or unsubscription is required.\n"); ! 70: firsttime=1; ! 71: if (argc) break; ! 72: continue; ! 73: } ! 74: strcat(response, instr); ! 75: strcat(response, "\n"); ! 76: numreq++; ! 77: } ! 78: ! 79: if (argc) break; ! 80: } /* end of subscription getting loop */ ! 81: ! 82: if (!numreq) { ! 83: printf("No subscription entered!\n"); ! 84: return; ! 85: } ! 86: /* output the record */ ! 87: signal(SIGINT, SIG_IGN); ! 88: #ifdef MSDOS ! 89: if ((sendfile = fopen("\\pipe.tmp", "w")) == NULL) { ! 90: #else ! 91: sprintf(instr, "%s %s", Cmd, whereto); ! 92: if ((sendfile = popen(instr, "w")) == NULL) { ! 93: #endif ! 94: fprintf(stderr, "Couldn't open mail pipe to send requests! No requests sent\n"); ! 95: exit(1); ! 96: } ! 97: fprintf(sendfile, "* *#SUB-%s\n%s\n%s\n**-**\n", libcntl, pan, req_name); ! 98: fputs(response, sendfile); ! 99: #ifdef MSDOS ! 100: fclose(sendfile); ! 101: sprintf(instr, "%s -f \\pipe.tmp -slibRequest %s", Cmd, whereto); ! 102: system(instr); ! 103: unlink("\\pipe.tmp"); ! 104: #else ! 105: pclose(sendfile); ! 106: #endif ! 107: if (logfile != NULL) { ! 108: fprintf(logfile, "From %s %sSubject: Subscription request\n", ! 109: req_name, dateptr); ! 110: fputs(response, logfile); ! 111: fputc('\n', logfile); ! 112: fclose(logfile); ! 113: } ! 114: fprintf(stdout, "Your %d subscription requests have been sent\n", numreq); ! 115: return; ! 116: } ! 117:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.