home *** CD-ROM | disk | FTP | other *** search
/ Best Objectech Shareware Selections / UNTITLED.iso / boss / word / text / 024 / tdecfg.c < prev    next >
C/C++ Source or Header  |  1993-06-04  |  23KB  |  747 lines

  1. /*
  2.  * A configuration utility was written to customize the tde executable file.
  3.  * You only need one file to run tde - the executable.  No configuration files
  4.  * to worry about.
  5.  *
  6.  * With this version, there is no need to figure the offsets each time
  7.  * tde.exe is modified.  The original program to find the offsets was written
  8.  * by Jim Lee, jlee@ece.orst.edu.  Simple pattern matching machines are used
  9.  * to find the offsets.  On one pass thru tde.exe, the machines will quickly
  10.  * find all signatures.  The pattern matching machines are loosely based on
  11.  * the multiple string search algorithm by Alfred Aho and Margaret Corasick.
  12.  *
  13.  * See:
  14.  *
  15.  *   Alfred V. Aho and Margaret J. Corasick, "Efficient String Matching:
  16.  *    An Aid to Bibliographic Search."  _Communications of the ACM_ 18
  17.  *    (No. 6): 333-340, 1975.
  18.  *
  19.  *
  20.  * Program name:  tdecfg
  21.  * Author:        Frank Davis
  22.  * Date:          October 5, 1991
  23.  * Date:          June 5, 1993
  24.  *
  25.  * This program is released into the public domain.  You may distribute
  26.  * it freely, Frank Davis.
  27.  */
  28.  
  29.  
  30. #include <bios.h>
  31. #include <dos.h>
  32. #include <io.h>
  33. #include <malloc.h>
  34. #include <stdlib.h>
  35. #include <stdio.h>
  36. #include <string.h>
  37.  
  38. #include "tdecfg.h"
  39.  
  40.  
  41. struct vcfg cfg;                /* video stuff */
  42. FILE *tde_exe;                  /* FILE pointer to tde.exe */
  43.  
  44. long sort_offset;
  45. long mode_offset;
  46. long color_offset;
  47. long macro_offset;
  48. long keys_offset;
  49. long two_key_offset;
  50. long help_offset;
  51.  
  52. struct screen cfg_choice[] = {
  53.    {5,25,"1.  Change colors" },
  54.    {7,25,"2.  Redefine keys" },
  55.    {9,25,"3.  Install new help screen" },
  56.   {11,25,"4.  Set default modes" },
  57.   {13,25,"5.  Install permanent macro file" },
  58.   {15,25,"6.  Read in a configuration file" },
  59.   {17,25,"7.  Exit" },
  60.  {20,20,"Please enter choice: " },
  61.   {0,0,NULL}
  62. };
  63.  
  64.  
  65. char *greatest_composer_ever = "W. A. Mozart, 1756-1791";
  66.  
  67.  
  68. /*
  69.  * Name:    main
  70.  * Date:    October 5, 1991
  71.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  72.  *          variables  2) show the user a color sample  3) make the changes
  73.  *          permanent if desired.
  74.  */
  75. void main( int argc, char *argv[] )
  76. {
  77. int  rc;
  78. int  c;
  79. char fname[82];
  80. char *buff;
  81.  
  82.    /*
  83.     * lets get a 8k buffer for our pattern matching machines.
  84.     */
  85.    if ((buff = malloc( 8200 )) == NULL) {
  86.       puts( "\nNot enough memory." );
  87.       exit( 1 );
  88.    }
  89.  
  90.    puts( "\nEnter tde executable file name (<Enter> = \"tde.exe\")  :" );
  91.    gets( fname );
  92.  
  93.    if (strlen(fname) == 0)
  94.       strcpy( fname, "tde.exe" );
  95.  
  96.    if ((rc = access( fname, EXIST )) != 0) {
  97.       puts( "\nFile not found." );
  98.       exit( 1 );
  99.    } else if ((tde_exe = fopen( fname, "r+b" )) == NULL ) {
  100.       puts( "\nCannot open executable file." );
  101.       exit( 2 );
  102.    }
  103.    find_offsets( buff );
  104.    free( buff );
  105.  
  106.    video_config( );
  107.    cls( );
  108.    show_box( 0, 0, cfg_choice, NORMAL );
  109.    for (rc=0; rc != 1;) {
  110.       xygoto( 42, 20 );
  111.       c = getkey( );
  112.       while (c != '1' && c != '2' && c != '3' && c != '4' && c != '5' &&
  113.              c != '6' && c != '7')
  114.          c = getkey( );
  115.       switch (c) {
  116.          case '1' :
  117.             tdecolor( );
  118.             show_box( 0, 0, cfg_choice, NORMAL );
  119.             break;
  120.          case '2' :
  121.             tdekeys( );
  122.             show_box( 0, 0, cfg_choice, NORMAL );
  123.             break;
  124.          case '3' :
  125.             tdehelp( );
  126.             show_box( 0, 0, cfg_choice, NORMAL );
  127.             break;
  128.          case '4' :
  129.             tdemodes( );
  130.             show_box( 0, 0, cfg_choice, NORMAL );
  131.             break;
  132.          case '5' :
  133.             tdemacro( );
  134.             show_box( 0, 0, cfg_choice, NORMAL );
  135.             break;
  136.          case '6' :
  137.             tdecfgfile( );
  138.             show_box( 0, 0, cfg_choice, NORMAL );
  139.             break;
  140.          case '7' :
  141.             rc = 1;
  142.             break;
  143.       }
  144.    }
  145.    fcloseall( );
  146.    puts( " " );
  147.    puts( " " );
  148. }
  149.  
  150.  
  151. /***********************  original comments  *************************/
  152. /*
  153. ** OFFSETS.C    -       Automatically scan tde.exe for config offsets
  154. **
  155. ** Author:  Jim Lee (jlee@ece.orst.edu)
  156. **   Date:  5/12/93
  157. ** Status:  Released to the public domain
  158. **
  159. **      This little utility takes the drudgery out of updating tdecfg.h
  160. **      every time you re-compile tde.exe.  Just remove the hard-coded
  161. **      offsets in tdecfg.h and replace them with '#include "newoff.h"'.
  162. **      Then run 'offsets tde.exe > newoff.h'.  Now re-compile tdecfg
  163. **      and you're done!
  164. **
  165. */
  166. /*****************************   end   *******************************/
  167.  
  168. /*
  169.  * Name:    find_offsets
  170.  * Date:    June 5, 1993
  171.  * Notes:   to increase the speed, I "wired" a pattern matching machine
  172.  *           for each of the signatures, Frank.  the states in the machines
  173.  *           correspond to the characters in the sig's.  on one pass through
  174.  *           the file, all 7 signatures will be found.  all signatures are
  175.  *           8 characters long.  it's also a little faster if we read the file
  176.  *           in big chunks.  also note that we never have to back-up or reread
  177.  *           the file.
  178.  */
  179. void find_offsets( char *buff )
  180. {
  181. long off;
  182. int  m1, m2, m3, m4, m5, m6, m7;
  183. char sig1[8] = { '\x00','\x01','\x02','\x03','\x04','\x05','\x06','\x07' };
  184. char sig2[8] = "$ modes";
  185. char sig3[8] = "$colors";
  186. char sig4[8] = "$macbuf";
  187. char sig5[8] = "$  keys";
  188. char sig6[8] = "$twokey";
  189. char sig7[8] = "$  help";
  190. unsigned int cnt;
  191. register char *b;
  192.  
  193.    /*
  194.     * Let's start the machines 100k into the executable.
  195.     */
  196.    m1 = m2 = m3 = m4 = m5 = m6 = m7 = 0;
  197.    off = 100000L;
  198.    fseek( tde_exe, off, SEEK_SET );
  199.    while (!feof( tde_exe )) {
  200.       cnt = fread( buff, sizeof(char), 8192, tde_exe );
  201.       b = (char *)buff;
  202.       for (; cnt > 0; off++, cnt--, b++) {
  203.          if (m1 < 8) {
  204.             m1 =  sig1[m1] == *b ? m1+1 : 0;
  205.             if (m1 == 8)
  206.                sort_offset = off - 7L;
  207.          }
  208.          if (m2 < 8) {
  209.             m2 =  sig2[m2] == *b ? m2+1 : 0;
  210.             if (m2 == 8)
  211.                mode_offset = off - 7L;
  212.          }
  213.          if (m3 < 8) {
  214.             m3 =  sig3[m3] == *b ? m3+1 : 0;
  215.             if (m3 == 8)
  216.                color_offset = off - 7L;
  217.          }
  218.          if (m4 < 8) {
  219.             m4 =  sig4[m4] == *b ? m4+1 : 0;
  220.             if (m4 == 8)
  221.                macro_offset = off - 7L;
  222.          }
  223.          if (m5 < 8) {
  224.             m5 =  sig5[m5] == *b ? m5+1 : 0;
  225.             if (m5 == 8)
  226.                keys_offset = off - 7L;
  227.          }
  228.          if (m6 < 8) {
  229.             m6 =  sig6[m6] == *b ? m6+1 : 0;
  230.             if (m6 == 8)
  231.                two_key_offset = off - 7L;
  232.          }
  233.          if (m7 < 8) {
  234.             m7 =  sig7[m7] == *b ? m7+1 : 0;
  235.             if (m7 == 8)
  236.                help_offset = off - 7L;
  237.          }
  238.       }
  239.    }
  240. }
  241.  
  242.  
  243. /*
  244.  * Name:    xygoto
  245.  * Date:    July 21, 1991
  246.  * Notes:   Use the video interrupt to set the cursor.
  247.  */
  248. void xygoto( int col, int row )
  249. {
  250. union REGS inregs, outregs;
  251.  
  252.    inregs.h.ah = 2;
  253.    inregs.h.bh = 0;
  254.    inregs.h.dh = row;
  255.    inregs.h.dl = col;
  256.    int86( VIDEO_INT, &inregs, &outregs );
  257. }
  258.  
  259.  
  260. /*
  261.  * Name:    video_config
  262.  * Date:    July 21, 1991
  263.  * Notes:   See main.c for more info.
  264.  */
  265. void video_config( void )
  266. {
  267. #pragma pack( 1 )    /* Use pragma to force packing on byte boundaries. */
  268.  
  269. struct LOWMEMVID
  270. {
  271.    char     vidmode;           /* 0x449 */
  272.    unsigned scrwid;            /* 0x44A */
  273.    unsigned scrlen;            /* 0x44C */
  274.    unsigned scroff;            /* 0x44E */
  275.    struct   LOCATE
  276.    {
  277.       unsigned char col;
  278.       unsigned char row;
  279.    } csrpos[8];                /* 0x450 */
  280.    struct   CURSIZE
  281.    {
  282.       unsigned char end;
  283.       unsigned char start;
  284.    } csrsize;                  /* 0x460 */
  285.    char      page;             /* 0x462 */
  286.    unsigned  addr_6845;        /* 0x463 */
  287.    char      crt_mode_set;     /* 0x465 */
  288.    char      crt_palette;      /* 0x466 */
  289.    char      system_stuff[29]; /* 0x467 */
  290.    char