|
|
1.1 root 1: /* library:library.c 1.33 */
2: #include "sccsid.h"
3: VERSION(@(#)library:library.c 1.33)
4:
5: /****************** library.c *****************************/
6:
7: /* This routine accepts requests for any type of document
8: * for which center 7811 and associated networks are responsible.
9: *
10: * Presently accepts requests for:
11: * document stored at ITDS (e.g. TMs, MFs, SLs)
12: * Bulletin items
13: * books
14: * photo copies of items
15: * (un)subscribe to bulletins
16: */
17:
18: #include "gnamef.h"
19: #include <stdio.h>
20: #include <ctype.h>
21: #include <signal.h>
22: char *malloc(), *realloc();
23: #ifdef MSDOS
24: char *Cmd="sendfile";
25: #else
26: char *Cmd="/bin/mail ";
27: #endif
28: char *whereto="library!techlib";
29: int expert=0;
30: char libcntl[100], pan[15], req_name[80];
31: char libfile[120]; /* full path and name of .lib file */
32: char read_cntl[50]; /* User specified controls of reader function */
33: char *pager=NULL; /* Pager to use in reading full things in opt7 */
34: void showavail();
35:
36: static char *program="@(#) R Waldstein, Dept 78111, general purpose orderer";
37: static char *version="@(#) library, ordering program, version 3.6++";
38:
39: #if ( defined SVR4 ) || ( defined MSDOS )
40: void ordint(int junk)
41: #else
42: ordint()
43: #endif
44: {
45: printf("\nInterrupt! No requests sent\n");
46: exit(0);
47: }
48:
49: main(argc, argv)
50: int argc;
51: char *argv[];
52: {
53: int len, reqint(), what;
54: int got_name=0, got_id=0;
55: char instr[250], copy_str[250], *tptr, *chrptr, *homeptr;
56: char *getenv(), logf_name[120], *strchr(), *ptr, *libptr;
57: FILE *fopen(), *idfile, *tfile, *logfile, *helpfile;
58:
59: (void)signal(SIGINT, ordint);
60: if ((argc == 2) && !strcmp(argv[1], "-v")) {
61: printf("%s\n", version);
62: exit(0);
63: }
64:
65: /* if they want let them enter info via a an id file */
66: *pan = '\0';
67: *req_name = '\0';
68: *libcntl = '\0';
69: *read_cntl = *logf_name = '\0';
70: logfile = NULL;
71: libptr = getenv("LIBFILE");
72: homeptr = getenv("HOME");
73: #ifdef MSDOS
74: if (libptr == NULL)
75: strcpy(libfile, "c:/library/library.lib");
76: else {
77: #endif
78: if (libptr != NULL) {
79: if (*libptr == '/')
80: strcpy(libfile, libptr);
81: else {
82: strcpy(libfile, homeptr);
83: strcat(libfile, "/");
84: strcat(libfile, libptr);
85: }
86: }
87: else if (homeptr != NULL) {
88: strcpy(libfile, homeptr);
89: strcat(libfile, "/.lib");
90: }
91: else
92: strcpy(libfile, ".lib");
93: #ifdef MSDOS
94: }
95: #endif
96:
97: if ((idfile = fopen(libfile, "r")) == NULL) {
98: /* let them use the old .id file */
99: if ( homeptr != NULL) {
100: strcpy(instr, homeptr);
101: strcat(instr, "/.id");
102: }
103: else
104: strcpy(instr, ".id");
105: idfile = fopen(instr, "r");
106: if (idfile != NULL) strcpy(libfile, instr);
107: }
108:
109: if (idfile != NULL) {
110: while (fgets(instr, 250, idfile) != NULL) {
111: if ((tptr = strchr(instr, '\n')) != NULL) *tptr = '\0';
112: strcpy(copy_str, instr);
113: uppercase(instr);
114: if ((strncmp(instr, "NAME", 4) == 0) || (strncmp(instr, "LIBNAME", 7) == 0)) {
115: tptr = instr + ((*instr == 'L') ? 7 : 4);
116: while (!isalpha(*tptr) ) tptr++;
117: if (strlen(tptr) > 79) {
118: fprintf(stderr, "library: Name <%s> from file unacceptably long! Max is 79 characters!\n", tptr);
119: exit(1);
120: }
121: strcpy(req_name, tptr);
122: }
123: else if ((strncmp(instr, "PAN", 3) == 0) || (strncmp(instr, "ID", 2) == 0)) {
124: tptr = instr + ((*instr == 'P') ? 3 : 2);
125: while (!isalnum(*tptr)) tptr++;
126: if (strlen(tptr) > 14) {
127: fprintf(stderr, "library: ID <%s> from file unacceptably long! Max is 14 characters!\n", tptr);
128: exit(1);
129: }
130: strcpy(pan, tptr);
131: }
132: /* see if they want any libcntl info on the request */
133: else if ((strncmp(instr, "ITDSCNTL", 8) == 0) ||
134: (strncmp(instr, "CNTL", 4) == 0) || (strncmp(instr, "LIBCNTL", 7) == 0) ) {
135: tptr = instr + ((*instr == 'C') ? 4 : 7);
136: if (*instr == 'I') tptr++;
137: while (!isalnum(*tptr) ) tptr++;
138: strcpy(libcntl, tptr);
139: }
140: /* see if they want any special reader control */
141: else if (strncmp(instr, "READER", 6) == 0) {
142: tptr = instr + 6;
143: while (!isalpha(*tptr) ) tptr++;
144: strncpy(read_cntl, tptr, 50);
145: }
146: /* see if they want any local cntl info for the session */
147: else if (strncmp(instr, "LIBLOCAL", 8) == 0) {
148: tptr = instr + 8;
149: while (!isalpha(*tptr) ) tptr++;
150: if ( strchr(tptr, 'F') != NULL)
151: fprintf(stderr, "Sorry - ask for fiche no longer supported!\n");
152: if ( strchr(tptr, 'X') != NULL) expert = 1;
153: }
154: /* see if they want an itds log */
155: else if ((strncmp(instr, "ITDSLOG", 7) == 0) || (strncmp(instr, "LIBLOG", 6) == 0)) {
156: tptr = copy_str + ((*instr == 'L') ? 6 : 7);
157: while ((*tptr != '/') && (*tptr != '.') && !isalnum(*tptr) )
158: tptr++;
159: if (*tptr != '/') {
160: strcpy(logf_name, homeptr);
161: strcat(logf_name, "/");
162: }
163: strcat(logf_name, tptr);
164: }
165: else if (!strncmp(instr, "PAGER", 5)) {
166: tptr = copy_str + 5;
167: while (*tptr && !ispunct(*tptr)) tptr++;
168: if (*tptr) tptr++;
169: while (isspace(*tptr)) tptr++;
170: if (*tptr) {
171: if (*tptr == '"') {
172: tptr++;
173: ptr = tptr + strlen(tptr) - 1;
174: if (*ptr == '"') *ptr = '\0';
175: }
176: pager = malloc(strlen(tptr) + 1);
177: if (pager != NULL) strcpy(pager, tptr);
178: }
179: }
180: }
181: fclose(idfile);
182: }
183:
184: tptr = getenv("LIBNAME");
185: if (tptr != NULL) strcpy(req_name, tptr);
186: tptr = getenv("LIBID");
187: if (tptr != NULL) strcpy(pan, tptr);
188: tptr = getenv("LIBCNTL");
189: if (tptr != NULL) strcpy(libcntl, tptr);
190: tptr = getenv("LIBLOCAL");
191: if (tptr != NULL) {
192: if ( (strchr(tptr, 'f') != NULL) || (strchr(tptr, 'F') != NULL))
193: fprintf(stderr, "Sorry - ask for fiche no longer supported!\n");
194: if ( (strchr(tptr, 'x') != NULL) || (strchr(tptr, 'X') != NULL))
195: expert = 1;
196: }
197: /* see if they want a log kept */
198: tptr = getenv("LIBLOG");
199: if (tptr != NULL) {
200: *logf_name = '\0';
201: if (*tptr != '/') {
202: strcpy(logf_name, homeptr);
203: strcat(logf_name, "/");
204: }
205: strcat(logf_name, tptr);
206: }
207: if (*logf_name != '\0') {
208: /* careful about the \n on the end of the log file name */
209: tptr = logf_name + strlen(logf_name) - 1;
210: if (*tptr == '\n') *tptr = '\0';
211: /* open up the log file. Note done here to assure that we can */
212: if ( (logfile = fopen(logf_name, "a+")) == NULL) {
213: fprintf(stderr, "library: Problems opening log file %s\n", logf_name);
214: exit(1);
215: }
216: }
217: /* open a temp file for use for the requests */
218: if (*pan == '\0' || *req_name == '\0') {
219: printf("Welcome to the library network request service\n");
220: printf("Use . <period> to exit, break to quit without sending requests.\n");
221: }
222: idfile = stdin;
223: if (!isatty(fileno(stdin)) &&
224: ((*pan == '\0') || (*req_name == '\0') || (argc < 2))) {
225: idfile = fopen("/dev/tty", "r");
226: }
227: while (*pan == '\0') {
228: printf("\nEnter AT&T Identification Number (e.g. SS#): ");
229: fflush(stdout);
230: if (fgets(instr, 250, idfile) == NULL) {
231: fprintf(stderr, "Input ended?! Bye.\n");
232: exit(1);
233: }
234: if ((tptr = strchr(instr, '\n')) != NULL) *tptr = '\0';
235: len = strlen(instr);
236: if ((*instr == '.') || !len) exit(1);
237: if ((len<3) || (len > 14)) {
238: printf("ID must be 3 to 14 characters long. Reenter");
239: continue;
240: }
241: strcpy(pan,instr);
242: got_id = 1;
243: }
244:
245: while (*req_name == '\0') {
246: printf("Enter your last name (note LAST):");
247: fflush(stdout);
248: if (fgets(instr, 250, idfile) == NULL) {
249: fprintf(stderr, "Input ended?! Bye.\n");
250: exit(1);
251: }
252: if ((tptr = strchr(instr, '\n')) != NULL) *tptr = '\0';
253: if (*instr == '.') exit(1);
254: tptr = instr;
255: while (*tptr && !isalpha(*tptr) ) tptr++;
256: if ((strlen(tptr) >= 2) && (strlen(tptr) < 79))
257: strcpy(req_name, tptr);
258: else
259: printf("A name is required!. Reenter\n");
260: got_name = 1;
261: }
262:
263: /* Save it for them if new entry */
264: while (got_name || got_id) {
265: printf("Do you want this personnel data saved (in file $HOME/.lib). Enter y if yes: ");
266: fflush(stdout);
267: if (fgets(instr, 250, idfile) == NULL) {
268: fprintf(stderr, "Input ended?! Bye.\n");
269: exit(1);
270: }
271: if ((*instr == 'y') || (*instr == 'Y')) {
272: if ((tfile = fopen(libfile, "a")) != NULL) {
273: if (got_id)
274: fprintf(tfile, "id: %s\n", pan);
275: if (got_name)
276: fprintf(tfile, "name: %s\n", req_name);
277: fclose(tfile);
278: chmod(libfile, 0600);
279: }
280: break;
281: }
282: else if (*instr == '?') {
283: printf("\n\
284: This feature allows you to save the personnel information prompted\n\
285: for above in a file. This will mean that in the future the library\n\
286: command will not ask again for this information, it will get the\n\
287: information from the file \"%s\". Do NOT do this if other\n\
288: people use this login - their orders would be placed in your name.\n\
289: For further information about this feature, or other questions\n\
290: about the library command call 908 582-4840. THank you.\n\n", libfile);
291: }
292: else
293: break;
294: }
295:
296: /* first see if they passed a parm saying what they wanted */
297: argc--;
298: argv++;
299: if (argc > 0 && *argv[0] == '-') {
300: uppercase(argv[0]);
301: chrptr = argv[0] + 1;
302: if ((*chrptr == 'C') || (*chrptr == '4'))
303: what = 4;
304: else if ((*chrptr == 'K') || (*chrptr == '1'))
305: what = 1;
306: else if ((*chrptr == 'P') || (*chrptr == '2'))
307: what = 2;
308: else if ((*chrptr == 'S') || (*chrptr == '3'))
309: what = 3;
310: else if ((*chrptr == 'R') || (*chrptr == '5'))
311: what = 5;
312: else if ((*chrptr == 'I') || (*chrptr == '6'))
313: what = 6;
314: else if ((*chrptr == 'B') || (*chrptr == '7'))
315: what = 7;
316: else {
317: printf("Illegal parameter passed\n\tk (or 1) = order known item (by number)\n");
318: printf("\tp (or 2) = order unannounced items\n");
319: printf("\ts (or 3) = subscribe (or unsubscribe) to a bulletin\n");
320: printf("\tc (or 4) = AT&T Library Network database search\n");
321: printf("\tr (or 5) = request human assistance\n");
322: printf("\ti (or 6) = AT&T Library Network information/document\n");
323: printf("\tb (or 7) = Read AT&T Library Network Email transmissions\n");
324: exit(1);
325: }
326: argc--;
327: argv++;
328: } /* end of specified type as parameter */
329:
330: else { /* let them select what they want */
331: showlist:
332: printf("\n");
333: printf("1) Order by number - this includes nearly everything announced\n");
334: printf("\tby the AT&T Library Network (e.g. TMs, bulletin items) or handled\n");
335: printf("\tby the Engineering Information Services (e.g. J docs, CPSs).\n");
336: printf("\n");
337: printf("2) Order item not announced by the AT&T Library Network. Available:\n");
338: showavail("2.");
339: printf("\n");
340: printf("3) Subscribe or unsubscribe to a bulletin (e.g. Mercury, CTP)\n");
341: printf("\n");
342: printf("4) Submit a database search. Examples of available databases:\n");
343: printf("\tbook catalog, internal documents, AT&T personnel, released papers\n");
344: printf("\n");
345: printf("5) Request human assistance / interaction. Type(s) available:\n");
346: showavail("5.");
347: printf("\n");
348: printf("6) Request AT&T Library Network information/services. Examples:\n");
349: printf("\tLINUS info, products/services descriptions, loan/reserve status\n");
350: printf("\n");
351: printf("7) Read AT&T Library Network email transmissions\n");
352: printf("\n");
353:
354:
355: while (1) {
356: printf("Enter number from menu (? for help [? number for specific help]): ");
357: if (fgets(instr, 250, idfile) == NULL) exit(0);
358: if (*instr == 'v') {
359: printf("%s\n", version);
360: continue;
361: }
362: if ((*instr == '.') || (*instr == 'q')) exit(0);
363: ptr = instr;
364: what = atoi(ptr);
365: if (what < 0 || what > 7) {
366: fprintf(stderr, "Illegal option %d picked. Must be in range 1-6\n", what);
367: continue;
368: }
369: if (what) {
370: ptr++;
371: while (*ptr && (*ptr == ' ')) ptr++;
372: }
373: if ( (toupper(*ptr) == 'H') || (*ptr == '?') ) {
374: if (!what) {
375: ptr++;
376: while (*ptr && (*ptr == ' ')) ptr++;
377: what = atoi(ptr);
378: }
379: if ((what > 0) && (what < 8)) {
380: sprintf(instr, "%s/option%d.help", WHERE, what);
381: if (access(instr, 04) != 0)
382: sprintf(instr, "%s/help.option%d", WHERE, what);
383: }
384: else
385: sprintf(instr, "%s/library.help", WHERE);
386: if ((helpfile = fopen(instr, "r")) == NULL) {
387: printf("Sorry. Help statement unavailable!\n");
388: goto showlist;
389: }
390: while (fgets(instr, 250, helpfile) != NULL)
391: fputs(instr, stdout);
392: fclose(helpfile);
393: }
394: else if (!what)
395: fprintf(stderr, "Sorry - don't understand your input <%s>\n", instr);
396: else
397: break;
398: }
399: }
400:
401: switch (what) {
402: case 1: option1(logfile, argc, argv);
403: break;
404: case 2: /* Option 2 is a request for an item */
405: option2(logfile, argc, argv, 2);
406: break;
407: case 3: /* a bulletin subscription */
408: option3(logfile, argc, argv);
409: break;
410: case 4: /* a search of the book catalog */
411: option2(logfile, argc, argv, 4);
412: break;
413: case 5: /* option 5 is request for human assistance */
414: option2(logfile, argc, argv, 5);
415: break;
416: case 6: /* a document request */
417: option2(logfile, argc, argv, 6);
418: break;
419: case 7: /* read some bulletin stuff */
420: reader(logfile, argc, argv);
421: break;
422: default: /* error */
423: fprintf(stderr, "Program error. Please call it in\n");
424: exit(1);
425: }
426:
427: /* Just come back in case we need to clean up anything */
428: exit(0);
429: }
430:
431:
432: void showavail(str)
433: char *str;
434: {
435: int i, j;
436: char filename[60], instr[100], *tptr;
437: FILE *tfile;
438: DIR *tdir;
439:
440: printf("\t ");
441: /* use the file names - or W line in the library directory */
442: if ((tdir = opendir(WHERE)) == NULL) {
443: printf("No %s directory!!\n", WHERE);
444: return;
445: }
446: i = 0;
447: j = 9; /* j keeps track of number of characters out */
448: while (gnamef(tdir, filename) == TRUE) {
449: if (strncmp(filename, str, strlen(str)) == 0) {
450: /* check if they say special words what to call it */
451: sprintf(instr, "%s/%s", WHERE, filename);
452: if ((tfile = fopen(instr, "r")) == NULL) continue;
453: if (i++ != 0) printf("; ");
454: if (fgets(instr, 100, tfile) == NULL) {
455: fclose(tfile);
456: continue;
457: }
458: if (*instr == 'W') {
459: tptr = instr+1;
460: while ((*tptr == ' ') || (*tptr == '\t')) tptr++;
461: strcpy(instr, tptr);
462: tptr = instr;
463: while (*tptr && (*tptr != '\n')) tptr++;
464: if (*tptr) *tptr = '\0';
465: if (!strlen(instr)) strcpy(instr, filename+2);
466: }
467: else strcpy(instr, filename+2);
468: fclose(tfile);
469: if ((strlen(instr) + j) > 74) {
470: printf("\n\t ");
471: j = 9;
472: }
473: printf("%s", instr);
474: j += strlen(instr) + 2; /* the +2 counts the semicolon put on */
475: }
476: }
477: if (!i) printf("Nothing");
478: printf(".\n");
479: closedir(tdir);
480: return;
481: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.