home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / snpd9707.zip / NLCNVRT.C < prev    next >
Text File  |  1997-07-05  |  3KB  |  112 lines

  1. .I 0 1
  2. /* +++Date last modified: 05-Jul-1997 */
  3. .D 1 1
  4. .I 6 1
  5. **  Mac support by Norman Dodge and Bob Stout
  6. .I 17 9
  7. static void usage(void);
  8. static void dos2unix(void);
  9. static void dos2mac(void);
  10. static void unix2dos(void);
  11. static void unix2mac(void);
  12. static void mac2dos(void);
  13. static void mac2unix(void);
  14. static void Cout(int ch, FILE *outfile);
  15. static void Sout(char *str, FILE *outfile);
  16. .D 18 6
  17. .I 44 1
  18.             unix2dos();
  19. .D 45 2
  20. .I 48 4
  21.       case 'D':
  22.             mac2dos();
  23.             break;
  24.  
  25. .I 49 13
  26.             dos2unix();
  27.             break;
  28.  
  29.       case 'U':
  30.             mac2unix();
  31.             break;
  32.  
  33.       case 'm':
  34.             dos2mac();
  35.             break;
  36.  
  37.       case 'M':
  38.             unix2mac();
  39. .D 50 7
  40. .I 77 7
  41.       puts("Usage: NLCNVRT -[d | u | m | D | U | M] infile [outfile]");
  42.       puts("Switches: -d  Convert to DOS  from Unix - converts LF   => CRLF");
  43.       puts("        : -u  Convert to Unix from DOS  - converts CRLF => LF");
  44.       puts("        : -m  Convert to Mac  from DOS  - converts CRLF => CR");
  45.       puts("        : -D  Convert to DOS  from Mac  - converts CR   => CRLF");
  46.       puts("        : -U  Convert to Unix from Mac  - converts CR   => LF");
  47.       puts("        : -M  Convert to Mac  from Unix - converts LF   => CR");
  48. .D 78 4
  49. .I 84 1
  50. void unix2dos(void)
  51. .D 85 1
  52. .I 98 1
  53. void dos2unix(void)
  54. .D 99 1
  55. .I 111 46
  56. void mac2dos(void)
  57. {
  58.       int ch, lastch = 0;
  59.  
  60.       while (EOF != (ch = fgetc(infile)))
  61.       {
  62.             fputc(lastch = ch, outfile);
  63.             if ('\r' == ch)
  64.                   fputc('\n', outfile);
  65.       }
  66.       if ('\r' != lastch)
  67.             fputs("\r\n", outfile);
  68. }
  69.  
  70. static void dos2mac(void)
  71. {
  72.       int ch, lastch = 0;
  73.  
  74.       while (EOF != (ch = fgetc(infile)) && '\x1a' != ch)
  75.       {
  76.             if ('\r' != ch)
  77.             {
  78.                   if ('\n' == ch)
  79.                         ch = '\r';
  80.                   fputc(lastch = ch, outfile);
  81.             }
  82.       }
  83.       if ('\r' != lastch)
  84.             fputc('\r', outfile);
  85. }
  86.  
  87. static void unix2mac(void)
  88. {
  89.       int ch, lastch = 0;
  90.  
  91.       while (EOF != (ch = fgetc(infile)))
  92.       {
  93.             if ('\n' == ch)
  94.                   ch = '\r';
  95.             fputc(lastch = ch, outfile);
  96.       }
  97.       if ('\r' != lastch)
  98.             fputc('\r', outfile);
  99. }
  100.  
  101. static void mac2unix(void)
  102. .D 112 1
  103. .I 118 7
  104.                   ch = '\n';
  105.             fputc(lastch = ch, outfile);
  106.       }
  107.       if ('\n' != lastch)
  108.             fputc('\n', outfile);
  109. }
  110.  
  111. .D 119 7
  112.