home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / GAMES / colossal.lzh / advent0.c < prev    next >
C/C++ Source or Header  |  1991-11-03  |  4KB  |  179 lines

  1.  
  2. /*    ADVENT0.C                    
  3. *
  4. *    execution will read the four adventure text files    
  5. *    files; "advent1.txt", "advent2.txt", "advent3.txt" &    
  6. *    "advent4.txt".  it will create the file "advtext.h"    
  7. *    which is an Index Sequential Access Method (ISAM)    
  8. *    header to be #included into "advent.c" before the    
  9. *    header "advdef.h" is #included.                
  10. *
  11. *    Help option added by M.Gregorie as part of the port to
  12. *    OS9/68K. ltoa() calls modified to match Borland C function
  13. *    definition.
  14. *
  15. */
  16.  
  17.  
  18. #include    <stdio.h>
  19. #include    "advent.h"
  20.  
  21. extern    int    fclose();
  22. extern    char    *fgets();
  23. extern    FILE    *fopen();
  24. extern    int    fprintf();
  25. extern    int    fputs();
  26. extern    long    ftell();
  27. extern    int    printf();
  28.  
  29.  
  30. main(argc, argv)
  31. int    argc;
  32. char    **argv;
  33. {
  34.  
  35.     FILE    *isam, *fd1, *fd2, *fd3, *fd4;
  36.     char    itxt[255], otxt[80], lstr[12];
  37.     int        cnt, llen,i;
  38.     
  39.     void showhelp();
  40.     
  41.     if (argc > 1)
  42.     {
  43.         for (i = 1; i < argc; i++)
  44.             if (argv[i][0] == '-' || argv[i][0] == '/')
  45.                 if (argv[i][1] == '?')
  46.                 {
  47.                     showhelp();
  48.                     exit(0);
  49.                 }
  50.     }
  51.  
  52.     isam = fopen("advtext.h", TEXTWRITE);
  53.     if (!isam) {
  54.         printf("Sorry, I can't open advtext.h...\n");
  55.         exit(0);
  56.     }
  57.     fd1 = fopen("advent1.txt", TEXTREAD);
  58.     if (!fd1) {
  59.         printf("Sorry, I can't open advent1.txt...\n");
  60.         exit(0);
  61.     }
  62.     fd2 = fopen("advent2.txt", TEXTREAD);
  63.     if (!fd2) {
  64.         printf("Sorry, I can't open advent2.txt...\n");
  65.         exit(0);
  66.     }
  67.     fd3 = fopen("advent3.txt", TEXTREAD);
  68.     if (!fd3) {
  69.         printf("Sorry, I can't open advent3.txt...\n");
  70.         exit(0);
  71.     }
  72.     fd4 = fopen("advent4.txt", TEXTREAD);
  73.     if (!fd4) {
  74.         printf("Sorry, I can't open advent4.txt...\n");
  75.         exit(0);
  76.     }
  77.  
  78.     fprintf(isam, "\n/");
  79.     fprintf(isam, "*\theader: ADVTEXT.H\t\t\t\t\t*/\n\n\n");
  80.  
  81.  
  82.     cnt = -1;
  83.     lstr[0] = '\0';
  84.     fprintf(isam, "long\tidx1[MAXLOC] = {\n\t");
  85.     while (fgets(itxt, 255, fd1)) {
  86.         printf("%s", itxt);
  87.         if (itxt[0] == '#') {
  88.             if (lstr[0])
  89.                 fprintf(isam, "%s,", lstr);
  90.             llen = ltoa(ftell(fd1), lstr, 10);
  91.             if (!llen) {
  92.                 printf("ltoa err in advent1.txt\n");
  93.                 exit(0);
  94.             }            /* if (!llen)    */
  95.             if (++cnt == 5) {
  96.                 fprintf(isam, "\n\t");
  97.                 cnt = 0;
  98.             }            /* if (cnt)    */
  99.         }                /* if (itxt[0])    */
  100.     }                    /* while fgets    */
  101.     fprintf(isam, "%s\n\t};\n\n", lstr);
  102.  
  103.     cnt = -1;
  104.     lstr[0] = '\0';
  105.     fprintf(isam, "long\tidx2[MAXLOC] = {\n\t");
  106.     while (fgets(itxt, 255, fd2)) {
  107.         printf("%s", itxt);
  108.         if (itxt[0] == '#') {
  109.             if (lstr[0])
  110.                 fprintf(isam, "%s,", lstr);
  111.             llen = ltoa(ftell(fd2), lstr, 10);
  112.             if (!llen) {
  113.                 printf("ltoa err in advent2.txt\n");
  114.                 exit(0);
  115.             }            /* if (!llen)    */
  116.             if (++cnt == 5) {
  117.                 fprintf(isam, "\n\t");
  118.                 cnt = 0;
  119.             }            /* if (cnt)    */
  120.         }                /* if (itxt[0])    */
  121.     }                    /* while fgets    */
  122.     fprintf(isam, "%s\n\t};\n\n", lstr);
  123.  
  124.     cnt = -1;
  125.     lstr[0] = '\0';
  126.     fprintf(isam, "long\tidx3[MAXOBJ] = {\n\t");
  127.     while (fgets(itxt, 255, fd3)) {
  128.         printf("%s", itxt);
  129.         if (itxt[0] == '#') {
  130.             if (lstr[0])
  131.                 fprintf(isam, "%s,", lstr);
  132.             llen = ltoa(ftell(fd3), lstr, 10);
  133.             if (!llen) {
  134.                 printf("ltoa err in advent3.txt\n");
  135.                 exit(0);
  136.             }            /* if (!llen)    */
  137.             if (++cnt == 5) {
  138.                 fprintf(isam, "\n\t");
  139.                 cnt = 0;
  140.             }            /* if (cnt)    */
  141.         }                /* if (itxt[0])    */
  142.     }                    /* while fgets    */
  143.     fprintf(isam, "%s\n\t};\n\n", lstr);
  144.  
  145.     cnt = -1;
  146.     lstr[0] = '\0';
  147.     fprintf(isam, "long\tidx4[MAXMSG] = {\n\t");
  148.     while (fgets(itxt, 255, fd4)) {
  149.         printf("%s", itxt);
  150.         if (itxt[0] == '#') {
  151.             if (lstr[0])
  152.                 fprintf(isam, "%s,", lstr);
  153.             llen = ltoa(ftell(fd4), lstr, 10);
  154.             if (!llen) {
  155.                 printf("ltoa err in advent4.txt\n");
  156.                 exit(0);
  157.             }            /* if (!llen)    */
  158.             if (++cnt == 5) {
  159.                 fprintf(isam, "\n\t");
  160.                 cnt = 0;
  161.             }            /* if (cnt)    */
  162.         }                /* if (itxt[0])    */
  163.     }                    /* while fgets    */
  164.     fprintf(isam, "%s\n\t};\n\n", lstr);
  165.  
  166.  
  167. }                        /* main        */
  168.  
  169.  
  170. void showhelp()
  171. {
  172.     printf("\nSyntax  : advent0\n");
  173.     printf("Function: Generate the Adventure system advtext.h header\n");
  174.     printf("          file from the text files advent1.txt .. advent4.txt\n");
  175.     printf("          These files must be in the current directory when\n");
  176.     printf("          advent0 is run.\n");
  177.     printf("Options:  none\n");
  178. }
  179.