Annotation of researchv10no/cmd/books.c, revision 1.1.1.1

1.1       root        1: #include <stdio.h>
                      2: #include <signal.h>
                      3: #include <time.h>
                      4: 
                      5: inter()
                      6: {
                      7:        printf("interrupted - no orders sent\n");
                      8:        exit(0);
                      9: }
                     10: 
                     11: struct Data {
                     12:        char *prompt;
                     13:        char store[512];
                     14: } data[] = {
                     15:        { "Book title", "" },
                     16:        { "Author(s)",  "" },
                     17:        { "Publisher", "" },
                     18:        { "Publication Date", "" },
                     19:        { "ISBN",       "" },
                     20:        { "Other info (e.g. volume,edition,paperback)", "" },
                     21:        { "Estimated price",    "" },
                     22:        { "Number of copies",   "" },
                     23:        { 0, 0 }
                     24: };
                     25: 
                     26: main(argc, argv)
                     27:        char *argv[];
                     28: {
                     29:        int i, cnt=0; char More[8];
                     30:        FILE *fd, *fdtmp;
                     31:        char Tmp[L_tmpnam], User[64], Log1[512], Log2[512], Sharon[512];
                     32:        long clock = time(0L);
                     33:        struct tm *tm = localtime(&clock);
                     34: 
                     35:        signal(SIGINT, inter);
                     36:        printf("1127 - Fast(er) Book Ordering System\n");
                     37:        printf("====================================\n");
                     38:        fflush(stdout);
                     39: 
                     40:        if ((fd = fopen("/lib/book_orders", "a")) == NULL)
                     41:        {       printf("error: cannot open /lib/book_orders\n");
                     42:                exit(1);
                     43:        }
                     44:        tmpnam(Tmp);
                     45:        if ((fdtmp = fopen(Tmp, "w")) == NULL)
                     46:        {       printf("error: cannot create temporary file\n");
                     47:                exit(1);
                     48:        }
                     49: 
                     50:        getlogname(User);
                     51:        sprintf(Log1, "Book Order by %s, %s", User, asctime(tm));
                     52: 
                     53: again: cnt++;
                     54:        for (i = 0; data[i].prompt; i++)
                     55:        {       printf("%s: ", data[i].prompt);
                     56:                fflush(stdout);
                     57:                fgets(data[i].store, 510, stdin);
                     58:        }
                     59:        fprintf(fdtmp, "\n%s", Log1);
                     60:        fprintf(fdtmp, "================================================\n");
                     61:        fprintf(fd, "%s", data[0].store); fflush(fd);
                     62: 
                     63:        for (i = 0; data[i].prompt; i++)
                     64:        {       fprintf(fdtmp, "%s: %s", data[i].prompt, data[i].store);
                     65:                memset(data[i].store, 0, 512);
                     66:        }
                     67:        fprintf(fdtmp, "      ==forwarded to [email protected]==        \n");
                     68:        fflush(fdtmp);
                     69: 
                     70:        printf("More (y/n)? ");
                     71:        fflush(stdout);
                     72:        fgets(More, 6, stdin);
                     73:        if (strcmp(More, "y\n") == 0)
                     74:                goto again;
                     75: 
                     76:        sprintf(Log2, "%d x %s", cnt, Log1);
                     77:        fprintf(fd, "%s", Log2); fflush(fd);
                     78:        fclose(fd);
                     79:        sprintf(Sharon, "/bin/mail %s sharon [email protected] < %s; rm -f %s",
                     80:                User, Tmp, Tmp);
                     81:        if (system(Sharon) == 127)
                     82:        {       printf("error on logfile - mail sharon\n");
                     83:                exit(1);
                     84:        }
                     85:        printf("\n%d order%s sent\n", cnt, (cnt>1)?"s":"");
                     86: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.