|
|
1.1 ! root 1: /* library:option1.c 1.15 */ ! 2: #include "sccsid.h" ! 3: VERSION(@(#)library:option1.c 1.15) ! 4: ! 5: /****************** option1.c *****************************/ ! 6: ! 7: /* This routine accepts requests for documents known by number. ! 8: * This includes: ! 9: * TMs, SLs (and variants - GLs, ILs, etc), DLs, DSs, ! 10: * technical reports, ctp items. ! 11: * ! 12: * In addition it includes two special classes of items: ! 13: * ! 14: * Memos kept by date (or switching case numbers). For these this ! 15: * routine also prompts for the following info: ! 16: * title ! 17: * author: - this author is looked up for location of memos ! 18: * ! 19: * Table of content items known by short number which has the form ! 20: * <letter><3 digits><optional letter> ! 21: * ! 22: * For these this routine also prompts for a page number. ! 23: */ ! 24: ! 25: #include <stdio.h> ! 26: #include <ctype.h> ! 27: #include <signal.h> ! 28: char *malloc(), *realloc(); ! 29: ! 30: option1(logfile, argc, argv) ! 31: FILE *logfile; ! 32: int argc; ! 33: char *argv[]; ! 34: { ! 35: int i, numreq=0; ! 36: extern char *Cmd, *whereto, libcntl[], pan[], req_name[]; ! 37: long day, resp_size; ! 38: char instr[512], done_flag=0, parm_flag=0, err_flag=0, ! 39: *dateptr, *ctime(), multi_flag, itemline[1000]; ! 40: register char *ptr; ! 41: char docid[256], *strptr, *tptr, *strchr(); ! 42: char *response; /* this is the buffer where requests go */ ! 43: int can_remark; /* flag to say whether remarks with this request */ ! 44: char *endptr, *eptr; ! 45: FILE *fopen(), *helpfile, *popen(), *sendfile; ! 46: ! 47: /* get the date - note used only in the log */ ! 48: time(&day); ! 49: dateptr = ctime(&day); ! 50: /* get initial buffer for requests */ ! 51: resp_size = 5000; ! 52: if ((response = malloc(resp_size)) == NULL) { ! 53: fprintf(stderr, "library: Couldn't get space for request (%d). No requests sent!\n", resp_size); ! 54: exit(1); ! 55: } ! 56: *response = '\0'; ! 57: ! 58: /* special handling in the case of parameters passed */ ! 59: if (argc) { ! 60: parm_flag = 1; ! 61: *itemline = '\0'; ! 62: for (i=0; i<argc; i++) { ! 63: if (*itemline) strcat(itemline, " "); ! 64: strcat(itemline, argv[i]); ! 65: } ! 66: } ! 67: ! 68: eptr = response; ! 69: while (!done_flag) { /* loop until break when the user types . <return> */ ! 70: /* check if getting low on space */ ! 71: if ((resp_size - strlen(response)) < 500) { ! 72: resp_size += 5000; ! 73: ptr = response; ! 74: if ((response = realloc(response, resp_size)) == NULL) { ! 75: fprintf(stderr, "library: Couldn't get space for this much request (%d). No requests sent!\n", resp_size); ! 76: exit(1); ! 77: } ! 78: eptr += (response - ptr); ! 79: } ! 80: /* now ready to get document id */ ! 81: if (err_flag || !parm_flag) { ! 82: printf("\nEnter item identifier(s) (. to exit):"); ! 83: if (fgets(itemline, 1000, stdin) == NULL) break; ! 84: if (*itemline == '.') break; ! 85: if ((tptr = strchr(itemline, '\n')) != NULL) *tptr = '\0'; ! 86: if (!strcmp(itemline, "exit") || !strcmp(itemline, "quit")) break; ! 87: if (strlen(itemline) == 0) { ! 88: printf("Please enter IDs of items requested. ? for help.\n"); ! 89: continue; ! 90: } ! 91: } ! 92: if (*itemline == '~') { ! 93: fprintf(stderr, "Tilde escape do not work in option 1! Please reeenter requests\n"); ! 94: continue; ! 95: } ! 96: uppercase(itemline); ! 97: /* check if help is desired */ ! 98: if ((strlen(itemline) == 1) && ((*itemline=='?')||(*itemline=='H')) ) { ! 99: sprintf(itemline, "%s/known.list", WHERE); ! 100: if ((helpfile = fopen(itemline, "r")) == NULL) { ! 101: printf("Sorry. Help statement unavailable!\n"); ! 102: continue; ! 103: } ! 104: while (fgets(itemline, BUFSIZ, helpfile) != NULL) ! 105: if (*itemline == '?') printf("%s", itemline+1); ! 106: fclose(helpfile); ! 107: continue; ! 108: } ! 109: ! 110: /* remove trailing blanks */ ! 111: ptr = itemline + strlen(itemline) - 1; ! 112: while ( (*ptr == ' ') || (*ptr == '\t') ) ! 113: ptr--; ! 114: *++ptr = '\0'; ! 115: ! 116: /* now break apart the input string to get ids */ ! 117: strptr = itemline; ! 118: multi_flag = err_flag = 0; ! 119: while ((strptr != NULL) && (strlen(strptr) > 0) ) { ! 120: /* Find start of the string */ ! 121: ptr = strptr; ! 122: while (*ptr && (*ptr == ' ' || *ptr == '\t') ) ptr++; ! 123: if (*ptr == '\0') break; ! 124: ! 125: /* find the end of this id - can be tricky */ ! 126: endptr = strchr(ptr, ' '); ! 127: /* ptr is pointing to the id */ ! 128: if (endptr != NULL) ! 129: *endptr++ = '\0'; ! 130: strptr = endptr; ! 131: strcpy(docid, ptr); ! 132: ! 133: if (strlen(docid) > 70) { ! 134: printf("Document id %s too long. Reenter\n", docid); ! 135: err_flag = 1; ! 136: continue; ! 137: } ! 138: ! 139: /* we need to know if there is more than one i|em on this line */ ! 140: if ( (strptr != NULL) && (*strptr != '\0') ) multi_flag = 1; ! 141: ! 142: if ((can_remark = checkdoc(docid)) < 0) { ! 143: /* error in id */ ! 144: err_flag = 1; ! 145: printf("Incorrect id %s given\n", docid); ! 146: continue; ! 147: } ! 148: ! 149: /* Check in the logfile to see if this has been ordered */ ! 150: if (logfile != NULL) { ! 151: rewind(logfile); ! 152: i = strlen(docid); ! 153: while (fgets(eptr, 100, logfile) != NULL) ! 154: if (!strncmp(eptr, docid, i) && (*(eptr+i) == '\n')) { ! 155: /* Make sure pointer at end, for write later */ ! 156: fseek(logfile, 0L, 2); ! 157: printf("Document ID %s already exists in your log file.\n", docid); ! 158: printf("Do you wish to request it again (type y if yes): "); ! 159: if ((fgets(eptr, 100, stdin) == NULL) || ((*eptr != 'y') && (*eptr != 'Y')) ) ! 160: i = 0; ! 161: break; ! 162: } /* end deling with already ordered */ ! 163: if (!i) continue; /* i is flag, only reorder if set to 0 */ ! 164: } /* end of check in logfile */ ! 165: ! 166: sprintf(eptr, "**-**\n%s\n", docid); ! 167: eptr += strlen(eptr); ! 168: if (can_remark && !parm_flag && !multi_flag) { ! 169: printf("Enter any additional remarks. End with a blank line.\n*"); ! 170: while (strlen(fgets(eptr, 200, stdin)) > 1) { ! 171: if (*eptr == '.') { ! 172: *eptr = '\0'; ! 173: done_flag = 1; ! 174: break; ! 175: } ! 176: printf("*"); ! 177: eptr += strlen(eptr); ! 178: } ! 179: } /* end of remark getting */ ! 180: ! 181: /* if first put on header */ ! 182: numreq++; ! 183: } /* end of parts of entered string handling loop */ ! 184: if (parm_flag && !err_flag) break; ! 185: } /* end of main request getting loop */ ! 186: ! 187: /* output the record */ ! 188: signal(SIGINT, SIG_IGN); ! 189: if (numreq == 0) { ! 190: printf("No requests sent!\n"); ! 191: return; ! 192: } ! 193: #ifdef MSDOS ! 194: if ((sendfile = fopen("\\pipe.tmp", "w")) == NULL) { ! 195: #else ! 196: sprintf(instr, "%s %s", Cmd, whereto); ! 197: if ((sendfile = popen(instr, "w")) == NULL) { ! 198: #endif ! 199: fprintf(stderr, "Couldn't open mail pipe to send requests! No requests sent\n"); ! 200: exit(1); ! 201: } ! 202: fprintf(sendfile, "* *#KNOWN-%s\n%s\n%s\n", libcntl, pan, req_name); ! 203: fputs(response, sendfile); ! 204: #ifdef MSDOS ! 205: fclose(sendfile); ! 206: sprintf(instr, "%s -f \\pipe.tmp -slibRequest %s", Cmd, whereto); ! 207: system(instr); ! 208: unlink("\\pipe.tmp"); ! 209: #else ! 210: pclose(sendfile); ! 211: #endif ! 212: if (logfile != NULL) { ! 213: ptr = response; ! 214: while (ptr != NULL) { ! 215: ptr = strchr(ptr, '\n')+1; /* skip **-** line */ ! 216: if (strlen(ptr) < 5) break; ! 217: fprintf(logfile, "From %s %sSubject: option 1 request\n", ! 218: req_name, dateptr); ! 219: tptr = ptr; ! 220: while ((tptr = strchr(tptr, '\n')) != NULL) ! 221: if (strncmp(++tptr, "**-**", 5) == 0) break; ! 222: if (tptr != NULL) *tptr++ = '\0'; ! 223: fputs(ptr, logfile); ! 224: fputc('\n', logfile); ! 225: ptr = tptr; ! 226: } ! 227: fclose(logfile); ! 228: } ! 229: if (numreq == 1) ! 230: fprintf(stdout, "Your request has been sent\n"); ! 231: else ! 232: fprintf(stdout, "Your %d requests have been sent\n", numreq); ! 233: return; ! 234: } ! 235:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.