/* Program: FIX Author : Kim Moser Date : 13 April, 1991 System : IBM PC / Borland Turbo C 2.0 Descrip: Given a file, removes unalphabetized lines Usage : */ #include #include #include static FILE *DUPFILE; #if 0 void lookfor(char *s, long ofs); void lookfor(char *s, long ofs) { long hold = ftell(stdin); long k; static char buf[100]; fprintf(stderr, "Word '%s' is out of order...\n", s); if (hold == -1L) { fprintf(stderr, "ftell() failed.\n"); exit(-1); } rewind(stdin); while (1) { if (gets(buf) == NULL) { fprintf(stderr, "gets() failed.\n"); exit(-1); } k = ftell(stdin); if (!strcmp(buf, s)) { break; } } if (k >= ofs) { fprintf(stderr, "Word '%s' out of order but found only once.\n", buf); exit(-1); } if (fseek(stdin, hold, SEEK_SET)) { fprintf(stderr, "fseek() failed.\n"); exit(-1); } } #endif void usage(void); void usage(void) { fprintf(stderr, "usage: FIX dupefilename\n"); fprintf(stderr, "pipes stdin to stdout, sending duplicate words to dupefile.\n"); exit(-1); } void main(int argc, char **argv) { char s[512], old[sizeof(s)]; if (argc == 1) usage(); if ((DUPFILE = fopen(argv[1], "w")) == NULL) { fprintf(stderr, "fopen() failed for dupe file '%s'.\n", argv[1]); exit(-1); } s[0] = old[0] = '\0'; while (gets(s) != NULL) { if (strcmp(old, s) >= 0 && (old[0])) { /* Word 's' is out of order */ fprintf(DUPFILE, "%s\n", s); strncpy(s, old, sizeof(s)); } else { /* Word 's' is in order */ printf("%s\n", s); strncpy(old, s, sizeof(old)); } } if (fclose(DUPFILE)) { fprintf(stderr, "fclose() failed for dupe file '%s'.\n", argv[1]); } }