home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / ixemul-45.0-src.tgz / tar.out / contrib / ixemul / utils / functions.c < prev    next >
C/C++ Source or Header  |  1996-10-01  |  8KB  |  324 lines

  1. /*
  2.     Ixprefs v.2.4--ixemul.library configuration program
  3.     Copyright © 1995,1996 Kriton Kyrimis
  4.  
  5.     This program is free software; you can redistribute it and/or modify
  6.     it under the terms of the GNU General Public License as published by
  7.     the Free Software Foundation; either version 2 of the License, or
  8.     (at your option) any later version.
  9.  
  10.     This program is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.     GNU General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU General Public License
  16.     along with this program; if not, write to the Free Software
  17.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <exec/types.h>
  22. #include <intuition/intuition.h>
  23. #include <proto/dos.h>
  24. #include <proto/intuition.h>
  25. #include "ixprefs.h"
  26. #include "ixemul.h"
  27. #include "version.h"
  28.  
  29. #define IXPREFS_VERSION "2.4"
  30.  
  31. #define RUNNING 1
  32. #define NOT_RUNNING 0
  33.  
  34. #define CONFIGFILE "ENVARC:" IX_ENV_SETTINGS
  35. #define ENVFILE "ENV:" IX_ENV_SETTINGS
  36.  
  37. /* These strings are long enough to have a high probability of being typed
  38.    incorrectly, especially as they are used more than once. Using these
  39.    definitions, we can detect typing errors at compile time */
  40. #define IX_NO_INSERT_DISK_REQUESTER "ix_no_insert_disk_requester"
  41. #define IX_UNIX_PATTERN_MATCHING_CASE_SENSITIVE "ix_unix_pattern_matching_case_sensitive"
  42. #define IX_TRANSLATE_SLASH "ix_translate_slash"
  43. #define IX_MEMBUF_LIMIT "ix_membuf_limit"
  44. #define IX_FS_BUF_FACTOR "ix_fs_buf_factor"
  45. #define IX_ALLOW_AMIGA_WILDCARD "ix_allow_amiga_wildcard"
  46.  
  47. extern void showrequester(struct Window*, char *, char *);
  48.  
  49. extern struct ixemul_base *ixemulbase;
  50. extern int translateslash, membuf, blocks, cases, suppress,
  51.        amigawildcard, noflush, ignoreenv, networking, enforcerhit,
  52.        profilemethod;
  53.  
  54. struct ix_settings settings;
  55.  
  56. extern void displayprefs(void);
  57.  
  58. void
  59. use(void)
  60. {
  61.   FILE *f;
  62.   unsigned long new_flags;
  63.  
  64.   membufClicked();
  65.   blocksClicked();
  66.   new_flags =
  67.     (translateslash ? ix_translate_slash : 0)
  68.   | (cases ? ix_unix_pattern_matching_case_sensitive : 0)
  69.   | (suppress ? ix_no_insert_disk_requester : 0)
  70.   | (amigawildcard ? ix_allow_amiga_wildcard : 0)
  71.   | (noflush ? ix_do_not_flush_library : 0)
  72.   | (ignoreenv ? ix_ignore_global_env : 0)
  73.   | (enforcerhit ? ix_create_enforcer_hit : 0)
  74.   | (profilemethod << 14);
  75.   settings.version = IX_VERSION;
  76.   settings.revision = IX_REVISION;
  77.   settings.flags = new_flags;
  78.   settings.membuf_limit = membuf;
  79.   settings.fs_buf_factor = blocks;
  80.   settings.network_type = networking;
  81.   ix_set_settings(&settings);
  82.   f = fopen(ENVFILE, "w");
  83.   if (f) {
  84.     fwrite(&settings, sizeof(settings), 1, f);
  85.     fclose(f);
  86.   } else {
  87.     showrequester(ixprefsWnd, "Can't open " ENVFILE, "OK");
  88.   }
  89. }
  90.  
  91. void
  92. save(void)
  93. {
  94.   FILE *f;
  95.  
  96.   use();
  97.   f = fopen(CONFIGFILE, "w");
  98.   if (f) {
  99.     fwrite(&settings, sizeof(settings), 1, f);
  100.     fclose(f);
  101.   }else{
  102.     showrequester(ixprefsWnd, "Can't open " CONFIGFILE, "OK");
  103.   }
  104. }
  105.  
  106. int
  107. selected(int which)
  108. {
  109.   if (ixprefsGadgets[which]->Flags & GFLG_SELECTED) {
  110.     return 1;
  111.   }else{
  112.     return 0;
  113.   }
  114. }
  115.  
  116. int savegadClicked( void )
  117. {
  118.   /* routine when gadget "Save" is clicked. */
  119.   save();
  120.   return NOT_RUNNING;
  121. }
  122.  
  123. int usegadClicked( void )
  124. {
  125.   /* routine when gadget "Use" is clicked. */
  126.   use();
  127.   return NOT_RUNNING;
  128. }
  129.  
  130. int cancelgadClicked( void )
  131. {
  132.   /* routine when gadget "Cancel" is clicked. */
  133.   return NOT_RUNNING;
  134. }
  135.  
  136. int translateslashClicked( void )
  137. {
  138.   /* routine when gadget "translate /" is clicked. */
  139.   translateslash = selected(GDX_translateslash);
  140.   return RUNNING;
  141. }
  142.  
  143. int membufClicked( void )
  144. {
  145.   /* routine when gadget "membuf size" is clicked. */
  146.   membuf = GetNumber(ixprefsGadgets[GDX_membuf]);
  147.   return RUNNING;
  148. }
  149.  
  150. int blocksClicked( void )
  151. {
  152.   /* routine when gadget "physical blocks to build one logical block (for stdio)" is clicked. */
  153.   blocks = GetNumber(ixprefsGadgets[GDX_blocks]);
  154.   return RUNNING;
  155. }
  156.  
  157. int caseClicked( void )
  158. {
  159.   /* routine when gadget "case sensitive)" is clicked. */
  160.   cases = selected(GDX_case);
  161.   return RUNNING;
  162. }
  163.  
  164. int suppressClicked( void )
  165. {
  166.   /* routine when gadget "suppress the \"Insert volume in drive\" requester" is clicked. */
  167.   suppress = selected(GDX_suppress);
  168.   return RUNNING;
  169. }
  170.  
  171. int networkingClicked( void )
  172. {
  173.   /* routine when cycle gadget "Networking support" is clicked. */
  174.   networking = ixprefsMsg.Code;
  175.   return RUNNING;
  176. }
  177.  
  178. int profilemethodClicked( void )
  179. {
  180.   /* routine when cycle gadget "Profile method" is clicked. */
  181.   profilemethod = ixprefsMsg.Code;
  182.   return RUNNING;
  183. }
  184.  
  185. int amigawildcardClicked( void )
  186. {
  187.   /* routine when gadget "allow Amiga wildcards" is clicked. */
  188.   amigawildcard = selected(GDX_amigawildcard);
  189.   return RUNNING;
  190. }
  191.  
  192. int noflushClicked( void )
  193. {
  194.   /* routine when gadget "do not flush library" is clicked. */
  195.   noflush = selected(GDX_noflush);
  196.   return RUNNING;
  197. }
  198.  
  199. int ignoreenvClicked( void )
  200. {
  201.   /* routine when gadget "ignore global environment (ENV:)" is clicked. */
  202.   ignoreenv = selected(GDX_ignoreenv);
  203.   return RUNNING;
  204. }
  205.  
  206. int enforcerhitClicked( void )
  207. {
  208.   /* routine when gadget "Create Enforcerhit on trap" is clicked. */
  209.   enforcerhit = selected(GDX_enforcerhit);
  210.   return RUNNING;
  211. }
  212.  
  213. int ixprefssave( void )
  214. {
  215.   /* routine when (sub)item "Save" is selected. */
  216.   save();
  217.   return NOT_RUNNING;
  218. }
  219.  
  220. int ixprefsuse( void )
  221. {
  222.   /* routine when (sub)item "Use" is selected. */
  223.   use();
  224.   return NOT_RUNNING;
  225. }
  226.  
  227. int ixprefsabout( void )
  228. {
  229.   /* routine when (sub)item "About" is selected. */
  230.   showrequester(ixprefsWnd,
  231.     "Ixprefs v." IXPREFS_VERSION "--ixemul.library configuration program\n"
  232.     "Copyright \251 1995,1996 Kriton Kyrimis\n\n"
  233.     "This program is free software; you can redistribute it\n"
  234.     "and/or modify it under the terms of the GNU General\n"
  235.     "Public License as published by the Free Software Foundation;\n"
  236.     "either version 2 of the License, or (at your option)\n"
  237.     "any later version.\n\n"
  238.     "GUI designed using GadToolsBox 2.0c by Jan van den Baard",
  239.     "OK");
  240.   return RUNNING;
  241. }
  242.  
  243. int ixprefsquit( void )
  244. {
  245.   /* routine when (sub)item "Quit" is selected. */
  246.   return NOT_RUNNING;
  247. }
  248.  
  249. void read_from_settings(struct ix_settings *settings)
  250. {
  251.   translateslash = (settings->flags & ix_translate_slash) != 0;
  252.   cases = (settings->flags & ix_unix_pattern_matching_case_sensitive) != 0;
  253.   suppress = (settings->flags & ix_no_insert_disk_requester) != 0;
  254.   amigawildcard = (settings->flags & ix_allow_amiga_wildcard) != 0;
  255.   noflush = (settings->flags & ix_do_not_flush_library) != 0;
  256.   ignoreenv = (settings->flags & ix_ignore_global_env) != 0;
  257.   enforcerhit = (settings->flags & ix_create_enforcer_hit) != 0;
  258.   membuf = settings->membuf_limit;
  259.   blocks = settings->fs_buf_factor;
  260.   networking = settings->network_type;
  261.   profilemethod = (settings->flags >> 14) & 3;
  262. }
  263.  
  264. void defaults(void)
  265. {
  266.   read_from_settings(ix_get_default_settings());
  267. }
  268.  
  269. int ixprefsreset(void)
  270. {
  271.   /* routine when (sub)item "Reset to defaults" is selected. */
  272.  
  273.   defaults();
  274.   displayprefs();
  275.   return RUNNING;
  276. }
  277.  
  278. int
  279. last_saved(void)
  280. {
  281.   FILE *f;
  282.   int status;
  283.  
  284.   f = fopen(CONFIGFILE, "r");
  285.   if (f) {
  286.     fread(&settings, sizeof(settings), 1, f);
  287.     fclose(f);
  288.     read_from_settings(&settings);
  289.     status = 0;
  290.   }else{
  291.     showrequester(ixprefsWnd, "Can't open " CONFIGFILE, "OK");
  292.     status = 1;
  293.   }
  294.   return status;
  295. }
  296.  
  297. int ixprefslast( void )
  298. {
  299.   /* routine when (sub)item "Last Saved" is selected. */
  300.   if (last_saved() == 0) {
  301.     displayprefs();
  302.   }
  303.   return RUNNING;
  304. }
  305.  
  306. int ixprefsrestore( void )
  307. {
  308.   struct ix_settings *settings;
  309.  
  310.   /* routine when (sub)item "Restore" is selected. */
  311.   settings = ix_get_settings();
  312.   read_from_settings(settings);
  313.  
  314.   displayprefs();
  315.  
  316.   return RUNNING;
  317. }
  318.  
  319. int ixprefsCloseWindow( void )
  320. {
  321.   /* routine for "IDCMP_CLOSEWINDOW". */
  322.   return NOT_RUNNING;
  323. }
  324.