home *** CD-ROM | disk | FTP | other *** search
- From: erc@khijol.UUCP (Ed Carp, aka Mr. Ed the talking horse...)
- Newsgroups: alt.sources
- Subject: BSD fmt(1) for SYSV/XENIX
- Message-ID: <1418@khijol.UUCP>
- Date: 27 Mar 90 07:15:33 GMT
-
-
- /*
- *
- * fmt - run through nroff with .br, .sp, and .na on, then chop off the
- * excess fat. Quick and dirty BSD fmt(1) for SYSV/XENIX.
- *
- * This is useful for joining/splitting lines while in vi, especially if you
- * watch the keyboard, rather than the screen, while typing, and run off the
- * screen, then have to go back and split the lines by hand (what a pain!)
- *
- * usage: fmt [file]
- *
- * Warning: over-writes input file!
- *
- * Written 03/26/90 by Edwin R. Carp
- *
- * Copyright 1990, by Edwin R. Carp
- *
- * Permission is hereby granted to distribute this code freely, provided
- * that you don't sell it, try to make money off it, or pretend you
- * wrote it.
- *
- */
- #include <stdio.h>
- #define TMP "/tmp/fmt.%05d" /* temp file */
- /*
- * LEAVE is set up for elm, so it leaves alone included lines in a message.
- */
- #define LEAVE '>' /* if lines begin with this character, leave alone */
- main(argc, argv)
- int argc;
- char **argv;
- {
- FILE *in, *tmp;
- char line[1024];
- char tmpfile[20];
- int len;
-
- if(argc < 2) in = stdin;
- else
- {
- if((in=fopen(argv[1], "r")) == (FILE *)NULL)
- {
- perror(argv[1]);
- exit(1);
- }
- }
- sprintf(tmpfile, TMP, getpid());
- if((tmp=fopen(tmpfile, "w")) == (FILE *)NULL)
- {
- perror(tmpfile);
- exit(1);
- }
- fprintf(tmp, ".ll 7.8i\n.nr PO 0\n.pl 1\n.na\n.hy 14\n");
- while(fgets(line, 1022, in) != (char *)NULL)
- {
- len = strlen(line);
- line[len-1] = NULL;
- len--;
- if(len == 0)
- {
- fprintf(tmp, ".br\n.sp\n");
- continue;
- }
- if(*line == LEAVE) /* leave line alone */
- {
- fprintf(tmp, "%s\n.br\n", line);
- continue;
- }
- fprintf(tmp, "%s\n", line);
- }
- fclose(tmp);
- fclose(in);
- sprintf(line, "nroff %s > %s", tmpfile, argv[1]);
- system(line);
- unlink(tmpfile);
- }
- --
- Ed Carp - N7EKG/5 (512) 832-5884 uunet!cs.utexas.edu!khijol!erc
-
- "The fool thinks he is wise. The true wise man knows better. I am a fool."
-