home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 1 / 1076 < prev    next >
Encoding:
Internet Message Format  |  1990-12-28  |  2.1 KB

  1. From: erc@khijol.UUCP (Ed Carp, aka Mr. Ed the talking horse...)
  2. Newsgroups: alt.sources
  3. Subject: BSD fmt(1) for SYSV/XENIX
  4. Message-ID: <1418@khijol.UUCP>
  5. Date: 27 Mar 90 07:15:33 GMT
  6.  
  7.  
  8. /*
  9. *
  10. * fmt - run through nroff with .br, .sp, and .na on, then chop off the
  11. * excess fat.  Quick and dirty BSD fmt(1) for SYSV/XENIX.
  12. *
  13. * This is useful for joining/splitting lines while in vi, especially if you
  14. * watch the keyboard, rather than the screen, while typing, and run off the
  15. * screen, then have to go back and split the lines by hand (what a pain!)
  16. *
  17. * usage:  fmt [file]
  18. *
  19. * Warning:  over-writes input file!
  20. *
  21. * Written 03/26/90 by Edwin R. Carp
  22. *
  23. * Copyright 1990, by Edwin R. Carp
  24. *
  25. * Permission is hereby granted to distribute this code freely, provided
  26. * that you don't sell it, try to make money off it, or pretend you
  27. * wrote it.
  28. *
  29. */
  30. #include <stdio.h>
  31. #define TMP "/tmp/fmt.%05d" /* temp file */
  32. /*
  33. * LEAVE is set up for elm, so it leaves alone included lines in a message.
  34. */
  35. #define LEAVE '>' /* if lines begin with this character, leave alone */
  36. main(argc, argv)
  37. int argc;
  38. char **argv;
  39. {
  40.    FILE *in, *tmp;
  41.    char line[1024];
  42.    char tmpfile[20];
  43.    int len;
  44.  
  45.    if(argc < 2) in = stdin;
  46.    else
  47.    {
  48.       if((in=fopen(argv[1], "r")) == (FILE *)NULL)
  49.       {
  50.          perror(argv[1]);
  51.          exit(1);
  52.       }
  53.    }
  54.    sprintf(tmpfile, TMP, getpid());
  55.    if((tmp=fopen(tmpfile, "w")) == (FILE *)NULL)
  56.    {
  57.       perror(tmpfile);
  58.       exit(1);
  59.    }
  60.    fprintf(tmp, ".ll 7.8i\n.nr PO 0\n.pl 1\n.na\n.hy 14\n");
  61.    while(fgets(line, 1022, in) != (char *)NULL)
  62.    {
  63.       len = strlen(line);
  64.       line[len-1] = NULL;
  65.       len--;
  66.       if(len == 0)
  67.       {
  68.          fprintf(tmp, ".br\n.sp\n");
  69.          continue;
  70.       }
  71.       if(*line == LEAVE) /* leave line alone */
  72.       {
  73.          fprintf(tmp, "%s\n.br\n", line);
  74.          continue;
  75.       }
  76.       fprintf(tmp, "%s\n", line);
  77.    }
  78.    fclose(tmp);
  79.    fclose(in);
  80.    sprintf(line, "nroff %s > %s", tmpfile, argv[1]);
  81.    system(line);
  82.    unlink(tmpfile);
  83. }
  84. -- 
  85. Ed Carp - N7EKG/5        (512) 832-5884         uunet!cs.utexas.edu!khijol!erc
  86.  
  87. "The fool thinks he is wise.  The true wise man knows better.  I am a fool."
  88.