home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / top2src.zip / CFG.C < prev    next >
C/C++ Source or Header  |  2000-07-13  |  10KB  |  377 lines

  1. /******************************************************************************
  2. CFG.C        Configuration file processor.
  3.  
  4.     Copyright 1993 - 2000 Paul J. Sidorsky
  5.  
  6.     This program is free software; you can redistribute it and/or modify
  7.     it under the terms of the GNU General Public License, version 2, as
  8.     published by the Free Software Foundation.
  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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19. This module contains the code to load and process TOP.CFG.
  20. ******************************************************************************/
  21.  
  22. #include "top.h"
  23.  
  24. /* Shorthand macro to save typing. */
  25. #define chkkeyword(kwd) (!stricmp(keyword, kwd))
  26.  
  27. /* processcfg() - Processes the TOP.CFG file.
  28.    Parameters:  keyword - Keyword (first word) of the line being processed.
  29.                 options - Options (remainder) of the line being processed.
  30.    Returns:  Nothing.
  31.    Notes:  TOP never calls this function directly.  It is called by
  32.            OpenDoors or Doors/2 during the od_init() function.
  33. */
  34. #ifdef __OS2__
  35. void LIBENTRY processcfg(char *keyword, char *options)
  36. #else
  37. void processcfg(char *keyword, char *options)
  38. #endif
  39. {
  40. XINT cd;
  41.  
  42. // Set defaults
  43.  
  44. // Each keyword needs an error detection system.  Also need a USED variable.
  45.  
  46. /* See TOP.CFG for details about each keyword.  Note that except in rare
  47.    cases, none of the described setting limitations are actually enforced. */
  48.  
  49. if (chkkeyword("BBSType"))
  50.     {
  51.     for (cd = 0; cd < BBSTYPES; cd++)
  52.         {
  53.         /* Compare options to a known BBS type name. */
  54.         if (!stricmp(options, bbsnames[cd]))
  55.             {
  56.             cfg.bbstype = cd;
  57. #ifndef __OS2__
  58.             /* Maximus v3.0x support is the same as v2.0x support under all
  59.                platforms except OS/2. */
  60.             if (cfg.bbstype == BBS_MAX3)
  61.                 {
  62.                 cfg.bbstype = BBS_MAX2;
  63.                 }
  64. #endif
  65.             break;
  66.             }
  67.         }
  68.     }
  69. if (chkkeyword("BBSName"))
  70.     {
  71.     strset(cfg.bbsname, 0);
  72.     strncpy(cfg.bbsname, options, 40);
  73.     }
  74. if (chkkeyword("SysopName"))
  75.     {
  76.     strset(cfg.sysopname, 0);
  77.     strncpy(cfg.sysopname, options, 40);
  78.     }
  79. if (chkkeyword("TOPPath"))
  80.     {
  81.     strset(cfg.toppath, 0);
  82.     strncpy(cfg.toppath, options, 79);
  83.     strupr(cfg.toppath);
  84.     verifypath(cfg.toppath);
  85.     }
  86. if (chkkeyword("TOPWorkPath"))
  87.     {
  88.     strset(cfg.topworkpath, 0);
  89.     strncpy(cfg.topworkpath, options, 79);
  90.     strupr(cfg.topworkpath);
  91.     verifypath(cfg.topworkpath);
  92.     }
  93. if (chkkeyword("TOPANSIPath"))
  94.     {
  95.     strset(cfg.topansipath, 0);
  96.     strncpy(cfg.topansipath, options, 79);
  97.     strupr(cfg.topansipath);
  98.     verifypath(cfg.topansipath);
  99.     }
  100. if (chkkeyword("BBSPath"))
  101.     {
  102.     strset(cfg.bbspath, 0);
  103.     strncpy(cfg.bbspath, options, 79);
  104.     strupr(cfg.bbspath);
  105.     verifypath(cfg.bbspath);
  106.     }
  107. if (chkkeyword("BBSIPCPath"))
  108.     {
  109.     strset(cfg.bbsmultipath, 0);
  110.     strncpy(cfg.bbsmultipath, options, 79);
  111.     strupr(cfg.bbsmultipath);
  112.     verifypath(cfg.bbsmultipath);
  113.     }
  114. if (chkkeyword("TOPActionPath"))
  115.     {
  116.     strset(cfg.topactpath, 0);
  117.     strncpy(cfg.topactpath, options, 79);
  118.     strupr(cfg.topactpath);
  119.     verifypath(cfg.topactpath);
  120.     }
  121. if (chkkeyword("SecuritySysop"))
  122.     {
  123.     cfg.sysopsec = atol(options);
  124.     }
  125. if (chkkeyword("SecurityNewUser"))
  126.     {
  127.     cfg.newusersec = atol(options);
  128.     }
  129. if (chkkeyword("SecurityTalk"))
  130.     {
  131.     cfg.talksec = atol(options);
  132.     }
  133. if (chkkeyword("SecurityChangeHandle"))
  134.     {
  135.     cfg.handlechgsec = atol(options);
  136.     }
  137. if (chkkeyword("SecurityForget"))
  138.     {
  139.     cfg.forgetsec = atol(options);
  140.     }
  141. if (chkkeyword("SecurityChangeSex"))
  142.     {
  143.     cfg.sexchangesec = atol(options);
  144.     }
  145. if (chkkeyword("SecurityChangeEXMsg"))
  146.     {
  147.     cfg.exmsgchangesec = atol(options);
  148.     }
  149. if (chkkeyword("SecuritySendPrivate"))
  150.     {
  151.     cfg.privmessagesec = atol(options);
  152.     }
  153. if (chkkeyword("SecurityActionUse"))
  154.     {
  155.     cfg.actionusesec = atol(options);
  156.     }
  157. if (chkkeyword("ShowTitle"))
  158.     {
  159.     cfg.showtitle = seektruth(options);
  160.     }
  161. if (chkkeyword("ShowNews"))
  162.     {
  163.     cfg.shownews = seektruth(options);
  164.     }
  165. if (chkkeyword("AllowActions"))
  166.     {
  167.     cfg.allowactions = seektruth(options);
  168.     }
  169. if (chkkeyword("AllowActions"))
  170.     {
  171.     cfg.allowgas = seektruth(options);
  172.     }
  173. if (chkkeyword("AllowHandles"))
  174.     {
  175.     cfg.allowhandles = seektruth(options);
  176.     }
  177. if (chkkeyword("AllowNewHandles"))
  178.     {
  179.     cfg.allownewhandles = seektruth(options);
  180.     }
  181. if (chkkeyword("AllowChangeHandle"))
  182.     {
  183.     cfg.allowhandlechange = seektruth(options);
  184.     }
  185. if (chkkeyword("AllowChangeSex"))
  186.     {
  187.     cfg.allowsexchange = seektruth(options);
  188.     }
  189. if (chkkeyword("AllowChangeEXMsg"))
  190.     {
  191.     cfg.allowexmessages = seektruth(options);
  192.     }
  193. if (chkkeyword("AllowPrivateMsgs"))
  194.     {
  195.     cfg.allowprivmsgs = seektruth(options);
  196.     }
  197. if (chkkeyword("AllowForgetting"))
  198.     {
  199.     cfg.allowforgetting = seektruth(options);
  200.     }
  201. if (chkkeyword("AllowHighASCII"))
  202.     {
  203.     cfg.allowhighascii = seektruth(options);
  204.     }
  205. if (chkkeyword("ShowOpeningCredits"))
  206.     {
  207.     cfg.showopeningcred = seektruth(options);
  208.     }
  209. if (chkkeyword("ShowClosingCredits"))
  210.     {
  211.     cfg.showclosingcred = seektruth(options);
  212.     }
  213. if (chkkeyword("UseHandles"))
  214.     {
  215.     cfg.usehandles = seektruth(options);
  216.     }
  217. if (chkkeyword("NoRegName"))
  218.     {
  219.     cfg.noregname = seektruth(options);
  220.     }
  221. if (chkkeyword("InactiveTimeout"))
  222.     {
  223.     cfg.inactivetime = atoi(options);
  224.     }
  225. if (chkkeyword("LocalBeeping"))
  226.     {
  227.     strupr(options);
  228.     cfg.localbeeping = BEEP_NONE;
  229.     /* Set flags for local beeping options. */
  230.     if (strstr(options, "NONE")) cfg.localbeeping = BEEP_NONE;
  231.     if (strstr(options, "REMOTE")) cfg.localbeeping |= BEEP_REMOTE;
  232.     if (strstr(options, "LOCAL")) cfg.localbeeping |= BEEP_LOCAL;
  233.     if (strstr(options, "LAN")) cfg.localbeeping |= BEEP_LAN;
  234.     if (strstr(options, "ALL")) cfg.localbeeping = BEEP_ALL;
  235.     }
  236. if (chkkeyword("LangFile"))
  237.     {
  238.     strset(cfg.langfile, 0);
  239.     strncpy(cfg.langfile, options, 8);
  240.     strupr(cfg.langfile);
  241.     strcat(cfg.langfile, ".LNG");
  242.     }
  243. if (chkkeyword("PollDelay"))
  244.     {
  245.     cfg.polldelay = atol(options);
  246.     }
  247. if (chkkeyword("RetryDelay"))
  248.     {
  249.     cfg.retrydelay = atol(options);
  250.     }
  251. if (chkkeyword("RetryMax"))
  252.     {
  253.     cfg.maxretries = atol(options);
  254.     }
  255. if (chkkeyword("CrashProtDelay"))
  256.     {
  257.     cfg.crashprotdelay = atol(options);
  258.     }
  259. if (chkkeyword("MaxNodes"))
  260.     {
  261.     cfg.maxnodes = atoi(options);
  262.     }
  263. if (chkkeyword("MaxPWTries"))
  264.     {
  265.     cfg.maxpwtries = atoi(options);
  266.     }
  267. if (chkkeyword("ActionFiles"))
  268.     {
  269.     memset(cfg.actfilestr, 0, 256);
  270.     strncpy(cfg.actfilestr, options, 255);
  271.     }
  272. if (chkkeyword("MaxChannelDefs"))
  273.     {
  274.     cfg.maxchandefs = strtol(options, NULL, 10);
  275.     }
  276. if (chkkeyword("PrivChatBufSize"))
  277.     {
  278.     cfg.privchatbufsize = strtol(options, NULL, 10);
  279.     }
  280. if (chkkeyword("PrivChatMaxTries"))
  281.     {
  282.     cfg.privchatmaxtries = strtol(options, NULL, 10);
  283.     }
  284. if (chkkeyword("UseCredits"))
  285.     {
  286.     cfg.usecredits = strtol(options, NULL, 10);
  287.     }
  288. if (chkkeyword("DefaultChannel"))
  289.     {
  290.     cfg.defaultchannel = strtoul(options, NULL, 10);
  291.     }
  292. if (chkkeyword("MaxCensorWarnHigh"))
  293.     {
  294.     cfg.maxcensorwarnhigh = atoi(options);
  295.     }
  296. if (chkkeyword("MaxCensorWarnLow"))
  297.     {
  298.     cfg.maxcensorwarnlow = atoi(options);
  299.     }
  300. if (chkkeyword("CensorTimerHigh"))
  301.     {
  302.     cfg.censortimerhigh = atoi(options);
  303.     }
  304. if (chkkeyword("CensorTimerLow"))
  305.     {
  306.     cfg.censortimerlow = atoi(options);
  307.     }
  308. if (chkkeyword("DefaultPrefs"))
  309.     {
  310.     cfg.defaultprefs[0] = 0;
  311.     cfg.defaultprefs[1] = 0;
  312.     cfg.defaultprefs[2] = 0;
  313.     /* Read the first 8 characters to process PREF1_ options. */
  314.     for (cd = 0; cd < 8; cd++)
  315.         {
  316.         if (options[cd] == '1' || toupper(options[cd]) == 'Y')
  317.             {
  318.             cfg.defaultprefs[0] |= 1 << cd;
  319.             }
  320.         else
  321.             {
  322.             cfg.defaultprefs[0] |= 0 << cd;
  323.             }
  324.         }
  325.     /* Read the last 4 characters to process PREF2_ options. */
  326.     for (cd = 0; cd < 4; cd++)
  327.         {
  328.         if (options[cd + 8] == '1' || toupper(options[cd + 8]) == 'Y')
  329.             {
  330.             cfg.defaultprefs[1] |= 1 << cd;
  331.             }
  332.         else
  333.             {
  334.             cfg.defaultprefs[1] |= 0 << cd;
  335.             }
  336.         }
  337.     }
  338. if (chkkeyword("ActionPrefix"))
  339.     {
  340.     if (!stricmp(options, "NONE"))
  341.         {
  342.         cfg.actionprefix[0] = '\0';
  343.         }
  344.     else
  345.         {
  346.         memset(cfg.actionprefix, 0, 11);
  347.         strncpy(cfg.actionprefix, options, 10);
  348.         }
  349.     }
  350. if (chkkeyword("ForceBio"))
  351.     {
  352.     cfg.forcebio = seektruth(options);
  353.     }
  354.  
  355. }
  356.  
  357. /* seektruth() - Determines the setting of a boolean option.
  358.    Parameters:  seekstr() - Options string to seek the truth from.
  359.    Returns:  Setting of the boolean option (TRUE or FALSE).
  360. */
  361. char seektruth(unsigned char *seekstr)
  362. {
  363.  
  364. /* Compare option against known "true" words. */
  365. if (!stricmp(seekstr, "Yes") ||
  366.     !stricmp(seekstr, "On") ||
  367.     !stricmp(seekstr, "1") ||
  368.     !stricmp(seekstr, "True") ||
  369.     !stricmp(seekstr, "Enabled"))
  370.     {
  371.     return 1;
  372.     }
  373.  
  374. /* Default to false. */
  375. return 0;
  376. }
  377.