home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / TEXT / EDITOR / TDE200.ZIP / CFGMODES.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-05  |  12.7 KB  |  550 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. /*******     EXTREMELY IMPORTANT   ************/
  25.  
  26.  
  27. #include <bios.h>
  28. #include <dos.h>
  29. #include <stdlib.h>
  30. #include <stdio.h>
  31. #include <string.h>
  32.  
  33. #include "tdecfg.h"
  34. #include "cfgmodes.h"
  35.  
  36.  
  37. extern struct vcfg cfg;         /* video stuff */
  38. extern FILE *tde_exe;           /* FILE pointer to tde.exe */
  39.  
  40. MODE_INFO in_modes;           /* play around with modes in this struct */
  41.  
  42. int color;
  43.  
  44. /*
  45.  * Name:    tdemodes
  46.  * Date:    July 21, 1991
  47.  * Notes:   Strategy is fairly straight forward -  1) initialize all the
  48.  *          variables  2) show the user a color sample  3) make the changes
  49.  *          permanent if desired.
  50.  */
  51. void tdemodes( void )
  52. {
  53.    color = 7;
  54.    initialize_modes( );
  55.    show_init_mode( );
  56.    change_modes( );
  57. }
  58.  
  59.  
  60. /*
  61.  * Name:    initialize_modes
  62.  * Date:    July 21, 1991
  63.  * Notes:   Set up the global mode variables.
  64.  */
  65. void initialize_modes( void )
  66. {
  67. int i, j;
  68.  
  69.    fseek( tde_exe, MODE_OFFSET, SEEK_SET );
  70.    fread( (void *)&in_modes, sizeof( MODE_INFO ), 1, tde_exe );
  71.  
  72.    mode[Ins].mode     = in_modes.insert;
  73.    mode[Ind].mode     = in_modes.indent;
  74.    mode[TAB].mode     = in_modes.tab_size;
  75.    mode[Smart].mode   = in_modes.smart_tab;
  76.    mode[Write_Z].mode = in_modes.control_z;
  77.    mode[Crlf].mode    = in_modes.crlf;
  78.    mode[Trim].mode    = in_modes.trailing;
  79.    mode[Eol].mode     = in_modes.show_eol;
  80.    mode[WW].mode      = in_modes.word_wrap;
  81.    mode[Left].mode    = in_modes.left_margin;
  82.    mode[Para].mode    = in_modes.parg_margin;
  83.    mode[Right].mode   = in_modes.right_margin;
  84.    mode[Size].mode    = in_modes.cursor_size;
  85.    mode[Backup].mode  = in_modes.do_backups;
  86.    mode[Ruler].mode   = in_modes.ruler;
  87.    mode[Date].mode    = in_modes.date_style;
  88.    mode[Time].mode    = in_modes.time_style;
  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<17; 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_smart_mode
  219.  * Date:    January 20, 1992
  220.  */
  221. void show_smart_mode( void )
  222. {
  223. char *p[] = {
  224.    "Off",
  225.    "On ",
  226. };
  227.  
  228.    s_output( p[mode[Smart].mode], mode[Smart].line, mode[Smart].col, color );
  229. }
  230.  
  231.  
  232. /*
  233.  * Name:    show_ww
  234.  * Date:    January 20, 1992
  235.  */
  236. void show_ww( void )
  237. {
  238. char *p[] = {
  239.    "Off                ",
  240.    "Fixed margins      ",
  241.    "Dynamic left margin",
  242. };
  243.  
  244.    s_output( p[mode[WW].mode], mode[WW].line, mode[WW].col, color );
  245. }
  246.  
  247.  
  248. /*
  249.  * Name:    show_left
  250.  * Date:    January 20, 1992
  251.  */
  252. void show_left( void )
  253. {
  254. char temp[10];
  255.  
  256.    s_output( "   ", mode[Left].line, mode[Left].col, color );
  257.    s_output( itoa( mode[Left].mode+1, temp, 10 ), mode[Left].line, mode[Left].col,
  258.              color);
  259. }
  260.  
  261.  
  262. /*
  263.  * Name:    show_para
  264.  * Date:    January 20, 1992
  265.  */
  266. void show_para( void )
  267. {
  268. char temp[10];
  269.  
  270.    s_output( "   ", mode[Para].line, mode[Para].col, color );
  271.    s_output( itoa( mode[Para].mode+1, temp, 10 ), mode[Para].line, mode[Para].col,
  272.              color);
  273. }
  274.  
  275.  
  276. /*
  277.  * Name:    show_right
  278.  * Date:    January 20, 1992
  279.  */
  280. void show_right( void )
  281. {
  282. char temp[10];
  283.  
  284.    s_output( "   ", mode[Right].line, mode[Right].col, color );
  285.    s_output( itoa(mode[Right].mode+1,temp,10), mode[Right].line, mode[Right].col,
  286.              color);
  287. }
  288.  
  289.  
  290. /*
  291.  * Name:    show_cursor_size
  292.  * Date:    January 20, 1992
  293.  */
  294. void show_cursor_size( void )
  295. {
  296. char *p[] = {
  297.    "Small Insert Cursor",
  298.    "Big Insert Cursor  ",
  299. };
  300.  
  301.    s_output( p[mode[Size].mode], mode[Size].line, mode[Size].col, color );
  302. }
  303.  
  304.  
  305. /*
  306.  * Name:    show_backup_mode
  307.  * Date:    January 20, 1992
  308.  */
  309. void show_backup_mode( void )
  310. {
  311. char *p[] = {
  312.    "No .bak files    ",
  313.    "Create .bak files"
  314. };
  315.  
  316.    s_output( p[mode[Backup].mode], mode[Backup].line, mode[Backup].col, color );
  317. }
  318.  
  319.  
  320. /*
  321.  * Name:    show_backup_mode
  322.  * Date:    January 20, 1992
  323.  */
  324. void show_ruler_mode( void )
  325. {
  326. char *p[] = {
  327.    "No ruler  ",
  328.    "Show ruler"
  329. };
  330.  
  331.    s_output( p[mode[Ruler].mode], mode[Ruler].line, mode[Ruler].col, color );
  332. }
  333.  
  334.  
  335. /*
  336.  * Name:    show_date_style
  337.  * Date:    June 5, 1992
  338.  */
  339. void show_date_style( void )
  340. {
  341. char *p[] = {
  342.    "MM_DD_YY  ",
  343.    "DD_MM_YY  ",
  344.    "YY_MM_DD  ",
  345.    "MM_DD_YYYY",
  346.    "DD_MM_YYYY",
  347.    "YYYY_MM_DD",
  348. };
  349.  
  350.    s_output( p[mode[Date].mode], mode[Date].line, mode[Date].col, color );
  351. }
  352.  
  353.  
  354. /*
  355.  * Name:    show_time_style
  356.  * Date:    June 5, 1992
  357.  */
  358. void show_time_style( void )
  359. {
  360. char *p[] = {
  361.    "12_HOUR",
  362.    "24_HOUR"
  363. };
  364.  
  365.    s_output( p[mode[Time].mode], mode[Time].line, mode[Time].col, color );
  366. }
  367.  
  368.  
  369. /*
  370.  * Name:    change_modes
  371.  * Date:    July 21, 1991
  372.  * Notes:   Real workhorse function of the utility.  Get a key and then
  373.  *          figure out what to do with it.
  374.  */
  375. void change_modes( void )
  376. {
  377. int c;
  378. int m;
  379. int new_field;
  380.  
  381.    m = 0;
  382.    xygoto( mode[m].col, mode[m].line );
  383.    color = 112;
  384.    (*mode[m].show_me)();
  385.    for (c=0; c != F3  &&  c != F10  &&  c != ESC;) {
  386.       c = getkey( );
  387.       new_field = FALSE;
  388.       color = 112;
  389.       switch (c) {
  390.          case RTURN :
  391.          case DOWN  :
  392.             color = 7;
  393.             (*mode[m].show_me)();
  394.             ++m;
  395.             if (m > 16)
  396.                m = 0;
  397.             new_field = TRUE;
  398.             break;
  399.          case UP    :
  400.             color = 7;
  401.             (*mode[m].show_me)();
  402.             --m;
  403.             if (m < 0)
  404.                m = 16;
  405.             new_field = TRUE;
  406.             break;
  407.          case LEFT  :
  408.             switch (m) {
  409.                case Ins     :
  410.                case Ind     :
  411.                case Write_Z :
  412.                case Smart   :
  413.                case Trim    :
  414.                case Eol     :
  415.                case Size    :
  416.                case Backup  :
  417.                case Ruler   :
  418.                case Time    :
  419.                   mode[m].mode = !mode[m].mode;
  420.                   break;
  421.                case TAB     :
  422.                   if (mode[m].mode > 1)
  423.                      --mode[m].mode;
  424.                   else
  425.                      mode[m].mode = 1040 / 2;
  426.                   break;
  427.                case WW      :
  428.                   --mode[m].mode;
  429.                   if (mode[m].mode < 0)
  430.                      mode[m].mode = 2;
  431.                   break;
  432.                case Date    :
  433.                   --mode[m].mode;
  434.                   if (mode[m].mode < 0)
  435.                      mode[m].mode = 5;
  436.                   break;
  437.                case Crlf    :
  438.                   if (mode[m].mode == CRLF)
  439.                      mode[m].mode = LF;
  440.                   else
  441.                      mode[m].mode = CRLF;
  442.                   break;
  443.                case Left    :
  444.                case Para    :
  445.                   if (mode[m].mode > 0)
  446.                      --mode[m].mode;
  447.                   else
  448.                      mode[m].mode = mode[Right].mode - 1;
  449.                   break;
  450.                case Right   :
  451.                   if (mode[m].mode > mode[Left].mode + 1 &&
  452.                       mode[m].mode > mode[Para].mode + 1)
  453.                      --mode[m].mode;
  454.                   else
  455.                      mode[m].mode = 1040;
  456.                   break;
  457.             }
  458.             (*mode[m].show_me)();
  459.             break;
  460.          case RIGHT :
  461.             switch (m) {
  462.                case Ins     :
  463.                case Ind     :
  464.                case Write_Z :
  465.                case Smart   :
  466.                case Trim    :
  467.                case Eol     :
  468.                case Size    :
  469.                case Backup  :
  470.                case Ruler   :
  471.                case Time    :
  472.                   mode[m].mode = !mode[m].mode;
  473.                   break;
  474.                case TAB     :
  475.                   if (mode[m].mode < 1040 / 2)
  476.                     ++mode[m].mode;
  477.                   else
  478.                      mode[m].mode = 1;
  479.                   break;
  480.                case WW      :
  481.                   ++mode[m].mode;
  482.                   if (mode[m].mode > 2)
  483.                      mode[m].mode = 0;
  484.                   break;
  485.                case Date    :
  486.                   ++mode[m].mode;
  487.                   if (mode[m].mode > 5)
  488.                      mode[m].mode = 0;
  489.                   break;
  490.                case Crlf    :
  491.                   if (mode[m].mode == CRLF)
  492.                      mode[m].mode = LF;
  493.                   else
  494.                      mode[m].mode = CRLF;
  495.                   break;
  496.                case Left    :
  497.                case Para    :
  498.                   if (mode[m].mode < mode[Right].mode)
  499.                      ++mode[m].mode;
  500.                   else
  501.                      mode[m].mode = 0;
  502.                   break;
  503.                case Right   :
  504.                   if (mode[m].mode < 1038)
  505.                      ++mode[m].mode;
  506.                   else {
  507.                      if (mode[Left].mode < mode[Para].mode)
  508.                         mode[m].mode = mode[Para].mode + 1;
  509.                      else
  510.                         mode[m].mode = mode[Left].mode + 1;
  511.                   }
  512.                   break;
  513.             }
  514.             (*mode[m].show_me)();
  515.             break;
  516.       }
  517.       if (new_field) {
  518.          color = 112;
  519.          (*mode[m].show_me)();
  520.          xygoto( mode[m].col, mode[m].line );
  521.       }
  522.    }
  523.  
  524.    /*
  525.     * write changes to "tde.exe" if user presses F10.
  526.     */
  527.    if (c == F10) {
  528.       in_modes.insert       = mode[Ins].mode;
  529.       in_modes.indent       = mode[Ind].mode;
  530.       in_modes.tab_size     = mode[TAB].mode;
  531.       in_modes.smart_tab    = mode[Smart].mode;
  532.       in_modes.control_z    = mode[Write_Z].mode;
  533.       in_modes.crlf         = mode[Crlf].mode;
  534.       in_modes.trailing     = mode[Trim].mode;
  535.       in_modes.show_eol     = mode[Eol].mode;
  536.       in_modes.word_wrap    = mode[WW].mode;
  537.       in_modes.left_margin  = mode[Left].mode;
  538.       in_modes.parg_margin  = mode[Para].mode;
  539.       in_modes.right_margin = mode[Right].mode;
  540.       in_modes.cursor_size  = mode[Size].mode;
  541.       in_modes.do_backups   = mode[Backup].mode;
  542.       in_modes.ruler        = mode[Ruler].mode;
  543.       in_modes.date_style   = mode[Date].mode;
  544.       in_modes.time_style   = mode[Time].mode;
  545.       fseek( tde_exe, MODE_OFFSET, SEEK_SET );
  546.       fwrite( (void *)&in_modes, sizeof( MODE_INFO ), 1, tde_exe );
  547.    }
  548.    cls( );
  549. }
  550.