home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Guide / c-cplusplus-interactive-guide.iso / c_ref / csource3 / 188_01 / hdrmsdos.c < prev    next >
Text File  |  1987-10-01  |  25KB  |  835 lines

  1. /* #include "bdscio.h"  */
  2.  
  3. /* in CI C86 need to compile this with the -u switch so that "char" is
  4.    treated as "unsigned char"
  5. */
  6.  
  7. #include "stdio.h"      /* CI C86 */
  8. #include "ctype.h"      /* CI C86 */
  9. #include "limits.h"     /* CI C86 */
  10. #include "setjmp.h"     /* CI C86 */
  11. #include "string.h"     /* CI C86 */
  12. #include "errno.h"      /* CI C86 */
  13. #include "stdlib.h"     /* CI C86 */
  14. #include "fileio2.h"    /* CI C86 */
  15. #undef  isspace         /* CI C86 */
  16. #define ERROR      0    /* CI C86 */
  17. #define OK        -1    /* CI C86 */
  18. #define FALSE      0    /* CI C86 */
  19. #define TRUE       1    /* CI C86 */
  20. char *ljust();          /* CI C86 */
  21. #define errmsg(num,str) printf("\n        Error %d: %s",(num),(str))/* CI C86 */
  22.  
  23.  
  24.  
  25. #define OPENCMNT   1
  26. #define HEADER     2
  27. #define ATTRIBUTE  3
  28. #define ENDCMNT    4
  29. #define TITLE      5
  30. #define VERSION    6
  31. #define DATE       7
  32. #define DESC       8
  33. #define KEYWD      9
  34. #define SYSTEM    10
  35. #define FNAME     11
  36. #define WARNING   12
  37. #define CRC       13
  38. #define ALSO      14
  39. #define AUTHOR    15
  40. #define COMP      16
  41. #define REF       17
  42. #define COMMA     18
  43. #define ENDREF    19
  44. #define REFAUTH   20
  45. #define REFTTL    21
  46. #define CITATION  22
  47. #define REFCIT    23
  48. #define COLON     24
  49. #define TOOLONG   25
  50. #define SEMI      26
  51. #define QUOTE     27
  52. #define FAULT     28
  53.  
  54. #define LEXSIZE 250
  55.  
  56. #define ON   1
  57. #define OFF  0
  58.  
  59. /* FILE source, list; */
  60. FILE *source, *list;     /* CI C86 */
  61.  
  62. /* char restart[6]; */
  63. jmp_buf *restart;        /* CI C86 */
  64. char catno[20];
  65. char lexval[LEXSIZE];
  66. int stoptoken;
  67. int debug, testonly;
  68. int parsing;
  69. int number;
  70.  
  71. main(argc,argv)
  72. int argc;
  73. char **argv;
  74.  
  75. {
  76. int fnumb, diskno;
  77. int i;
  78. char *lname;
  79. char *first;         /* CI C86 */
  80. char *next;          /* CI C86 */
  81. char filespec[255];  /* CI C86 */
  82. char *namestrt;      /* CI C86 */
  83. extern char *filedir(); /* CI C86 */
  84. extern char *upper();   /* CI C86 */
  85. extern unsigned char *strchr();  /* CI C86 */
  86. extern unsigned char *strrchr(); /* CI C86 */
  87.  
  88. /* if (wildexp(&argc,&argv) == ERROR)  / * CI C86 handles this differently * /
  89.    exit(puts("Wildexp Overflow\n"));    */
  90.  
  91. number = debug = testonly = OFF;
  92. fnumb = diskno = 0;
  93.  
  94. if (argc < 2) {
  95.     printf("USAGE:  header [-o<filespec>] [-t] [-d] [-nd] {<inpathspec>} \n\n"); /* CI C86 */
  96.     printf("   function:    Normally used to extract header information\n");
  97.     printf("                from the files in inpathspec, reformatting the\n");  /* CI C86 */
  98.     printf("                information in a fixed field format suitable\n");
  99.     printf("                for input to a relational database. The formatted\n");
  100.     printf("                output defaults to 'hdrout' on the current drive.\n\n");
  101.     printf("   options:     -o  use filespec for the list file name.\n");
  102.     printf("                -t  test only...checks syntax with no listing\n");
  103.     printf("                -n  number mode. Generates sequential file numbers\n");
  104.     printf("                    for all files on the disk. d is used as the\n");
  105.     printf("                    volume number. Headers consisting of only a \n");
  106.     printf("                    filename are generated for all files which don't\n");
  107.     printf("                    have a header. These are written to the list\n");
  108.     printf("                    file. Automatically sets -t, that is, since\n");
  109.     printf("                    the list file is being used to capture headers\n");
  110.     printf("                    no attempt is made to generate normal output.\n");
  111.     printf("                -d  debug...prints trace info to stdout.\n");
  112.     exit();
  113.     }
  114. lname="hdrout";
  115. for (i=1; i<argc; i++){
  116.    if (*argv[i] == '-'){
  117. /*    switch (*(argv[i]+1)){ */
  118.       switch (*upper(argv[i]+1)){                           /* CI C86 */
  119.          case 'D': debug = ON; break;
  120.          case 'T': testonly = ON; break;
  121.          case 'N': sscanf(argv[i]+2,"%d",&diskno);
  122.                    number = ON;
  123.                    testonly = ON;
  124.                    if (diskno < 100){
  125.                       printf("\nCUG numbers start at 100!\n");
  126.                       exit();
  127.                       }
  128.                    break;
  129.          case 'O': lname= argv[i]+2;
  130.                    break;
  131.          default:  printf("\nUnrecognized option %s",argv[i]);
  132.                    break;
  133.          }
  134.       }
  135.    if (debug) printf("\nargv[%d] = %s",i,argv[i]);   /* CI C86 */
  136.    }
  137.  
  138. if ((!testonly) || number) openlist(lname);
  139. if (debug) printf("\n open list passed");
  140.  
  141. for (i=1; i<argc; i++){
  142.    if (*argv[i] != '-'){
  143.  
  144.      strcpy(filespec,upper(argv[i]));                           /* CI C86 */
  145.      if (debug) printf("\nExpanding filespec %s",filespec);     /* CI C86 */
  146.      if ((namestrt = strrchr(filespec,'\\')) == NULL)           /* CI C86 */
  147.        if ((namestrt = strchr(filespec,':')) == NULL)           /* CI C86 */
  148.          namestrt = filespec - 1;                               /* CI C86 */
  149.      namestrt += 1;                                             /* CI C86 */
  150.      if ((first = filedir(filespec,0)) == NULL)                 /* CI C86 */
  151.        { printf("\nNo files match %s",filespec);                /* CI C86 */
  152.          continue; /* with next argv */                         /* CI C86 */
  153.        };                                                       /* CI C86 */
  154.      for (next = first; *next != NULL; next +=(strlen(next)+1)) /* CI C86 */
  155.       {                                                         /* CI C86 */
  156.        strcpy(namestrt,next); /* add name to drive:\path spec *//* CI C86 */
  157. /*     printf("\n%-15s",argv[i]);  */
  158.        printf("\n%s",filespec);                                 /* CI C86 */
  159. /*     if (fopen(argv[i],source) == ERROR) printf(" ...Can't open ");*/
  160.        if ((source=fopen(filespec,"r")) == NULL)                /* CI C86 */
  161.                                      printf(" ...Can't open "); /* CI C86 */
  162.  
  163.        else {
  164.           if (debug) {                                          /* CI C86 */
  165.              putchar('\n');                                     /* CI C86 */
  166.              for (debug=1;debug++ < 160;)                       /* CI C86 */
  167.                 printf("%c",getc(source));                      /* CI C86 */
  168.              rewind(source); debug=ON;                          /* CI C86 */
  169.              };                                                 /* CI C86 */
  170.           if (number) {
  171.              fnumb++;
  172. /*           if (dofile() == OK) numfile(argv[i], diskno, fnumb);*/
  173.              if (dofile() == OK) numfile(namestrt,diskno, \
  174.                                          fnumb,filespec);    /* CI C86 */
  175.              else {
  176.                 fclose(source);
  177.                 fprintf(list,"/* HEADER: CUG%03d.%02d; FILENAME: %s; */\n",
  178. /*                           diskno,fnumb,argv[i]); */
  179.                              diskno,fnumb,namestrt);         /* CI C86 */
  180.                 }
  181.              }
  182.           else {
  183.              dofile();
  184.              fclose(source);
  185.              }
  186.           }         /* of opening one source file */         /* CI C86 */
  187.        }            /* of expanding one filespec  */         /* CI C86 */
  188.        free(first);                                          /* CI C86 */
  189.      }              /* of *argv[i] != '-' */                 /* CI C86 */
  190.     }               /* of loop thru all argv[] values */     /* CI C86 */
  191.  
  192. if ((!testonly) || number){
  193.    fprintf(list,"%c",0x1a);
  194.    fflush(list);
  195.    fclose(list);
  196.    }
  197. }
  198.  
  199. /*
  200.    process a single file, adding results to output file
  201. */
  202. int dofile()
  203. {
  204. int att;
  205. int laterpass;
  206.  
  207. parsing = FAULT;
  208. laterpass = setjmp(restart);
  209. if (laterpass) return OK;
  210.  
  211. if (scantoken() != OPENCMNT) {
  212.    printf(" ...File doesn't begin with comment");
  213.    return !OK;
  214.    }
  215. if (scantoken() != HEADER) {
  216.    printf(" ...First comment isn't header ");
  217.    return !OK;
  218.    }
  219. printf(" ...Processing header");
  220. if (scantoken() != COLON) {
  221.    printf(" ...No colon after header keywork");
  222.    return !OK;
  223.    }
  224. scancatno(); /* sets catno as sidee