home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / TELECOM / UUCPbb_2_1_src.lzh / UUCPBB21 / fixtext.c < prev    next >
Text File  |  1994-09-25  |  4KB  |  137 lines

  1. /*  fixtext.c    Fixs text file so it has OS9 tabbing and line terminators.
  2.     Copyright (C) 1990, 1993  Rick Adams and Bob Billson
  3.  
  4.     This file is part of the OS-9 UUCP package, UUCPbb.
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License as published by
  8.     the Free Software Foundation; either version 2 of the License, or
  9.     (at your option) any later version.
  10.  
  11.     This program is distributed in the hope that it will be useful,
  12.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.     GNU General Public License for more details.
  15.  
  16.     You should have received a copy of the GNU General Public License
  17.     along with this program; if not, write to the Free Software
  18.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20.     The author of UUCPbb, Bob Billson, can be contacted at:
  21.     bob@kc2wz.bubble.org  or  uunet!kc2wz!bob  or  by snail mail:
  22.     21 Bates Way, Westfield, NJ 07090
  23. */
  24.  
  25. /* Usage: fixtext [- | infile] [outfile]",
  26.  
  27.    Examples:
  28.  
  29.     fixtext                  -read standard in, output sent to standard out
  30.     fixtext - outfile        -read standard in, output sent to outfile
  31.     fixtext infile           -read infile, output sent to standard out
  32.     fixtext infile outfile   -read infile, output sent to outfile
  33. */
  34.  
  35. #define MAIN
  36.  
  37. #include "uucp.h"
  38.  
  39.  
  40. main (argc, argv)
  41. int argc;
  42. char *argv[];
  43. {
  44.      FILE *infile, *outfile;
  45.      char line[512], *p;
  46.  
  47.      switch (argc)
  48.        {
  49.           /* fixtext <infile >outfile */
  50.           case 1:
  51.                infile = stdin;
  52.                outfile = stdout;
  53.                break;
  54.  
  55.           /* fixtext infile >outfile  or  fixtext -?  (help) */
  56.           case 2:
  57.                if (argv[1][0] == '-'  &&  argv[1][1] == '?')
  58.                     usage();
  59.                else
  60.                  {
  61.                     if ((infile = fopen (argv[1], "r")) == NULL)
  62.                          fatal ("cannot open input file:", argv[1]);
  63.                     outfile = stdout;
  64.                  }
  65.                break;
  66.  
  67.           /* fixtext - outfile   or   fixtext infile outfile */
  68.           case 3:
  69.                /* get input from standard input */
  70.                if (argv[1][0] == '-'  &&  argv[1][1] == '\0')
  71.                     infile = stdin;
  72.                else
  73.                     /* Get input from file */
  74.                     if ((infile = fopen (argv[1], "r")) == NULL)
  75.                          fatal ("cannot open input file:", argv[1]);
  76.  
  77.                if ((outfile = fopen (argv[2], "w")) == NULL)
  78.                     fatal ("cannot create output file:", argv[2]);
  79.                break;
  80.  
  81.           default:
  82.                usage();
  83.        }
  84.  
  85.      p = line;
  86.      while (mfgets (p, sizeof (line), infile) != NULL)
  87.        {
  88.           fixline (line);
  89.           fprintf (outfile, "%s\n", line);
  90.        }
  91.  
  92.      if (infile != stdin)
  93.           fclose (infile);
  94.  
  95.      if (outfile != stdout)
  96.           fclose (outfile);
  97. }
  98.  
  99.  
  100.  
  101. int fatal (reason, arg)
  102. char *reason, *arg;
  103. {
  104.      fprintf (stderr, "fixtext: %s %s ...error %d\n", reason, arg, errno);
  105.      exit (0);
  106. }
  107.  
  108.  
  109.  
  110. int usage()
  111. {
  112.      register char **use;
  113.      static char *usetxt[] = {
  114.          "\nfixtext: A text file filter.  Removes escape sequences, expand tabs and change",
  115.          "         end-of-line terminators to OS-9 ones.",
  116.          " ",
  117.          "Usage:  fixtext [infile] [outfile]",
  118.          "          if infile is a '-', the standard input is read",
  119.          " ",
  120.          "Examples:",
  121.          " ",
  122.          "fixtext                  -read standard in, write to standard out",
  123.          "fixtext - outfile        -read standard in, write to outfile",
  124.          "fixtext infile           -read infile, write to standard out",
  125.          "fixtext infile outfile   -read infile, write to outfile",
  126.          NULL
  127.        }; 
  128.  
  129.      for (use = usetxt; *use != NULL; ++use)
  130.           fprintf (stderr, "%s\n", *use);
  131.  
  132.      fprintf (stderr, "\nv%s (%s) This is free software released under the GNU General Public\n",
  133.                       version, VERDATE);
  134.      fputs ("License.  Please send suggestions/bug reports to:  bob@kc2wz.bubble.org\n", stderr);
  135.      exit (0);
  136. }
  137.