ex_diag.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /* ex_diag.c - Diagnostic door program, written to test environment in which
  2. * an OpenDooors door will run. Reads configuration settings from
  3. * command line and configuration file, and displays diagnostic
  4. * information on the local (and when possible, remote) screens.
  5. */
  6. #include <string.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include "OpenDoor.h"
  10. /******************/
  11. /* Wrapper macros */
  12. /******************/
  13. #if defined(__unix__)
  14. #if !defined(stricmp)
  15. #define stricmp(x,y) strcasecmp(x,y)
  16. #define strnicmp(x,y,z) strncasecmp(x,y,z)
  17. #endif
  18. #endif
  19. typedef enum
  20. {
  21. kParamLocal,
  22. kParamBPS,
  23. kParamPort,
  24. kParamNode,
  25. kParamHelp,
  26. kParamPersonality,
  27. kParamMaxTime,
  28. kParamAddress,
  29. kParamIRQ,
  30. kParamNoFOSSIL,
  31. kParamNoFIFO,
  32. kParamDropFile,
  33. kParamUserName,
  34. kParamTimeLeft,
  35. kParamSecurity,
  36. kParamLocation,
  37. kParamUnknown
  38. } tCommandLineParameter;
  39. char *BoolAsStr(int bValue);
  40. void ParseStandardCommandLine(int nArgCount, char *papszArguments[]);
  41. static void AdvanceToNextArg(int *pnCurrentArg, int nArgCount,
  42. char *pszOption);
  43. static void GetNextArgName(int *pnCurrentArg, int nArgCount,
  44. char *papszArguments[], char *pszString,
  45. int nStringSize);
  46. static tCommandLineParameter GetCommandLineParameter(char *pszArgument);
  47. int main(int argc, char *argv[])
  48. {
  49. char sz[80];
  50. int n;
  51. /* Parse command-line. */
  52. ParseStandardCommandLine(argc, argv);
  53. /* Initialize OpenDoors. */
  54. od_init();
  55. od_clr_scr();
  56. od_printf("OpenDoors has been initialized.\n\r");
  57. for(;;)
  58. {
  59. od_printf("\n\rPOST-INITIALIZATION DIAGNOSTIC INFORMATION:\n\r");
  60. od_printf(" Running in REMOTE mode : %s\n\r",
  61. BoolAsStr(od_control.baud));
  62. od_printf(" Port <-> Modem BPS Rate : %lu\n\r", od_control.baud);
  63. od_printf(" Serial Port Number : %d (COM%d:)\n\r", od_control.port,
  64. od_control.port + 1);
  65. od_printf(" Serial I/O Method : ");
  66. switch(od_control.od_com_method)
  67. {
  68. case COM_FOSSIL:
  69. od_printf("FOSSIL Driver\n\r");
  70. break;
  71. case COM_INTERNAL:
  72. od_printf("OpenDoors Internal I/O Module\n\r");
  73. break;
  74. case COM_SOCKET:
  75. od_printf("TCP Socket/Telnet\n\r");
  76. break;
  77. default:
  78. od_printf("Unknown\n\r");
  79. break;
  80. }
  81. od_printf(" Drop File Type : ");
  82. switch(od_control.od_info_type)
  83. {
  84. case DORINFO1:
  85. od_printf("DORINFO?.DEF\n\r");
  86. break;
  87. case EXITINFO:
  88. od_printf("Basic EXITINFO.BBS & DORINFO1.DEF\n\r");
  89. break;
  90. case RA1EXITINFO:
  91. od_printf("RA 1.x EXITINFO.BBS & DORINFO1.DEF\n\r");
  92. break;
  93. case CHAINTXT:
  94. od_printf("CHAIN.TXT\n\r");
  95. break;
  96. case SFDOORSDAT:
  97. od_printf("SFDOORS.DAT\n\r");
  98. break;
  99. case CALLINFO:
  100. od_printf("CALLINFO.BBS\n\r");
  101. break;
  102. case DOORSYS_GAP:
  103. od_printf("GAP style DOOR.SYS\n\r");
  104. break;
  105. case DOORSYS_DRWY:
  106. od_printf("DoorWay DOOR.SYS\n\r");
  107. break;
  108. case QBBS275EXITINFO:
  109. od_printf("QuickBBS 2.75+ EXITINFO.BBS\n\r");
  110. break;
  111. case CUSTOM:
  112. od_printf("User-Defined Custom Format\n\r");
  113. break;
  114. case DOORSYS_WILDCAT:
  115. od_printf("WildCat! DOOR.SYS\n\r");
  116. break;
  117. case RA2EXITINFO:
  118. od_printf("RA 2.x+ EXITINFO.BBS & DORINFO1.DEF\n\r");
  119. break;
  120. case NO_DOOR_FILE:
  121. od_printf("No Drop File in Use\n\r");
  122. break;
  123. case DOOR32SYS:
  124. od_printf("Door32.sys\n\r");
  125. break;
  126. default:
  127. od_printf("Unknown Type\n\r");
  128. break;
  129. }
  130. od_printf(" ANSI Mode Available : %s\n\r",
  131. BoolAsStr(od_control.user_ansi));
  132. od_printf(" AVATAR Mode Available : %s\n\r",
  133. BoolAsStr(od_control.user_avatar));
  134. od_printf(" RIP Graphics Available : %s\n\r",
  135. BoolAsStr(od_control.user_rip));
  136. od_printf(" User's Time Limit : %d\n\r", od_control.user_timelimit);
  137. od_printf(" User's Full Name : %s\n\r", od_control.user_name);
  138. od_printf("\n\rChoose Option: [E]xit, [T]yping Test,");
  139. if(od_control.od_com_method == COM_INTERNAL)
  140. {
  141. od_printf(" [I]nternal I/O Diags,");
  142. }
  143. od_printf("\n\r");
  144. od_printf(" [A]utodetect ANSI/RIP, [R]e-Display, [D]isplay Tests\n\r");
  145. n=od_get_answer("eitard");
  146. switch(n)
  147. {
  148. case 'e':
  149. od_clr_scr();
  150. od_printf("\n\rExit - Are You Sure (Y/N)? ");
  151. if(od_get_answer("yn") == 'y')
  152. {
  153. return(0);
  154. }
  155. break;
  156. case 'i':
  157. od_clr_scr();
  158. od_printf("INTERNAL SERIAL I/O DIAGNOSTIC INFORMATION:\n\r");
  159. od_printf(" Serial Port Base Address : %x\n\r",
  160. od_control.od_com_address);
  161. od_printf(" IRQ Line Number : %d\n\r",
  162. od_control.od_com_irq);
  163. od_printf(" Receive Buffer Size : %d\n\r",
  164. od_control.od_com_rx_buf);
  165. od_printf(" Transmit Buffer Size : %d\n\r",
  166. od_control.od_com_tx_buf);
  167. od_printf(" Use FIFO Buffer, if avail : %s\n\r",
  168. BoolAsStr(!od_control.od_com_no_fifo));
  169. od_printf(" FIFO Trigger Size : %d\n\r",
  170. od_control.od_com_fifo_trigger);
  171. od_printf("\n\rPress [ENTER] to return.\n\r");
  172. od_get_answer("\n\r");
  173. break;
  174. case 't':
  175. od_clr_scr();
  176. od_printf("\n\rTyping Test - Type any text below:\n\r");
  177. od_printf("[------------------------------------------------------"
  178. "-----------------------]\n\r");
  179. od_input_str(sz, 79, 0, 255);
  180. od_printf("\n\rEntered Text:\n\r%s\n\r", sz);
  181. od_printf("\n\rPress [ENTER] to return.\n\r");
  182. od_get_answer("\n\r");
  183. break;
  184. case 'a':
  185. od_clr_scr();
  186. od_printf("\n\rAutodetecting ANSI/RIP mode ...\n\r");
  187. od_printf("(Detected modes will be turned on.)\n\r");
  188. od_autodetect(0);
  189. od_printf("\n\rDone, press [ENTER] to return.\n\r");
  190. od_get_answer("\n\r");
  191. break;
  192. case 'd':
  193. od_clr_scr();
  194. od_printf("CLEAR SCREEN TEST\n\r");
  195. od_printf("About to test clear screen. The screen should\n\r");
  196. od_printf("be cleared before the next test if screen\n\r");
  197. od_printf("clearing is enabled.\n\r");
  198. od_printf("\n\rPress [ENTER] to perform test.\n\r");
  199. od_get_answer("\n\r");
  200. od_clr_scr();
  201. od_printf("CARRIAGE RETURN TEST:\n\r");
  202. od_printf("This should not be visible\r");
  203. od_printf("This should cover it up...\n\r\n\r");
  204. od_printf("The text \"This should not be visible\" will\n\r");
  205. od_printf("appear above if this test failed.\n\r");
  206. od_printf("\n\rPress [ENTER] to perform next test.\n\r");
  207. od_get_answer("\n\r");
  208. od_clr_scr();
  209. od_printf("COLOR TEST:\n\r\n\r");
  210. for(n = 0; n < 256; ++n)
  211. {
  212. od_set_attrib(n);
  213. od_printf("%x", n % 16);
  214. if(n % 32 == 31)
  215. {
  216. od_set_attrib(0x07);
  217. od_printf("\n\r");
  218. }
  219. }
  220. od_printf("\n\rIf ANSI or AVATAR modes are available, the\n\r");
  221. od_printf("above test pattern should print in color.\n\r");
  222. od_printf("\n\rPress [ENTER] to perform next test.\n\r");
  223. od_get_answer("\n\r");
  224. od_clr_scr();
  225. od_printf("CURSOR POSITIONING TEST:\n\r");
  226. for(n = 15; n > 2; --n)
  227. {
  228. od_set_cursor(n, n);
  229. od_printf("\\");
  230. }
  231. for(n = 15; n > 2; --n)
  232. {
  233. od_set_cursor(n, 17 - n);
  234. od_printf("/");
  235. }
  236. od_set_cursor(17, 1);
  237. od_printf("If ANSI or AVATAR modes are available, a large X\n\r");
  238. od_printf("should appear on lines 3 to 15.\n\r");
  239. od_printf("\n\rPress [ENTER] to return.\n\r");
  240. od_get_answer("\n\r");
  241. break;
  242. }
  243. od_clr_scr();
  244. }
  245. /* Return with success. */
  246. return(0);
  247. }
  248. char *BoolAsStr(int bValue)
  249. {
  250. return(bValue ? "Yes (TRUE)" : "No (FALSE)");
  251. }
  252. void ParseStandardCommandLine(int nArgCount, char *papszArguments[])
  253. {
  254. char *pszCurrentArg;
  255. int nCurrentArg;
  256. for(nCurrentArg = 1; nCurrentArg < nArgCount; ++nCurrentArg)
  257. {
  258. pszCurrentArg = papszArguments[nCurrentArg];
  259. switch(GetCommandLineParameter(pszCurrentArg))
  260. {
  261. case kParamLocal:
  262. od_control.od_force_local = TRUE;
  263. break;
  264. case kParamBPS:
  265. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  266. od_control.baud = atol(papszArguments[nCurrentArg]);
  267. break;
  268. case kParamPort:
  269. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  270. od_control.port = atoi(papszArguments[nCurrentArg]);
  271. break;
  272. case kParamHelp:
  273. printf("AVALIABLE COMMAND LINE PARAMETERS:\n");
  274. printf(" -L or -LOCAL - Causes door to operate in local mode, without requiring a\n");
  275. printf(" door information (drop) file.\n");
  276. printf(" -DROPFILE x - Door information file directory or directory+filename.\n");
  277. printf(" -N x or -NODE x - Sets the node number to use.\n");
  278. printf(" -B x or -BPS x - Sets the serial port <---> modem bps (baud) rate to use.\n");
  279. printf(" -P x or -PORT x - Sets the serial port to use, were 0=COM1, 1=COM2, etc.\n");
  280. printf(" -ADDRESS x - Sets serial port address in decimal NOT hexidecimal\n");
  281. printf(" (only has effect if FOSSIL driver is not being used).\n");
  282. printf(" -IRQ x - Sets the serial port IRQ line (only has effect if FOSSIL\n");
  283. printf(" driver is not being used).\n");
  284. printf(" -NOFOSSIL - Disables use of FOSSIL driver, even if available.\n");
  285. printf(" -NOFIFO - Disables use of 16550 FIFO buffers (only if FOSSIL driver\n");
  286. printf(" is not being used).\n");
  287. printf(" -PERSONALITY x - Sets the sysop status line / function key personality to\n");
  288. printf(" use - one of Standard, PCBoard, RemoteAccess or Wildcat.\n");
  289. printf(" -MAXTIME x - Sets the maximum number of minutes that any user will be\n");
  290. printf(" permitted to access the door.\n");
  291. printf(" -USERNAME x - Name of user who is currently online.\n");
  292. printf(" -TIMELEFT x - User's time remaining online.\n");
  293. printf(" -SECURITY x - User's security level.\n");
  294. printf(" -LOCATION x - Location from which user is calling.\n");
  295. printf(" -?, -H or -HELP - Displays command-line help and exits.\n");
  296. exit(1);
  297. break;
  298. case kParamNode:
  299. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  300. od_control.od_node = atoi(papszArguments[nCurrentArg]);
  301. break;
  302. case kParamPersonality:
  303. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  304. if(stricmp(papszArguments[nCurrentArg], "Standard") == 0)
  305. {
  306. od_control.od_default_personality = PER_OPENDOORS;
  307. }
  308. else if(stricmp(papszArguments[nCurrentArg], "PCBoard") == 0)
  309. {
  310. od_control.od_default_personality = PER_PCBOARD;
  311. }
  312. else if(stricmp(papszArguments[nCurrentArg], "RemoteAccess") == 0)
  313. {
  314. od_control.od_default_personality = PER_RA;
  315. }
  316. else if(stricmp(papszArguments[nCurrentArg], "Wildcat") == 0)
  317. {
  318. od_control.od_default_personality = PER_WILDCAT;
  319. }
  320. else
  321. {
  322. printf("Unknown personality: %s\n", papszArguments[nCurrentArg]);
  323. exit(1);
  324. }
  325. break;
  326. case kParamMaxTime:
  327. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  328. od_control.od_maxtime = atoi(papszArguments[nCurrentArg]);
  329. break;
  330. case kParamAddress:
  331. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  332. od_control.od_com_address = atoi(papszArguments[nCurrentArg]);
  333. break;
  334. case kParamIRQ:
  335. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  336. od_control.od_com_irq = atoi(papszArguments[nCurrentArg]);
  337. break;
  338. case kParamNoFOSSIL:
  339. od_control.od_no_fossil = TRUE;
  340. break;
  341. case kParamNoFIFO:
  342. od_control.od_com_no_fifo = TRUE;
  343. break;
  344. case kParamDropFile:
  345. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  346. strncpy(od_control.info_path, papszArguments[nCurrentArg],
  347. sizeof(od_control.info_path) - 1);
  348. od_control.info_path[sizeof(od_control.info_path) - 1] = '\0';
  349. break;
  350. case kParamUserName:
  351. GetNextArgName(&nCurrentArg, nArgCount, papszArguments,
  352. od_control.user_name, sizeof(od_control.user_name));
  353. break;
  354. case kParamTimeLeft:
  355. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  356. od_control.user_timelimit = atoi(papszArguments[nCurrentArg]);
  357. break;
  358. case kParamSecurity:
  359. AdvanceToNextArg(&nCurrentArg, nArgCount, pszCurrentArg);
  360. od_control.user_security = atoi(papszArguments[nCurrentArg]);
  361. break;
  362. case kParamLocation:
  363. GetNextArgName(&nCurrentArg, nArgCount, papszArguments,
  364. od_control.user_location, sizeof(od_control.user_location));
  365. break;
  366. default:
  367. printf("Unrecognized command line option: %s\n", pszCurrentArg);
  368. exit(1);
  369. break;
  370. }
  371. }
  372. }
  373. static void AdvanceToNextArg(int *pnCurrentArg, int nArgCount, char *pszOption)
  374. {
  375. if(++*pnCurrentArg >= nArgCount)
  376. {
  377. printf("Missing parameter for option: %s\n", pszOption);
  378. exit(1);
  379. }
  380. }
  381. static void GetNextArgName(int *pnCurrentArg, int nArgCount,
  382. char *papszArguments[], char *pszString,
  383. int nStringSize)
  384. {
  385. int bFirst = TRUE;
  386. if((*pnCurrentArg) + 1 >= nArgCount)
  387. {
  388. printf("Missing parameter for option: %s\n",
  389. papszArguments[(*pnCurrentArg) - 1]);
  390. exit(1);
  391. }
  392. pszString[0] = '\0';
  393. while(++*pnCurrentArg < nArgCount)
  394. {
  395. if(GetCommandLineParameter(papszArguments[*pnCurrentArg])
  396. != kParamUnknown)
  397. {
  398. --*pnCurrentArg;
  399. break;
  400. }
  401. if(strlen(pszString) >= nStringSize - 1)
  402. {
  403. break;
  404. }
  405. if(!bFirst)
  406. {
  407. strcat(pszString, " ");
  408. }
  409. strncat(pszString, papszArguments[*pnCurrentArg],
  410. strlen(pszString) - nStringSize - 1);
  411. pszString[nStringSize - 1] = '\0';
  412. bFirst = FALSE;
  413. }
  414. }
  415. static tCommandLineParameter GetCommandLineParameter(char *pszArgument)
  416. {
  417. if(*pszArgument == '-' || *pszArgument == '/')
  418. {
  419. ++pszArgument;
  420. }
  421. if(stricmp(pszArgument, "L") == 0
  422. || stricmp(pszArgument, "LOCAL") == 0)
  423. {
  424. return(kParamLocal);
  425. }
  426. else if(stricmp(pszArgument, "B") == 0
  427. || stricmp(pszArgument, "BPS") == 0
  428. || stricmp(pszArgument, "BAUD") == 0)
  429. {
  430. return(kParamBPS);
  431. }
  432. else if(stricmp(pszArgument, "P") == 0
  433. || stricmp(pszArgument, "PORT") == 0)
  434. {
  435. return(kParamPort);
  436. }
  437. else if(stricmp(pszArgument, "N") == 0
  438. || stricmp(pszArgument, "NODE") == 0)
  439. {
  440. return(kParamNode);
  441. }
  442. else if(stricmp(pszArgument, "?") == 0
  443. || stricmp(pszArgument, "H") == 0
  444. || stricmp(pszArgument, "HELP") == 0)
  445. {
  446. return(kParamHelp);
  447. }
  448. else if(stricmp(pszArgument, "PERSONALITY") == 0)
  449. {
  450. return(kParamPersonality);
  451. }
  452. else if(stricmp(pszArgument, "MAXTIME") == 0)
  453. {
  454. return(kParamMaxTime);
  455. }
  456. else if(stricmp(pszArgument, "ADDRESS") == 0)
  457. {
  458. return(kParamAddress);
  459. }
  460. else if(stricmp(pszArgument, "IRQ") == 0)
  461. {
  462. return(kParamIRQ);
  463. }
  464. else if(stricmp(pszArgument, "NOFOSSIL") == 0)
  465. {
  466. return(kParamNoFOSSIL);
  467. }
  468. else if(stricmp(pszArgument, "NOFIFO") == 0)
  469. {
  470. return(kParamNoFIFO);
  471. }
  472. else if(stricmp(pszArgument, "DROPFILE") == 0)
  473. {
  474. return(kParamDropFile);
  475. }
  476. else if(stricmp(pszArgument, "USERNAME") == 0)
  477. {
  478. return(kParamUserName);
  479. }
  480. else if(stricmp(pszArgument, "TIMELEFT") == 0)
  481. {
  482. return(kParamTimeLeft);
  483. }
  484. else if(stricmp(pszArgument, "SECURITY") == 0)
  485. {
  486. return(kParamSecurity);
  487. }
  488. else if(stricmp(pszArgument, "LOCATION") == 0)
  489. {
  490. return(kParamLocation);
  491. }
  492. else
  493. {
  494. return(kParamUnknown);
  495. }
  496. }
  497. void NoDoorFileHandler(void)
  498. {
  499. /* Alter OpenDoors behaviour, so that we proceed with defaults if */
  500. /* no door information file is available, rather than exiting with */
  501. /* an error. Set od_no_file_func to point to this function. */
  502. if(strlen(od_control.user_name) == 0)
  503. {
  504. strcpy(od_control.user_name, "Unknown User");
  505. }
  506. if(strlen(od_control.user_location) == 0)
  507. {
  508. strcpy(od_control.user_location, "Unknown Location");
  509. }
  510. if(od_control.user_timelimit == 0)
  511. {
  512. od_control.user_timelimit = 30;
  513. }
  514. od_control.od_info_type = CUSTOM;
  515. }