home *** CD-ROM | disk | FTP | other *** search
- /*
- This program will convert TCDEBUG recorded <M>acros (from TCDEBUG.MAC)
- into readable form. Output goes to stdout.
-
- Created by Steve York.
-
- COPYRIGHT (C) 1987, SAYSoft Inc.
- All rights reserved.
- */
-
- /* ----------------------------------------------------------------------- */
-
- #include <stdio.h>
- #include <mydefs.h>
- #include <stdlib.h>
- #include <fcntl.h>
- #include <io.h>
-
- #define MACRO_NAME "TTCD.MAC"
- #define BREAD (O_RDONLY|O_BINARY)
- #define OUTPUT_WIDTH 60
- #define HEADER_SIZE 20L
-
- /* ----------------------------------------------------------------------- */
-
- void error(char *s1,char *s2),
- macros_2_text(void),
- read_macros(void);
- int print_key(int);
-
- int macros[10][100];
-
- /* ======================================================================= */
-
- main()
- {
- read_macros();
- macros_2_text();
- exit(0);
- }
-
-
- void macros_2_text()
- {
- int i,cnt,len,retval;
-
- for(i=0;i<10;i++)
- {
- printf("F%c:\n{Start}",((i+1) % 10)+'0');
-
- for(cnt=0,len=0;;cnt++)
- {
- if (!(retval=print_key(macros[i][cnt]))) /* End of macro. */
- break;
- else
- if ((len+=retval)>OUTPUT_WIDTH) /* Wrap above OUTPUT_WIDTH. */
- {
- puts("\\");
- len=0;
- }
- }
- puts("\n");
- }
- }
-
-
- int print_key(keyval)
- int keyval;
- {
- if (keyval<256)
- switch(keyval)
- {
- case 0: printf("{End}");
- return 0;
-
- case 8: printf("<BKSP>");
- return 6;
-
- case 9: printf("<TAB>");
- return 5;
-
- case 13: printf("<RETURN>");
- return 8;
-
- case 27: printf("<ESC>");
- return 5;
-
- case 32: printf("<SPACE>");
- return 7;
-
- default: printf("%c",keyval);
- return 1;
- }
- /* The debugger does not have any commands that require extended-
- key sequences, but such a key could still be in a macro. */
- else
- printf("<ext key>");
- return 9;
- }
-
-
- void read_macros()
- {
- int macro_fp,j,cnt;
-
- if ((macro_fp=open(MACRO_NAME,BREAD))==ERR)
- error("Can't open %s",MACRO_NAME);
- else
- {
- lseek(macro_fp,HEADER_SIZE,0);
-
- for(j=0;j<10;j++)
- for(cnt=0;;cnt++)
- if (read(macro_fp,¯os[j][cnt],2)==ERR)
- error("Read error in %s",MACRO_NAME);
- else
- if (!macros[j][cnt])
- break;
- }
-
- close(macro_fp);
- }
-
-
- void error(s1,s2)
- char *s1,*s2;
- {
- printf(s1,s2);
- exit(1);
- }
-