int main(void) { char code[MAX_LENGTH]; /* Buffer that stores the inputted code */ char stripped[MAX_LENGTH]; while( fgets(code,sizeof(code),stdin) ) { //printf("%s\n",code); // //strip comments... stripcomments(stripped,code); if( strlen(stripped) > 0 ) printf("%s",stripped); } }
void parse_module() { static int havecomment = 0; static int havekeyword = 0; static int valid_entry = 0; static char cmdline[256]; static char *cp,*sp; static int n,code; /* Structure list to hold entry table to allow for dynamic allocation of entry table space. */ struct table_point *tempentry; n = 0; open_modulefiles(); /* Go into loop to search for keywords and then fill in the appropriate information given by those keywords. */ /* NOTE: havekeyword || is used to be able to bypass string reads if exiting from EXPORT section due to a left-justified *ALPHABETIC* character. */ /* NOTE: Left-justified *ALPHABETIC* character supposed to always cause keyword lookup and break from whatever mode (i.e. EXPORT). */ while (havekeyword || (cp = get_string(cmdline,256))) { havekeyword=0; /* Reset havekeyword. */ sp = (char *)parse(cp,KEEP); if(sp == NULL) continue; code = 0; for(n=0;ModDefTable[n].command;n++) if(strcasecmp(ModDefTable[n].command,sp) == 0) { code = ModDefTable[n].code; break; } if(code) { switch(code) { /* Fill in module name. */ case MD_NAME: sp = parse(CURRENT,DUMP); if(sp && strlen(sp)) modulename = strdup(sp); break; case MD_LIB: n = 0; IsLibrary++; sp = parse(CURRENT,DUMP); if(sp && strlen(sp)) modulename = strdup(sp); break; /* Fill in library description. */ case MD_DESC: n = 0; /* get the whole string... */ sp = parse(CURRENT,DUMP); if(sp && strlen(sp)) { if(*sp == '\'') { sp++; cp = (char *) strrchr(sp,'\''); if(cp) *cp = 0; } if(description) WARNING(("Overriding module description string (was %s, now %s)",sp,description)); else description = (char *) strdup(sp); break; } break; /* ideally make this like exports... */ case MD_SEGMENTS: bSegmentTable = 1; break; case MD_RESOURCE: bResourceOnly = 1; sp = parse(CURRENT,DUMP); if(sp && strlen(sp)) strcpy(tbl_name,sp); break; /* Start parsing EXPORT section. */ case MD_EXP: max = 0; while ((cp = get_string(cmdline,256))) { if(leftjustify(cmdline)) { havekeyword=1; break; } valid_entry = 1; havecomment = 0; sp = parse(cmdline,KEEP); cp = parse(CURRENT,DUMP); /* Take care of comments */ havecomment=stripcomments(sp); if(sp && *sp=='\000') valid_entry=0; /* Get entry point number. A no-number point gets NONUMBER value. */ if(cp && *cp == '@' && !havecomment) n = atoi(cp+1); else if(cp) n = NONUMBER; else valid_entry=0; if(valid_entry) { if(n > max) max = n; /* Increment entry point number count. */ currentnum++; /* Allocate space for another entry and fill in info. */ tempentry=(struct table_point *)malloc(sizeof(struct table_point)); tempentry->index=n; tempentry->name=(char *) strdup(sp); tempentry->next=entrytable; entrytable = tempentry; } } break; default: continue; } } } }
int main(int argc, char *argv[]) { char infilename[FILENAME_MAX], outfilename[FILENAME_MAX], bakfilename[FILENAME_MAX]; FILE *input, *output; int m, firstarg = 1; int backflag; /* whether had to rename in file */ char *s; if (argc < firstarg + 1) showusage(argc, argv); /* while (*argv[firstarg] == '-') */ while (firstarg < argc && *argv[firstarg] == '-') { if (strchr(argv[firstarg], '?') != NULL) showusage(argc, argv); if (strchr(argv[firstarg], 'v') != NULL) verboseflag = 1; if (strchr(argv[firstarg], 't') != NULL) traceflag = 1; if (strchr(argv[firstarg], 'l') != NULL) linestrip = 1; if (strchr(argv[firstarg], 'i') != NULL) inlineflag = 1; if (strchr(argv[firstarg], 'p') != NULL) commentflag = 1; if (strchr(argv[firstarg], 'r') != NULL) stripcontrolm = 1; if (strchr(argv[firstarg], 'c') != NULL) checkcontrol = 1; if (strchr(argv[firstarg], 'f') != NULL) deleteback = 1; if (strchr(argv[firstarg], 'd') != NULL) { firstarg++; destination = argv[firstarg]; } firstarg++; } for (m = firstarg; m < argc; m++) { backflag=0; linestripped=0; inlinestrip=0; strcpy(infilename, argv[m]); if (strcmp(destination, "") != 0) { strcpy(outfilename, destination); strcat(outfilename, "\\"); strcat(outfilename, stripname(argv[m])); } else strcpy(outfilename, stripname(argv[m])); if (strcmp(infilename, outfilename) == 0) { strcpy (bakfilename, infilename); if ((s = strrchr(infilename, '.')) != NULL) { strcpy (s, ".bak"); remove (infilename); rename (bakfilename, infilename); backflag++; } } if (traceflag != 0) printf("Opening %s and %s\n", infilename, outfilename); if ((input = fopen(infilename, "r")) == NULL) { perror(infilename); exit(1); } if (stripcontrolm != 0) { if ((output = fopen(outfilename, "wb")) == NULL) { perror(outfilename); exit(1); } } else { if ((output = fopen(outfilename, "w")) == NULL) { perror(outfilename); exit(1); } } if (traceflag != 0) printf("Stripping %s\n", infilename); while (fgets(buffer, MAXLINE, input) != NULL) { if (stripcomments (buffer) == 0) { if (checkcontrol != 0) scancontrol(buffer); if (fputs(buffer, output) == EOF) { perror(outfilename); break; } } } if (traceflag != 0) printf("Closing %s and %s\n", infilename, outfilename); fclose(input); if (ferror(output) != 0) { perror(outfilename); exit(1); } else fclose(output); if (verboseflag != 0) { if (linestripped > 0 || inlinestrip > 0) { printf("Stripped "); if (linestripped > 0) printf("%d complete lines ", linestripped); if (inlinestrip > 0) printf("%d comments in lines ", inlinestrip); putc('\n', stdout); } } if (traceflag != 0) printf("Copying date and time\n"); if (getinfo(infilename, verboseflag) < 0) { exit(1); } timebuf.actime = statbuf.st_atime; timebuf.modtime = statbuf.st_atime; if (_utime(outfilename, &timebuf) != 0) { fprintf(stderr, "Unable to modify date/time\n"); perror(outfilename); /* exit(3); */ } /* see if it worked */ if (getinfo(outfilename, traceflag) < 0) exit(1); if (backflag != 0 && deleteback != 0) remove(infilename); } return 0; }