static char rcsid[] = "$Id: asksam_listing_to_text.c,v 1.1 1992/11/13 18:30:04 putz Exp $"; /*************************************************************************** * asksam_listing_to_text.c - convert askSam text output to Unix text * Created by Steve Putz, Tue Sep 8 09:42:21 PDT 1992 *************************************************************************** This program cleans up the output resulting from using AskSam to write out a database as text (in "ASKSAM" mode -- i.e. with record separators). However It is much easier to use the asksam_to_text program instead, which will convert from the raw ".ask" file directly to Unix text, without needing to run AskSam at all. This version replaces 0377 with space, but does not do anything special with other non-printing characters. ***************************************************************************/ #include #define RECORDSEP "===DOCUMENT BOUNDARY===" main(argc,argv) int argc; char *argv[]; { register int ch, ncount; if (argc > 1 && strcmp(argv[1], "-")) { if ((freopen(argv[1], "r", stdin)) == NULL) { fprintf(stderr, "%s: unable to open %s\n", argv[0], argv[1]); exit(1); } } if (argc > 2 && strcmp(argv[2], "-")) { if ((freopen(argv[2], "w", stdout)) == NULL) { fprintf(stderr, "%s: unable to open %s\n", argv[0], argv[2]); exit(2); } } ncount = 0; ch = getchar(); while (ch != EOF) { if (ch == '\r') { ncount = 0; } else if (ch == 0) { ncount++; if (ncount == 1) putchar('\n'); if (ncount == 2) puts(RECORDSEP); } else if (ch == 0377) { putchar(' '); ncount = 0; } else { putchar(ch); ncount = 0; } ch = getchar(); } exit(0); } /* end main */ /***************************************************************************/