home *** CD-ROM | disk | FTP | other *** search
/ Zodiac Super OZ / MEDIADEPOT.ISO / FILES / 16 / FREEDOS.ZIP / FD_A4PRE.ZIP / SOURCE / MICROC.ZIP / UNIX2DOS.C < prev    next >
C/C++ Source or Header  |  1995-03-14  |  2KB  |  98 lines

  1. /*
  2.    UNIX2DOS cr -> cr/lf filter for converting UNIX text files to DOS.
  3.    Author: James Hall, ported to MICRO-C by M. Hannibal Toal
  4. */
  5.  
  6. /*
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2 of the License, or
  10.    (at your option) any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21.  
  22.  
  23. #include <stdio.h>
  24. #include "freedos.h"
  25. #include "getopt.c"
  26.  
  27.  
  28. void usage (void);
  29. int trch (FILE * p, char ch1, char ch2);
  30.  
  31. main (int argc, char **argv)
  32.  
  33. {
  34.   int i;
  35.   FILE *pFile;
  36.  
  37.   /* Scan the command line */
  38.  
  39.   while ((i = getopt (argc, argv, "", "")) != EOF)
  40.     {
  41.       switch (i)
  42.     {
  43.     default:
  44.       usage ();
  45.       break;
  46.     }
  47.     }
  48.  
  49.   /* Convert the files */
  50.  
  51.   if ((argc - optind) < 1)
  52.     {
  53.       trch (stdin, UNIX_NL, DOS_NL);
  54.       exit (0);
  55.     }
  56.  
  57.   for (i = optind; i < argc; i++)
  58.     {
  59.       if ((pFile = fopen (argv[i], "r")) != NULL)
  60.     {
  61.       trch (pFile, UNIX_NL, DOS_NL);
  62.       fclose (pFile);
  63.     }
  64.  
  65.       else
  66.     fprintf (stderr, "Cannot open file %s\n", argv[i]);
  67.     }
  68.  
  69.   exit (0);
  70. }
  71.  
  72. int trch (FILE * p, char ch1, char ch2)
  73. {
  74.   char chBuf;
  75.  
  76.   /* Convert characters in the input stream */
  77.  
  78.   while ((chBuf = fgetc (p)) != EOF)
  79.     {
  80.       if (chBuf == ch1)
  81.     {
  82.       putchar (ch2);
  83.     }
  84.  
  85.       else
  86.     putchar (chBuf);
  87.     }
  88.  
  89.   return (0);
  90. }
  91.  
  92. void usage (void)
  93. {
  94.   printp ("UNIX2DOS", "Converts a file from the UNIX newline format to DOS.");
  95.   printu ("UNIX2DOS", "[file..]");
  96.   exit (1);
  97. }
  98.