home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / editors / tde150.arj / CFGMODES.C < prev    next >
C/C++ Source or Header  |  1992-04-01  |  11KB  |  475 lines

  1. /*
  2.  * Author:        Frank Davis
  3.  * Date:          January 20, 1992
  4.  * Compiler:      MSC 6.0a and QuickC 2.5
  5.  *
  6.  * This program is released into the public domain.  You may distribute
  7.  * it freely, Frank Davis
  8.  */
  9.  
  10.  
  11. /********    EXTREMELY IMPORTANT   ************/
  12. /*
  13.  * If you modify tde, it is your responsibility to find the offset of
  14.  * "mode_infos mode", a global structure declared in ed.c.
  15.  *
  16.  * If you don't change the default modes, search for the following string,
  17.  * a hexadecimal integer array, in your new executable file:
  18.  *
  19.  *  0000 0000 0100 0100 0100 0800 0000 0000
  20.  *
  21.  * Then, replace MODE_OFFSET with your new one and recompile tdecfg
  22.  * with the new offset.
  23.  */
  24.  
  25. #define  MODE_OFFSET   67914l
  26.  
  27. /*******     EXTREMELY IMPORTANT   ************/
  28.  
  29.  
  30. #include <bios.h>
  31. #include <dos.h>
  32. #include <stdlib.h>
  33. #include <stdio.h>
  34. #include <string.h>
  35.  
  36. #include "tdecfg.h"
  37. #include "cfgmodes.h"
  38.  
  39.  
  40. extern struct vcfg cfg;         /* video stuff */
  41. extern FILE *tde_exe;           /* FILE pointer to tde.exe */
  42.  
  43. MODE_INFO in_modes;           /* play around with modes in this struct */
  44.  
  45. int color;
  46.  
  47. /*
  48.  * Name:    tdemodes
  49.  * Date:    July 21, 1991
  50.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  51.  *          variables  2) show the user a color sample  3) make the changes
  52.  *          permanent if desired.
  53.  */
  54. void tdemodes( void )
  55. {
  56.    color = 7;
  57.    initialize_modes( );
  58.    show_init_mode( );
  59.    change_modes( );
  60. }
  61.  
  62.  
  63. /*
  64.  * Name:    initialize_modes
  65.  * Date:    July 21, 1991
  66.  * Notes:   Set up the global mode variables.
  67.  */
  68. void initialize_modes( void )
  69. {
  70. int i, j;
  71.  
  72.    fseek( tde_exe, MODE_OFFSET, SEEK_SET );
  73.    fread( (void *)&in_modes, sizeof( MODE_INFO ), 1, tde_exe );
  74.  
  75.    mode[Ins].mode     = in_modes.insert;
  76.    mode[Ind].mode     = in_modes.indent;
  77.    mode[Tab].mode     = in_modes.tab_size;
  78.    mode[Write_Z].mode = in_modes.control_z;
  79.    mode[Crlf].mode    = in_modes.crlf;
  80.    mode[Trim].mode    = in_modes.trailing;
  81.    mode[Eol].mode     = in_modes.show_eol;
  82.    mode[WW].mode      = in_modes.word_wrap;
  83.    mode[Left].mode    = in_modes.left_margin;
  84.    mode[Para].mode    = in_modes.parg_margin;
  85.    mode[Right].mode   = in_modes.right_margin;
  86.    mode[Size].mode    = in_modes.cursor_size;
  87.    mode[Backup].mode  = in_modes.do_backups;
  88.    mode[Ruler].mode   = in_modes.ruler;
  89. }
  90.  
  91.  
  92. /*
  93.  * Name:    show_init_mode
  94.  * Date:    July 21, 1991
  95.  * Notes:   Draw the sample screen.
  96.  */
  97. void show_init_mode( void )
  98. {
  99. char *sample;
  100. int line, i;
  101.  
  102.    cls( );
  103.    xygoto( -1, -1 );
  104.    for (i=0,line=3; sample != NULL; line++, i++) {
  105.       sample = mode_screen[i];
  106.       s_output( (char far *)sample, line, 0, 7 );
  107.    }
  108.    for (i=0; i<14; i++)
  109.       (*mode[i].show_me)();
  110. }
  111.  
  112.  
  113. /*
  114.  * Name:    show_insert_mode
  115.  * Date:    January 20, 1992
  116.  */
  117. void show_insert_mode( void )
  118. {
  119. char *p[] = {
  120.    "Overwrite",
  121.    "Insert   "
  122. };
  123.  
  124.    s_output( p[mode[Ins].mode], mode[Ins].line, mode[Ins].col, color );
  125. }
  126.  
  127.  
  128. /*
  129.  * Name:    show_indent_mode
  130.  * Date:    January 20, 1992
  131.  */
  132. void show_indent_mode( void )
  133. {
  134. char *p[] = {
  135.    "Indent off",
  136.    "Indent on "
  137. };
  138.  
  139.    s_output( p[mode[Ind].mode], mode[Ind].line, mode[Ind].col, color );
  140. }
  141.  
  142.  
  143. /*
  144.  * Name:    show_tabsize
  145.  * Date:    January 20, 1992
  146.  */
  147. void show_tabsize( void )
  148. {
  149. char temp[10];
  150.  
  151.    s_output( "   ", mode[Tab].line, mode[Tab].col, color );
  152.    s_output( itoa(mode[Tab].mode,temp,10), mode[Tab].line, mode[Tab].col,color);
  153. }
  154.  
  155.  
  156. /*
  157.  * Name:    show_controlz
  158.  * Date:    January 20, 1992
  159.  */
  160. void show_controlz( void )
  161. {
  162. char *p[] = {
  163.    "Write ^Z",
  164.    "No ^Z   ",
  165. };
  166.  
  167.    s_output( p[mode[Write_Z].mode], mode[Write_Z].line,mode[Write_Z].col,color);
  168. }
  169.  
  170.  
  171. /*
  172.  * Name:    show_eol_out
  173.  * Date:    January 20, 1992
  174.  */
  175. void show_eol_out( void )
  176. {
  177. char *p[] = {
  178.    "",
  179.    "CRLF",
  180.    "LF  ",
  181. };
  182.  
  183.    s_output( p[mode[Crlf].mode], mode[Crlf].line, mode[Crlf].col, color );
  184. }
  185.  
  186.  
  187. /*
  188.  * Name:    show_trail
  189.  * Date:    January 20, 1992
  190.  */
  191. void show_trail( void )
  192. {
  193. char *p[] = {
  194.    "No Trim",
  195.    "Trim   ",
  196. };
  197.  
  198.    s_output( p[mode[Trim].mode], mode[Trim].line, mode[Trim].col, color );
  199. }
  200.  
  201.  
  202. /*
  203.  * Name:    show_eol_display
  204.  * Date:    January 20, 1992
  205.  */
  206. void show_eol_display( void )
  207. {
  208. char *p[] = {
  209.    "Off",
  210.    "On ",
  211. };
  212.  
  213.    s_output( p[mode[Eol].mode], mode[Eol].line, mode[Eol].col, color );
  214. }
  215.  
  216.  
  217. /*
  218.  * Name:    show_ww
  219.  * Date:    January 20, 1992
  220.  */
  221. void show_ww( void )
  222. {
  223. char *p[] = {
  224.    "Off",
  225.    "On ",
  226. };
  227.  
  228.    s_output( p[mode[WW].mode], mode[WW].line, mode[WW].col, color );
  229. }
  230.  
  231.  
  232. /*
  233.  * Name:    show_left
  234.  * Date:    January 20, 1992
  235.  */
  236. void show_left( void )
  237. {
  238. char temp[10];
  239.  
  240.    s_output( "   ", mode[Left].line, mode[Left].col, color );
  241.    s_output( itoa( mode[Left].mode+1, temp, 10 ), mode[Left].line, mode[Left].col,
  242.              color);
  243. }
  244.  
  245.  
  246. /*
  247.  * Name:    show_para
  248.  * Date:    January 20, 1992
  249.  */
  250. void show_para( void )
  251. {
  252. char temp[10];
  253.  
  254.    s_output( "   ", mode[Para].line, mode[Para].col, color );
  255.    s_output( itoa( mode[Para].mode+1, temp, 10 ), mode[Para].line, mode[Para].col,
  256.              color);
  257. }
  258.  
  259.  
  260. /*
  261.  * Name:    show_right
  262.  * Date:    January 20, 1992
  263.  */
  264. void show_right( void )
  265. {
  266. char temp[10];
  267.  
  268.    s_output( "   ", mode[Right].line, mode[Right].col, color );
  269.    s_output( itoa(mode[Right].mode+1,temp,10), mode[Right].line, mode[Right].col,
  270.              color);
  271. }
  272.  
  273.  
  274. /*
  275.  * Name:    show_cursor_size
  276.  * Date:    January 20, 1992
  277.  */
  278. void show_cursor_size( void )
  279. {
  280. char *p[] = {
  281.    "Small Insert Cursor",
  282.    "Big Insert Cursor  ",
  283. };
  284.  
  285.    s_output( p[mode[Size].mode], mode[Size].line, mode[Size].col, color );
  286. }
  287.  
  288.  
  289. /*
  290.  * Name:    show_backup_mode
  291.  * Date:    January 20, 1992
  292.  */
  293. void show_backup_mode( void )
  294. {
  295. char *p[] = {
  296.    "No .bak files    ",
  297.    "Create .bak files"
  298. };
  299.  
  300.    s_output( p[mode[Backup].mode], mode[Backup].line, mode[Backup].col, color );
  301. }
  302.  
  303.  
  304. /*
  305.  * Name:    show_backup_mode
  306.  * Date:    January 20, 1992
  307.  */
  308. void show_ruler_mode( void )
  309. {
  310. char *p[] = {
  311.    "No ruler  ",
  312.    "Show ruler"
  313. };
  314.  
  315.    s_output( p[mode[Ruler].mode], mode[Ruler].line, mode[Ruler].col, color );
  316. }
  317.  
  318.  
  319. /*
  320.  * Name:    change_modes
  321.  * Date:    July 21, 1991
  322.  * Notes:   Real workhorse function of the utility.  Get a key and then
  323.  *          figure out what to do with it.
  324.  */
  325. void change_modes( void )
  326. {
  327. int c;
  328. int m;
  329. int new_field;
  330.  
  331.    m = 0;
  332.    xygoto( mode[m].col, mode[m].line );
  333.    color = 112;
  334.    (*mode[m].show_me)();
  335.    for (c=0; c != F3  &&  c != F10  &&  c != ESC;) {
  336.       c = getkey( );
  337.       new_field = FALSE;
  338.       color = 112;
  339.       switch (c) {
  340.          case RTURN :
  341.          case DOWN  :
  342.             color = 7;
  343.             (*mode[m].show_me)();
  344.             ++m;
  345.             if (m > 13)
  346.                m = 0;
  347.             new_field = TRUE;
  348.             break;
  349.          case UP    :
  350.             color = 7;
  351.             (*mode[m].show_me)();
  352.             --m;
  353.             if (m < 0)
  354.                m = 13;
  355.             new_field = TRUE;
  356.             break;
  357.          case LEFT  :
  358.             switch (m) {
  359.                case Ins     :
  360.                case Ind     :
  361.                case Write_Z :
  362.                case Trim    :
  363.                case Eol     :
  364.                case WW      :
  365.                case Size    :
  366.                case Backup  :
  367.                case Ruler   :
  368.                   mode[m].mode = !mode[m].mode;
  369.                   break;
  370.                case Tab     :
  371.                   if (mode[m].mode > 1)
  372.                      --mode[m].mode;
  373.                   else
  374.                      mode[m].mode = 255 / 2;
  375.                   break;
  376.                case Crlf    :
  377.                   if (mode[m].mode == CRLF)
  378.                      mode[m].mode = LF;
  379.                   else
  380.                      mode[m].mode = CRLF;
  381.                   break;
  382.                case Left    :
  383.                case Para    :
  384.                   if (mode[m].mode > 0)
  385.                      --mode[m].mode;
  386.                   else
  387.                      mode[m].mode = mode[Right].mode - 1;
  388.                   break;
  389.                case Right   :
  390.                   if (mode[m].mode > mode[Left].mode + 1 &&
  391.                       mode[m].mode > mode[Para].mode + 1)
  392.                      --mode[m].mode;
  393.                   else
  394.                      mode[m].mode = 254;
  395.                   break;
  396.             }
  397.             (*mode[m].show_me)();
  398.             break;
  399.          case RIGHT :
  400.             switch (m) {
  401.                case Ins     :
  402.                case Ind     :
  403.                case Write_Z :
  404.                case Trim    :
  405.                case Eol     :
  406.                case WW      :
  407.                case Size    :
  408.                case Backup  :
  409.                case Ruler   :
  410.                   mode[m].mode = !mode[m].mode;
  411.                   break;
  412.                case Tab     :
  413.                   if (mode[m].mode < 255 / 2)
  414.                     ++mode[m].mode;
  415.                   else
  416.                      mode[m].mode = 1;
  417.                   break;
  418.                case Crlf    :
  419.                   if (mode[m].mode == CRLF)
  420.                      mode[m].mode = LF;
  421.                   else
  422.                      mode[m].mode = CRLF;
  423.                   break;
  424.                case Left    :
  425.                case Para    :
  426.                   if (mode[m].mode < mode[Right].mode)
  427.                      ++mode[m].mode;
  428.                   else
  429.                      mode[m].mode = 0;
  430.                   break;
  431.                case Right   :
  432.                   if (mode[m].mode < 254)
  433.                      ++mode[m].mode;
  434.                   else {
  435.                      if (mode[Left].mode < mode[Para].mode)
  436.                         mode[m].mode = mode[Para].mode + 1;
  437.                      else
  438.                         mode[m].mode = mode[Left].mode + 1;
  439.                   }
  440.                   break;
  441.             }
  442.             (*mode[m].show_me)();
  443.             break;
  444.       }
  445.       if (new_field) {
  446.          color = 112;
  447.          (*mode[m].show_me)();
  448.          xygoto( mode[m].col, mode[m].line );
  449.       }
  450.    }
  451.  
  452.    /*
  453.     * write changes to "tde.exe" if user presses F10.
  454.     */
  455.    if (c == F10) {
  456.       in_modes.insert       = mode[Ins].mode;
  457.       in_modes.indent       = mode[Ind].mode;
  458.       in_modes.tab_size     = mode[Tab].mode;
  459.       in_modes.control_z    = mode[Write_Z].mode;
  460.       in_modes.crlf         = mode[Crlf].mode;
  461.       in_modes.trailing     = mode[Trim].mode;
  462.       in_modes.show_eol     = mode[Eol].mode;
  463.       in_modes.word_wrap    = mode[WW].mode;
  464.       in_modes.left_margin  = mode[Left].mode;
  465.       in_modes.parg_margin  = mode[Para].mode;
  466.       in_modes.right_margin = mode[Right].mode;
  467.       in_modes.cursor_size  = mode[Size].mode;
  468.       in_modes.do_backups   = mode[Backup].mode;
  469.       in_modes.ruler        = mode[Ruler].mode;
  470.       fseek( tde_exe, MODE_OFFSET, SEEK_SET );
  471.       fwrite( (void *)&in_modes, sizeof( MODE_INFO ), 1, tde_exe );
  472.    }
  473.    cls( );
  474. }
  475.