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