home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / OP2DEV.ZIP / ADVENT0.C < prev    next >
Text File  |  1990-05-10  |  3KB  |  143 lines

  1.  
  2. /*    program ADVENT0.C                    *\
  3. \*    execution will read the four adventure text files    *\
  4. \*    files; "advent1.txt", "advent2.txt", "advent3.txt" &    *\
  5. \*    "advent4.txt".  it will create the file "advtext.h"    *\
  6. \*    which is an Index Sequential Access Method (ISAM)    *\
  7. \*    header to be #included into "advent.c" before the    *\
  8. \*    header "advdef.h" is #included.                */
  9.  
  10. #define radix 10
  11. #include    <stdio.h>    /* drv = 1.1st file 2.def 3.A    */
  12. #include    <stdlib.h>
  13. #include    "advent.h"
  14.  
  15. main(argc, argv)
  16. int    argc;
  17. char    **argv;
  18. {
  19.  
  20.     FILE    *isam, *fd1, *fd2, *fd3, *fd4;
  21.     char    itxt[255], otxt[80], lstr[12];
  22.     int    cnt, llen;
  23.  
  24.     isam = fopen("advtext.h", "w");
  25.     if (!isam) {
  26.         printf("Sorry, I can't open advtext.h...\n");
  27.         exit(1);
  28.     }
  29.     fd1 = fopen("advent1.txt", "r");
  30.     if (!fd1) {
  31.         printf("Sorry, I can't open advent1.txt...\n");
  32.         exit(1);
  33.     }
  34.     fd2 = fopen("advent2.txt", "r");
  35.     if (!fd2) {
  36.         printf("Sorry, I can't open advent2.txt...\n");
  37.         exit(1);
  38.     }
  39.     fd3 = fopen("advent3.txt", "r");
  40.     if (!fd3) {
  41.         printf("Sorry, I can't open advent3.txt...\n");
  42.         exit(1);
  43.     }
  44.     fd4 = fopen("advent4.txt", "r");
  45.     if (!fd4) {
  46.         printf("Sorry, I can't open advent4.txt...\n");
  47.         exit(1);
  48.     }
  49.  
  50.     fprintf(isam, "\n/");
  51.     fprintf(isam, "*\theader: ADVTEXT.H\t\t\t\t\t*/\n\n\n");
  52.  
  53.  
  54.     cnt = -1;
  55.     lstr[0] = '\0';
  56.     fprintf(isam, "long\tidx1[MAXLOC] = {\n\t");
  57.     while (fgets(itxt, 255, fd1)) {
  58.         printf("%s", itxt);
  59.         if (itxt[0] == '#') {
  60.             if (lstr[0])
  61.                 fprintf(isam, "%s,", lstr);
  62.             llen = ltoa(ftell(fd1), lstr, radix);
  63.             if (!llen) {
  64.                 printf("ltoa err in advent1.txt\n");
  65.                 exit(1);
  66.             }            /* if (!llen)    */
  67.             if (++cnt == 5) {
  68.                 fprintf(isam, "\n\t");
  69.                 cnt = 0;
  70.             }            /* if (cnt)    */
  71.         }                /* if (itxt[0])    */
  72.     }                    /* while fgets    */
  73.     fprintf(isam, "%s\n\t};\n\n", lstr);
  74.  
  75.     cnt = -1;
  76.     lstr[0] = '\0';
  77.     fprintf(isam, "long\tidx2[MAXLOC] = {\n\t");
  78.     while (fgets(itxt, 255, fd2)) {
  79.         printf("%s", itxt);
  80.         if (itxt[0] == '#') {
  81.             if (lstr[0])
  82.                 fprintf(isam, "%s,", lstr);
  83.             llen = ltoa(ftell(fd2), lstr, radix);
  84.             if (!llen) {
  85.                 printf("ltoa err in advent2.txt\n");
  86.                 exit(1);
  87.             }            /* if (!llen)    */
  88.             if (++cnt == 5) {
  89.                 fprintf(isam, "\n\t");
  90.                 cnt = 0;
  91.             }            /* if (cnt)    */
  92.         }                /* if (itxt[0])    */
  93.     }                    /* while fgets    */
  94.     fprintf(isam, "%s\n\t};\n\n", lstr);
  95.  
  96.     cnt = -1;
  97.     lstr[0] = '\0';
  98.     fprintf(isam, "long\tidx3[MAXOBJ] = {\n\t");
  99.     while (fgets(itxt, 255, fd3)) {
  100.         printf("%s", itxt);
  101.         if (itxt[0] == '#') {
  102.             if (lstr[0])
  103.                 fprintf(isam, "%s,", lstr);
  104.             llen = ltoa(ftell(fd3), lstr, radix);
  105.             if (!llen) {
  106.                 printf("ltoa err in advent3.txt\n");
  107.                 exit(1);
  108.             }            /* if (!llen)    */
  109.             if (++cnt == 5) {
  110.                 fprintf(isam, "\n\t");
  111.                 cnt = 0;
  112.             }            /* if (cnt)    */
  113.         }                /* if (itxt[0])    */
  114.     }                    /* while fgets    */
  115.     fprintf(isam, "%s\n\t};\n\n", lstr);
  116.  
  117.     cnt = -1;
  118.     lstr[0] = '\0';
  119.     fprintf(isam, "long\tidx4[MAXMSG] = {\n\t");
  120.     while (fgets(itxt, 255, fd4)) {
  121.         printf("%s", itxt);
  122.         if (itxt[0] == '#') {
  123.             if (lstr[0])
  124.                 fprintf(isam, "%s,", lstr);
  125.             llen = ltoa(ftell(fd4), lstr, radix);
  126.             if (!llen) {
  127.                 printf("ltoa err in advent4.txt\n");
  128.                 exit(1);
  129.             }            /* if (!llen)    */
  130.             if (++cnt == 5) {
  131.                 fprintf(isam, "\n\t");
  132.                 cnt = 0;
  133.             }            /* if (cnt)    */
  134.         }                /* if (itxt[0])    */
  135.     }                    /* while fgets    */
  136.     fprintf(isam, "%s\n\t};\n\n", lstr);
  137.  
  138.     exit(0);
  139. }                        /* main        */
  140.  
  141.  
  142. 
  143.