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 >
Wrap
Text File
|
1987-10-01
|
25KB
|
835 lines
/* #include "bdscio.h" */
/* in CI C86 need to compile this with the -u switch so that "char" is
treated as "unsigned char"
*/
#include "stdio.h" /* CI C86 */
#include "ctype.h" /* CI C86 */
#include "limits.h" /* CI C86 */
#include "setjmp.h" /* CI C86 */
#include "string.h" /* CI C86 */
#include "errno.h" /* CI C86 */
#include "stdlib.h" /* CI C86 */
#include "fileio2.h" /* CI C86 */
#undef isspace /* CI C86 */
#define ERROR 0 /* CI C86 */
#define OK -1 /* CI C86 */
#define FALSE 0 /* CI C86 */
#define TRUE 1 /* CI C86 */
char *ljust(); /* CI C86 */
#define errmsg(num,str) printf("\n Error %d: %s",(num),(str))/* CI C86 */
#define OPENCMNT 1
#define HEADER 2
#define ATTRIBUTE 3
#define ENDCMNT 4
#define TITLE 5
#define VERSION 6
#define DATE 7
#define DESC 8
#define KEYWD 9
#define SYSTEM 10
#define FNAME 11
#define WARNING 12
#define CRC 13
#define ALSO 14
#define AUTHOR 15
#define COMP 16
#define REF 17
#define COMMA 18
#define ENDREF 19
#define REFAUTH 20
#define REFTTL 21
#define CITATION 22
#define REFCIT 23
#define COLON 24
#define TOOLONG 25
#define SEMI 26
#define QUOTE 27
#define FAULT 28
#define LEXSIZE 250
#define ON 1
#define OFF 0
/* FILE source, list; */
FILE *source, *list; /* CI C86 */
/* char restart[6]; */
jmp_buf *restart; /* CI C86 */
char catno[20];
char lexval[LEXSIZE];
int stoptoken;
int debug, testonly;
int parsing;
int number;
main(argc,argv)
int argc;
char **argv;
{
int fnumb, diskno;
int i;
char *lname;
char *first; /* CI C86 */
char *next; /* CI C86 */
char filespec[255]; /* CI C86 */
char *namestrt; /* CI C86 */
extern char *filedir(); /* CI C86 */
extern char *upper(); /* CI C86 */
extern unsigned char *strchr(); /* CI C86 */
extern unsigned char *strrchr(); /* CI C86 */
/* if (wildexp(&argc,&argv) == ERROR) / * CI C86 handles this differently * /
exit(puts("Wildexp Overflow\n")); */
number = debug = testonly = OFF;
fnumb = diskno = 0;
if (argc < 2) {
printf("USAGE: header [-o<filespec>] [-t] [-d] [-nd] {<inpathspec>} \n\n"); /* CI C86 */
printf(" function: Normally used to extract header information\n");
printf(" from the files in inpathspec, reformatting the\n"); /* CI C86 */
printf(" information in a fixed field format suitable\n");
printf(" for input to a relational database. The formatted\n");
printf(" output defaults to 'hdrout' on the current drive.\n\n");
printf(" options: -o use filespec for the list file name.\n");
printf(" -t test only...checks syntax with no listing\n");
printf(" -n number mode. Generates sequential file numbers\n");
printf(" for all files on the disk. d is used as the\n");
printf(" volume number. Headers consisting of only a \n");
printf(" filename are generated for all files which don't\n");
printf(" have a header. These are written to the list\n");
printf(" file. Automatically sets -t, that is, since\n");
printf(" the list file is being used to capture headers\n");
printf(" no attempt is made to generate normal output.\n");
printf(" -d debug...prints trace info to stdout.\n");
exit();
}
lname="hdrout";
for (i=1; i<argc; i++){
if (*argv[i] == '-'){
/* switch (*(argv[i]+1)){ */
switch (*upper(argv[i]+1)){ /* CI C86 */
case 'D': debug = ON; break;
case 'T': testonly = ON; break;
case 'N': sscanf(argv[i]+2,"%d",&diskno);
number = ON;
testonly = ON;
if (diskno < 100){
printf("\nCUG numbers start at 100!\n");
exit();
}
break;
case 'O': lname= argv[i]+2;
break;
default: printf("\nUnrecognized option %s",argv[i]);
break;
}
}
if (debug) printf("\nargv[%d] = %s",i,argv[i]); /* CI C86 */
}
if ((!testonly) || number) openlist(lname);
if (debug) printf("\n open list passed");
for (i=1; i<argc; i++){
if (*argv[i] != '-'){
strcpy(filespec,upper(argv[i])); /* CI C86 */
if (debug) printf("\nExpanding filespec %s",filespec); /* CI C86 */
if ((namestrt = strrchr(filespec,'\\')) == NULL) /* CI C86 */
if ((namestrt = strchr(filespec,':')) == NULL) /* CI C86 */
namestrt = filespec - 1; /* CI C86 */
namestrt += 1; /* CI C86 */
if ((first = filedir(filespec,0)) == NULL) /* CI C86 */
{ printf("\nNo files match %s",filespec); /* CI C86 */
continue; /* with next argv */ /* CI C86 */
}; /* CI C86 */
for (next = first; *next != NULL; next +=(strlen(next)+1)) /* CI C86 */
{ /* CI C86 */
strcpy(namestrt,next); /* add name to drive:\path spec *//* CI C86 */
/* printf("\n%-15s",argv[i]); */
printf("\n%s",filespec); /* CI C86 */
/* if (fopen(argv[i],source) == ERROR) printf(" ...Can't open ");*/
if ((source=fopen(filespec,"r")) == NULL) /* CI C86 */
printf(" ...Can't open "); /* CI C86 */
else {
if (debug) { /* CI C86 */
putchar('\n'); /* CI C86 */
for (debug=1;debug++ < 160;) /* CI C86 */
printf("%c",getc(source)); /* CI C86 */
rewind(source); debug=ON; /* CI C86 */
}; /* CI C86 */
if (number) {
fnumb++;
/* if (dofile() == OK) numfile(argv[i], diskno, fnumb);*/
if (dofile() == OK) numfile(namestrt,diskno, \
fnumb,filespec); /* CI C86 */
else {
fclose(source);
fprintf(list,"/* HEADER: CUG%03d.%02d; FILENAME: %s; */\n",
/* diskno,fnumb,argv[i]); */
diskno,fnumb,namestrt); /* CI C86 */
}
}
else {
dofile();
fclose(source);
}
} /* of opening one source file */ /* CI C86 */
} /* of expanding one filespec */ /* CI C86 */
free(first); /* CI C86 */
} /* of *argv[i] != '-' */ /* CI C86 */
} /* of loop thru all argv[] values */ /* CI C86 */
if ((!testonly) || number){
fprintf(list,"%c",0x1a);
fflush(list);
fclose(list);
}
}
/*
process a single file, adding results to output file
*/
int dofile()
{
int att;
int laterpass;
parsing = FAULT;
laterpass = setjmp(restart);
if (laterpass) return OK;
if (scantoken() != OPENCMNT) {
printf(" ...File doesn't begin with comment");
return !OK;
}
if (scantoken() != HEADER) {
printf(" ...First comment isn't header ");
return !OK;
}
printf(" ...Processing header");
if (scantoken() != COLON) {
printf(" ...No colon after header keywork");
return !OK;
}
scancatno(); /* sets catno as sidee