home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / BEEHIVE / ZCAT / WORK-VMN.LBR / AN.C next >
Text File  |  2000-06-30  |  4KB  |  155 lines

  1. /* an.c (asm_neat) -- converts assembly language source to uniform
  2.    appearance.    three options are available from the menu:
  3.  
  4.         a - convert comments to all lower case, code to
  5.             all upper.
  6.         b - convert comments and code to upper case
  7.         c - convert code to upper case, comments remain
  8.             unchanged.
  9.  
  10.     note: characters within a single or double quoted string remain
  11.           unchanged, if in code (label, mnemonic, or operand) area
  12.           of source.
  13.  
  14.     usage: >an oldfile newfile
  15.  
  16. 06/07/86  made menu easier to understand.  frank gaude'
  17.  
  18. 08/10/83  added three function options from menu.  added error
  19. trapping for usage.  frank gaude'
  20.  
  21. 12/23/82  original program (aspretty.c) written by william meyer.
  22. assembly language version (neat.asm) written by joe wright (05/21/83)
  23. then enchanced by irv hoff (05/27/83) into three 'neat' programs.
  24.  
  25. compiles with c/80 from software toolworks or manx aztec c ii controlled
  26. by the define below.                            */
  27.  
  28. #define C/80        /* define as C/80 or AZTEC compiler here             */
  29.  
  30. #ifdef C/80
  31. #include "tprintf.c"    /* special short "printf" function        */
  32. #define NULL 0
  33. #define EOF -1
  34. #endif
  35.  
  36. #ifdef AZTEC
  37. #include "stdio.h"
  38. #endif
  39.  
  40. main(argc,argv)
  41. int argc;
  42. char **argv;
  43.     {
  44.     static int byte, comment, cu, f1, f2, lc, onequote, twoquote, uc;
  45.     register int c;
  46.  
  47.     if (argc != 3)        /* test for correct number of auguments */
  48.         {
  49.         printf("usage: >an <oldfile> <newfile>");
  50.         exit(1);
  51.         }
  52.     if ((f1 = fopen(argv[1],"r")) == NULL)     /* open file 1     */
  53.         {
  54.         printf("Unable to find/open/read %s\n", argv[1]);
  55.         exit(1);
  56.         }
  57.     if ((f2 = fopen(argv[2],"w")) == NULL)     /* open file 2     */
  58.         {
  59.         printf("Unable to write to %s\n", argv[2]);
  60.         exit(1);
  61.         }
  62.     byte = lc = uc = cu = 0;
  63. agn:    cls();
  64.     printf("\n\t               AN -- AsmNeat Program Menu\n\n");
  65.     printf("\t     For desired function, enter character then <RETURN>\n\n");
  66.     printf("\t    Conversion: A - Comments to lower case, code to upper\n");
  67.     printf("\t                B - Comments and code to upper case\n");
  68.     printf("\t                C - Code to upper case, comments unchanged\n");
  69.     printf("\t         <CTRL-C> - Exit to Z-System\n\n");
  70.     printf("\t            Choice: ");
  71.     if ((byte = getresp()) == EOF)
  72.         exit(0);
  73.     switch(byte)
  74.         {
  75.         case 'a':
  76.             lc = 1;
  77.             break;
  78.         case 'b':
  79.             uc = 1;
  80.             break;
  81.         case 'c':
  82.             cu = 1;
  83.             break;
  84.         default :
  85.             goto agn;
  86.         }
  87.     printf("\n---> Converting Assembly Source File -- ");
  88.     comment = onequote = twoquote = 0;     /* initialize        */
  89.     while ((c = getc(f1)) != EOF)
  90.         {
  91.         switch (c)
  92.             {
  93.             case ';' :
  94.                 comment = 1;
  95.                 break;
  96.             case '\n':
  97.                 comment = onequote = twoquote = 0;
  98.                 break;
  99.             case '"' :
  100.                 twoquote = ~twoquote;    /* toggle    */
  101.                 break;
  102.             case '\'':
  103.                 onequote = ~onequote;
  104.                 break;
  105.             default  :
  106.                 break;
  107.             }
  108.         if ((onequote != 0 || twoquote != 0) & (comment == 0))
  109.             putc(c,f2);
  110.         else if ((comment == 1) & (cu == 1))
  111.             putc(c,f2);
  112.         else if ((comment == 0) | (comment == 1 && uc == 1))
  113.             putc(toupper(c),f2);
  114.         else if ((comment == 1) | (lc == 1))
  115.             putc(tolower(c),f2);
  116.         }
  117.     fclose(f1);
  118.     fclose(f2);
  119.     printf("done\n");    /* go home msg                */
  120.     exit(0);
  121.     }
  122.  
  123. cls()        /* clear screen function                */
  124.     {
  125.     static int i;
  126.  
  127.     for (i = 0; i < 25; i++)
  128.         printf("\n");
  129.     }
  130.  
  131. getresp()    /* get nonwhite space character from keyboard input    */
  132.     {
  133.     static int byte;
  134.  
  135.     for (;;)
  136.         {
  137.         if ((byte = getchar()) == EOF)
  138.             break;
  139.         else if ((byte != ' ') && (byte != '\t') &&
  140.             (byte != '\n'))
  141.             break;
  142.         }
  143.     return(tolower(byte));    
  144.     }
  145.  
  146. #ifdef C/80
  147. #include "stdlib.c"    /* must be at end of source file for inclusion    */
  148. #endif
  149. }
  150.     return(tolower(byte));    
  151.     }
  152.  
  153. #ifdef C/80
  154. #include "stdlib.c"    /* must be at end of source file for inclusion    */
  155.