ODCFile.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. /* OpenDoors Online Software Programming Toolkit
  2. * (C) Copyright 1991 - 1999 by Brian Pirie.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with this library; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *
  18. *
  19. * File: ODCFile.c
  20. *
  21. * Description: Implements the configuration file sub-system.
  22. *
  23. * Revisions: Date Ver Who Change
  24. * ---------------------------------------------------------------
  25. * Oct 13, 1994 6.00 BP New file header format.
  26. * Dec 09, 1994 6.00 BP Standardized coding style.
  27. * Nov 11, 1995 6.00 BP 32-bit portability.
  28. * Nov 11, 1995 6.00 BP Removed register keyword.
  29. * Nov 16, 1995 6.00 BP Removed oddoor.h, added odcore.h.
  30. * Dec 30, 1995 6.00 BP Added ODCALL for calling convention.
  31. * Jan 01, 1996 6.00 BP Added DisableDTR and NoDTRDisable.
  32. * Jan 19, 1996 6.00 BP Display error if config file not found
  33. * Feb 19, 1996 6.00 BP Changed version number to 6.00.
  34. * Mar 03, 1996 6.10 BP Begin version 6.10.
  35. * Mar 19, 1996 6.10 BP MSVC15 source-level compatibility.
  36. * Aug 10, 2003 6.23 SH *nix support
  37. */
  38. #define BUILDING_OPENDOORS
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include <ctype.h>
  43. #include <time.h>
  44. #include "OpenDoor.h"
  45. #include "ODStr.h"
  46. #include "ODCore.h"
  47. #include "ODGen.h"
  48. #include "ODInEx.h"
  49. #include "ODUtil.h"
  50. /* Internal private variables */
  51. static WORD awTimeVal[3];
  52. static BYTE btTimeNumVals;
  53. /* Local functions. */
  54. static WORD ODCfgGetWordDecimal(char *pszConfigText);
  55. static DWORD ODCfgGetDWordDecimal(char *pszConfigText);
  56. static WORD ODCfgGetWordHex(char *pszConfigText);
  57. static void ODCfgGetNextTime(char **ppchConfigText);
  58. static BOOL ODCfgIsTrue(char *pszConfigText);
  59. /* ----------------------------------------------------------------------------
  60. * ODConfigInit()
  61. *
  62. * Called to perform OpenDoors initialization when the configuration file
  63. * system is being used. This function is called from the normal od_init(),
  64. * and also uses the normal od_init() to perform base initialization after
  65. * the configuration file has been read, but before certain configuration
  66. * settings are set in od_control.
  67. *
  68. * Parameters: none
  69. *
  70. * Return: void
  71. */
  72. ODAPIDEF void ODCALL ODConfigInit(void)
  73. {
  74. void (*custom_line_function)(char *keyword, char *options)
  75. = od_control.config_function;
  76. char *pchConfigText;
  77. WORD wCurrent;
  78. INT nConfigOption;
  79. BOOL bConfigFileRequired = TRUE;
  80. static FILE *pfConfigFile;
  81. static FILE *pfCustomDropFile = NULL;
  82. static char szConfigLine[257];
  83. static char szToken[33];
  84. static char szTempString[256];
  85. static char szWorkDir[80];
  86. static BOOL bWorkDirSet = FALSE;
  87. static time_t nUnixTime;
  88. static struct tm *TimeBlock;
  89. static INT16 nPageStart;
  90. static INT16 nPageEnd;
  91. static BOOL bPageSet = FALSE;
  92. static BOOL bInactivitySet = FALSE;
  93. static INT16 nInactivity;
  94. static char *pszWork;
  95. static BOOL bPageLengthSet = FALSE;
  96. static BYTE btPageLength;
  97. static char *apszFileNames[1];
  98. bIsCallbackActive = TRUE;
  99. nUnixTime = time(NULL);
  100. TimeBlock = localtime(&nUnixTime);
  101. /* Use default configuration file filename if none has been specified. */
  102. if(od_control.od_config_filename == NULL)
  103. {
  104. od_control.od_config_filename = "door.cfg";
  105. bConfigFileRequired = FALSE;
  106. }
  107. if((pfConfigFile = fopen(od_control.od_config_filename, "rt")) == NULL)
  108. {
  109. if(strchr(od_control.od_config_filename, DIRSEP) != NULL
  110. || strchr(od_control.od_config_filename, ':') != NULL)
  111. {
  112. wCurrent = strlen(od_control.od_config_filename);
  113. pchConfigText = (char *)od_control.od_config_filename + (wCurrent - 1);
  114. while(wCurrent > 0)
  115. {
  116. if(*pchConfigText == DIRSEP || *pchConfigText == ':')
  117. {
  118. strcpy(szConfigLine, (char *)pchConfigText + 1);
  119. pfConfigFile = fopen(szConfigLine, "rt");
  120. break;
  121. }
  122. --pchConfigText;
  123. --wCurrent;
  124. }
  125. }
  126. else
  127. {
  128. strcpy(szConfigLine, od_control.od_config_filename);
  129. }
  130. }
  131. /* If we were able to open the configuration file. */
  132. if(pfConfigFile != NULL)
  133. {
  134. /* Get configuration file strings in upper case. */
  135. for(wCurrent = 0; wCurrent < TEXT_SIZE; ++wCurrent)
  136. {
  137. strupr(od_config_text[wCurrent]);
  138. }
  139. for(wCurrent = 0; wCurrent < LINES_SIZE; ++wCurrent)
  140. {
  141. strupr(od_config_lines[wCurrent]);
  142. }
  143. for(;;)
  144. {
  145. /* Read the next line from the configuration file. */
  146. if(fgets(szConfigLine, 257, pfConfigFile) == NULL) break;
  147. /* Ignore all of line after comments or CR/LF char. */
  148. pchConfigText = (char *)szConfigLine;
  149. while(*pchConfigText)
  150. {
  151. if(*pchConfigText == '\n' || *pchConfigText == '\r'
  152. || *pchConfigText == ';')
  153. {
  154. *pchConfigText = '\0';
  155. break;
  156. }
  157. ++pchConfigText;
  158. }
  159. /* Search for beginning of first token on line. */
  160. pchConfigText = (char *)szConfigLine;
  161. while(*pchConfigText
  162. && (*pchConfigText == ' ' || *pchConfigText == '\t'))
  163. {
  164. ++pchConfigText;
  165. }
  166. if(!*pchConfigText) continue;
  167. /* Get first token from line. */
  168. wCurrent = 0;
  169. while(*pchConfigText
  170. && !(*pchConfigText == ' ' || *pchConfigText == '\t'))
  171. {
  172. if(wCurrent < 32) szToken[wCurrent++] = *pchConfigText;
  173. ++pchConfigText;
  174. }
  175. if(wCurrent <= 32)
  176. {
  177. szToken[wCurrent] = '\0';
  178. }
  179. else
  180. {
  181. szToken[32] = '\0';
  182. }
  183. strupr(szToken);
  184. /* Find beginning of configuration option parameters */
  185. while(*pchConfigText && (*pchConfigText == ' '
  186. || *pchConfigText == '\t'))
  187. {
  188. ++pchConfigText;
  189. }
  190. /* Trim trailing spaces from setting string. */
  191. for(wCurrent = strlen(pchConfigText) - 1; wCurrent > 0; --wCurrent)
  192. {
  193. if(pchConfigText[wCurrent] == ' '
  194. || pchConfigText[wCurrent] == '\t')
  195. {
  196. pchConfigText[wCurrent] = '\0';
  197. }
  198. else
  199. {
  200. break;
  201. }
  202. }
  203. for(wCurrent = 0; wCurrent < TEXT_SIZE; ++wCurrent)
  204. {
  205. if(strcmp(szToken, od_config_text[wCurrent]) == 0)
  206. {
  207. switch(wCurrent)
  208. {
  209. case 0:
  210. wODNodeNumber = ODCfgGetWordDecimal(pchConfigText);
  211. break;
  212. case 1:
  213. strcpy(od_control.info_path,pchConfigText);
  214. break;
  215. case 2:
  216. if(pchConfigText[strlen(pchConfigText) - 1] == DIRSEP
  217. && pchConfigText[strlen(pchConfigText) - 2] != ':'
  218. && strlen(pchConfigText) > 1)
  219. {
  220. pchConfigText[strlen(pchConfigText) - 1] = '\0';
  221. }
  222. szOriginalDir = (char *)malloc(256);
  223. if(szOriginalDir != NULL)
  224. {
  225. ODDirGetCurrent(szOriginalDir, 256);
  226. }
  227. strcpy(szWorkDir, pchConfigText);
  228. bWorkDirSet = TRUE;
  229. break;
  230. case 3:
  231. strcpy(od_control.od_logfile_name, pchConfigText);
  232. break;
  233. case 4:
  234. od_control.od_logfile_disable = TRUE;
  235. break;
  236. case 5:
  237. case 6:
  238. case 7:
  239. case 8:
  240. case 9:
  241. case 10:
  242. case 11:
  243. if((wCurrent - 5) == (WORD)TimeBlock->tm_wday)
  244. {
  245. ODCfgGetNextTime((char **)&pchConfigText);
  246. nPageStart = awTimeVal[0] * 60 + awTimeVal[1];
  247. ODCfgGetNextTime((char **)&pchConfigText);
  248. nPageEnd = awTimeVal[0] * 60 + awTimeVal[1];
  249. bPageSet = TRUE;
  250. }
  251. break;
  252. case 12:
  253. od_control.od_maxtime = ODCfgGetWordDecimal(pchConfigText);
  254. break;
  255. case 13:
  256. bSysopNameSet = TRUE;
  257. strncpy((char *)&szForcedSysopName, pchConfigText, 39);
  258. szForcedSysopName[39] = '\0';
  259. break;
  260. case 14:
  261. bSystemNameSet = TRUE;
  262. strncpy((char *)&szForcedSystemName, pchConfigText, 39);
  263. szForcedSystemName[39] = '\0';
  264. break;
  265. case 15:
  266. od_control.od_swapping_disable = TRUE;
  267. break;
  268. case 16:
  269. strncpy(od_control.od_swapping_path, pchConfigText, 79);
  270. od_control.od_swapping_path[79] = '\0';
  271. break;
  272. case 17:
  273. od_control.od_swapping_noems = TRUE;
  274. break;
  275. case 18:
  276. dwForcedBPS = ODCfgGetDWordDecimal(pchConfigText);
  277. break;
  278. case 19:
  279. nForcedPort = ODCfgGetWordDecimal(pchConfigText);
  280. break;
  281. case 20:
  282. if(pfCustomDropFile == NULL && !od_control.od_force_local)
  283. {
  284. apszFileNames[0] = (char *)pchConfigText;
  285. if(ODSearchForDropFile(apszFileNames, 1, szTempString,
  286. NULL) != -1)
  287. {
  288. if((pfCustomDropFile = fopen(szTempString, "rt"))
  289. != NULL)
  290. {
  291. od_control.od_info_type = CUSTOM;
  292. od_control.user_attribute = 0x06;
  293. od_control.user_screen_length = 23;
  294. od_control.user_ansi = TRUE;
  295. od_control.user_rip = FALSE;
  296. od_control.user_avatar = FALSE;
  297. od_control.od_page_pausing = TRUE;
  298. od_control.od_page_len = 15;
  299. od_control.user_timelimit = 0;
  300. strcpy(od_control.user_name, "Unknown User");
  301. strcpy(od_control.user_location,
  302. "Unknown Location");
  303. od_control.user_security = 1;
  304. }
  305. }
  306. }
  307. break;
  308. case 21:
  309. if(pfCustomDropFile != NULL)
  310. {
  311. if(fgets(szTempString, 255, pfCustomDropFile)!=NULL)
  312. {
  313. if(szTempString[strlen(szTempString) - 1] == '\n')
  314. {
  315. szTempString[strlen(szTempString) - 1] = '\0';
  316. }
  317. else
  318. {
  319. INT ch;
  320. do
  321. {
  322. ch = fgetc(pfCustomDropFile);
  323. } while(ch != '\n' && ch != EOF);
  324. }
  325. if(szTempString[strlen(szTempString) - 1] == '\r')
  326. {
  327. szTempString[strlen(szTempString) - 1] = '\0';
  328. }
  329. strupr(pchConfigText);
  330. for(nConfigOption = 0; nConfigOption < LINES_SIZE;
  331. ++nConfigOption)
  332. {
  333. if(strcmp(pchConfigText,
  334. od_config_lines[nConfigOption]) == 0)
  335. {
  336. switch(nConfigOption)
  337. {
  338. case 1:
  339. od_control.port =
  340. ODCfgGetWordDecimal(szTempString) - 1;
  341. break;
  342. case 2:
  343. od_control.port =
  344. ODCfgGetWordDecimal(szTempString);
  345. break;
  346. case 3:
  347. od_control.baud =
  348. ODCfgGetWordDecimal(szTempString);
  349. break;
  350. case 4:
  351. if(ODCfgIsTrue(szTempString))
  352. {
  353. #ifdef ODPLAT_NIX
  354. od_control.baud = 1;
  355. #else
  356. od_control.baud = 0;
  357. #endif
  358. }
  359. break;
  360. case 5:
  361. case 6:
  362. ODStringToName(szTempString);
  363. strncpy(od_control.user_name,
  364. szTempString, 34);
  365. od_control.user_name[34] = '\0';
  366. break;
  367. case 7:
  368. strcat(od_control.user_name, " ");
  369. ODStringToName(szTempString);
  370. strncat(od_control.user_name,
  371. szTempString,
  372. 35 - strlen(od_control.user_name));
  373. od_control.user_name[35] = '\0';
  374. break;
  375. case 8:
  376. ODStringToName(szTempString);
  377. strncpy(od_control.user_handle,
  378. szTempString, 35);
  379. od_control.user_handle[35] = '\0';
  380. break;
  381. case 9:
  382. pszWork = (char *)szTempString;
  383. ODCfgGetNextTime((char **)&pszWork);
  384. od_control.user_timelimit +=
  385. (awTimeVal[0] * 60);
  386. break;
  387. case 10:
  388. pszWork = (char *)szTempString;
  389. ODCfgGetNextTime((char **)&pszWork);
  390. if(btTimeNumVals <= 1)
  391. {
  392. od_control.user_timelimit +=
  393. awTimeVal[0];
  394. }
  395. else
  396. {
  397. od_control.user_timelimit +=
  398. awTimeVal[1] + (awTimeVal[0] * 60);
  399. }
  400. break;
  401. case 11:
  402. pszWork = (char *)szTempString;
  403. ODCfgGetNextTime((char **)&pszWork);
  404. if(btTimeNumVals <= 1)
  405. {
  406. od_control.user_timelimit +=
  407. awTimeVal[0] / 60;
  408. }
  409. else if(btTimeNumVals == 2)
  410. {
  411. od_control.user_timelimit +=
  412. (awTimeVal[1] / 60) + awTimeVal[0];
  413. }
  414. else
  415. {
  416. od_control.user_timelimit +=
  417. (awTimeVal[2] / 60) + awTimeVal[1]
  418. + (awTimeVal[0] * 60);
  419. }
  420. break;
  421. case 12:
  422. od_control.user_ansi =
  423. ODCfgIsTrue(szTempString);
  424. break;
  425. case 13:
  426. od_control.user_avatar =
  427. ODCfgIsTrue(szTempString);
  428. break;
  429. case 14:
  430. od_control.od_page_pausing =
  431. ODCfgIsTrue(szTempString);
  432. break;
  433. case 15:
  434. od_control.user_screen_length =
  435. ODCfgGetWordDecimal(szTempString);
  436. break;
  437. case 16:
  438. if(ODCfgIsTrue(szTempString))
  439. {
  440. od_control.user_attribute |= 0x02;
  441. }
  442. else
  443. {
  444. od_control.user_attribute &=~ 0x02;
  445. }
  446. break;
  447. case 17:
  448. od_control.user_security =
  449. ODCfgGetWordDecimal(szTempString);
  450. break;
  451. case 18:
  452. ODStringToName(szTempString);
  453. strncpy(od_control.user_location,
  454. szTempString, 25);
  455. od_control.user_location[25] = '\0';
  456. break;
  457. case 19:
  458. wODNodeNumber =
  459. ODCfgGetWordDecimal(szTempString);
  460. break;
  461. case 20:
  462. case 21:
  463. ODStringToName(szTempString);
  464. strncpy(od_control.sysop_name,
  465. szTempString, 38);
  466. od_control.sysop_name[38] = '\0';
  467. break;
  468. case 22:
  469. strcat(od_control.sysop_name, " ");
  470. ODStringToName(szTempString);
  471. strncat(od_control.sysop_name,
  472. szTempString,
  473. 39 - strlen(od_control.system_name));
  474. od_control.sysop_name[39] = '\0';
  475. break;
  476. case 23:
  477. strncpy(od_control.system_name,
  478. szTempString, 39);
  479. od_control.system_name[39] = '\0';
  480. break;
  481. case 24:
  482. od_control.user_rip =
  483. ODCfgIsTrue(szTempString);
  484. }
  485. }
  486. }
  487. }
  488. }
  489. break;
  490. case 22:
  491. bInactivitySet = TRUE;
  492. nInactivity = ODCfgGetWordDecimal(pchConfigText);
  493. if(nInactivity < 0) nInactivity = 0;
  494. break;
  495. case 23:
  496. btPageLength = (BYTE)ODCfgGetWordDecimal(pchConfigText);
  497. bPageLengthSet = TRUE;
  498. break;
  499. case 24:
  500. od_control.od_chat_color2 =
  501. od_color_config(pchConfigText);
  502. break;
  503. case 25:
  504. od_control.od_chat_color1 =
  505. od_color_config(pchConfigText);
  506. break;
  507. case 26:
  508. od_control.od_list_title_col =
  509. od_color_config(pchConfigText);
  510. break;
  511. case 27:
  512. od_control.od_list_name_col =
  513. od_color_config(pchConfigText);
  514. break;
  515. case 28:
  516. od_control.od_list_size_col =
  517. od_color_config(pchConfigText);
  518. break;
  519. case 29:
  520. od_control.od_list_comment_col =
  521. od_color_config(pchConfigText);
  522. break;
  523. case 30:
  524. od_control.od_list_offline_col =
  525. od_color_config(pchConfigText);
  526. break;
  527. case 31:
  528. strncpy(szDesiredPersonality, pchConfigText, 32);
  529. szDesiredPersonality[32] = '\0';
  530. break;
  531. case 32:
  532. /* "NoFossil" */
  533. od_control.od_no_fossil = TRUE;
  534. break;
  535. case 33:
  536. /* "PortAddress" */
  537. od_control.od_com_address = ODCfgGetWordHex(pchConfigText);
  538. break;
  539. case 34:
  540. /* "PortIRQ" */
  541. od_control.od_com_irq =
  542. (char)ODCfgGetWordDecimal(pchConfigText);
  543. break;
  544. case 35:
  545. /* "ReceiveBuffer" */
  546. od_control.od_com_rx_buf =
  547. ODCfgGetWordDecimal(pchConfigText);
  548. break;
  549. case 36:
  550. /* "TransmitBuffer" */
  551. od_control.od_com_tx_buf =
  552. ODCfgGetWordDecimal(pchConfigText);
  553. break;
  554. case 37:
  555. /* "PagePromptColour" */
  556. od_control.od_continue_col =
  557. od_color_config(pchConfigText);
  558. break;
  559. case 38:
  560. /* "LocalMode" */
  561. od_control.od_force_local = TRUE;
  562. break;
  563. case 39:
  564. /* "PopupMenuTitleColour" */
  565. od_control.od_menu_title_col =
  566. od_color_config(pchConfigText);
  567. break;
  568. case 40:
  569. /* "PopupMenuBorderColour" */
  570. od_control.od_menu_border_col =
  571. od_color_config(pchConfigText);
  572. break;
  573. case 41:
  574. /* "PopupMenuTextColour" */
  575. od_control.od_menu_text_col =
  576. od_color_config(pchConfigText);
  577. break;
  578. case 42:
  579. /* "PopupMenuKeyColour" */
  580. od_control.od_menu_key_col =
  581. od_color_config(pchConfigText);
  582. break;
  583. case 43:
  584. /* "PopupMenuHighlightColour" */
  585. od_control.od_menu_highlight_col =
  586. od_color_config(pchConfigText);
  587. break;
  588. case 44:
  589. /* "PopupMenuHighKeyColour" */
  590. od_control.od_menu_highkey_col =
  591. od_color_config(pchConfigText);
  592. break;
  593. case 45:
  594. /* "NoFIFO" */
  595. od_control.od_com_no_fifo = TRUE;
  596. break;
  597. case 46:
  598. /* "FIFOTriggerSize" */
  599. od_control.od_com_fifo_trigger =
  600. (BYTE)ODCfgGetWordDecimal(pchConfigText);
  601. break;
  602. case 47:
  603. /* "DisableDTR" */
  604. ODStringCopy(od_control.od_disable_dtr, pchConfigText,
  605. sizeof(od_control.od_disable_dtr));
  606. break;
  607. case 48:
  608. /* "NoDTRDisable" */
  609. od_control.od_disable |= DIS_DTR_DISABLE;
  610. break;
  611. }
  612. }
  613. }
  614. /* Check if command is a programmer customized option. */
  615. if(wCurrent >= TEXT_SIZE && custom_line_function != NULL)
  616. {
  617. (*custom_line_function)((char *)&szToken, pchConfigText);
  618. }
  619. }
  620. /* Close the configuration file. */
  621. fclose(pfConfigFile);}
  622. else
  623. {
  624. if(bConfigFileRequired)
  625. {
  626. od_control.od_error = ERR_FILEOPEN;
  627. ODInitError("Unable to access configuration file.");
  628. exit(od_control.od_errorlevel[1]);
  629. }
  630. }
  631. /* Close custom door info file */
  632. if(pfCustomDropFile != NULL)
  633. {
  634. fclose(pfCustomDropFile);
  635. }
  636. bIsCallbackActive = FALSE;
  637. /* Carry out normal OpenDoors initialization. */
  638. bCalledFromConfig = TRUE;
  639. od_init();
  640. bCalledFromConfig = FALSE;
  641. /* Update any settings that need to be updated. */
  642. if(bPageSet)
  643. {
  644. od_control.od_pagestartmin = nPageStart;
  645. od_control.od_pageendmin = nPageEnd;
  646. }
  647. if(bInactivitySet && nInactivity != 0)
  648. {
  649. od_control.od_inactivity = nInactivity;
  650. }
  651. if(bSysopNameSet)
  652. {
  653. strcpy((char *)&od_control.sysop_name, (char *)&szForcedSysopName);
  654. }
  655. if(bSystemNameSet)
  656. {
  657. strcpy((char *)&od_control.system_name, (char *)&szForcedSystemName);
  658. }
  659. if(bPageLengthSet)
  660. {
  661. od_control.od_page_len = btPageLength;
  662. }
  663. if(bWorkDirSet)
  664. {
  665. ODDirChangeCurrent(szWorkDir);
  666. }
  667. }
  668. /* ----------------------------------------------------------------------------
  669. * ODCfgGetWordDecimal() *** PRIVATE FUNCTION ***
  670. *
  671. * Obtains the value of the next decimal number in the provided string, in the
  672. * form of a WORD (16 bit value).
  673. *
  674. * Parameters: pszConfigText - String to examine.
  675. *
  676. * Return: The first number obtained from the string.
  677. */
  678. static WORD ODCfgGetWordDecimal(char *pszConfigText)
  679. {
  680. ASSERT(pszConfigText != NULL);
  681. /* Skip any initial non-numerical characters. */
  682. while(*pszConfigText && (*pszConfigText < '0' || *pszConfigText > '9'))
  683. {
  684. ++pszConfigText;
  685. }
  686. /* Return value of number. */
  687. return(atoi(pszConfigText));
  688. }
  689. /* ----------------------------------------------------------------------------
  690. * ODCfgGetDWordDecimal() *** PRIVATE FUNCTION ***
  691. *
  692. * Obtains the value of the next decimal number in the provided string, in the
  693. * form of a DWORD (32 bit value).
  694. *
  695. * Parameters: pszConfigText - String to examine.
  696. *
  697. * Return: The first number obtained from the string.
  698. */
  699. static DWORD ODCfgGetDWordDecimal(char *pszConfigText)
  700. {
  701. ASSERT(pszConfigText != NULL);
  702. /* Skip any initial non-numerical characters. */
  703. while(*pszConfigText && (*pszConfigText < '0' || *pszConfigText > '9'))
  704. {
  705. ++pszConfigText;
  706. }
  707. /* Return value of number. */
  708. return(atol(pszConfigText));
  709. }
  710. /* ----------------------------------------------------------------------------
  711. * ODCfgGetWordHex() *** PRIVATE FUNCTION ***
  712. *
  713. * Obtains the value of the next hexidecimal number in the provided string, in
  714. * the form of a WORD (16 bit value).
  715. *
  716. * Parameters: pszConfigText - String to examine.
  717. *
  718. * Return: The first number obtained from the string.
  719. */
  720. static WORD ODCfgGetWordHex(char *pszConfigText)
  721. {
  722. WORD wToReturn;
  723. ASSERT(pszConfigText != NULL);
  724. /* Skip any initial non-hexidecimal characters. */
  725. while(*pszConfigText && (*pszConfigText < '0' || *pszConfigText > '9')
  726. && (toupper(*pszConfigText) < 'A' || toupper(*pszConfigText) > 'F'))
  727. {
  728. ++pszConfigText;
  729. }
  730. sscanf(pszConfigText, "%x", &wToReturn);
  731. return(wToReturn);
  732. }
  733. /* ----------------------------------------------------------------------------
  734. * ODCfgGetNextTime() *** PRIVATE FUNCTION ***
  735. *
  736. * Obtains the next time from a string, updating the string pointer to point to
  737. * the position in the string after the end of the time. The time information
  738. * is stored in the btTimeNumVals and awTimeVal private global variables.
  739. *
  740. * Parameters: ppchConfigText - Pointer to character pointer to the string,
  741. * which is to be updated.
  742. *
  743. * Return: void
  744. */
  745. static void ODCfgGetNextTime(char **ppchConfigText)
  746. {
  747. char *pchConfigText = (char *)(*ppchConfigText);
  748. ASSERT(ppchConfigText != NULL);
  749. ASSERT(*ppchConfigText != NULL);
  750. btTimeNumVals = 0;
  751. awTimeVal[0] = 0;
  752. awTimeVal[1] = 0;
  753. awTimeVal[2] = 0;
  754. while(*pchConfigText && (*pchConfigText == ' ' || *pchConfigText == '\t'))
  755. {
  756. ++pchConfigText;
  757. }
  758. while(*pchConfigText && btTimeNumVals < 3)
  759. {
  760. if(*pchConfigText < '0' || *pchConfigText > '9') break;
  761. awTimeVal[btTimeNumVals++] = atoi(pchConfigText);
  762. while(*pchConfigText && *pchConfigText >= '0' && *pchConfigText <= '9')
  763. {
  764. ++pchConfigText;
  765. }
  766. if(*pchConfigText == ':' || *pchConfigText == '.' || *pchConfigText == ','
  767. || *pchConfigText == ';')
  768. {
  769. ++pchConfigText;
  770. }
  771. }
  772. *ppchConfigText = (char *)pchConfigText;
  773. }
  774. /* ----------------------------------------------------------------------------
  775. * ODCfgIsTrue() *** PRIVATE FUNCTION ***
  776. *
  777. * Determines whether the specified string represents a TRUE or FALSE value.
  778. * For example "Yes", "TRUE", "Y" and "1" all represent TRUE values, while
  779. * "No", "FALSE", "N" and "0" all represent FALSE values.
  780. *
  781. * Parameters: pszConfigText - String to examine.
  782. *
  783. * Return: The Boolean value represented by the string.
  784. */
  785. static BOOL ODCfgIsTrue(char *pszConfigText)
  786. {
  787. ASSERT(pszConfigText != NULL);
  788. while(*pszConfigText && (*pszConfigText == ' ' || *pszConfigText == '\t'))
  789. {
  790. ++pszConfigText;
  791. }
  792. switch(*pszConfigText)
  793. {
  794. case '1':
  795. case 't':
  796. case 'T':
  797. case 'y':
  798. case 'Y':
  799. case 'g':
  800. case 'G':
  801. return(TRUE);
  802. }
  803. return(FALSE);
  804. }