home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / cpm / unix2cpm.c < prev   
C/C++ Source or Header  |  1995-07-15  |  2KB  |  46 lines

  1. /* UNIX2CPM.COM - A program to convert a UNIX style text file,
  2.    using a LF (0AH) for a line delimiter, to one using the CP/M
  3.    convention sequence CR/LF (0DH/0AH).  */  /* ch: 07/14/95 */
  4.  
  5. #include "stdio.h"
  6. main(argc, argv)        /* requires command line */
  7. int argc;
  8. char *argv[];
  9. {
  10.         FILE *fopen(), *fi, *fo;
  11.         int c;          /* character read and written */
  12.         int d;          /* temporary stuffed character */
  13.  
  14.         if (argc != 3) {        /* if command line is incorrect */
  15.                 printf("\tCopies infile to outfile and converts\n");
  16.                 printf("\tLF newline characters (UNIX) to a CR/LF\n");
  17.                 printf("\tsequence acceptable to CP/M\n\n");
  18.                 printf("\tSyntax is UNIX2CPM <infile> <outfile>\n");
  19.                 exit(1);
  20.         }
  21.                 /* try to open files */
  22.         if ((fi = fopen(argv[1], "r")) == NULL) {
  23.                 printf("\tCan't open infile...\n");
  24.                 exit(1);
  25.         }
  26.         if ((fo = fopen(argv[2], "w")) == NULL) {
  27.                 printf("\tCan't open outfile...\n");
  28.                 exit(1);
  29.         }
  30.                 /* char by char copy */
  31.         while ((c = getc(fi)) != EOF) {
  32.                 c = c & 0x7F;   /* strip 8-bit */
  33.                 if (c == 0x0A) {
  34.                     c = 0x0D;
  35.                     putc(c, fo);
  36.                     c = 0x0A;
  37.                     putc(c, fo);
  38.                 }
  39.                 else putc(c, fo);
  40.         }
  41.                 /* close files and exit */
  42.         fclose(fi);
  43.         fclose(fo);
  44.         exit(0);
  45. }
  46.