home *** CD-ROM | disk | FTP | other *** search
/ 64'er / 64ER_CD.iso / utilpc / c64dearc / tt.c < prev    next >
C/C++ Source or Header  |  1989-09-17  |  5KB  |  145 lines

  1. /*  typcbm.c
  2.     ====================================================================
  3.     Types a file that is in Commodore ASCII to STDOUT       30Jul88 - CS
  4.     ====================================================================
  5.     Requires ANSI.SYS
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10.  
  11. /*  cflag is set to true if the file being typed has an extension of .C
  12.  
  13.     This is nessessary since the C128/C64 does not have curly braces,
  14.     tildas or underscores and the two C compilers for those machines
  15.     redefine the character set slightly.
  16. */
  17.  
  18.  
  19. char cflag;
  20.  
  21. void main(argc, argv)
  22. int    argc;
  23. char * argv[];
  24. {
  25.     FILE * fp;
  26.     int    c, i;
  27.     char * a;
  28.     char * p2a();
  29.  
  30.     if (argc != 2) {
  31.         puts("\nUsage:    tt [d:path\\]filename\n");
  32.         puts("\nPurpose:  Type a Commodore ASCII file to STDOUT.\n");
  33.         puts("          (Assumes ANSI.SYS is active)\n");
  34.         exit(1);
  35.     }
  36.  
  37.     if ((fp = fopen(argv[1], "r")) == 0) {
  38.         fputs("\nCan't open \"",stdout);
  39.         fputs(argv[1],stdout);
  40.         fputs("\"\n",stdout);
  41.         exit(1);
  42.     }
  43.  
  44.     i=strlen(argv[1]);
  45.     cflag=0;
  46.  
  47.     if ( (toupper(argv[1][i-1])=='C') && (argv[1][i-2]=='.') )
  48.         cflag=1;
  49.  
  50.     while((c=getc(fp))!=EOF) {
  51.         a = p2a(c);
  52.         fputs(a,stdout);
  53.     }
  54.  
  55.     fclose(fp);
  56.  
  57. }
  58.  
  59. /* Convert CBM ASCII as implemented on the Commodore 128 to 'Standard' ASCII */
  60. /* as implemented on an IBM PC or compatible using ANSI.SYS                  */
  61.  
  62. char * p2a(c)
  63. int c;
  64. {
  65.     static unsigned cc;
  66.     static unsigned oldcc;
  67.     static char     s[2];
  68.     extern char     cflag;
  69.  
  70.     oldcc = cc;
  71.     cc    = c;
  72.  
  73.     switch (cc) {
  74.  
  75.        case 5:  return  "\033[37;1m";                /* White        */
  76.        case 10: {                                    /* LF           */
  77.                 if (oldcc!=13)
  78.                    return  "\012";
  79.                 else
  80.                    return  "\0";
  81.                 }
  82.        case 13:  return  "\n";                       /* CR           */
  83.        case 17:  return  "\033[B";                   /* Cursor Down  */
  84.        case 18:  return  "\033[44m";                 /* Reverse On   */
  85.        case 19:  return  "\033[H";                   /* Cursor Home  */
  86.        case 28:  return  "\033[31;1m";               /* Red          */
  87.        case 29:  return  "\033[C";                   /* Cursor Right */
  88.        case 30:  return  "\033[32;1m";               /* Green        */
  89.        case 31:  return  "\033[34;1m";               /* Blue         */
  90.        case 129: return  "\033[0m\033[35m";          /* Orange       */
  91.        case 135: return  "\033[A";                   /* Cursor up    */
  92.        case 144: return  "\033[30;1m";               /* Black        */
  93.        case 146: return  "\033[40m";                 /* Reverse Off  */
  94.        case 147: return  "\033[2J";                  /* Clear Screen */
  95.        case 149: return  "\033[0m\033[33m";          /* Brown        */
  96.        case 150: return  "\033[0m\033[31m";          /* Light Red    */
  97.        case 151: return  "\033[0m\033[37m";          /* Dark Grey    */
  98.        case 152: return  "\033[0m\033[37m";          /* Medium Grey  */
  99.        case 153: return  "\033[0m\033[32m";          /* Light Green  */
  100.        case 154: return  "\033[0m\033[34m";          /* Light Blue   */
  101.        case 155: return  "\033[0m\033[37m";          /* Light grey   */
  102.        case 156: return  "\033[35;1m";               /* Purple       */
  103.        case 157: return  "\033[D";                   /* Cursor Left  */
  104.        case 158: return  "\033[33;1m";               /* Yellow       */
  105.        case 159: return  "\033[36;1m";               /* Cyan         */
  106.        case 160: return  " ";                        /* Shift+space  */
  107.        case 164: return  "_";
  108.        case 171: return  "╠";
  109.        case 173: return  "╚";
  110.        case 174: return  "╗";
  111.        case 175: return  "~";
  112.        case 176: return  "╔";
  113.        case 177: return  "╩";
  114.        case 178: return  "╦";
  115.        case 179: return  "╣";
  116.        case 189: return  "╝";
  117.        case 192: return  "═";
  118.        case 219: return (cflag) ?  "{" :  "╬";
  119.        case 221: return (cflag) ?  "}" :  "║";
  120.        case  95: return (cflag) ? 0xa4 :  cc;
  121.        case 223: return  "|";
  122.  
  123.        default:  {
  124.  
  125.             s[0]=cc;
  126.             s[1]=0;
  127.  
  128.             if (cc<65 || cc>219)
  129.                 return s;
  130.  
  131.             if (cc<91) {
  132.                 s[0]=cc|0x20;
  133.                 return s;
  134.             }
  135.  
  136.             if (cc<193)
  137.                 return s;
  138.  
  139.             s[0]=cc&0x7f;
  140.             return s;
  141.        }
  142.    }
  143. }
  144.  
  145.