home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / debug / tt_cdeb / mac2text.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-10  |  2.5 KB  |  132 lines

  1. /*
  2.     This program will convert TCDEBUG recorded <M>acros (from TCDEBUG.MAC)
  3.     into readable form.  Output goes to stdout.
  4.  
  5.                          Created by Steve York.
  6.  
  7.                    COPYRIGHT (C) 1987,  SAYSoft Inc.
  8.                           All rights reserved.
  9. */
  10.  
  11. /* ----------------------------------------------------------------------- */
  12.  
  13. #include <stdio.h>
  14. #include <mydefs.h>
  15. #include <stdlib.h>
  16. #include <fcntl.h>
  17. #include <io.h>
  18.  
  19. #define MACRO_NAME    "TTCD.MAC"
  20. #define BREAD         (O_RDONLY|O_BINARY)
  21. #define OUTPUT_WIDTH  60
  22. #define HEADER_SIZE   20L
  23.  
  24. /* ----------------------------------------------------------------------- */
  25.  
  26. void error(char *s1,char *s2),
  27.      macros_2_text(void),
  28.      read_macros(void);
  29. int print_key(int);
  30.  
  31. int macros[10][100];
  32.  
  33. /* ======================================================================= */
  34.  
  35. main()
  36. {
  37.   read_macros();
  38.   macros_2_text();
  39.   exit(0);
  40. }
  41.  
  42.  
  43. void macros_2_text()
  44. {
  45.   int i,cnt,len,retval;
  46.  
  47.   for(i=0;i<10;i++)
  48.   {
  49.     printf("F%c:\n{Start}",((i+1) % 10)+'0');
  50.  
  51.     for(cnt=0,len=0;;cnt++)
  52.     {
  53.       if (!(retval=print_key(macros[i][cnt])))  /*  End of macro.  */
  54.         break;
  55.       else
  56.         if ((len+=retval)>OUTPUT_WIDTH)    /*  Wrap above OUTPUT_WIDTH.  */
  57.         {
  58.           puts("\\");
  59.           len=0;
  60.         }
  61.     }
  62.     puts("\n");
  63.   }
  64. }
  65.  
  66.  
  67. int print_key(keyval)
  68. int keyval;
  69. {
  70.   if (keyval<256)
  71.     switch(keyval)
  72.     {
  73.       case 0: printf("{End}");
  74.         return 0;
  75.  
  76.       case 8: printf("<BKSP>");
  77.         return 6;
  78.  
  79.       case 9: printf("<TAB>");
  80.         return 5;
  81.  
  82.       case 13: printf("<RETURN>");
  83.         return 8;
  84.  
  85.       case 27: printf("<ESC>");
  86.         return 5;
  87.  
  88.       case 32: printf("<SPACE>");
  89.         return 7;
  90.  
  91.       default: printf("%c",keyval);
  92.         return 1;
  93.     }
  94.         /*  The debugger does not have any commands that require extended-
  95.             key sequences, but such a key could still be in a macro.  */
  96.   else
  97.     printf("<ext key>");
  98.     return 9;
  99. }
  100.  
  101.  
  102. void read_macros()
  103. {
  104.   int macro_fp,j,cnt;
  105.  
  106.   if ((macro_fp=open(MACRO_NAME,BREAD))==ERR)
  107.     error("Can't open %s",MACRO_NAME);
  108.   else
  109.   {
  110.     lseek(macro_fp,HEADER_SIZE,0);
  111.  
  112.     for(j=0;j<10;j++)
  113.       for(cnt=0;;cnt++)
  114.         if (read(macro_fp,¯os[j][cnt],2)==ERR)
  115.           error("Read error in %s",MACRO_NAME);
  116.         else
  117.           if (!macros[j][cnt])
  118.             break;
  119.   }
  120.  
  121.   close(macro_fp);
  122. }
  123.  
  124.  
  125. void error(s1,s2)
  126. char *s1,*s2;
  127. {
  128.   printf(s1,s2);
  129.   exit(1);
  130. }
  131.  
  132.