home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 21 / CD_ASCQ_21_040595.iso / dos / prg / c / freedos3 / source / jh_utils / unix2dos.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-01-07  |  1.8 KB  |  81 lines

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