home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 110_01 / symbug.c < prev    next >
C/C++ Source or Header  |  1984-03-03  |  4KB  |  107 lines

  1. /*    Symbol Table Sort
  2.  
  3.     Written by
  4.     Bob Pasky
  5.     36 Wiswall Rd.    Newton Centre, MA 02159
  6.     Makes BDS-C .SYM file compatible with VBUG symbol table.
  7.  
  8.     VBUG is mnemonic & symbolic debugger for Z-80(tm, Zilog Inc.)
  9.     micros which I wrote. It displays its trace addresses as
  10.     a symbol plus offset, and allows the user to reference a
  11.     location in the same manner. So that the trace runs as fast as
  12.     possible, the symbol table is ordered by the address of the
  13.     symbol, and vbug does a linear search of the addresses until
  14.     it finds one which is greater than the address to be displayed
  15.     and backs off to the previous symbol. It will then print that
  16.     symbol and a hex byte for the difference between the actual
  17.     address and the symbol's address, e.g., "FOOBAR +0A:".
  18.     In vbug, as in my assembler, only the first 7 characters are
  19.     significant -- I must take in to account that fact when creating
  20.     symbol names in my C programs.
  21.  
  22.     The format for VBUG's symbol file is:
  23.         2 bytes: address (low byte-high byte order),
  24.         1 byte: symbol length + 3,
  25.         1-7 bytes: symbol characters;
  26.     Addresses must be sorted in ascending order.
  27.     An address field of 0xFFFF ends table.
  28.  
  29.     The program reads the .sym file produced by "Clink", storing
  30.     the symbols and their addresses in "sym" and "ad" arrays,
  31.     respectively. The addresses and an index into "sym" array
  32.     are sorted using the "qsort" function. The .sym file is
  33.     renamed to .csy, and a new .sym file is opened (vbug uses the
  34.     .sym type also). Finally, the symbols and their addresses are
  35.     written to this file in the format described above.
  36.  
  37.     The program is called by:
  38.         A>symbug [<symbolfile> [<symbolfile> ...] ]
  39.     where <symbolfile> is the name of the .sym file produced by
  40.     "Clink". If no name is given at invocation of the program,
  41.     a prompt will be printed requesting a <symbolfile> name.
  42.     Entering simply <CR> at the prompt will cause the program
  43.     to exit().
  44.  
  45.     This program may not be DIRECTLY useable by anyone else, but
  46.     it demonstrates some simple string manipulation functions.
  47.     One feature which should be noted is that the string data
  48.     are not moved around in memory; only a pointer to the
  49.     string (actually the index number into the array) is moved.
  50.     When the sorting is complete, reading the index numbers
  51.     sequentially from the array "ad" gives the string array index in
  52.     the order desired. (Remember, this program outputs by ascending
  53.     address field; the symbols already happen to be in alphabetical
  54.     order.)
  55.  
  56. */
  57.  
  58. #include "bdscio.h"
  59.  
  60. #define CTRLQ 0x11    /* quit key: control-q */
  61.             /* YOU may want to change this to control-c */
  62.  
  63. #define MAXSYM 200    /* max number of symbols expected in file */
  64. #define MAXSYMLEN 10    /* max symbol length expected from input */
  65. #define SYMLEN 7    /* max symbol length to be output */
  66.  
  67. struct adtab {
  68.     int v;        /* value */
  69.     int o;        /* offset into sym */
  70.     } ad[MAXSYM];    /* max number of symbols expected */
  71.  
  72. char sym[MAXSYM][MAXSYMLEN];    /*array of symbol names */
  73.  
  74. main(argc,argv)
  75. char **argv;
  76. {
  77.     int i, j, fd;
  78.     int total;
  79.     char fnbuf[30], *fname;        /* filename buffer & ptr */
  80.     char onbuf[30], *oname;        /* output filename buf & ptr */
  81.     char ibuf[BUFSIZ];        /* buffered input buffer */
  82.     char *gets();
  83.     char tempstr[80];        /* size of line produced by CLINK */
  84.     int cmpadd();
  85.  
  86.     while (1)
  87.     {
  88.         oname = onbuf;
  89.         if (argc-1)
  90.         {
  91.             fname = *++argv;
  92.             argc--;
  93.         }
  94.         else
  95.         {
  96.             printf ("\nEnter SYM file name: ");
  97.             if (!*(fname = gets(fnbuf))) break;
  98.         }
  99.         strcpy (oname,fname);
  100.         strcat (fname,".SYM");
  101.  
  102.         if ((fd = fopen(fname,ibuf)) == ERROR)
  103.         {
  104.             printf("Can't open %s\n",fname);
  105.             continue;
  106.         }
  107.         else    printf("\nReading %-13s\n",fname