home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / XDME / Src / prefs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  10.6 KB  |  580 lines

  1. /******************************************************************************
  2.  
  3.     MODUL
  4.     prefs.c
  5.  
  6.     DESCRIPTION
  7.     Everything to set, edit, get, load and save settings !
  8.  
  9.     NOTES
  10.  
  11.     BUGS
  12.  
  13.     TODO
  14.  
  15.     EXAMPLES
  16.  
  17.     SEE ALSO
  18.  
  19.     INDEX
  20.  
  21.     HISTORY
  22.     14. Nov 1992    ada created
  23.  
  24. ******************************************************************************/
  25.  
  26. /**************************************
  27.         Includes
  28. **************************************/
  29. #include "defs.h"
  30.  
  31.  
  32. /**************************************
  33.         Globale Variable
  34. **************************************/
  35. Prototype void do_margin      (void);
  36. Prototype void do_wordwrap      (void);
  37. Prototype void do_global      (void);
  38. Prototype void do_setparcol      (void);
  39. Prototype void do_tabstop      (void);
  40. Prototype void do_chfilename      (void);
  41. Prototype void do_savetabs      (void);
  42. Prototype void do_setfont      (void);
  43. Prototype void do_ignorecase      (void);
  44. Prototype void loadconfig      (ED *);
  45. Prototype void do_saveconfig      (void);
  46. Prototype void do_fgpen       (void);
  47. Prototype void do_bgpen       (void);
  48. Prototype void do_hgpen       (void);
  49. Prototype void do_bbpen       (void);
  50. Prototype void do_tpen          (void);
  51. Prototype void do_modified      (void);
  52. Prototype void do_autoindent      (void);
  53. Prototype void do_sizewindow      (void);
  54. Prototype void do_autosplit      (void);
  55. Prototype void do_taskpri      (void);
  56. Prototype void do_debug       (void);
  57. Prototype void do_autounblock      (void);
  58. Prototype void do_followcursor      (void);
  59. Prototype void do_setlinedistance (void);
  60.  
  61.  
  62. /**************************************
  63.       Interne Defines & Strukturen
  64. **************************************/
  65.  
  66.  
  67. /**************************************
  68.         Interne Variable
  69. **************************************/
  70.  
  71.  
  72. /**************************************
  73.        Interne Prototypes
  74. **************************************/
  75.  
  76.  
  77. void do_margin (void)
  78. {
  79.     Ep->config.margin = atoi((char *)av[1]);
  80. } /* do_margin */
  81.  
  82.  
  83. void do_wordwrap (void)
  84. {
  85.     if (Ep->config.wordwrap = test_arg (av[1], Ep->config.wordwrap))
  86.     title("Wordwrap ON");
  87.     else
  88.     title("Wordwrap OFF");
  89. } /* do_wordwrap() */
  90.  
  91.  
  92. void do_global (void)
  93. {
  94.     if (globalflags.global_search = test_arg (av[1], globalflags.global_search))
  95.     title ("Global search ON");
  96.     else
  97.     title ("Global search OFF");
  98. } /* global_search */
  99.  
  100.  
  101. void do_setparcol (void)
  102. {
  103.     Ep->config.wwcol = atoi ((char *)av[1]);
  104. } /* do_setparcol() */
  105.  
  106.  
  107. void do_tabstop (void)
  108. {
  109.     Ep->config.tabstop = atoi ((char *)av[1]);
  110. } /* do_tabstop() */
  111.  
  112.  
  113. void do_insertmode (void)
  114. {
  115.     Ep->config.insertmode = test_arg (av[1], Ep->config.insertmode);
  116.  
  117.     window_title ();
  118. } /* do_insertmode() */
  119.  
  120.  
  121. void do_chfilename (void)
  122. {
  123.     BPTR    new_lock;
  124.     UBYTE * ptr;
  125.  
  126.     text_sync ();
  127.  
  128.     getpathto (Ep->dirlock, av[1], tmp_buffer);
  129.  
  130.     ptr = FilePart (tmp_buffer);
  131.     if (ptr != tmp_buffer)
  132.     {
  133.     char c = *ptr;
  134.     *ptr = 0;
  135.  
  136.     if (new_lock = Lock (tmp_buffer, SHARED_LOCK))
  137.     {
  138.         UnLock (Ep->dirlock);
  139.  
  140.         Ep->dirlock = new_lock;
  141.     } else
  142.     {
  143.         error ("%s:\nCannot get lock for\n`%s'.", av[0], tmp_buffer);
  144.  
  145.         return;
  146.     }
  147.  
  148.     *ptr = c;
  149.     }
  150.  
  151.     strncpy ((char *)Ep->name, ptr, 63);
  152.     Ep->name[63] = 0;
  153.  
  154.     globalflags.MForceTitle = 1;
  155. } /* do_chfilename */
  156.  
  157.  
  158. void do_savetabs (void)
  159. {
  160.     globalflags.Savetabs = test_arg (av[1], globalflags.Savetabs);
  161. } /* do_savetabs() */
  162.  
  163.  
  164. /*
  165.  *  SETFONT font size
  166.  */
  167.  
  168. void do_setfont (void)
  169. {
  170.     FONT * font;
  171.     ED     * ep    = Ep;
  172.     ULONG  size;
  173.  
  174.     size = atoi ((char *)av[2]);
  175.  
  176.     if (size > MAX_FONT_SIZE)
  177.     {
  178.     error ("setfont:\nSize %ld too large !", size);
  179.     return;
  180.     }
  181.  
  182.     font = (FONT *)GetFont ((char *)av[1], size);
  183.  
  184.     if (font)
  185.     {
  186.     if (ep->font)
  187.         CloseFont (ep->font);
  188.  
  189.     ep->font = font;
  190.  
  191.     SetFont (ep->win->RPort, font);
  192.     SetRast (ep->win->RPort, 0);
  193.     RefreshWindowFrame (ep->win);
  194.     set_window_params ();
  195.     text_adjust (TRUE);
  196.     } else
  197.     {
  198.     error ("setfont:\nUnable to find font\n%s/%ld", av[1], size);
  199.     }
  200. } /* do_setfont */
  201.  
  202.  
  203. void do_ignorecase (void)
  204. {
  205.     ED *ep = Ep;
  206.  
  207.     ep->config.ignorecase = test_arg (av[1], ep->config.ignorecase);
  208.  
  209.     if (ep->config.ignorecase)
  210.     title ("Case Insensitive");
  211.     else
  212.     title ("Case Sensitive");
  213. } /* do_ignorecase */
  214.  
  215.  
  216. void do_saveconfig (void)
  217. {
  218.     ED     * ep = Ep;
  219.     FILE * fi;
  220.     WIN  * win = ep->win;
  221.  
  222.    if (ep->iconmode)
  223.    {
  224.     ep->config.iwinx = win->LeftEdge;
  225.     ep->config.iwiny = win->TopEdge;
  226.    } else
  227.    {
  228.     ep->config.winx      = win->LeftEdge;
  229.     ep->config.winy      = win->TopEdge;
  230.     ep->config.winwidth  = win->Width;
  231.     ep->config.winheight = win->Height;
  232.    }
  233.  
  234.     if (fi = fopen (XDME_CONFIG, "w"))
  235.     {
  236.     fwrite (CONFIG_VERSION, sizeof(CONFIG_VERSION)-1, 1, fi);
  237.     fwrite (&ep->beginconfig, CONFIG_SIZE, 1, fi);
  238.     fclose (fi);
  239.     }
  240. } /* do_saveconfig */
  241.  
  242.  
  243. void loadconfig (ED * ep)
  244. {
  245.     static int showed_error = 0;
  246.     FILE * fi;
  247.  
  248.     /* Always init the fields */
  249.     movmem (&default_config, &ep->beginconfig, CONFIG_SIZE);
  250.  
  251.     if (fi = fopen (XDME_CONFIG, "r"))
  252.     {
  253.     fread (tmp_buffer, sizeof(CONFIG_VERSION)-1, 1, fi);
  254.  
  255.     if (strncmp (CONFIG_VERSION, tmp_buffer, sizeof(CONFIG_VERSION)-1) )
  256.     {
  257.         if (!showed_error)
  258.         {
  259.         error ("loadconfig:\n"
  260.             "Wrong version for\n"
  261.             "configuration file !\n"
  262.             "Using defaults");
  263.         showed_error = 1;
  264.         }
  265.     } else
  266.         fread (&ep->beginconfig, 1, CONFIG_SIZE, fi);
  267.  
  268.     fclose (fi);
  269.     }
  270. } /* loadconfig */
  271.  
  272.  
  273. void do_fgpen (void)
  274. {
  275.     int pen;
  276.  
  277.     pen = atoi((char *)av[1]);
  278.  
  279.     if (pen != TEXT_BPEN)
  280.     {
  281.     TEXT_FPEN = pen;
  282.     text_redisplay ();
  283.     } else
  284.     error ("fgpen:\n"
  285.            "Cannot choose same color\n"
  286.            "for both back- and fore-\n"
  287.            "ground");
  288. } /* do_fgpen */
  289.  
  290.  
  291. void do_tpen (void)
  292. {
  293.     int pen;
  294.  
  295.     pen = atoi((char *)av[1]);
  296.  
  297.     if (pen != TEXT_FPEN)
  298.     {
  299.     TITLE_BPEN = pen;
  300.     text_redisplay ();
  301.     } else
  302.     error ("tpen:\n"
  303.            "Cannot choose same color\n"
  304.            "for both back- and fore-\n"
  305.            "ground");
  306. } /* do_tpen */
  307.  
  308.  
  309. void do_bgpen (void)
  310. {
  311.     int pen;
  312.  
  313.     pen = atoi((char *)av[1]);
  314.  
  315.     if (pen != TEXT_FPEN)
  316.     {
  317.     TEXT_BPEN = pen;
  318.     text_redisplay ();
  319.     } else
  320.     error ("bgpen:\n"
  321.            "Cannot choose same color\n"
  322.            "for both back- and fore-\n"
  323.            "ground");
  324. } /* do_bgpen */
  325.  
  326.  
  327. void do_hgpen (void)
  328. {
  329.     int pen;
  330.  
  331.     pen = atoi((char *)av[1]);
  332.  
  333.     if (pen != BLOCK_BPEN)
  334.     {
  335.     BLOCK_FPEN = pen;
  336.  
  337.     if (block_ok ())
  338.         text_redisplay ();
  339.     } else
  340.     error ("hgpen:\n"
  341.            "Cannot choose same color\n"
  342.            "for both back- and fore-\n"
  343.            "ground");
  344. } /* do_hgpen */
  345.  
  346.  
  347. void do_bbpen (void)
  348. {
  349.     int pen;
  350.  
  351.     pen = atoi((char *)av[1]);
  352.  
  353.     if (pen != BLOCK_FPEN)
  354.     {
  355.     BLOCK_BPEN = pen;
  356.  
  357.     if (block_ok ())
  358.         text_redisplay ();
  359.     } else
  360.     error ("bbpen:\n"
  361.            "Cannot choose same color\n"
  362.            "for both back- and fore-\n"
  363.            "ground");
  364. } /* do_hgpen */
  365.  
  366.  
  367. void do_modified (void)
  368. {
  369.     register ED *ep = Ep;
  370.  
  371.     if (av[1][0])
  372.     {
  373.     switch(av[1][1] & 0x1F)
  374.     {
  375.     case 'n' & 0x1F:
  376.         ep->modified = 1;
  377.         break;
  378.     case 'f' & 0x1F:
  379.         ep->modified = 0;
  380.         break;
  381.     case 'o' & 0x1F:
  382.         ep->modified = ep->modified ? 0 : 1;
  383.         break;
  384.     }
  385.     }
  386. } /* do_modified */
  387.  
  388.  
  389. void do_autoindent (void)
  390. {
  391.     Ep->config.autoindent = test_arg ((char *)av[1], Ep->config.autoindent);
  392.  
  393.     if (Ep->config.autoindent)
  394.     title ("Autoindent ON");
  395.     else
  396.     title ("Autoindent OFF");
  397. } /* do_autoindent */
  398.  
  399.  
  400. void do_sizewindow (void)
  401. {
  402.     WIN * win = Ep->win;
  403.     struct NewWindow nw;
  404.     int mdx, mdy;
  405.  
  406.     GeometryToNW (av[1], &nw);
  407.  
  408.     if (nw.LeftEdge + nw.Width <= win->WScreen->Width &&
  409.         nw.TopEdge + nw.Height <= win->WScreen->Height &&
  410.         nw.Width >= win->MinWidth &&
  411.         nw.Height >= win->MinHeight)
  412.         {
  413.  
  414.     mdx = nw.LeftEdge - win->LeftEdge;
  415.     mdy = nw.TopEdge - win->TopEdge;
  416.  
  417.     if (mdx > 0)
  418.         mdx = 0;
  419.  
  420.     if (mdy > 0)
  421.         mdy = 0;
  422.  
  423.     MoveWindow (win, mdx, mdy);
  424.     SizeWindow (win, nw.Width - win->Width, nw.Height - win->Height);
  425.     MoveWindow (win, nw.LeftEdge - win->LeftEdge, nw.TopEdge - win->TopEdge);
  426.     }
  427. }
  428.  
  429.  
  430. void do_autosplit (void)
  431. {
  432.     Ep->config.autosplit = test_arg (av[1], Ep->config.autosplit);
  433.  
  434.     if (Ep->config.autosplit)
  435.     title ("AutoSplit is now ON");
  436.     else
  437.     title ("AutoSplit is now OFF");
  438. } /* do_autosplit */
  439.  
  440.  
  441. void do_taskpri (void)
  442. {
  443.     LONG pri;
  444.  
  445.     pri = atoi (av[1]);
  446.  
  447.     if (pri > 5 || pri < -5)
  448.     {
  449.     error ("taskpri:\nWrong TaskPri %ld. Taskpri must\nbe between -5 and 5 !", pri);
  450.     return ;
  451.     }
  452.  
  453.     SetTaskPri (FindTask(NULL), pri);
  454. } /* do_taskpri */
  455.  
  456.  
  457. void do_debug (void)
  458. {
  459.     if (globalflags.debug = test_arg (av[1], globalflags.debug))
  460.     title ("DEBUG is now ON");
  461.     else
  462.     title ("DEBUG is now OFF");
  463. } /* do_debug */
  464.  
  465.  
  466. /*****************************************************************************
  467.  
  468.     NAME
  469.  
  470.     PARAMETER
  471.  
  472.     RETURN
  473.  
  474.     DESCRIPTION
  475.  
  476. ******************************************************************************/
  477.  
  478. void do_autounblock (void)
  479. {
  480.     Ep->config.autounblock = test_arg (av[1], Ep->config.autounblock);
  481. } /* do_autounblock */
  482.  
  483.  
  484. /*****************************************************************************
  485.  
  486.     NAME
  487.  
  488.     PARAMETER
  489.  
  490.     RETURN
  491.  
  492.     DESCRIPTION
  493.  
  494. ******************************************************************************/
  495.  
  496. void do_followcursor (void)
  497. {
  498.     globalflags.FollowCursor = test_arg (av[1], globalflags.FollowCursor);
  499. } /* do_followcursor */
  500.  
  501.  
  502. /*****************************************************************************
  503.  
  504.     NAME
  505.     do_setlinedistance
  506.  
  507.     PARAMETER
  508.     av[1] : integer offset (>= 0)
  509.  
  510.     DESCRIPTION
  511.     Sets the LineDistance. The offset must be positive.
  512.  
  513. ******************************************************************************/
  514.  
  515. void do_setlinedistance (void)
  516. {
  517.     int offset = strtol (av[1], NULL, 0);
  518.  
  519.     if (offset < 0)
  520.     error ("%s:\nYou cannot set a negative\nspace between the lines", av[0]);
  521.     else
  522.     {
  523.     ED   * ep     = Ep;
  524.     RP   * rp     = ep->win->RPort;
  525.     UWORD old_Xpixs = Xpixs;
  526.     UWORD old_Ypixs = Ypixs;
  527.  
  528.     LineDistance = offset;
  529.  
  530.     set_window_params ();       /* recalc new offsets */
  531.  
  532.     if (old_Xpixs != Xpixs || old_Ypixs != Ypixs)
  533.     {
  534.         UWORD x1, x2, y1, y2;
  535.  
  536.         /* Prepare for clear */
  537.  
  538.         SetAPen (rp, TEXT_BPEN);
  539.         SetWrMsk (rp, BLOCK_MASK);
  540.  
  541.         /* #1 is lower, #2 is higher coordinate */
  542.  
  543.         if (old_Xpixs < Xpixs)
  544.         {
  545.         x1 = old_Xpixs;
  546.         x2 = Xpixs;
  547.         } else
  548.         {
  549.         x2 = old_Xpixs;
  550.         x1 = Xpixs;
  551.         }
  552.  
  553.         if (old_Ypixs < Ypixs)
  554.         {
  555.         y1 = old_Ypixs;
  556.         y2 = Ypixs;
  557.         } else
  558.         {
  559.         y2 = old_Ypixs;
  560.         y1 = Ypixs;
  561.         }
  562.  
  563.         /* clear obsolete areas */
  564.  
  565.         if (x1 != x2)
  566.         RectFill (rp, x1, Ybase, x2, y2);
  567.  
  568.         if (y1 != y2)
  569.         RectFill (rp, Xbase, y1, x2, y2);
  570.     }
  571.  
  572.     text_adjust (TRUE);
  573.     }
  574. } /* do_setlinedistance */
  575.  
  576.  
  577. /******************************************************************************
  578. *****  ENDE prefs.c
  579. ******************************************************************************/
  580.