home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / utils / atconv.arc / ATCONV.C next >
Encoding:
C/C++ Source or Header  |  1987-02-08  |  2.1 KB  |  98 lines

  1. /*
  2.  
  3.     atconv.c
  4.  
  5.     
  6.  
  7.     program to translate ATASCII to ASCII or vice-versa.
  8.  
  9.     call:
  10.  
  11.         atconv filename
  12.  
  13.         
  14.  
  15.     function: program translates all occurrences of 0x9b to
  16.  
  17.           ox0d,0x0a and all occurrences of 0x0a to 0x9b.
  18.  
  19.           Occurrences of 0x0d in the input are ignored.
  20.  
  21.           The result of this translation is that files in
  22.  
  23.           ATASCII are readable in ASCII and files in ASCII
  24.  
  25.           are readable in ATASCII.
  26.  
  27.           
  28.  
  29.     warnings: This program writes a temporary file "xyzzy.tmp"
  30.  
  31.           which replaces the original file upon completion.
  32.  
  33.           If the user wishes to retain the original file, a copy
  34.  
  35.           should be made beforehand.
  36.  
  37.           
  38.  
  39.     author:      Bruce D. Nelson
  40.  
  41. */
  42.  
  43.  
  44.  
  45. #include <stdio.h>
  46.  
  47. #include <osbind.h>
  48.  
  49.  
  50.  
  51. main (argc, argv)
  52.  
  53. int     argc;
  54.  
  55. char   *argv[];
  56.  
  57. {
  58.  
  59.     int    c1,dtabuff[22],whway;
  60.  
  61.     long   l,len;
  62.  
  63.     FILE   *fp1,*fp2;
  64.  
  65.  
  66.  
  67.     if (argc < 2) {
  68.  
  69.         printf("Usage: atconv filename\n");
  70.  
  71.         exit();
  72.  
  73.         }
  74.  
  75.  
  76.  
  77.     if ((fp1 = fopen (argv[1], "br")) == NULL) {
  78.  
  79.         printf ("Can't open %s\n",argv[1]);
  80.  
  81.             exit();
  82.  
  83.     }
  84.  
  85.     if ((fp2 = fopen ("xyzzy.tmp", "bw")) == NULL) {
  86.  
  87.         printf ("Can't open xyzzy.tmp");
  88.  
  89.             exit();
  90.  
  91.     }
  92.  
  93.  
  94.  
  95.     Fsetdta (dtabuff);
  96.  
  97.     Fsfirst (argv[1],0);
  98.  
  99.     len = *(long *)(dtabuff+13);
  100.  
  101.     whway = 0; /* indicates which way the translation was assumed */
  102.  
  103.  
  104.  
  105.     for (l=0;l<len;l++){
  106.  
  107.         c1 = fgetc(fp1);
  108.  
  109.         switch (c1){
  110.  
  111.             case 0x9b:{
  112.  
  113.                 whway = 1;
  114.  
  115.                 wputc(0x0d,fp2);
  116.  
  117.                 wputc(0x0a,fp2);
  118.  
  119.                 break;
  120.  
  121.             }
  122.  
  123.             case 0x0d:{
  124.  
  125.                 break;
  126.  
  127.             }
  128.  
  129.             case 0x0a:{
  130.  
  131.                 whway = 2;
  132.  
  133.                 wputc(0x9b,fp2);
  134.  
  135.                 break;
  136.  
  137.             }
  138.  
  139.             default:{
  140.  
  141.                 wputc(c1,fp2);
  142.  
  143.                 break;
  144.  
  145.             }
  146.  
  147.         } /* end switch */
  148.  
  149.     }/* end for */
  150.  
  151.             
  152.  
  153.     fclose (fp1);
  154.  
  155.     fclose (fp2);
  156.  
  157.  
  158.  
  159.     Fdelete(argv[1]);
  160.  
  161.     Frename(0,"xyzzy.tmp",argv[1]);
  162.  
  163.         
  164.  
  165.     if (whway == 1) printf ("%s converted from ATASCII to ASCII",argv[1]);
  166.  
  167.     if (whway == 2) printf ("%s converted from ASCII to ATASCII",argv[1]);
  168.  
  169.     
  170.  
  171. }
  172.  
  173.  
  174.  
  175. wputc (c,f) /* fputc with error handling */
  176.  
  177. int c;
  178.  
  179. FILE *f;
  180.  
  181. {
  182.  
  183.     if ((fputc(c,f))==EOF){
  184.  
  185.         printf ("End of file on temp file\n");
  186.  
  187.         exit();
  188.  
  189.     }
  190.  
  191. }
  192.  
  193.  
  194.  
  195.