home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3.4.17 [SPARC, PA-RISC] / nextstep33_risc.iso / usr / netware / lib / nuc / etc / unix2dos.c < prev   
Encoding:
C/C++ Source or Header  |  1993-07-13  |  2.4 KB  |  118 lines

  1.  
  2. /*
  3.  
  4. $Header: unix2dos.c
  5.  
  6. $Project: <NFS for Netware/386>, <UNIX To DOS translation util - DOS version>
  7.  
  8. $Creator: <Wen H. Chiu>    $
  9.  
  10. $Locker:  $
  11.  
  12. $Source: /proj/nwnfs2/REL1.2b/s_xlat/unix/RCS/unix2dos.c,v $
  13.  
  14.  
  15.  *****************************************************************************
  16.  *
  17.  *    (C) Copyright 1989, 1990 Novell, Inc.
  18.  *    All Rights Reserved.
  19.  *
  20.  *    This program is an unpublished copyrighted work which is proprietary
  21.  *    to Novell, Inc. and contains confidential information that is not
  22.  *    to be reproduced or disclosed to any other person or entity without
  23.  *    prior written consent from Novell, Inc. in each and every instance.
  24.  *
  25.  *    WARNING:  Unauthorized reproduction of this program as well as
  26.  *    unauthorized preparation of derivative works based upon the
  27.  *    program or distribution of copies by sale, rental, lease or
  28.  *    lending are violations of federal copyright laws and state trade
  29.  *    secret laws, punishable by civil and criminal penalties.
  30.  *
  31.  ****************************************************************************
  32.  
  33. */
  34.  
  35. #include <stdio.h>
  36. #include <fcntl.h>
  37.  
  38. #define START 0
  39. #define CRFOUND 1
  40.  
  41. #define RBYTES 4096
  42.  
  43. char rbuf[RBYTES];
  44. FILE *rfp;
  45.  
  46. print_argmsg()
  47. {
  48.     printf("\n  Usage: unix2dos source_file [ > dest_file]\n");
  49.     exit(-1);
  50. }
  51.  
  52. print_rmsg(file)
  53. char *file;
  54. {
  55.     printf("read error from source file %s\n", file);
  56.     fclose(rfp);
  57.     exit(-1);
  58. }
  59.  
  60. print_wmsg(file)
  61. char *file;
  62. {
  63.     printf("write error to destination file %s\n", file);
  64.     fclose(rfp);
  65.     exit(-1);
  66. }
  67.  
  68. main(argc, argv)
  69. int argc;
  70. char *argv[];
  71. {
  72.     int rlen, len, i;
  73.     char c;
  74.  
  75.     if (argc < 2)
  76.         print_argmsg();
  77.  
  78.     if (!(rfp=fopen(argv[1], "rb"))) {
  79.         printf("can't open source file %s\n", argv[1]);
  80.         exit(-1);
  81.     }
  82.  
  83. #ifdef ON_DOS
  84.     /* set mode of stdout to binary */
  85.     if ((setmode(fileno(stdout), O_BINARY)) == 1) {
  86.         printf("can't set stdout to binary mode\n");
  87.         exit(-1);
  88.     }
  89. #endif
  90.  
  91.     do {
  92.         if ((rlen=fread(rbuf, 1, RBYTES, rfp)) == -1)
  93.             print_rmsg(argv[1]);
  94.  
  95.         if (rlen == 0)
  96.             break;
  97.  
  98.         len = rlen;
  99.         i = 0;
  100.         while (len--) {
  101.             c = rbuf[i++];
  102.             switch (c) {
  103.                 case '\n':
  104.                     if (fwrite("\r\n", 1, 2, stdout) < 2)
  105.                         print_wmsg(argv[2]);
  106.                     break;
  107.                 default:
  108.                     if (fwrite(&c, 1, 1, stdout) < 1)
  109.                         print_wmsg(argv[2]);
  110.                     break;
  111.             };
  112.         };
  113.     } while (rlen == RBYTES);
  114.     
  115.     fclose(rfp);
  116.     exit(0);
  117. }
  118.