home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 376_01 / os2tool.000 / DOS2UNIX.C < prev    next >
C/C++ Source or Header  |  1991-11-23  |  2KB  |  106 lines

  1. /*
  2. * DOS2UNIX.C - Translates files between DOS/OS/2 and UNIX.
  3. *
  4. *
  5. * PROGRAMMER:        Martti Ylikoski
  6. * CREATED:        24.11.1991
  7. */
  8. static char *VERSION = "Version 1.0, Copyright(c) Martti Ylikoski, 1991" ;
  9. /*
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <fcntl.h>
  14. #include <io.h>
  15. #include <errno.h>
  16. #include <param.h>
  17. #include <paramstd.h>
  18.  
  19. static char *progname ;
  20.  
  21. extern unsigned long pflags ;
  22.  
  23. ParamEntry pentry[12] = {
  24.      "P", &ParamSetPause, 0,
  25.      "F", &ParamSetFold, 0,
  26.      "V", &ParamSetVerbose, 0,
  27.      "R", &ParamSetReport, 0,
  28.      "S", &ParamSetSubDirs, 0,
  29.      "?", &ParamSetHelp, 1,
  30.      "H", &ParamSetHelp, 1,
  31.      "NOD", &ParamSetNoDefault, 0,
  32.      "TEST", &ParamSetTest, 0,
  33.      "Y", &ParamSetYes, 0,
  34.      "N", &ParamSetTest, 0,
  35.      "\0", NULL, 0
  36. } ;
  37.  
  38. ParamBlock params = {
  39.     "/-",   IGNORECASE | NOPRIORITY | NOTRIGGERSALLOWED ,
  40.     pentry
  41. } ;
  42.  
  43.  
  44. main(int argc, char *argv[])
  45. {
  46. FILE *fpin, *fpout ;
  47. char buf[1024] ;
  48.    progname = argv[0] ;
  49.  
  50.    ParamHandle(¶ms, &argc, argv) ;
  51.  
  52.    if (pflags & PA_HELP)
  53.    {
  54.       printf("%s - Translates files between DOS/OS/2 and UNIX.\n", progname) ;
  55.       puts(VERSION) ;
  56.       puts("Usage: UNIX2DOS [file1 [file2]] [/? | /H]") ;
  57.       puts("Where,") ;
  58.       puts("     /H,/? = Help") ;
  59.       puts("If file1 is missing, DOS2UNIX reads from the standard input") ;
  60.       puts("if file2 is missing, DOS2UNIX writes to the standard output") ;
  61.       return( 0 ) ;
  62.    }
  63.  
  64.    if (argc == 1)
  65.       fpin = stdin ;
  66.    else
  67.    {
  68.       if ((fpin = fopen(argv[1], "rt")) == NULL)
  69.       {
  70.      fprintf(stderr, "%s unable to open input file %s\n", progname, argv[1]) ;
  71.      return( 1 ) ;
  72.       }
  73.    }
  74.  
  75.    if (argc < 3)
  76.    {
  77.       setmode(1, O_BINARY) ;
  78.       fpout = stdout ;
  79.    }
  80.    else
  81.    {
  82.       if ((fpout = fopen(argv[2], "wb")) == NULL)
  83.       {
  84.      fprintf(stderr, "%s unable to open output file %s\n", progname, argv[2]) ;
  85.      fclose(fpin) ;
  86.      return( 1 ) ;
  87.       }
  88.    }
  89.  
  90.    while(fgets(buf, sizeof(buf), fpin) != NULL)
  91.    {
  92.       fputs(buf, fpout) ;
  93.       if (ferror(fpin) || ferror(fpout))
  94.       {
  95.      fprintf(stderr, "%s: error in processing\nFiles may be only partially converted\n", progname) ;
  96.      fclose(fpin) ;
  97.      fclose (fpout) ;
  98.      return( 1 ) ;
  99.       }
  100.    }
  101.  
  102.    fclose(fpin) ;
  103.    fclose(fpout) ;
  104.    return( 0 ) ;
  105. }
  106.