home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / EDITOR / TDE120.ZIP / TDECOLOR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-05  |  10.7 KB  |  404 lines

  1. /*
  2.  * I have had several requests to implement a method for changing the colors
  3.  * used in tde.  I thought about using a configuration file, but I really
  4.  * didn't like that route.  Changing the executable file seemed the best way
  5.  * to go.  That way, you only need one file to run tde - the executable.
  6.  * Also, I didn't have to add a bunch of code to tde to parse a configuration
  7.  * file.  It doesn't take a lot of time to figure out the offsets of the those
  8.  * variables to initialize in tde.exe, so it's fairly easy to do.
  9.  *
  10.  * Program name:  tdecolor
  11.  * Author:        Frank Davis
  12.  * Date:          July 21, 1991
  13.  * Compiler:      MSC 6.0a and QuickC 2.5
  14.  *                cl /AS /Gs tdecolor.c
  15.  *                exehdr /max:1000 tdecolor
  16.  *
  17.  * This program is released into the public domain.  You may distribute
  18.  * it freely, Frank Davis
  19.  */
  20.  
  21.  
  22. /********    EXTREMELY IMPORTANT   ************/
  23. /*
  24.  * If you modify tde, it is your responsibility to find the offset of
  25.  * "static int colors" in function "hw_initialize" in file "main.c" in your
  26.  * new executable, tde.exe.
  27.  *
  28.  * If you don't change the default colors, search for the following string (a
  29.  * hexadecimal integer array) in your new executable file:
  30.  *
  31.  *  7000 0700
  32.  *
  33.  * Then, replace COLOR_OFFSET with your new one and recompile tdecolor.exe
  34.  * with the new offset.
  35.  */
  36.  
  37. #define  COLOR_OFFSET   50432l
  38.  
  39. /*******     EXTREMELY IMPORTANT   ************/
  40.  
  41.  
  42. #include <bios.h>
  43. #include <dos.h>
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <string.h>
  47.  
  48. #include "tdecolor.h"
  49. #include "tdecfg.h"
  50.  
  51.  
  52. /*
  53.  * Default color settings.  Incidentally, I'm color blind (mild red-green) and
  54.  * the default colors look fine to me. ;*)
  55.  */
  56. static int colors[2][8] = {
  57.    { HERC_REVERSE, HERC_NORMAL, HERC_REVERSE, HERC_REVERSE, HERC_HIGH,
  58.      HERC_NORMAL, HERC_NORMAL, HERC_HIGH },
  59.    { COLOR_HEAD, COLOR_TEXT, COLOR_MODE, COLOR_BLOCK, COLOR_MESSAGE,
  60.      COLOR_HELP, COLOR_WRAP, COLOR_EOF }
  61. };
  62.  
  63. extern struct vcfg cfg;         /* video stuff */
  64. extern FILE *tde_exe;           /* FILE pointer to tde.exe */
  65.  
  66. static int temp_colors[2][8];   /* play around with colors in this array */
  67. static int index;               /* 0 = Monochrome colors, 1 = color colors */
  68.  
  69.  
  70. /*
  71.  * Name:    tdecolor
  72.  * Date:    July 21, 1991
  73.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  74.  *          variables  2) show the user a color sample  3) make the changes
  75.  *          permanent if desired.
  76.  */
  77. void tdecolor( void )
  78. {
  79.    initialize_color( );
  80.    show_init_sample( );
  81.    change_colors( );
  82. }
  83.  
  84.  
  85. /*
  86.  * Name:    initialize
  87.  * Date:    July 21, 1991
  88.  * Notes:   Set up all of the global variables.
  89.  */
  90. void initialize_color( void )
  91. {
  92. int i, j;
  93.  
  94.    fseek( tde_exe, COLOR_OFFSET, SEEK_SET );
  95.    fread( (void *)temp_colors, sizeof( temp_colors ), 1, tde_exe );
  96.  
  97.    if (cfg.color == FALSE)
  98.       index = 0;
  99.    else
  100.       index = 1;
  101.  
  102.    fields[0].color = temp_colors[index][HELP];
  103.    fields[1].color = temp_colors[index][HEAD];
  104.    fields[2].color = temp_colors[index][TEXT];
  105.    fields[3].color = temp_colors[index][BLOCK];
  106.    fields[4].color = temp_colors[index][WARNING];
  107.    fields[5].color = temp_colors[index][MODE];
  108.    fields[6].color = temp_colors[index][WRAP];
  109.    fields[7].color = temp_colors[index][CEOF];
  110.  
  111.    fields[0].show_me = show_help_color;
  112.    fields[1].show_me = show_fileheader_color;
  113.    fields[2].show_me = show_text_color;
  114.    fields[3].show_me = show_block_color;
  115.    fields[4].show_me = show_warning_color;
  116.    fields[5].show_me = show_mode_color;
  117.    fields[6].show_me = show_wrapped_color;
  118.    fields[7].show_me = show_eof_color;
  119. }
  120.  
  121.  
  122. /*
  123.  * Name:    show_init_sample
  124.  * Date:    July 21, 1991
  125.  * Notes:   Draw all of the sample screens.
  126.  */
  127. void show_init_sample( void )
  128. {
  129. char *sample;
  130. int line, i, j, k, l;
  131. char temp[6], num[6];
  132. char far *p;
  133.  
  134.    xygoto( -1, -1 );
  135.    sample = sample_screen[0];
  136.    for (line=0; sample != NULL; ) {
  137.       s_output( (char far *)sample, line, 0, 7 );
  138.       sample = sample_screen[++line];
  139.    }
  140.    for (i=0; i<8; i++)
  141.       (*fields[i].show_me)();
  142.    sample = field_screen[0];
  143.    for (line=12, i=1; sample != NULL; line++,i++) {
  144.       s_output( (char far *)sample, line, 0, 7 );
  145.       sample = field_screen[i];
  146.    }
  147.    p = (char far *)temp;
  148.    for (i=0,k=0,line=17; i<8; i++, line++) {
  149.       for (j=0,l=0; j<16; j++, k++,l+=5) {
  150.          color_number( temp, k );
  151.          s_output( p, line, l, k );
  152.       }
  153.    }
  154.    for (i=0; i<8; i++) {
  155.       color_number( temp, fields[i].color );
  156.       s_output( p, fields[i].line, fields[i].col, fields[i].color );
  157.    }
  158. }
  159.  
  160.  
  161. /*
  162.  * Name:    color_number
  163.  * Date:    July 21, 1991
  164.  * Passed:  dest:  buffer to store the color sample
  165.  *          num:   attribute number
  166.  * Notes:   Show the use what the foreground and background colors look like.
  167.  */
  168. void color_number( char *dest, int num )
  169. {
  170. int i, j, k;
  171. char temp[6];
  172.  
  173.    strcpy( dest, "[   ]" );
  174.    itoa( num, temp, 10 );
  175.    i = strlen( temp );
  176.    j = 4 - i;
  177.    for (k=0; i > 0; i--,j++, k++)
  178.       dest[j] = temp[k];
  179. }
  180.  
  181.  
  182. /*
  183.  * Name:    current_color_number
  184.  * Date:    July 21, 1991
  185.  * Passed:  dest:  buffer to store the color sample
  186.  *          num:   attribute number
  187.  * Notes:   Put '*' around the sample color to give the user an idea of where
  188.  *          the current field is.
  189.  */
  190. void current_color_number( char *dest, int num )
  191. {
  192. int i, j, k;
  193. char temp[6];
  194.  
  195.    strcpy( dest, "*   *" );
  196.    itoa( num, temp, 10 );
  197.    i = strlen( temp );
  198.    j = 4 - i;
  199.    for (k=0; i > 0; i--,j++, k++)
  200.       dest[j] = temp[k];
  201. }
  202.  
  203.  
  204. /*
  205.  * Name:    show_help_color
  206.  * Date:    July 21, 1991
  207.  */
  208. void show_help_color( void )
  209. {
  210. int color;
  211. int line, len;
  212.  
  213.    color = fields[0].color;
  214.    for (line=1; line <11; line++)
  215.       hlight_line( 1, line, 37, color );
  216. }
  217.  
  218.  
  219. /*
  220.  * Name:    show_fileheader_color
  221.  * Date:    July 21, 1991
  222.  */
  223. void show_fileheader_color( void )
  224. {
  225.    hlight_line( 41, 1, 38, fields[1].color );
  226. }
  227.  
  228.  
  229. /*
  230.  * Name:    show_text_color
  231.  * Date:    July 21, 1991
  232.  */
  233. void show_text_color( void )
  234. {
  235. int color;
  236. int line, len;
  237.  
  238.    color = fields[2].color;
  239.    for (line=2; line <6; line++)
  240.       hlight_line( 41, line, 38, color );
  241. }
  242.  
  243.  
  244. /*
  245.  * Name:    show_block_color
  246.  * Date:    July 21, 1991
  247.  */
  248. void show_block_color( void )
  249. {
  250. int color;
  251. int line, len;
  252.  
  253.    color = fields[3].color;
  254.    for (line=6; line <8; line++)
  255.       hlight_line( 41, line, 38, color );
  256. }
  257.  
  258.  
  259. /*
  260.  * Name:    show_warning_color
  261.  * Date:    July 21, 1991
  262.  */
  263. void show_warning_color( void )
  264. {
  265.    hlight_line( 41, 9, 38, fields[4].color );
  266. }
  267.  
  268.  
  269. /*
  270.  * Name:    show_mode_color
  271.  * Date:    July 21, 1991
  272.  */
  273. void show_mode_color( void )
  274. {
  275.    hlight_line( 41, 10, 26, fields[5].color );
  276. }
  277.  
  278.  
  279. /*
  280.  * Name:    show_wrapped_color
  281.  * Date:    July 21, 1991
  282.  */
  283. void show_wrapped_color( void )
  284. {
  285.    hlight_line( 67, 10, 12, fields[6].color );
  286. }
  287.  
  288.  
  289. /*
  290.  * Name:    show_eof_color
  291.  * Date:    July 21, 1991
  292.  */
  293. void show_eof_color( void )
  294. {
  295.    hlight_line( 41, 8, 38, fields[7].color );
  296. }
  297.  
  298.  
  299. /*
  300.  * Name:    change_colors
  301.  * Date:    July 21, 1991
  302.  * Notes:   Real workhorse function of the utility.  Get a key and then
  303.  *          figure out what to do with it.
  304.  */
  305. void change_colors( void )
  306. {
  307. int c;
  308. int area;
  309. int color;
  310. int new_color;
  311. int i;
  312. char temp[6];
  313. char far *p;
  314.  
  315.    p = (char far *)temp;
  316.    area = 0;
  317.    current_color_number( temp, fields[area].color );
  318.    s_output( p, fields[area].line, fields[area].col, fields[area].color );
  319.    xygoto( fields[area].col+3, fields[area].line );
  320.    for (c=0; c != F3  &&  c != F10  &&  c != ESC;) {
  321.       new_color = FALSE;
  322.       c = getkey( );
  323.       switch (c) {
  324.          case RTURN :
  325.             color_number( temp, fields[area].color );
  326.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  327.             ++area;
  328.             if (area > 7)
  329.                area = 0;
  330.             current_color_number( temp, fields[area].color );
  331.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  332.             xygoto( fields[area].col+3, fields[area].line );
  333.             break;
  334.          case UP :
  335.             --fields[area].color;
  336.             if (fields[area].color < 0)
  337.                fields[area].color = 127;
  338.             new_color = TRUE;
  339.             break;
  340.          case DOWN :
  341.             ++fields[area].color;
  342.             if (fields[area].color > 127)
  343.                fields[area].color = 0;
  344.             new_color = TRUE;
  345.             break;
  346.          case PGUP :
  347.             fields[area].color -= 16;
  348.             if (fields[area].color < 0)
  349.                fields[area].color = (fields[area].color & 0x000f) + 0x70;
  350.             new_color = TRUE;
  351.             break;
  352.          case PGDN :
  353.             fields[area].color += 16;
  354.             if (fields[area].color > 127)
  355.                fields[area].color = fields[area].color & 0x000f;
  356.             new_color = TRUE;
  357.             break;
  358.          case F2 :
  359.  
  360.             /*
  361.              * get back the original colors and display
  362.              */
  363.             fields[0].color = colors[index][HELP];
  364.             fields[1].color = colors[index][HEAD];
  365.             fields[2].color = colors[index][TEXT];
  366.             fields[3].color = colors[index][BLOCK];
  367.             fields[4].color = colors[index][WARNING];
  368.             fields[5].color = colors[index][MODE];
  369.             fields[6].color = colors[index][WRAP];
  370.             fields[7].color = colors[index][CEOF];
  371.             for (i=0; i<8; i++) {
  372.                color_number( temp, fields[i].color );
  373.                s_output( p, fields[i].line, fields[i].col, fields[i].color );
  374.                (*fields[i].show_me)();
  375.             }
  376.             current_color_number( temp, fields[area].color );
  377.             s_output( p, fields[area].line, fields[area].col, fields[area].color );
  378.             break;
  379.       }
  380.       if (new_color) {
  381.          current_color_number( temp, fields[area].color );
  382.          s_output( p, fields[area].line, fields[area].col, fields[area].color );
  383.          (*fields[area].show_me)();
  384.       }
  385.    }
  386.  
  387.    /*
  388.     * write changes to "tde.exe" if user presses F10.
  389.     */
  390.    if (c == F10) {
  391.       temp_colors[index][HELP]    = fields[0].color;
  392.       temp_colors[index][HEAD]    = fields[1].color;
  393.       temp_colors[index][TEXT]    = fields[2].color;
  394.       temp_colors[index][BLOCK]   = fields[3].color;
  395.       temp_colors[index][WARNING] = fields[4].color;
  396.       temp_colors[index][MODE]    = fields[5].color;
  397.       temp_colors[index][WRAP]    = fields[6].color;
  398.       temp_colors[index][CEOF]    = fields[7].color;
  399.       fseek( tde_exe, COLOR_OFFSET, SEEK_SET );
  400.       fwrite( (void *)temp_colors, sizeof( temp_colors ), 1, tde_exe );
  401.    }
  402.    cls( );
  403. }
  404.