home *** CD-ROM | disk | FTP | other *** search
- /*
- * tear - tear.c - 10/04/90 - Brendan Kehoe
- *
- * a replacement for the tear shell script & awk procedure
- */
-
- #include <stdio.h>
- #include <string.h>
-
- extern char *safemalloc(), *get_a_line();
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- register char *lp;
- register int curline;
- extern char *safemalloc(), *get_a_line();
- char *line, *hdr, *body;
- short inbody, doit;
- FILE *fin, *fout;
-
- line = safemalloc(1001);
- hdr = safemalloc(100);
- body = safemalloc(100);
-
- if (argc < 2)
- exit(1);
-
- if (argc == 2)
- fin = stdin;
- else if ((fin = fopen(*(argv+2),"r"))==(FILE *)NULL) {
- exit(1);
- }
-
- strcpy(hdr,*(argv+1));
- strcpy(body,*(argv+1));
- strcat(hdr,"hdr");
- strcat(body,"body");
- fout = fopen(hdr,"w");
-
- lp=line;
- inbody = doit = curline = 0;
- while (get_a_line(line,1000,fin)) {
- curline++;
- if (inbody == 0) {
- if ((*lp != ' ') && (*lp != '\t')) {
- if ((!strchr(lp,':'))||
- ((curline>1)&&(*lp == '\n')))
- doit = 1;
- }
- if (doit) {
- inbody = 1;
- fclose(fout);
- fout = fopen(body,"w");
- }
- }
- fputs(line,fout);
- }
- fclose(fout);
- fclose(fin);
- return(0); /* shut UP lint! */
- }
-