ChipMaster's bwBASIC This also includes history going back to v2.10. *WARN* some binary files might have been corrupted by CRLF.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

3692 lines
87 KiB

  1. /***************************************************************
  2. bwbasic.c Main Program File
  3. for Bywater BASIC Interpreter
  4. Copyright (c) 1993, Ted A. Campbell
  5. Bywater Software
  6. email: tcamp@delphi.com
  7. Copyright and Permissions Information:
  8. All U.S. and international rights are claimed by the author,
  9. Ted A. Campbell.
  10. This software is released under the terms of the GNU General
  11. Public License (GPL), which is distributed with this software
  12. in the file "COPYING". The GPL specifies the terms under
  13. which users may copy and use the software in this distribution.
  14. A separate license is available for commercial distribution,
  15. for information on which you should contact the author.
  16. ***************************************************************/
  17. /*---------------------------------------------------------------*/
  18. /* NOTE: Modifications marked "JBV" were made by Jon B. Volkoff, */
  19. /* 11/1995 (eidetics@cerf.net). */
  20. /* */
  21. /* Those additionally marked with "DD" were at the suggestion of */
  22. /* Dale DePriest (daled@cadence.com). */
  23. /* */
  24. /* Version 3.00 by Howard Wulf, AF5NE */
  25. /* */
  26. /* Version 3.10 by Howard Wulf, AF5NE */
  27. /* */
  28. /* Version 3.20 by Howard Wulf, AF5NE */
  29. /* */
  30. /* Version 3.20f by KenUNIX & Chipmaster */
  31. /* */
  32. /*---------------------------------------------------------------*/
  33. #include "bwbasic.h"
  34. static void break_handler (void);
  35. static void break_mes (int x);
  36. static int bwb_init (void);
  37. static void bwb_initialize_warnings (void);
  38. static void bwb_interact (void);
  39. static int bwb_ladd (char *buffer, LineType * p, int IsUser);
  40. static void bwb_single_step (char *buffer);
  41. static void bwb_xtxtline (char *buffer);
  42. static int bwx_signon (void);
  43. static void execute_profile (char *FileName);
  44. static void execute_program (char *FileName);
  45. static char *FindClassicStatementEnd (char *C);
  46. static int FixQuotes (char *tbuf);
  47. static void ImportClassicIfThenElse (char *InBuffer);
  48. static int is_ln (char *buffer);
  49. static int is_numconst (char *buffer);
  50. static void mark_preset_variables (void);
  51. static FILE *nice_open (char *BaseName);
  52. static void process_basic_line (char *buffer);
  53. GlobalType *My = NULL;
  54. static char *Banner[] = {
  55. "######## ## ## ## ## ### ######## ######## ######## ",
  56. "## ## ## ## ## ## ## ## ## ## ## ## ## ",
  57. "## ## #### ## ## ## ## ## ## ## ## ## ",
  58. "######## ## ## ## ## ## ## ## ###### ######## ",
  59. "## ## ## ## ## ## ######### ## ## ## ## ",
  60. "## ## ## ## ## ## ## ## ## ## ## ## ",
  61. "######## ## ### ### ## ## ## ######## ## ## ",
  62. " ",
  63. " ######## ### ###### #### ###### ",
  64. " ## ## ## ## ## ## ## ## ##",
  65. " ## ## ## ## ## ## ## ",
  66. " ######## ## ## ###### ## ## ",
  67. " ## ## ######### ## ## ## ",
  68. " ## ## ## ## ## ## ## ## ##",
  69. " ######## ## ## ###### #### ###### ",
  70. " ",
  71. "Bywater BASIC Interpreter, version 3.20f ",
  72. "Copyright (c) 1993, Ted A. Campbell ",
  73. "Copyright (c) 1995-1997 , Jon B. Volkoff ",
  74. "Copyright (c) 2014-2017 , Howard Wulf, AF5NE ",
  75. " 2019-2021 , KenUNIX & Chipmaster with fixes ",
  76. " ",
  77. NULL
  78. };
  79. #define NUM_WARNINGS 80
  80. static char *ERROR4[NUM_WARNINGS];
  81. static void
  82. bwb_initialize_warnings (void)
  83. {
  84. int i;
  85. for (i = 0; i < NUM_WARNINGS; i++)
  86. {
  87. ERROR4[i] = NULL;
  88. }
  89. /* Error code tree */
  90. ERROR4[1] = "NEXT without FOR";
  91. ERROR4[2] = "Syntax error";
  92. ERROR4[3] = "RETURN without GOSUB";
  93. ERROR4[4] = "Out of DATA";
  94. ERROR4[5] = "Illegal function call";
  95. ERROR4[6] = "Overflow";
  96. ERROR4[7] = "Out of memory";
  97. ERROR4[8] = "Undefined line";
  98. ERROR4[9] = "Subscript out of range";
  99. ERROR4[10] = "Redimensioned array";
  100. ERROR4[11] = "Division by zero";
  101. ERROR4[12] = "Illegal direct";
  102. ERROR4[13] = "Type mismatch";
  103. ERROR4[14] = "Out of string space";
  104. ERROR4[15] = "String too long";
  105. ERROR4[16] = "String formula too complex";
  106. ERROR4[17] = "Can't continue";
  107. ERROR4[18] = "Undefined user function";
  108. ERROR4[19] = "No RESUME";
  109. ERROR4[20] = "RESUME without error";
  110. ERROR4[21] = "Unprintable error";
  111. ERROR4[22] = "Missing operand";
  112. ERROR4[23] = "Line buffer overflow";
  113. ERROR4[26] = "FOR without NEXT";
  114. ERROR4[27] = "Bad DATA";
  115. ERROR4[29] = "WHILE without WEND";
  116. ERROR4[30] = "WEND without WHILE";
  117. ERROR4[31] = "EXIT FUNCTION without FUNCTION";
  118. ERROR4[32] = "END FUNCTION without FUNCTION";
  119. ERROR4[33] = "EXIT SUB without SUB";
  120. ERROR4[34] = "END SUB without SUB";
  121. ERROR4[35] = "EXIT FOR without FOR";
  122. ERROR4[50] = "Field overflow";
  123. ERROR4[51] = "Internal error";
  124. ERROR4[52] = "Bad file number";
  125. ERROR4[53] = "File not found";
  126. ERROR4[54] = "Bad file mode";
  127. ERROR4[55] = "File already open";
  128. ERROR4[57] = "Disk I/O error";
  129. ERROR4[58] = "File already exists";
  130. ERROR4[61] = "Disk full";
  131. ERROR4[62] = "Input past end";
  132. ERROR4[63] = "Bad record number";
  133. ERROR4[64] = "Bad file name";
  134. ERROR4[66] = "Direct statement in file";
  135. ERROR4[67] = "Too many files";
  136. ERROR4[70] = "Variable Not Declared";
  137. ERROR4[73] = "Advanced Feature";
  138. }
  139. /***************************************************************
  140. FUNCTION: bwx_terminate()
  141. DESCRIPTION: This function terminates program execution.
  142. ***************************************************************/
  143. void
  144. bwx_terminate (void)
  145. {
  146. exit (0);
  147. }
  148. /***************************************************************
  149. FUNCTION: break_handler()
  150. DESCRIPTION: This function is called by break_mes()
  151. and handles program interruption by break
  152. (or by the STOP command).
  153. ***************************************************************/
  154. static void
  155. break_handler (void)
  156. {
  157. /*
  158. **
  159. **
  160. */
  161. assert( My != NULL );
  162. My->AutomaticLineNumber = 0;
  163. My->AutomaticLineIncrement = 0;
  164. if (My->IsInteractive)
  165. {
  166. /* INTERACTIVE: terminate program */
  167. /* reset all stack counters */
  168. bwb_clrexec ();
  169. SetOnError (0);
  170. My->ERR = -1; /* in break_handler() */
  171. /* reset the break handler */
  172. signal (SIGINT, break_mes);
  173. longjmp (My->mark, -1);
  174. return;
  175. }
  176. /* NOT INTERACTIVE: terminate immediately */
  177. bwx_terminate ();
  178. }
  179. /***************************************************************
  180. FUNCTION: break_mes()
  181. DESCRIPTION: This function is called (a) by a SIGINT
  182. signal or (b) by bwb_STOP via bwx_STOP.
  183. It prints an error message then calls
  184. break_handler() to terminate the program.
  185. ***************************************************************/
  186. static void
  187. break_mes (int x /* Parameter 'x' is never used */ )
  188. {
  189. /*
  190. **
  191. ** break_mes is FATAL.
  192. ** x == SIGINT for control-C
  193. ** x == 0 for bwx_STOP
  194. **
  195. */
  196. assert( My != NULL );
  197. assert( My->SYSOUT != NULL );
  198. assert( My->SYSOUT->cfp != NULL );
  199. assert( My->CurrentVersion != NULL );
  200. if (My->ERR < 0) /* in break_mes(), do not make a bad situation worse */
  201. {
  202. /* an error has already ben reported */
  203. }
  204. else
  205. {
  206. fputc ('\n', My->SYSOUT->cfp);
  207. ResetConsoleColumn ();
  208. if (My->CurrentVersion->OptionVersionValue & (C77))
  209. {
  210. if (is_empty_string (My->ProgramFilename) == FALSE)
  211. {
  212. fprintf (My->SYSOUT->cfp, "FILE:%s, ", My->ProgramFilename);
  213. }
  214. }
  215. fprintf (My->SYSOUT->cfp, "Program interrupted");
  216. if (My->ThisLine) /* break_mes */
  217. {
  218. if (My->ThisLine->LineFlags & (LINE_USER)) /* break_mes */
  219. {
  220. /* don't print the line number */
  221. }
  222. else
  223. {
  224. fprintf (My->SYSOUT->cfp, " at line %d", My->ThisLine->number); /* break_mes */
  225. }
  226. }
  227. fputc ('\n', My->SYSOUT->cfp);
  228. ResetConsoleColumn ();
  229. fflush (My->SYSOUT->cfp);
  230. }
  231. break_handler ();
  232. }
  233. extern void
  234. bwx_STOP (int IsShowMessage)
  235. {
  236. if (IsShowMessage)
  237. {
  238. break_mes (0);
  239. }
  240. else
  241. {
  242. break_handler ();
  243. }
  244. }
  245. static int
  246. bwx_signon (void)
  247. {
  248. /*
  249. **
  250. ** Display a sign-on banner.
  251. ** NOT called if a file is provided on the command line.
  252. **
  253. */
  254. int i;
  255. assert( My != NULL );
  256. assert( My->SYSOUT != NULL );
  257. assert( My->SYSOUT->cfp != NULL );
  258. for (i = 0; Banner[i] != NULL; i++)
  259. {
  260. fprintf (My->SYSOUT->cfp, "%s\n", Banner[i]);
  261. }
  262. ResetConsoleColumn ();
  263. return TRUE;
  264. }
  265. DoubleType
  266. bwx_TIMER (DoubleType Seconds)
  267. {
  268. /*
  269. **
  270. ** Return a number representing Seconds in the future. Seconds >= 0.
  271. ** Seconds may be non-integer, such as 0.001 or 86399.999. The
  272. ** maximum allowed Seconds is MAXDBL. This is used two ways:
  273. **
  274. ** 1) in bwb_TIMER(), the ON TIMER count (>0) is used to determine
  275. ** the expiration time. In this case, simply return what the value
  276. ** will be in the future. Note that ON TIMER enforces
  277. ** Seconds > (1 / CLOCKS_PER_SEC), and
  278. **
  279. ** 2) in bwb_execline(), zero (=0) is used to determine the current
  280. ** time and compare it to #1. In this case, simply return what the
  281. ** value is now.
  282. **
  283. ** Both the resolution of the timer, and the frequency of update,
  284. ** are implementation defined.
  285. **
  286. */
  287. if (Seconds < 0)
  288. {
  289. WARN_INTERNAL_ERROR;
  290. return 0;
  291. }
  292. else
  293. {
  294. DoubleType Result;
  295. Result = clock ();
  296. assert (CLOCKS_PER_SEC > 0);
  297. Result /= CLOCKS_PER_SEC;
  298. if (Seconds > 0)
  299. {
  300. Result += Seconds;
  301. }
  302. return Result;
  303. }
  304. }
  305. void
  306. CleanLine (char *buffer)
  307. {
  308. /*
  309. **
  310. ** cleanup the line, so it is easier to parse
  311. **
  312. */
  313. char *newbuffer;
  314. if (is_empty_string (buffer))
  315. {
  316. /* do nothing */
  317. return;
  318. }
  319. /* remove CR/LF */
  320. newbuffer = bwb_strchr (buffer, '\r');
  321. if (newbuffer != NULL)
  322. {
  323. *newbuffer = NulChar;
  324. }
  325. newbuffer = bwb_strchr (buffer, '\n');
  326. if (newbuffer != NULL)
  327. {
  328. *newbuffer = NulChar;
  329. }
  330. /* remove ALL embedded control characters */
  331. /* if you want a control character, then use CHR$ */
  332. newbuffer = buffer;
  333. while (*newbuffer != NulChar)
  334. {
  335. if (bwb_isprint (*newbuffer))
  336. {
  337. /* OK */
  338. }
  339. else
  340. {
  341. *newbuffer = ' ';
  342. }
  343. newbuffer++;
  344. }
  345. /* LTRIM$ */
  346. newbuffer = buffer;
  347. if (*newbuffer != NulChar)
  348. {
  349. /* not an empty line, so remove one (or more) leading spaces */
  350. while (*newbuffer == ' ')
  351. {
  352. newbuffer++;
  353. }
  354. if (newbuffer > buffer)
  355. {
  356. bwb_strcpy (buffer, newbuffer);
  357. }
  358. }
  359. /* RTRIM$ */
  360. newbuffer = buffer;
  361. if (*newbuffer != NulChar)
  362. {
  363. /* not an empty line, so remove one (or more) trailing spaces */
  364. char *E;
  365. E = bwb_strchr (newbuffer, NulChar);
  366. E--;
  367. while (E >= newbuffer && *E == ' ')
  368. {
  369. *E = NulChar;
  370. E--;
  371. }
  372. }
  373. }
  374. static int
  375. bwb_init (void)
  376. {
  377. /*
  378. **
  379. ** initialize Bywater BASIC
  380. **
  381. */
  382. int n;
  383. static char start_buf[] = "";
  384. static char end_buf[] = "";
  385. /* Memory allocation */
  386. if ((My = (GlobalType *) calloc (1, sizeof (GlobalType))) == NULL)
  387. {
  388. return FALSE;
  389. }
  390. if ((My->MaxLenBuffer =
  391. (char *) calloc (MAXLEN + 1 /* NulChar */ , sizeof (char))) == NULL)
  392. {
  393. return FALSE;
  394. }
  395. if ((My->NumLenBuffer =
  396. (char *) calloc (NUMLEN + 1 /* NulChar */ , sizeof (char))) == NULL)
  397. {
  398. return FALSE;
  399. }
  400. if ((My->ConsoleOutput =
  401. (char *) calloc (MAX_LINE_LENGTH + 1 /* NulChar */ ,
  402. sizeof (char))) == NULL)
  403. {
  404. return FALSE;
  405. }
  406. if ((My->ConsoleInput =
  407. (char *) calloc (MAX_LINE_LENGTH + 1 /* NulChar */ ,
  408. sizeof (char))) == NULL)
  409. {
  410. return FALSE;
  411. }
  412. if ((My->SYSIN = (FileType *) calloc (1, sizeof (FileType))) == NULL)
  413. {
  414. return FALSE;
  415. }
  416. if ((My->SYSOUT = (FileType *) calloc (1, sizeof (FileType))) == NULL)
  417. {
  418. return FALSE;
  419. }
  420. if ((My->SYSPRN = (FileType *) calloc (1, sizeof (FileType))) == NULL)
  421. {
  422. return FALSE;
  423. }
  424. if ((My->StartMarker = (LineType *) calloc (1, sizeof (LineType))) == NULL)
  425. {
  426. return FALSE;
  427. }
  428. if ((My->UserMarker = (LineType *) calloc (1, sizeof (LineType))) == NULL)
  429. {
  430. return FALSE;
  431. }
  432. if ((My->EndMarker = (LineType *) calloc (1, sizeof (LineType))) == NULL)
  433. {
  434. return FALSE;
  435. }
  436. if ((My->EndMarker = (LineType *) calloc (1, sizeof (LineType))) == NULL)
  437. {
  438. return FALSE;
  439. }
  440. if ((My->ERROR4 =
  441. (char *) calloc (MAX_ERR_LENGTH + 1 /* NulChar */ ,
  442. sizeof (char))) == NULL)
  443. {
  444. return FALSE;
  445. }
  446. My->CurrentVersion = &bwb_vertable[0];
  447. My->IsInteractive = TRUE;
  448. My->OptionSleepDouble = 1;
  449. My->OptionIndentInteger = 2;
  450. My->OptionTerminalType = C_OPTION_TERMINAL_NONE;
  451. My->OptionRoundType = C_OPTION_ROUND_BANK;
  452. My->NextValidLineNumber = MINLIN;
  453. My->IncludeLevel = 0; /* %INCLUDE */
  454. My->IsCommandLineFile = FALSE;
  455. My->ExternalInputFile = NULL; /* for automated testing, --TAPE command line parameter */
  456. My->IsPrinter = FALSE; /* CBASIC-II: CONSOLE and LPRINTER commands */
  457. My->OptionPromptString = DEF_PROMPT;
  458. My->OptionEditString = DEF_EDITOR;
  459. My->OptionFilesString = DEF_FILES;
  460. My->OptionRenumString = DEF_RENUM;
  461. My->OptionExtensionString = DEF_EXTENSION;
  462. My->OptionScaleInteger = 0;
  463. My->OptionDigitsInteger = SIGNIFICANT_DIGITS;
  464. My->OptionZoneInteger = ZONE_WIDTH;
  465. My->UseParameterString = NULL;
  466. My->ProgramFilename = NULL;
  467. My->StartMarker->number = MINLIN - 1;
  468. My->StartMarker->next = My->EndMarker;
  469. My->StartMarker->position = 0;
  470. My->StartMarker->buffer = start_buf;
  471. My->EndMarker->number = MAXLIN + 1;
  472. My->EndMarker->next = My->EndMarker;
  473. My->EndMarker->position = 0;
  474. My->EndMarker->buffer = end_buf;
  475. My->UserMarker->number = MINLIN - 1;
  476. My->UserMarker->next = My->EndMarker;
  477. My->UserMarker->position = 0;
  478. My->UserMarker->buffer = NULL;
  479. My->DataLine = My->EndMarker;
  480. My->DataPosition = 0;
  481. My->StackHead = NULL;
  482. My->StackDepthInteger = 0;
  483. My->FieldHead = NULL;
  484. My->VirtualHead = NULL;
  485. My->FileHead = NULL;
  486. My->ThisLine = My->StartMarker; /* bwb_init */
  487. My->SYSIN->DevMode = DEVMODE_INPUT;
  488. My->SYSIN->width = 80;
  489. My->SYSIN->col = 1;
  490. My->SYSIN->row = 1;
  491. My->SYSIN->delimit = ',';
  492. My->SYSIN->cfp = stdin;
  493. My->SYSOUT->DevMode = DEVMODE_OUTPUT;
  494. My->SYSOUT->width = 80;
  495. My->SYSOUT->col = 1;
  496. My->SYSOUT->row = 1;
  497. My->SYSOUT->delimit = ',';
  498. My->SYSOUT->cfp = stdout;
  499. My->SYSPRN->DevMode = DEVMODE_OUTPUT;
  500. My->SYSPRN->width = 80;
  501. My->SYSPRN->col = 1;
  502. My->SYSPRN->row = 1;
  503. My->SYSPRN->delimit = ',';
  504. My->SYSPRN->cfp = stderr;
  505. My->LPRINT_NULLS = 0;
  506. My->SCREEN_ROWS = 24;
  507. /* OPEN #0 is an ERROR. */
  508. /* CLOSE #0 is an ERROR. */
  509. /* WIDTH #0, 80 is the same as WIDTH 80. */
  510. /* LPRINT and LLIST are sent to bwx_LPRINT() */
  511. /* default variable type */
  512. for (n = 0; n < 26; n++)
  513. {
  514. My->DefaultVariableType[n] = DoubleTypeCode;
  515. }
  516. /* default COMMAND$(0-9) */
  517. for (n = 0; n < 10; n++)
  518. {
  519. My->COMMAND4[n] = NULL;
  520. }
  521. /* initialize tables of variables, functions */
  522. bwb_initialize_warnings ();
  523. SortAllCommands ();
  524. SortAllFunctions ();
  525. SortAllOperators ();
  526. var_init ();
  527. IntrinsicFunction_init ();
  528. UserFunction_init ();
  529. OptionVersionSet (0);
  530. /* OK */
  531. return TRUE;
  532. }
  533. /***************************************************************
  534. FUNCTION: main()
  535. DESCRIPTION: As in any C program, main() is the basic
  536. function from which the rest of the
  537. program is called. Some environments,
  538. however, provide their own main() functions
  539. (Microsoft Windows (tm) is an example).
  540. In these cases, the following code will
  541. have to be included in the initialization
  542. function that is called by the environment.
  543. ***************************************************************/
  544. static void
  545. process_basic_line (char *buffer)
  546. {
  547. CleanLine (buffer);
  548. if (is_empty_string (buffer))
  549. {
  550. /* empty -- do nothing */
  551. }
  552. else if (is_ln (buffer) == FALSE)
  553. {
  554. /* If there is no line number, then execute the line as received */
  555. /* RUN */
  556. WARN_CLEAR; /* process_basic_line */
  557. SetOnError (0);
  558. bwb_xtxtline (buffer); /* process_basic_line */
  559. }
  560. else if (is_numconst (buffer) == TRUE)
  561. {
  562. /*-----------------------------------------------------------------*/
  563. /* Another possibility: if buffer is a numeric constant, */
  564. /* then delete the indicated line number (JBV) */
  565. /*-----------------------------------------------------------------*/
  566. /* 100 */
  567. int LineNumber;
  568. LineNumber = atoi (buffer);
  569. WARN_CLEAR; /* process_basic_line */
  570. SetOnError (0);
  571. sprintf (buffer, "delete %d", LineNumber);
  572. bwb_xtxtline (buffer); /* process_basic_line */
  573. }
  574. else
  575. {
  576. /* If there is a line number, then add it to the BASIC program */
  577. /* 100 REM */
  578. bwb_ladd (buffer, My->StartMarker, FALSE);
  579. }
  580. }
  581. static void
  582. bwb_single_step (char *buffer)
  583. {
  584. assert( My != NULL );
  585. assert (buffer != NULL);
  586. process_basic_line (buffer);
  587. while (My->StackHead != NULL)
  588. {
  589. bwb_execline ();
  590. }
  591. }
  592. static void
  593. mark_preset_variables (void)
  594. {
  595. /* mark all existing variables as preset */
  596. /* this includes all variables declared in any PROFILE */
  597. VariableType *v;
  598. assert( My != NULL );
  599. for (v = My->VariableHead; v != NULL; v = v->next)
  600. {
  601. v->VariableFlags |= VARIABLE_PRESET;
  602. v->VariableFlags |= VARIABLE_COMMON;
  603. }
  604. }
  605. static void
  606. execute_profile (char *FileName)
  607. {
  608. FILE *profile;
  609. assert( My != NULL );
  610. assert (FileName != NULL);
  611. My->NextValidLineNumber = MINLIN;
  612. #ifdef HAVE_UNIX
  613. /* Begin 20200806 ChipMaster@YeOlPiShack.net Patch --
  614. *
  615. * on *nix check the current folder, user's home folder and then /etc for
  616. * the profile script
  617. *
  618. * WARN: I assume that $HOME and FileName are reasonably sized. If one
  619. * or the other are oversized then an attempt to load a weird-named
  620. * script will happen.
  621. *
  622. * 1 to open [profile.bas]
  623. * 2 to open [$HOME/profile.bas]
  624. * 3 to open [$HOME/.profile.bas] - because ChipMaster doesn't like clutter
  625. * 4 to open [/etc/profile.bas]
  626. * */
  627. char home[1024]; home[0]=home[sizeof(home)-1]=0;
  628. char pname[1024]; pname[0]=pname[sizeof(pname)-1]=0;
  629. profile = fopen(FileName, "rt");
  630. if(profile == NULL) {
  631. strncpy(home, getenv("HOME"), sizeof(home)-1);
  632. if(home[0]) {
  633. snprintf(pname, sizeof(pname)-1, "%s/%s", home, FileName);
  634. profile = fopen (pname, "rt");
  635. }
  636. if(profile == NULL) {
  637. snprintf(pname, sizeof(pname)-1, "%s/.%s", home, FileName);
  638. profile = fopen (pname, "rt");
  639. }
  640. }
  641. if(profile == NULL) {
  642. snprintf(pname, sizeof(pname)-1, "/etc/%s", FileName);
  643. profile = fopen(pname, "rt");
  644. }
  645. #else
  646. profile = fopen (FileName, "rt");
  647. #endif
  648. /* End 20200806 Patch */
  649. if (profile == NULL)
  650. {
  651. /* NOT FOUND */
  652. /* OPTIONAL */
  653. return;
  654. }
  655. /* FOUND */
  656. if (My->IsInteractive)
  657. {
  658. /*
  659. **
  660. ** set a buffer for jump: program execution returns to this point in
  661. ** case of a jump (error, interrupt, or finish program)
  662. **
  663. */
  664. My->program_run = 0;
  665. signal (SIGINT, break_mes);
  666. setjmp (My->mark);
  667. if (My->program_run > 0)
  668. {
  669. /* error in PROFILE */
  670. exit (1);
  671. }
  672. My->program_run++;
  673. }
  674. /*
  675. The profile only exists to allow executing OPTION ... commands.
  676. No other use is supported.
  677. */
  678. {
  679. char *tbuf;
  680. int tlen;
  681. tbuf = My->ConsoleInput;
  682. tlen = MAX_LINE_LENGTH;
  683. while (fgets (tbuf, tlen, profile)) /* execute_profile */
  684. {
  685. tbuf[tlen] = NulChar;
  686. bwb_single_step (tbuf); /* in execute_profile() */
  687. }
  688. bwb_fclose (profile);
  689. mark_preset_variables ();
  690. }
  691. }
  692. static void
  693. execute_program (char *FileName)
  694. {
  695. assert( My != NULL );
  696. assert( My->SYSOUT != NULL );
  697. assert( My->SYSOUT->cfp != NULL );
  698. assert (FileName != NULL);
  699. My->NextValidLineNumber = MINLIN;
  700. My->IsCommandLineFile = TRUE;
  701. if (bwb_fload (FileName) == FALSE)
  702. {
  703. fprintf (My->SYSOUT->cfp, "Failed to open file %s\n", FileName);
  704. /* the file load has failed, so do NOT run the program */
  705. exit (1);
  706. }
  707. if (My->ERR < 0 /* in execute_program(), file load failed */ )
  708. {
  709. /* the file load has failed, so do NOT run the program */
  710. exit (1);
  711. }
  712. bwb_RUN (My->StartMarker);
  713. }
  714. extern int
  715. main (int argc, char **argv)
  716. {
  717. int i;
  718. assert (argc >= 0);
  719. assert (argv != NULL);
  720. if (bwb_init () == FALSE)
  721. {
  722. /* FATAL */
  723. puts ("Out of memory");
  724. return 1;
  725. }
  726. assert( My != NULL );
  727. assert( My->SYSOUT != NULL );
  728. assert( My->SYSOUT->cfp != NULL );
  729. assert( My->SYSIN != NULL );
  730. assert( My->SYSIN->cfp != NULL );
  731. /* Signon message banner */
  732. if (argc < 2)
  733. {
  734. /* no parameters */
  735. if (My->IsInteractive)
  736. {
  737. bwx_signon ();
  738. }
  739. else
  740. {
  741. /* if INTERACTIVE is FALSE, then we must have a program file */
  742. fputs ("Program file not specified\n", My->SYSOUT->cfp);
  743. return 1;
  744. }
  745. }
  746. if (My->IsInteractive)
  747. {
  748. /*
  749. **
  750. ** set a buffer for jump: program execution returns to this point in
  751. ** case of a jump (error, interrupt, or finish program)
  752. **
  753. */
  754. My->program_run = 0;
  755. signal (SIGINT, break_mes);
  756. setjmp (My->mark);
  757. if (My->program_run > 0)
  758. {
  759. /* error in profile */
  760. return 1;
  761. }
  762. My->program_run++;
  763. }
  764. #if PROFILE
  765. execute_profile (PROFILENAME);
  766. #endif
  767. /* check to see if there is a program file: but do
  768. * this only the first time around! */
  769. for (i = 1; i < argc; i++)
  770. {
  771. /*
  772. SYNTAX:
  773. bwbasic [ --profile profile.bas ] [ --tape tapefile.inp ] [ program.bas ]
  774. */
  775. if (bwb_stricmp (argv[i], "--profile") == 0
  776. || bwb_stricmp (argv[i], "-p") == 0
  777. || bwb_stricmp (argv[i], "/profile") == 0
  778. || bwb_stricmp (argv[i], "/p") == 0)
  779. {
  780. i++;
  781. if (i < argc)
  782. {
  783. /* --profile profile.bas */
  784. execute_profile (argv[i]);
  785. }
  786. }
  787. else
  788. if (bwb_stricmp (argv[i], "--tape") == 0
  789. || bwb_stricmp (argv[i], "-t") == 0
  790. || bwb_stricmp (argv[i], "/tape") == 0
  791. || bwb_stricmp (argv[i], "/t") == 0)
  792. {
  793. i++;
  794. if (i < argc)
  795. {
  796. /* --tape tapefile.inp */
  797. My->ExternalInputFile = fopen (argv[i], "r");
  798. }
  799. }
  800. else
  801. {
  802. /* program.bas */
  803. {
  804. int j;
  805. int n;
  806. j = i;
  807. for (n = 0; n < 10 && j < argc; n++, j++)
  808. {
  809. My->COMMAND4[n] = argv[j];
  810. }
  811. }
  812. execute_program (argv[i]);
  813. break;
  814. }
  815. }
  816. if (My->IsInteractive)
  817. {
  818. /*
  819. **
  820. ** set a buffer for jump: program execution returns to this point in
  821. ** case of a jump (error, interrupt, or finish program)
  822. **
  823. */
  824. My->program_run = 0;
  825. signal (SIGINT, break_mes);
  826. setjmp (My->mark);
  827. if (My->program_run > 0)
  828. {
  829. /* error in console mode */
  830. }
  831. My->program_run++;
  832. }
  833. /* main program loop */
  834. My->NextValidLineNumber = MINLIN;
  835. while (!feof (My->SYSIN->cfp)) /* condition !feof( My->SYSIN->cfp ) added in v1.11 */
  836. {
  837. bwb_mainloop ();
  838. }
  839. bwx_terminate (); /* allow ^D (Unix) exit with grace */
  840. return 0;
  841. }
  842. /***************************************************************
  843. FUNCTION: bwb_interact()
  844. DESCRIPTION: This function gets a line from the user
  845. and processes it.
  846. ***************************************************************/
  847. static void
  848. bwb_interact (void)
  849. {
  850. char *tbuf;
  851. int tlen;
  852. assert( My != NULL );
  853. tbuf = My->ConsoleInput;
  854. tlen = MAX_LINE_LENGTH;
  855. My->NextValidLineNumber = MINLIN;
  856. /* take input from keyboard */
  857. if (My->AutomaticLineNumber > 0 && My->AutomaticLineIncrement > 0)
  858. {
  859. /* AUTO 100, 10 */
  860. char *zbuf; /* end of the prompt, start of the response */
  861. int zlen; /* length of the prompt */
  862. char LineExists;
  863. LineType *l;
  864. LineExists = ' ';
  865. for (l = My->StartMarker->next; l != My->EndMarker; l = l->next)
  866. {
  867. if (l->number == My->AutomaticLineNumber)
  868. {
  869. /* FOUND */
  870. LineExists = '*';
  871. break;
  872. }
  873. else if (l->number > My->AutomaticLineNumber)
  874. {
  875. /* NOT FOUND */
  876. LineExists = ' ';
  877. break;
  878. }
  879. }
  880. sprintf (tbuf, "%d%c", My->AutomaticLineNumber, LineExists);
  881. zbuf = bwb_strchr (tbuf, NulChar);
  882. zlen = bwb_strlen (tbuf);
  883. bwx_input (tbuf, FALSE, zbuf, tlen - zlen);
  884. zbuf[-1] = ' '; /* remove LineExists indicator */
  885. CleanLine (zbuf); /* JBV */
  886. if (is_empty_string (zbuf))
  887. {
  888. /* empty response */
  889. if (LineExists == '*')
  890. {
  891. /*
  892. An empty response with an existing line,
  893. causes AUTO to continue with the next line,
  894. leaving the current line intact.
  895. */
  896. My->AutomaticLineNumber += My->AutomaticLineIncrement;
  897. }
  898. else
  899. {
  900. /*
  901. An empty response with a non-existing line,
  902. causes AUTO to terminate.
  903. */
  904. My->AutomaticLineNumber = 0;
  905. My->AutomaticLineIncrement = 0;
  906. }
  907. }
  908. else
  909. {
  910. /* non-empty response */
  911. if (bwb_stricmp (zbuf, "MAN") == 0)
  912. {
  913. /* MAN terminates AUTO mode */
  914. My->AutomaticLineNumber = 0;
  915. My->AutomaticLineIncrement = 0;
  916. }
  917. else
  918. {
  919. /* overwrite any existing line */
  920. bwb_ladd (tbuf, My->StartMarker, FALSE);
  921. My->AutomaticLineNumber += My->AutomaticLineIncrement;
  922. }
  923. }
  924. }
  925. else
  926. {
  927. bwx_input (My->OptionPromptString, FALSE, tbuf, tlen);
  928. process_basic_line (tbuf);
  929. }
  930. }
  931. /***************************************************************
  932. FUNCTION: bwb_fload()
  933. DESCRIPTION: This function loads a BASIC program
  934. file into memory given a FILE pointer.
  935. ***************************************************************/
  936. static int
  937. FixQuotes (char *tbuf)
  938. {
  939. /* fix unbalanced quotes */
  940. /* 'tbuf' shall be declared "char tbuf[ tlen + 1]". */
  941. int p;
  942. int QuoteCount;
  943. int tlen;
  944. assert( My != NULL );
  945. assert( My->CurrentVersion != NULL );
  946. assert (tbuf != NULL);
  947. QuoteCount = 0;
  948. tlen = MAX_LINE_LENGTH;
  949. tbuf[tlen] = NulChar;
  950. p = 0;
  951. while (tbuf[p])
  952. {
  953. if (tbuf[p] == My->CurrentVersion->OptionQuoteChar)
  954. {
  955. QuoteCount++;
  956. }
  957. p++;
  958. }
  959. if (QuoteCount & 1)
  960. {
  961. /* odd == missing trailing quote */
  962. if (p < tlen)
  963. {
  964. /* we have room to put the missig quote */
  965. tbuf[p] = My->CurrentVersion->OptionQuoteChar;
  966. p++;
  967. tbuf[p] = NulChar;
  968. }
  969. else
  970. {
  971. /* we cannot fix it */
  972. return FALSE;
  973. }
  974. }
  975. /* OK */
  976. return TRUE;
  977. }
  978. static FILE *
  979. nice_open (char *BaseName)
  980. {
  981. FILE *file;
  982. assert( My != NULL );
  983. if (BaseName == NULL)
  984. {
  985. BaseName = My->ProgramFilename;
  986. }
  987. if (is_empty_string (BaseName))
  988. {
  989. WARN_BAD_FILE_NAME;
  990. return NULL;
  991. }
  992. file = fopen (BaseName, "r");
  993. if (file == NULL)
  994. if (is_empty_string (My->OptionExtensionString) == FALSE)
  995. {
  996. char *FileName;
  997. FileName = bwb_strdup2 (BaseName, My->OptionExtensionString);
  998. if (FileName == NULL)
  999. {
  1000. WARN_OUT_OF_MEMORY;
  1001. return NULL;
  1002. }
  1003. file = fopen (FileName, "r");
  1004. if (file == NULL)
  1005. {
  1006. free (FileName);
  1007. }
  1008. else if (BaseName == My->ProgramFilename)
  1009. {
  1010. if (My->ProgramFilename != NULL)
  1011. {
  1012. free (My->ProgramFilename);
  1013. }
  1014. My->ProgramFilename = FileName;
  1015. }
  1016. }
  1017. return file;
  1018. }
  1019. extern int
  1020. bwb_fload (char *FileName)
  1021. {
  1022. /*
  1023. **
  1024. ** Load a BASIC program from the specified 'FileName'.
  1025. ** If 'FileName' is NULL, then load from My->ProgramFilename,
  1026. **
  1027. */
  1028. char *Magic_Word; /* SYNTAX: %INCLUDE literal.file.name */
  1029. int Magic_Length;
  1030. FILE *file;
  1031. char *tbuf;
  1032. int tlen;
  1033. Magic_Word = "%INCLUDE "; /* SYNTAX: %INCLUDE literal.file.name */
  1034. Magic_Length = bwb_strlen (Magic_Word);
  1035. tbuf = My->MaxLenBuffer;
  1036. tlen = MAXLEN;
  1037. /*
  1038. Just in case you are wondering...
  1039. Although this handles the most common cases, it does not
  1040. handle all possible cases.
  1041. The correct solution is to provide the actual filename (with extension),
  1042. as it exists in the operating system.
  1043. */
  1044. file = nice_open (FileName);
  1045. if (file == NULL)
  1046. {
  1047. WARN_BAD_FILE_NAME;
  1048. return FALSE;
  1049. }
  1050. My->NextValidLineNumber = MINLIN;
  1051. while (fgets (tbuf, tlen, file)) /* bwb_fload */
  1052. {
  1053. tbuf[tlen] = NulChar;
  1054. CleanLine (tbuf);
  1055. if (is_empty_string (tbuf))
  1056. {
  1057. /* ignore */
  1058. }
  1059. else if (bwb_strnicmp (tbuf, Magic_Word, Magic_Length) == 0)
  1060. {
  1061. /* %iNCLUDE */
  1062. int Result;
  1063. int p;
  1064. char varname[NameLengthMax + 1];
  1065. p = Magic_Length;
  1066. if (buff_read_varname (tbuf, &p, varname) == FALSE)
  1067. {
  1068. fprintf (My->SYSOUT->cfp, "%s Filename\n", Magic_Word);
  1069. ResetConsoleColumn ();
  1070. return FALSE;
  1071. }
  1072. My->IncludeLevel++; /* %INCLUDE */
  1073. Result = bwb_fload (varname);
  1074. My->IncludeLevel--; /* %INCLUDE */
  1075. if (Result == FALSE)
  1076. {
  1077. fprintf (My->SYSOUT->cfp, "%s %s Failed\n", Magic_Word, varname);
  1078. ResetConsoleColumn ();
  1079. return FALSE;
  1080. }
  1081. }
  1082. else
  1083. {
  1084. /* normal */
  1085. bwb_ladd (tbuf, My->StartMarker, FALSE);
  1086. }
  1087. }
  1088. /* close file stream */
  1089. bwb_fclose (file); /* file != NULL */
  1090. My->NextValidLineNumber = MINLIN;
  1091. return TRUE;
  1092. }
  1093. static char *
  1094. FindClassicStatementEnd (char *C)
  1095. {
  1096. /*
  1097. ** find the end of the current statement
  1098. */
  1099. assert( My != NULL );
  1100. assert( My->CurrentVersion != NULL );
  1101. assert (C != NULL);
  1102. if (My->CurrentVersion->OptionStatementChar == NulChar
  1103. && My->CurrentVersion->OptionCommentChar == NulChar)
  1104. {
  1105. /* DO NOTHING: Multi-statment lines are not possible */
  1106. return NULL;
  1107. }
  1108. /* skip line number */
  1109. while (bwb_isdigit (*C))
  1110. {
  1111. C++;
  1112. }
  1113. /* skip spaces */
  1114. while (*C == ' ')
  1115. {
  1116. C++;
  1117. }
  1118. if (IS_CHAR (*C, My->CurrentVersion->OptionCommentChar))
  1119. {
  1120. /* The entire line is a comment */
  1121. return NULL;
  1122. }
  1123. if (bwb_strnicmp (C, "REM", 3) == 0)
  1124. {
  1125. /* The entire line is a comment */
  1126. return NULL;
  1127. }
  1128. if ((My->CurrentVersion->OptionFlags & OPTION_LABELS_ON)
  1129. && (My->CurrentVersion->OptionStatementChar != NulChar))
  1130. {
  1131. /* determine if this line is a LABEL */
  1132. int p;
  1133. char label[NameLengthMax + 1];
  1134. p = 0;
  1135. if (buff_read_label (C, &p, label))
  1136. {
  1137. if (buff_skip_char (C, &p, My->CurrentVersion->OptionStatementChar))
  1138. {
  1139. if (buff_is_eol (C, &p))
  1140. {
  1141. /* The entire line is a label */
  1142. /* LABEL : \0 */
  1143. return NULL;
  1144. }
  1145. }
  1146. }
  1147. }
  1148. /* not a special case, so split on the first unquoted
  1149. * OptionCommentChar or OptionStatementChar */
  1150. while (*C != NulChar)
  1151. {
  1152. if (*C == My->CurrentVersion->OptionQuoteChar)
  1153. {
  1154. /* skip leading quote */
  1155. C++;
  1156. while (*C != NulChar && *C != My->CurrentVersion->OptionQuoteChar)
  1157. {
  1158. /* skip string constant */
  1159. C++;
  1160. }
  1161. if (*C == My->CurrentVersion->OptionQuoteChar)
  1162. {
  1163. /* skip trailing quote */
  1164. C++;
  1165. }
  1166. }
  1167. else if (IS_CHAR (*C, My->CurrentVersion->OptionCommentChar) /* ', ! */ )
  1168. {
  1169. /* FOUND */
  1170. return C;
  1171. }
  1172. else
  1173. if (IS_CHAR (*C, My->CurrentVersion->OptionStatementChar) /* :, \ */ )
  1174. {
  1175. /* FOUND */
  1176. return C;
  1177. }
  1178. else
  1179. {
  1180. C++;
  1181. }
  1182. }
  1183. /* NOT FOUND */
  1184. return NULL;
  1185. }
  1186. static void
  1187. ImportClassicIfThenElse (char *InBuffer)
  1188. {
  1189. /*
  1190. **
  1191. ** Determine the type of IF command:
  1192. **
  1193. ** a) STANDARD:
  1194. ** IF x THEN line ELSE line
  1195. **
  1196. ** b) CLASSIC:
  1197. ** IF x THEN stmt(s) ELSE stmt(s)
  1198. **
  1199. ** c) STRUCTURED:
  1200. ** IF x THEN
  1201. ** stmts
  1202. ** ELSE
  1203. ** stmts
  1204. ** END IF
  1205. **
  1206. ** The STANDARD and STRUCTURED forms
  1207. ** are natively supported.
  1208. **
  1209. ** The CLASSIC form is converted to
  1210. ** the STRUCTURED form.
  1211. **
  1212. */
  1213. int i;
  1214. int nIF = 0;
  1215. int nTHEN = 0;
  1216. int nELSE = 0;
  1217. int nENDIF = 0;
  1218. #define NO_COMMAND 0
  1219. #define IF_COMMAND 1
  1220. #define THEN_COMMAND 2
  1221. #define ELSE_COMMAND 3
  1222. #define ENDIF_COMMAND 4
  1223. int LastCommand = NO_COMMAND;
  1224. const char *REM = "REM ";
  1225. const char *IF = "IF ";
  1226. const char *THEN = "THEN ";
  1227. const char *THEN2 = "THEN";
  1228. const char *ELSE = "ELSE ";
  1229. const char *ENDIF = "END IF";
  1230. const char *GOTO = "GOTO ";
  1231. const char *DATA = "DATA ";
  1232. const char *CASE = "CASE ";
  1233. char *OutBuffer = My->ConsoleOutput;
  1234. char *Input;
  1235. char *Output;
  1236. char LastChar = My->CurrentVersion->OptionStatementChar;
  1237. int REM_len = bwb_strlen (REM);
  1238. int IF_len = bwb_strlen (IF);
  1239. int THEN_len = bwb_strlen (THEN);
  1240. int THEN2_len = bwb_strlen (THEN2);
  1241. int ELSE_len = bwb_strlen (ELSE);
  1242. int ENDIF_len = bwb_strlen (ENDIF);
  1243. int GOTO_len = bwb_strlen (GOTO);
  1244. int DATA_len = bwb_strlen (DATA);
  1245. int CASE_len = bwb_strlen (CASE);
  1246. #define OUTPUTCHAR( c ) { *Output = c; Output++; }
  1247. #define COPYCHAR { LastChar = *Input; *Output = *Input; Output++; Input++; }
  1248. #define COPY_LINENUMBER while( bwb_isdigit( *Input ) ) COPYCHAR;
  1249. #define COPY_SPACES while( *Input == ' ' ) COPYCHAR;
  1250. #define COPY_IF for( i = 0; i < IF_len; i++ ) COPYCHAR;
  1251. #define COPY_THEN for( i = 0; i < THEN_len; i++ ) COPYCHAR;
  1252. #define COPY_THEN2 for( i = 0; i < THEN2_len; i++ ) COPYCHAR;
  1253. #define COPY_ELSE for( i = 0; i < ELSE_len; i++ ) COPYCHAR;
  1254. #define COPY_ENDIF for( i = 0; i < ENDIF_len; i++ ) COPYCHAR;
  1255. #define FORCE_ENDIF for( i = 0; i < ENDIF_len; i++ ) OUTPUTCHAR( ENDIF[ i ] );
  1256. #define FORCE_GOTO for( i = 0; i < GOTO_len; i++ ) OUTPUTCHAR( GOTO[ i ] );
  1257. #define FORCE_COLON if( LastChar != My->CurrentVersion->OptionStatementChar ) OUTPUTCHAR( My->CurrentVersion->OptionStatementChar );
  1258. assert( My != NULL );
  1259. assert( My->CurrentVersion != NULL );
  1260. assert (InBuffer != NULL);
  1261. Input = InBuffer;
  1262. Output = OutBuffer;
  1263. if (My->CurrentVersion->OptionStatementChar == NulChar)
  1264. {
  1265. /* DO NOTHING: All IFs must be STANDARD or STRUCTURED */
  1266. return;
  1267. }
  1268. COPY_LINENUMBER;
  1269. COPY_SPACES;
  1270. LastChar = My->CurrentVersion->OptionStatementChar;
  1271. while (*Input != NulChar)
  1272. {
  1273. if (*Input == My->CurrentVersion->OptionCommentChar)
  1274. {
  1275. /* comment */
  1276. break;
  1277. }
  1278. else if (*Input == My->CurrentVersion->OptionQuoteChar)
  1279. {
  1280. /* string constant */
  1281. COPYCHAR;
  1282. while (*Input != NulChar
  1283. && *Input != My->CurrentVersion->OptionQuoteChar)
  1284. {
  1285. COPYCHAR;
  1286. }
  1287. if (*Input == My->CurrentVersion->OptionQuoteChar)
  1288. {
  1289. COPYCHAR;
  1290. }
  1291. else
  1292. {
  1293. /* add missing Quote */
  1294. OUTPUTCHAR (My->CurrentVersion->OptionQuoteChar);
  1295. }
  1296. COPY_SPACES;
  1297. }
  1298. else if (bwb_isalnum (LastChar))
  1299. {
  1300. /* can NOT be the start of a command */
  1301. COPYCHAR;
  1302. }
  1303. else if (!bwb_isalpha (*Input))
  1304. {
  1305. /* can NOT be the start of a command */
  1306. COPYCHAR;
  1307. }
  1308. else if (bwb_strnicmp (Input, REM, REM_len) == 0)
  1309. {
  1310. break;
  1311. }
  1312. else if (bwb_strnicmp (Input, DATA, DATA_len) == 0)
  1313. {
  1314. /* DATA ... */
  1315. break;
  1316. }
  1317. else if (bwb_strnicmp (Input, CASE, CASE_len) == 0)
  1318. {
  1319. /* CASE ... */
  1320. break;
  1321. }
  1322. else if (bwb_strnicmp (Input, IF, IF_len) == 0)
  1323. {
  1324. /* IF */
  1325. LastCommand = IF_COMMAND;
  1326. nIF++;
  1327. COPY_IF;
  1328. COPY_SPACES;
  1329. }
  1330. else if (bwb_strnicmp (Input, GOTO, GOTO_len) == 0 && nIF > nTHEN)
  1331. {
  1332. /* IF x GOTO line ELSE line */
  1333. LastCommand = THEN_COMMAND;
  1334. nTHEN++;
  1335. COPY_THEN;
  1336. COPY_SPACES;
  1337. COPY_LINENUMBER;
  1338. COPY_SPACES;
  1339. if (bwb_strnicmp (Input, ELSE, ELSE_len) == 0)
  1340. {
  1341. /* ELSE line */
  1342. COPY_ELSE;
  1343. COPY_SPACES;
  1344. COPY_LINENUMBER;
  1345. COPY_SPACES;
  1346. }
  1347. /* IS STANDARD, NOT CLASSIC */
  1348. nENDIF++;
  1349. LastCommand = ENDIF_COMMAND;
  1350. }
  1351. else if (bwb_strnicmp (Input, THEN, THEN_len) == 0)
  1352. {
  1353. /* THEN */
  1354. LastCommand = THEN_COMMAND;
  1355. nTHEN++;
  1356. COPY_THEN;
  1357. COPY_SPACES;
  1358. if (bwb_isdigit (*Input))
  1359. {
  1360. /* STANDARD: IF x THEN line ELSE line */
  1361. char *SavedInput;
  1362. char *SavedOutput;
  1363. SavedInput = Input;
  1364. SavedOutput = Output;
  1365. COPY_LINENUMBER;
  1366. COPY_SPACES;
  1367. if (bwb_strnicmp (Input, ELSE, ELSE_len) == 0)
  1368. {
  1369. /* ELSE line */
  1370. COPY_ELSE;
  1371. COPY_SPACES;
  1372. if (bwb_isdigit (*Input))
  1373. {
  1374. COPY_LINENUMBER;
  1375. COPY_SPACES;
  1376. /* IS STANDARD, NOT CLASSIC */
  1377. nENDIF++;
  1378. LastCommand = ENDIF_COMMAND;
  1379. }
  1380. else
  1381. {
  1382. /* IF x THEN line ELSE stmts */
  1383. Input = SavedInput;
  1384. Output = SavedOutput;
  1385. FORCE_COLON;
  1386. FORCE_GOTO;
  1387. COPY_LINENUMBER;
  1388. COPY_SPACES;
  1389. }
  1390. }
  1391. else
  1392. {
  1393. /* IS STANDARD, NOT CLASSIC */
  1394. nENDIF++;
  1395. LastCommand = ENDIF_COMMAND;
  1396. }
  1397. }
  1398. else
  1399. if (*Input == My->CurrentVersion->OptionCommentChar
  1400. || *Input == NulChar)
  1401. {
  1402. /* IS STRUCTURED, NOT CLASSIC */
  1403. nENDIF++;
  1404. LastCommand = ENDIF_COMMAND;
  1405. }
  1406. else
  1407. {
  1408. /* CLASSIC: IF x THEN stmts ELSE stmts */
  1409. }
  1410. FORCE_COLON;
  1411. }
  1412. else if (bwb_strnicmp (Input, THEN2, THEN2_len) == 0)
  1413. {
  1414. /* trailing THEN ? */
  1415. char *PeekInput;
  1416. PeekInput = Input;
  1417. PeekInput += THEN2_len;
  1418. while (*PeekInput == ' ')
  1419. {
  1420. PeekInput++;
  1421. }
  1422. if (*PeekInput == My->CurrentVersion->OptionCommentChar
  1423. || *PeekInput == NulChar)
  1424. {
  1425. /* IS STRUCTURED, NOT CLASSIC */
  1426. nTHEN++;
  1427. COPY_THEN2;
  1428. nENDIF++;
  1429. LastCommand = ENDIF_COMMAND;
  1430. FORCE_COLON;
  1431. }
  1432. else
  1433. {
  1434. /* THEN line */
  1435. }
  1436. }
  1437. else if (bwb_strnicmp (Input, ELSE, ELSE_len) == 0)
  1438. {
  1439. /* ELSE */
  1440. if (LastCommand == ELSE_COMMAND)
  1441. {
  1442. /* we need an ENDIF here */
  1443. FORCE_COLON;
  1444. FORCE_ENDIF;
  1445. FORCE_COLON;
  1446. nENDIF++;
  1447. }
  1448. LastCommand = ELSE_COMMAND;
  1449. nELSE++;
  1450. FORCE_COLON;
  1451. COPY_ELSE;
  1452. FORCE_COLON;
  1453. COPY_SPACES;
  1454. if (bwb_isdigit (*Input))
  1455. {
  1456. /* IF x THEN stmts ELSE line */
  1457. FORCE_GOTO;
  1458. COPY_LINENUMBER;
  1459. COPY_SPACES;
  1460. }
  1461. FORCE_COLON;
  1462. }
  1463. else if (bwb_strnicmp (Input, ENDIF, ENDIF_len) == 0)
  1464. {
  1465. /* ENDIF */
  1466. LastCommand = ENDIF_COMMAND;
  1467. nENDIF++;
  1468. COPY_ENDIF;
  1469. FORCE_COLON;
  1470. }
  1471. else
  1472. {
  1473. /* was NOT the start of a command */
  1474. COPYCHAR;
  1475. }
  1476. }
  1477. /* end of input */
  1478. if (nENDIF < nIF)
  1479. {
  1480. while (nENDIF < nIF)
  1481. {
  1482. /* we need trailing ENDIF's */
  1483. nENDIF++;
  1484. FORCE_COLON;
  1485. FORCE_ENDIF;
  1486. }
  1487. }
  1488. /* fixup trailing REMark command */
  1489. if (bwb_strnicmp (Input, REM, REM_len) == 0)
  1490. {
  1491. /* REMark */
  1492. /* 100 A=1 REMark */
  1493. /* 100 A=1:REMark */
  1494. /* 100 A=1'REMark */
  1495. FORCE_COLON;
  1496. }
  1497. /* copy the comments */
  1498. while (*Input != NulChar)
  1499. {
  1500. COPYCHAR;
  1501. /* cppcheck: (style) Variable 'LastChar' is assigned a value that is never used. */
  1502. }
  1503. OUTPUTCHAR (NulChar);
  1504. bwb_strcpy (InBuffer, OutBuffer);
  1505. }
  1506. /***************************************************************
  1507. FUNCTION: bwb_ladd()
  1508. DESCRIPTION: This function adds a new line (in the
  1509. buffer) to the program in memory.
  1510. ***************************************************************/
  1511. static int
  1512. bwb_ladd (char *buffer, LineType * p, int IsUser)
  1513. {
  1514. LineType *l;
  1515. LineType *previous;
  1516. char *newbuffer;
  1517. char *NextStatement;
  1518. char *ThisStatement;
  1519. int Replace;
  1520. char BreakChar;
  1521. assert( My != NULL );
  1522. assert( My->SYSOUT != NULL );
  1523. assert( My->SYSOUT->cfp != NULL );
  1524. assert( My->CurrentVersion != NULL );
  1525. assert (buffer != NULL);
  1526. assert (p != NULL);
  1527. Replace = TRUE;
  1528. BreakChar = NulChar;
  1529. CleanLine (buffer);
  1530. if (is_empty_string (buffer))
  1531. {
  1532. /* silengtly ignore blank lines */
  1533. return FALSE;
  1534. }
  1535. /*
  1536. from here, the line WILL be added so the user can EDIT it,
  1537. we just complain and refuse to run if any error is detected.
  1538. */
  1539. My->IsScanRequired = TRUE; /* program needs to be scanned again */
  1540. /* AUTO-FIX UNBALANCED QUOTES */
  1541. if (FixQuotes (buffer) == FALSE)
  1542. {
  1543. /* ERROR */
  1544. fprintf (My->SYSOUT->cfp, "UNBALANCED QUOTES: %s\n", buffer);
  1545. ResetConsoleColumn ();
  1546. My->ERR = -1; /* bwb_ladd, UNBALANCED QUOTES */
  1547. }
  1548. if (IS_CHAR (*buffer, My->CurrentVersion->OptionStatementChar))
  1549. {
  1550. /* part of a multi-statement line */
  1551. }
  1552. else if (IS_CHAR (*buffer, My->CurrentVersion->OptionCommentChar))
  1553. {
  1554. /* part of a multi-statement line */
  1555. }
  1556. else
  1557. {
  1558. ImportClassicIfThenElse (buffer);
  1559. }
  1560. ThisStatement = buffer;
  1561. NextStatement = NULL;
  1562. BreakChar = NulChar;
  1563. do
  1564. {
  1565. if (BreakChar == NulChar)
  1566. {
  1567. /* first pass thru the do{} while loop, do nothing */
  1568. }
  1569. else if (IS_CHAR (BreakChar, My->CurrentVersion->OptionCommentChar))
  1570. {
  1571. /* ThisStatment will turn out to be the last 08082020 Ken ? */
  1572. * ThisStatement = My->CurrentVersion->OptionCommentChar;
  1573. }
  1574. else if (IS_CHAR (BreakChar, My->CurrentVersion->OptionStatementChar))
  1575. {
  1576. /* we are NOT the last statement, skip over the OptionStatementChar */
  1577. ThisStatement++;
  1578. }
  1579. else
  1580. {
  1581. /* Internal Error */
  1582. }
  1583. if (BreakChar == NulChar
  1584. && IS_CHAR (*buffer, My->CurrentVersion->OptionStatementChar))
  1585. {
  1586. /* first pass thru and line begins with colon */
  1587. /* part of a multi-statement line */
  1588. NextStatement = NULL;
  1589. if (My->NextValidLineNumber > 1)
  1590. {
  1591. My->NextValidLineNumber--;
  1592. }
  1593. Replace = FALSE;
  1594. }
  1595. else
  1596. if (BreakChar == NulChar
  1597. && IS_CHAR (*buffer, My->CurrentVersion->OptionCommentChar))
  1598. {
  1599. /* first pass thru and line begins with apostrophe */
  1600. /* part of a multi-statement line */
  1601. NextStatement = NULL;
  1602. if (My->NextValidLineNumber > 1)
  1603. {
  1604. My->NextValidLineNumber--;
  1605. }
  1606. Replace = FALSE;
  1607. }
  1608. else
  1609. {
  1610. NextStatement = FindClassicStatementEnd (ThisStatement);
  1611. }
  1612. if (NextStatement == NULL)
  1613. {
  1614. /* we are the last statement */
  1615. }
  1616. else
  1617. {
  1618. /* another statement follows */
  1619. BreakChar = *NextStatement;
  1620. *NextStatement = NulChar;
  1621. }
  1622. CleanLine (ThisStatement);
  1623. if (is_empty_string (ThisStatement) == FALSE)
  1624. {
  1625. /* get memory for this line */
  1626. if ((l = (LineType *) calloc (1, sizeof (LineType))) == NULL)
  1627. {
  1628. /* ERROR */
  1629. fprintf (My->SYSOUT->cfp, "Out of memory\n");
  1630. ResetConsoleColumn ();
  1631. My->ERR = -1; /* bwb_ladd, Out of memory */
  1632. return FALSE;
  1633. }
  1634. /* this line has not been executed or numbered */
  1635. l->LineFlags = 0;
  1636. if (IsUser)
  1637. {
  1638. l->LineFlags |= LINE_USER;
  1639. }
  1640. l->IncludeLevel = My->IncludeLevel; /* %INCLUDE */
  1641. l->position = 0;
  1642. /*
  1643. **
  1644. ** ALL lines have a line number.
  1645. ** If a line number is not provided,
  1646. ** then the next available line number is assigned.
  1647. **
  1648. */
  1649. newbuffer = ThisStatement;
  1650. l->number = My->NextValidLineNumber;
  1651. if (buff_read_line_number (newbuffer, &(l->position), &l->number))
  1652. {
  1653. if (l->number < My->NextValidLineNumber)
  1654. {
  1655. /* ERROR */
  1656. fprintf (My->SYSOUT->cfp, "%d < %d - LINE OUT OF ORDER: %s\n",
  1657. l->number, My->NextValidLineNumber, buffer);
  1658. ResetConsoleColumn ();
  1659. My->ERR = -1; /* bwb_ladd, LINE OUT OF ORDER */
  1660. l->number = My->NextValidLineNumber; /* sane default */
  1661. }
  1662. else if (l->number < MINLIN || l->number > MAXLIN)
  1663. {
  1664. /* ERROR */
  1665. fprintf (My->SYSOUT->cfp, "INVALID LINE NUMBER: %s\n", buffer);
  1666. ResetConsoleColumn ();
  1667. My->ERR = -1; /* bwb_ladd, INVALID LINE NUMBER */
  1668. l->number = My->NextValidLineNumber; /* sane default */
  1669. }
  1670. else
  1671. {
  1672. /* OK */
  1673. My->NextValidLineNumber = l->number;
  1674. l->LineFlags |= LINE_NUMBERED; /* line was manually numbered */
  1675. }
  1676. /* A SPACE IS REQUIRED AFTER THE LINE NUMBER -- NO EXCEPTIONS */
  1677. if (newbuffer[l->position] != ' ')
  1678. {
  1679. /* ERROR */
  1680. fprintf (My->SYSOUT->cfp, "MISSING SPACE AFTER LINE NUMBER: %s\n",
  1681. buffer);
  1682. ResetConsoleColumn ();
  1683. My->ERR = -1; /* bwb_ladd, MISSING SPACE AFTER LINE NUMBER */
  1684. }
  1685. /* newuffer does NOT contain the line number */
  1686. newbuffer += l->position;
  1687. }
  1688. /* the next valid line number is this line number plus one */
  1689. CleanLine (newbuffer);
  1690. if (*newbuffer != NulChar
  1691. && *newbuffer == My->CurrentVersion->OptionStatementChar)
  1692. {
  1693. /* this is part of a multi-statement line */
  1694. newbuffer++;
  1695. CleanLine (newbuffer);
  1696. }
  1697. /*
  1698. **
  1699. ** copy into the line buffer
  1700. **
  1701. */
  1702. if (l->buffer != NULL)
  1703. {
  1704. free (l->buffer);
  1705. l->buffer = NULL; /* JBV */
  1706. }
  1707. if ((l->buffer =
  1708. (char *) calloc (bwb_strlen (newbuffer) + 1 /* NulChar */ ,
  1709. sizeof (char))) == NULL)
  1710. {
  1711. /* ERROR */
  1712. fprintf (My->SYSOUT->cfp, "Out of memory\n");
  1713. ResetConsoleColumn ();
  1714. My->ERR = -1; /* bwb_ladd, Out of memory */
  1715. return FALSE; /* we cannot determine the command */
  1716. }
  1717. bwb_strcpy (l->buffer, newbuffer);
  1718. /*
  1719. **
  1720. ** determine command
  1721. **
  1722. */
  1723. line_start (l);
  1724. if (l->cmdnum)
  1725. {
  1726. /* OK */
  1727. }
  1728. else
  1729. {
  1730. /* ERROR */
  1731. fprintf (My->SYSOUT->cfp,
  1732. "ILLEGAL COMMAND AFTER LINE NUMBER: %d %s\n", l->number,
  1733. l->buffer);
  1734. ResetConsoleColumn ();
  1735. My->ERR = -1; /* bwb_ladd, ILLEGAL COMMAND AFTER LINE NUMBER */
  1736. }
  1737. /*
  1738. **
  1739. ** add the line to the linked-list of lines
  1740. **
  1741. */
  1742. for (previous = p; previous != My->EndMarker; previous = previous->next)
  1743. {
  1744. if (previous->number == l->number)
  1745. {
  1746. if (Replace == TRUE)
  1747. {
  1748. /* REPLACE 'previous' */
  1749. while (previous->number == l->number)
  1750. {
  1751. LineType *z;
  1752. z = previous;
  1753. previous = previous->next;
  1754. bwb_freeline (z);
  1755. }
  1756. l->next = previous;
  1757. p->next = l;
  1758. }
  1759. else
  1760. {
  1761. /* APPEND after 'previous' */
  1762. while (previous->next->number == l->number)
  1763. {
  1764. previous = previous->next;
  1765. }
  1766. l->next = previous->next;
  1767. previous->next = l;
  1768. }
  1769. break;
  1770. }
  1771. else
  1772. if (previous->number < l->number
  1773. && l->number < previous->next->number)
  1774. {
  1775. /* INSERT BETWEEN 'previous' AND 'previous->next' */
  1776. l->next = previous->next;
  1777. previous->next = l;
  1778. break;
  1779. }
  1780. p = previous;
  1781. }
  1782. }
  1783. /* another statement may follow */
  1784. ThisStatement = NextStatement;
  1785. Replace = FALSE;
  1786. }
  1787. while (ThisStatement != NULL);
  1788. My->NextValidLineNumber++;
  1789. return TRUE;
  1790. }
  1791. /***************************************************************
  1792. FUNCTION: bwb_xtxtline()
  1793. DESCRIPTION: This function executes a text line, i.e.,
  1794. places it in memory and then relinquishes
  1795. control.
  1796. ***************************************************************/
  1797. static void
  1798. bwb_xtxtline (char *buffer)
  1799. {
  1800. assert( My != NULL );
  1801. assert (buffer != NULL);
  1802. /* remove old program from memory */
  1803. bwb_xnew (My->UserMarker);
  1804. CleanLine (buffer);
  1805. if (is_empty_string (buffer))
  1806. {
  1807. /* silengtly ignore blank lines */
  1808. return;
  1809. }
  1810. /* add to the user line list */
  1811. bwb_ladd (buffer, My->UserMarker, TRUE);
  1812. /* execute the line as BASIC command line */
  1813. if (bwb_incexec ())
  1814. {
  1815. My->StackHead->line = My->UserMarker->next; /* and set current line in it */
  1816. My->StackHead->ExecCode = EXEC_NORM;
  1817. }
  1818. }
  1819. /***************************************************************
  1820. FUNCTION: bwb_incexec()
  1821. DESCRIPTION: This function increments the EXEC
  1822. stack counter.
  1823. ***************************************************************/
  1824. int
  1825. bwb_incexec (void)
  1826. {
  1827. StackType *StackItem;
  1828. assert( My != NULL );
  1829. if (My->StackDepthInteger >= EXECLEVELS)
  1830. {
  1831. WARN_OUT_OF_MEMORY;
  1832. return FALSE;
  1833. }
  1834. if ((StackItem = (StackType *) calloc (1, sizeof (StackType))) == NULL)
  1835. {
  1836. WARN_OUT_OF_MEMORY;
  1837. return FALSE;
  1838. }
  1839. StackItem->ExecCode = EXEC_NORM; /* sane default */
  1840. StackItem->line = My->ThisLine; /* bwb_incexec */
  1841. StackItem->LoopTopLine = NULL;
  1842. StackItem->local_variable = NULL;
  1843. StackItem->OnErrorGoto = 0;
  1844. StackItem->next = My->StackHead;
  1845. My->StackHead = StackItem;
  1846. My->StackDepthInteger++;
  1847. return TRUE;
  1848. }
  1849. /***************************************************************
  1850. FUNCTION: bwb_decexec()
  1851. DESCRIPTION: This function decrements the EXEC
  1852. stack counter.
  1853. ***************************************************************/
  1854. void
  1855. bwb_clrexec (void)
  1856. {
  1857. assert( My != NULL );
  1858. while (My->StackHead != NULL)
  1859. {
  1860. bwb_decexec ();
  1861. }
  1862. }
  1863. void
  1864. bwb_decexec (void)
  1865. {
  1866. StackType *StackItem;
  1867. assert( My != NULL );
  1868. if (My->StackHead == NULL)
  1869. {
  1870. WARN_RETURN_WITHOUT_GOSUB;
  1871. return;
  1872. }
  1873. StackItem = My->StackHead;
  1874. My->StackHead = StackItem->next;
  1875. free (StackItem);
  1876. My->StackDepthInteger--;
  1877. }
  1878. /***************************************************************
  1879. FUNCTION: bwb_mainloop()
  1880. DESCRIPTION: This C function performs one iteration
  1881. of the interpreter. In a non-preemptive
  1882. scheduler, this function should be called
  1883. by the scheduler, not by bwBASIC code.
  1884. ***************************************************************/
  1885. void
  1886. bwb_mainloop (void)
  1887. {
  1888. assert( My != NULL );
  1889. if (My->StackHead)
  1890. {
  1891. /* BASIC program running */
  1892. bwb_execline (); /* execute one line of program */
  1893. return;
  1894. }
  1895. /* BASIC program completed */
  1896. if (My->ExternalInputFile != NULL)
  1897. {
  1898. /* for automated testing, --TAPE command line parameter */
  1899. if (bwb_is_eof (My->ExternalInputFile) == FALSE)
  1900. {
  1901. /* --TAPE command line parameter is active */
  1902. bwb_interact (); /* get user interaction */
  1903. return;
  1904. }
  1905. }
  1906. /* TAPE command inactive or completed */
  1907. if (My->IsCommandLineFile)
  1908. {
  1909. /* BASIC program was started from command line */
  1910. bwx_terminate ();
  1911. return;
  1912. }
  1913. /* BASIC program was not started from command line */
  1914. if (My->IsInteractive)
  1915. {
  1916. /* interactive */
  1917. bwb_interact (); /* get user interaction */
  1918. return;
  1919. }
  1920. /* non-interactive */
  1921. bwx_terminate ();
  1922. }
  1923. /***************************************************************
  1924. FUNCTION: bwb_execline()
  1925. DESCRIPTION: This function executes a single line of
  1926. a program in memory. This function is
  1927. called by bwb_mainloop().
  1928. ***************************************************************/
  1929. extern int
  1930. bwx_Error (int ERR, char *ErrorMessage)
  1931. {
  1932. /*
  1933. ERR is the error number
  1934. ErrorMessage is used to override the default error
  1935. message, and is usually NULL
  1936. */
  1937. assert( My != NULL );
  1938. switch (ERR)
  1939. {
  1940. case 0:
  1941. /*
  1942. **
  1943. ** Clear any existing error
  1944. **
  1945. */
  1946. My->IsErrorPending = FALSE; /* bwx_Error, ERR == 0 */
  1947. My->ERR = 0; /* bwx_Error, ERR == 0 */
  1948. My->ERL = NULL; /* bwx_Error, ERR == 0 */
  1949. bwb_strcpy (My->ERROR4, ""); /* bwx_Error, ERR == 0 */
  1950. return FALSE;
  1951. #ifdef CMDEBUG
  1952. case 57: /* ChipMaster testing ... */
  1953. fprintf(stderr, "I/O Error: feof=%d ferror=%d errno=%d\n",
  1954. (int)feof(My->CurrentFile->cfp),
  1955. (int)ferror(My->CurrentFile->cfp),
  1956. errno
  1957. );
  1958. break;
  1959. #endif
  1960. case 6: /* WARN_OVERFLOW */
  1961. case 11: /* WARN_DIVISION_BY_ZERO */
  1962. case 15: /* WARN_STRING_TOO_LONG */
  1963. /*
  1964. **
  1965. ** Behavior depends upon whether an Error handler is active.
  1966. **
  1967. */
  1968. if (GetOnError () == 0)
  1969. {
  1970. /*
  1971. **
  1972. ** Error handler is NOT active.
  1973. ** Do NOT set ERL, ERR, and ERROR$.
  1974. ** Continue processing.
  1975. **
  1976. */
  1977. if (ErrorMessage == NULL)
  1978. {
  1979. /* use the default error message */
  1980. if (ERR > 0 && ERR < NUM_WARNINGS)
  1981. {
  1982. ErrorMessage = ERROR4[ERR];
  1983. }
  1984. }
  1985. if (ErrorMessage != NULL)
  1986. {
  1987. if (bwb_strlen (ErrorMessage) > 0)
  1988. {
  1989. fprintf (My->SYSOUT->cfp, "%s\n", ErrorMessage);
  1990. ResetConsoleColumn ();
  1991. }
  1992. }
  1993. return FALSE; /* continue processing */
  1994. }
  1995. /*
  1996. **
  1997. ** Error handler IS active.
  1998. ** Fall-thru to set ERL, ERR, and ERROR$.
  1999. ** Abort processing.
  2000. **
  2001. */
  2002. }
  2003. if (My->IsErrorPending == FALSE) /* no errors pending */
  2004. {
  2005. /*
  2006. **
  2007. ** only keep the first pending error to occur
  2008. **
  2009. */
  2010. My->IsErrorPending = TRUE; /* bwx_Error, ERR != 0 */
  2011. My->ERR = ERR; /* bwx_Error, ERR != 0 */
  2012. My->ERL = NULL; /* bwx_Error, ERR != 0 */
  2013. bwb_strcpy (My->ERROR4, ""); /* bwx_Error, ERR != 0 */
  2014. if (My->StackHead)
  2015. {
  2016. My->ERL = My->StackHead->line;
  2017. }
  2018. if (ErrorMessage == NULL)
  2019. {
  2020. /* use the default error message */
  2021. if (ERR > 0 && ERR < NUM_WARNINGS)
  2022. {
  2023. ErrorMessage = ERROR4[ERR];
  2024. }
  2025. }
  2026. if (ErrorMessage != NULL)
  2027. {
  2028. if (bwb_strlen (ErrorMessage) > MAX_ERR_LENGTH)
  2029. {
  2030. ErrorMessage[MAX_ERR_LENGTH] = NulChar;
  2031. }
  2032. bwb_strcpy (My->ERROR4, ErrorMessage);
  2033. }
  2034. }
  2035. return TRUE; /* abort processing */
  2036. }
  2037. void
  2038. bwb_execline (void)
  2039. {
  2040. LineType *r, *l;
  2041. assert( My != NULL );
  2042. assert( My->SYSOUT != NULL );
  2043. assert( My->SYSOUT->cfp != NULL );
  2044. assert( My->CurrentVersion != NULL );
  2045. if (My->StackHead == NULL) /* in bwb_execline(), FATAL ERROR PENDING */
  2046. {
  2047. return;
  2048. }
  2049. l = My->StackHead->line;
  2050. /* if the line is My->EndMarker, then break out of EXEC loops */
  2051. if (l == NULL || l == My->EndMarker || My->ERR < 0) /* in bwb_execline(), FATAL ERROR PENDING */
  2052. {
  2053. bwb_clrexec ();
  2054. return;
  2055. }
  2056. My->ThisLine = l; /* bwb_execline */
  2057. /* Print line number if trace is on */
  2058. if (My->IsTraceOn == TRUE)
  2059. {
  2060. if (l->LineFlags & (LINE_USER))
  2061. {
  2062. /* USER line in console */
  2063. }
  2064. else if (l->number > 0)
  2065. {
  2066. fprintf (My->SYSOUT->cfp, "[ %d %s ]", l->number, l->buffer);
  2067. }
  2068. }
  2069. l->position = l->Startpos;
  2070. /* if there is a BASIC command in the line, execute it here */
  2071. if (l->cmdnum)
  2072. {
  2073. /* OK */
  2074. }
  2075. else
  2076. {
  2077. WARN_ILLEGAL_DIRECT;
  2078. l->cmdnum = C_REM;
  2079. }
  2080. /* l->cmdnum != 0 */
  2081. if (l->LineFlags & LINE_BREAK)
  2082. {
  2083. /* BREAK line */
  2084. l->LineFlags &= ~LINE_BREAK;
  2085. My->ContinueLine = l;
  2086. bwx_STOP (TRUE);
  2087. return;
  2088. }
  2089. /* advance beyond whitespace */
  2090. line_skip_spaces (l); /* keep this */
  2091. /* execute the command vector */
  2092. if (My->CurrentVersion->OptionFlags & (OPTION_COVERAGE_ON))
  2093. {
  2094. /* We do this here so "END" and "STOP" are marked */
  2095. if (l->cmdnum == C_DATA)
  2096. {
  2097. /* DATA lines are marked when they are READ */
  2098. }
  2099. else
  2100. {
  2101. /* this line was executed */
  2102. l->LineFlags |= LINE_EXECUTED;
  2103. }
  2104. }
  2105. r = bwb_vector (l);
  2106. if (r == NULL)
  2107. {
  2108. WARN_INTERNAL_ERROR;
  2109. return;
  2110. }
  2111. assert (r != NULL);
  2112. if (My->ERR < 0) /* in bwb_execline(), FATAL ERROR PENDING */
  2113. {
  2114. /* FATAL */
  2115. bwb_clrexec ();
  2116. return;
  2117. }
  2118. if (My->IsErrorPending /* Keep This */ )
  2119. {
  2120. /* we are probably not at the end-of-the-line */
  2121. }
  2122. else if (r == l)
  2123. {
  2124. /* we should be at the end-of-the-line */
  2125. if (line_is_eol (l))
  2126. {
  2127. /* OK */
  2128. }
  2129. else
  2130. {
  2131. WARN_SYNTAX_ERROR;
  2132. return;
  2133. }
  2134. }
  2135. else
  2136. {
  2137. /* we are probably not at the end-of-the-line */
  2138. }
  2139. if (My->IsErrorPending /* Keep This */ )
  2140. {
  2141. /*
  2142. **
  2143. ** a NON-FATAL ERROR has occurred. ERR, ERL, and ERROR$ were
  2144. ** already set using bwb_warning(ERR,ERROR$)
  2145. **
  2146. */
  2147. int err_gotol;
  2148. My->IsErrorPending = FALSE; /* Error Recognized */
  2149. err_gotol = GetOnError ();
  2150. if (l->LineFlags & (LINE_USER))
  2151. {
  2152. /*
  2153. **
  2154. ** ---------------------------------------------------------------------
  2155. ** USER line in console
  2156. ** ---------------------------------------------------------------------
  2157. **
  2158. ** fall thru to the DEFAULT ERROR HANDLER
  2159. **
  2160. */
  2161. }
  2162. else if (l->number == 0)
  2163. {
  2164. /* fall thru to the DEFAULT ERROR HANDLER */
  2165. }
  2166. else if (My->ERL == NULL)
  2167. {
  2168. /* fall thru to the DEFAULT ERROR HANDLER */
  2169. }
  2170. else if (My->ERL->number == 0)
  2171. {
  2172. /* fall thru to the DEFAULT ERROR HANDLER */
  2173. }
  2174. else if (err_gotol == -1)
  2175. {
  2176. /*
  2177. **
  2178. ** ---------------------------------------------------------------------
  2179. ** ON ERROR RESUME NEXT
  2180. ** ---------------------------------------------------------------------
  2181. **
  2182. */
  2183. assert (r != NULL);
  2184. assert (r->next != NULL);
  2185. r->next->position = 0;
  2186. assert (My->StackHead != NULL);
  2187. My->StackHead->line = r->next;
  2188. return;
  2189. }
  2190. else if (err_gotol == 0)
  2191. {
  2192. /*
  2193. **
  2194. ** ---------------------------------------------------------------------
  2195. ** ON ERROR GOTO 0
  2196. ** ---------------------------------------------------------------------
  2197. **
  2198. ** fall thru to the DEFAULT ERROR HANDLER
  2199. **
  2200. */
  2201. }
  2202. else if (err_gotol == My->ERL->number)
  2203. {
  2204. /*
  2205. **
  2206. ** ---------------------------------------------------------------------
  2207. ** RECURSION
  2208. ** ---------------------------------------------------------------------
  2209. **
  2210. ** For example:
  2211. ** 10 ON ERROR GOTO 20
  2212. ** 20 ERROR 1
  2213. **
  2214. ** fall thru to the DEFAULT ERROR HANDLER
  2215. **
  2216. */
  2217. }
  2218. else
  2219. {
  2220. /* USER ERROR HANDLER SPECIFIED */
  2221. /* find the user-specified error handler and jump there */
  2222. LineType *x;
  2223. for (x = My->StartMarker->next; x != My->EndMarker; x = x->next)
  2224. {
  2225. if (x->number == err_gotol)
  2226. {
  2227. /* FOUND */
  2228. if (My->CurrentVersion->OptionFlags & (OPTION_ERROR_GOSUB))
  2229. {
  2230. /*
  2231. **
  2232. ** ---------------------------------------------------------------
  2233. ** OPTION ERROR GOSUB
  2234. ** ---------------------------------------------------------------
  2235. **
  2236. ** RETURN should act like RESUME NEXT...
  2237. ** Execution resumes at the statement immediately following
  2238. ** the one which caused the error.
  2239. ** For structured commands, this is the bottom line of the structure.
  2240. **
  2241. */
  2242. switch (l->cmdnum)
  2243. {
  2244. case C_IF8THEN:
  2245. /* skip to END_IF */
  2246. assert (l->OtherLine != NULL);
  2247. for (l = l->OtherLine; l->cmdnum != C_END_IF; l = l->OtherLine);
  2248. break;
  2249. case C_SELECT_CASE:
  2250. /* skip to END_SELECT */
  2251. assert (l->OtherLine != NULL);
  2252. for (l = l->OtherLine; l->cmdnum != C_END_SELECT;
  2253. l = l->OtherLine);
  2254. break;
  2255. default:
  2256. l = l->next;
  2257. }
  2258. l->position = 0;
  2259. My->StackHead->line = l;
  2260. if (bwb_incexec ())
  2261. {
  2262. x->position = 0;
  2263. assert (My->StackHead != NULL);
  2264. My->StackHead->line = x;
  2265. My->StackHead->ExecCode = EXEC_GOSUB;
  2266. }
  2267. else
  2268. {
  2269. /* ERROR -- OUT OF MEMORY */
  2270. assert (My->StackHead != NULL);
  2271. My->StackHead->line = My->EndMarker;
  2272. }
  2273. }
  2274. else
  2275. {
  2276. /*
  2277. **
  2278. ** ---------------------------------------------------------------
  2279. ** OPTION ERROR GOTO
  2280. ** ---------------------------------------------------------------
  2281. **
  2282. */
  2283. x->position = 0; /* start of line */
  2284. assert (My->StackHead != NULL);
  2285. My->StackHead->line = x;
  2286. }
  2287. return;
  2288. }
  2289. }
  2290. /* NOT FOUND */
  2291. /* fall thru to the DEFAULT ERROR HANDLER */
  2292. }
  2293. /*
  2294. **
  2295. ** -----------------------------------------------------------------------
  2296. ** DEFAULT ERROR HANDLER (FATAL)
  2297. ** -----------------------------------------------------------------------
  2298. **
  2299. */
  2300. /*
  2301. **
  2302. ** display error message
  2303. **
  2304. */
  2305. if (l->LineFlags & (LINE_USER) || l->number <= 0)
  2306. {
  2307. /* USER line in console */
  2308. fprintf (My->SYSOUT->cfp, "\nERROR: %s\n", My->ERROR4);
  2309. ResetConsoleColumn ();
  2310. }
  2311. else
  2312. {
  2313. /* BASIC program line */
  2314. fprintf (My->SYSOUT->cfp, "\nERROR in line %d: %s\n", l->number,
  2315. My->ERROR4);
  2316. ResetConsoleColumn ();
  2317. /*
  2318. **
  2319. ** display stack trace
  2320. **
  2321. */
  2322. if (My->CurrentVersion->OptionFlags & (OPTION_TRACE_ON))
  2323. {
  2324. /*
  2325. ** Dump the BASIC stack trace when a FATAL error occurs.
  2326. ** First line is the TOP of the stack.
  2327. ** Last line is the BOTTOM of the stack.
  2328. */
  2329. StackType *StackItem;
  2330. fprintf (My->SYSOUT->cfp, "\nSTACK TRACE:\n");
  2331. for (StackItem = My->StackHead; StackItem != NULL;
  2332. StackItem = StackItem->next)
  2333. {
  2334. LineType *l;
  2335. l = StackItem->line;
  2336. if (l != NULL)
  2337. {
  2338. if (MINLIN <= l->number && l->number <= MAXLIN)
  2339. {
  2340. /* BASIC program line */
  2341. if (l->buffer == NULL)
  2342. {
  2343. fprintf (My->SYSOUT->cfp, "%d\n", l->number);
  2344. }
  2345. else
  2346. {
  2347. fprintf (My->SYSOUT->cfp, "%d:%s\n", l->number, l->buffer);
  2348. }
  2349. }
  2350. }
  2351. }
  2352. ResetConsoleColumn ();
  2353. }
  2354. }
  2355. My->AutomaticLineNumber = 0;
  2356. My->AutomaticLineIncrement = 0;
  2357. if (My->IsInteractive)
  2358. {
  2359. /* INTERACTIVE: terminate program */
  2360. /* reset all stack counters */
  2361. bwb_clrexec ();
  2362. SetOnError (0);
  2363. My->ERR = -1; /* in bwb_execline(), default error handler */
  2364. /* reset the break handler */
  2365. signal (SIGINT, break_mes);
  2366. return;
  2367. }
  2368. /* NOT INTERACTIVE: terminate immediately */
  2369. bwx_terminate ();
  2370. return; /* never reached */
  2371. }
  2372. if (l->number > 0)
  2373. {
  2374. /* These events only occur in running programs */
  2375. if (My->IsTimerOn)
  2376. {
  2377. /* TIMER ON */
  2378. if (My->OnTimerCount > 0)
  2379. {
  2380. if (bwx_TIMER (0) > My->OnTimerExpires)
  2381. {
  2382. My->IsTimerOn = FALSE;
  2383. if (My->OnTimerLineNumber > 0)
  2384. {
  2385. /* ON TIMER( My->OnTimerCount ) GOSUB My->OnTimerLineNumber */
  2386. LineType *x;
  2387. for (x = My->StartMarker->next; x != My->EndMarker; x = x->next)
  2388. {
  2389. if (x->number == My->OnTimerLineNumber)
  2390. {
  2391. /* FOUND */
  2392. /* save current stack level */
  2393. assert (My->StackHead != NULL);
  2394. My->StackHead->line = r;
  2395. /* increment exec stack */
  2396. if (bwb_incexec ())
  2397. {
  2398. /* set the new position to x and return x */
  2399. x->position = 0;
  2400. assert (My->StackHead != NULL);
  2401. My->StackHead->line = x;
  2402. My->StackHead->ExecCode = EXEC_GOSUB;
  2403. }
  2404. else
  2405. {
  2406. /* ERROR */
  2407. assert (My->StackHead != NULL);
  2408. My->StackHead->line = My->EndMarker;
  2409. }
  2410. return;
  2411. }
  2412. }
  2413. /* NOT FOUND */
  2414. }
  2415. }
  2416. }
  2417. }
  2418. }
  2419. /* check for end of line: if so, advance to next line and return */
  2420. if (r == l)
  2421. {
  2422. /* advance to the next line */
  2423. l->next->position = 0;
  2424. r = l->next;
  2425. }
  2426. else if (line_is_eol (r))
  2427. {
  2428. /* we could be at the end-of-the-line, added for RETURN */
  2429. /* advance to the next line */
  2430. r->next->position = 0;
  2431. r = r->next;
  2432. }
  2433. /* else reset with the value in r */
  2434. assert (My->StackHead != NULL);
  2435. My->StackHead->line = r;
  2436. }
  2437. /***************************************************************
  2438. FUNCTION: is_ln()
  2439. DESCRIPTION: This function determines whether a program
  2440. line (in buffer) begins with a line number.
  2441. ***************************************************************/
  2442. static int
  2443. is_ln (char *buffer)
  2444. {
  2445. int position;
  2446. assert (buffer != NULL);
  2447. position = 0;
  2448. buff_skip_spaces (buffer, &position); /* keep this */
  2449. if (bwb_isdigit (buffer[position]))
  2450. {
  2451. return TRUE;
  2452. }
  2453. return FALSE;
  2454. }
  2455. /***************************************************************
  2456. FUNCTION: is_numconst()
  2457. DESCRIPTION: This function reads the string in <buffer>
  2458. and returns TRUE if it is a numerical
  2459. constant and FALSE if it is not. At
  2460. this point, only decimal (base 10)
  2461. constants are detected.
  2462. ***************************************************************/
  2463. static int
  2464. is_numconst (char *buffer)
  2465. {
  2466. char *p;
  2467. assert (buffer != NULL);
  2468. /* Return FALSE for empty buffer */
  2469. if (buffer[0] == NulChar)
  2470. {
  2471. return FALSE;
  2472. }
  2473. /* else check digits */
  2474. p = buffer;
  2475. while (*p != NulChar)
  2476. {
  2477. switch (*p)
  2478. {
  2479. case '0':
  2480. case '1':
  2481. case '2':
  2482. case '3':
  2483. case '4':
  2484. case '5':
  2485. case '6':
  2486. case '7':
  2487. case '8':
  2488. case '9':
  2489. break;
  2490. default:
  2491. return FALSE;
  2492. }
  2493. p++;
  2494. }
  2495. /* only numerical characters detected */
  2496. return TRUE;
  2497. }
  2498. /* SWITCH */
  2499. LineType *
  2500. bwb_vector( LineType *l )
  2501. {
  2502. LineType *r;
  2503. assert (l != NULL);
  2504. switch( l->cmdnum )
  2505. {
  2506. case C_DEF8LBL:
  2507. r = bwb_DEF8LBL( l );
  2508. break;
  2509. case C_APPEND:
  2510. r = bwb_APPEND( l );
  2511. break;
  2512. case C_AS:
  2513. r = bwb_AS( l );
  2514. break;
  2515. case C_AUTO:
  2516. r = bwb_AUTO( l );
  2517. break;
  2518. case C_BACKSPACE:
  2519. r = bwb_BACKSPACE( l );
  2520. break;
  2521. case C_BREAK:
  2522. r = bwb_BREAK( l );
  2523. break;
  2524. case C_BUILD:
  2525. r = bwb_BUILD( l );
  2526. break;
  2527. case C_BYE:
  2528. r = bwb_BYE( l );
  2529. break;
  2530. case C_CALL:
  2531. r = bwb_CALL( l );
  2532. break;
  2533. case C_CASE:
  2534. r = bwb_CASE( l );
  2535. break;
  2536. case C_CASE_ELSE:
  2537. r = bwb_CASE_ELSE( l );
  2538. break;
  2539. case C_CHAIN:
  2540. r = bwb_CHAIN( l );
  2541. break;
  2542. case C_CHANGE:
  2543. r = bwb_CHANGE( l );
  2544. break;
  2545. case C_CLEAR:
  2546. r = bwb_CLEAR( l );
  2547. break;
  2548. case C_CLOAD:
  2549. r = bwb_CLOAD( l );
  2550. break;
  2551. case C_CLOAD8:
  2552. r = bwb_CLOAD8( l );
  2553. break;
  2554. case C_CLOSE:
  2555. r = bwb_CLOSE( l );
  2556. break;
  2557. case C_CLR:
  2558. r = bwb_CLR( l );
  2559. break;
  2560. case C_CMDS:
  2561. r = bwb_CMDS( l );
  2562. break;
  2563. case C_COMMON:
  2564. r = bwb_COMMON( l );
  2565. break;
  2566. case C_CONSOLE:
  2567. r = bwb_CONSOLE( l );
  2568. break;
  2569. case C_CONST:
  2570. r = bwb_CONST( l );
  2571. break;
  2572. case C_CONT:
  2573. r = bwb_CONT( l );
  2574. break;
  2575. case C_CONTINUE:
  2576. r = bwb_CONTINUE( l );
  2577. break;
  2578. case C_COPY:
  2579. r = bwb_COPY( l );
  2580. break;
  2581. case C_CREATE:
  2582. r = bwb_CREATE( l );
  2583. break;
  2584. case C_CSAVE:
  2585. r = bwb_CSAVE( l );
  2586. break;
  2587. case C_CSAVE8:
  2588. r = bwb_CSAVE8( l );
  2589. break;
  2590. case C_DATA:
  2591. r = bwb_DATA( l );
  2592. break;
  2593. case C_DEC:
  2594. r = bwb_DEC( l );
  2595. break;
  2596. case C_DEF:
  2597. r = bwb_DEF( l );
  2598. break;
  2599. case C_DEFBYT:
  2600. r = bwb_DEFBYT( l );
  2601. break;
  2602. case C_DEFCUR:
  2603. r = bwb_DEFCUR( l );
  2604. break;
  2605. case C_DEFDBL:
  2606. r = bwb_DEFDBL( l );
  2607. break;
  2608. case C_DEFINT:
  2609. r = bwb_DEFINT( l );
  2610. break;
  2611. case C_DEFLNG:
  2612. r = bwb_DEFLNG( l );
  2613. break;
  2614. case C_DEFSNG:
  2615. r = bwb_DEFSNG( l );
  2616. break;
  2617. case C_DEFSTR:
  2618. r = bwb_DEFSTR( l );
  2619. break;
  2620. case C_DELETE:
  2621. r = bwb_DELETE( l );
  2622. break;
  2623. case C_DELIMIT:
  2624. r = bwb_DELIMIT( l );
  2625. break;
  2626. case C_DIM:
  2627. r = bwb_DIM( l );
  2628. break;
  2629. case C_DISPLAY:
  2630. r = bwb_DISPLAY( l );
  2631. break;
  2632. case C_DO:
  2633. r = bwb_DO( l );
  2634. break;
  2635. case C_DOS:
  2636. r = bwb_DOS( l );
  2637. break;
  2638. case C_DSP:
  2639. r = bwb_DSP( l );
  2640. break;
  2641. case C_EDIT:
  2642. r = bwb_EDIT( l );
  2643. break;
  2644. case C_ELSE:
  2645. r = bwb_ELSE( l );
  2646. break;
  2647. case C_ELSEIF:
  2648. r = bwb_ELSEIF( l );
  2649. break;
  2650. case C_END:
  2651. r = bwb_END( l );
  2652. break;
  2653. case C_END_FUNCTION:
  2654. r = bwb_END_FUNCTION( l );
  2655. break;
  2656. case C_END_IF:
  2657. r = bwb_END_IF( l );
  2658. break;
  2659. case C_END_SELECT:
  2660. r = bwb_END_SELECT( l );
  2661. break;
  2662. case C_END_SUB:
  2663. r = bwb_END_SUB( l );
  2664. break;
  2665. case C_ERASE:
  2666. r = bwb_ERASE( l );
  2667. break;
  2668. case C_EXCHANGE:
  2669. r = bwb_EXCHANGE( l );
  2670. break;
  2671. case C_EXIT:
  2672. r = bwb_EXIT( l );
  2673. break;
  2674. case C_EXIT_DO:
  2675. r = bwb_EXIT_DO( l );
  2676. break;
  2677. case C_EXIT_FOR:
  2678. r = bwb_EXIT_FOR( l );
  2679. break;
  2680. case C_EXIT_FUNCTION:
  2681. r = bwb_EXIT_FUNCTION( l );
  2682. break;
  2683. case C_EXIT_REPEAT:
  2684. r = bwb_EXIT_REPEAT( l );
  2685. break;
  2686. case C_EXIT_SUB:
  2687. r = bwb_EXIT_SUB( l );
  2688. break;
  2689. case C_EXIT_WHILE:
  2690. r = bwb_EXIT_WHILE( l );
  2691. break;
  2692. case C_FEND:
  2693. r = bwb_FEND( l );
  2694. break;
  2695. case C_FIELD:
  2696. r = bwb_FIELD( l );
  2697. break;
  2698. case C_FILE:
  2699. r = bwb_FILE( l );
  2700. break;
  2701. case C_FILES:
  2702. r = bwb_FILES( l );
  2703. break;
  2704. case C_FLEX:
  2705. r = bwb_FLEX( l );
  2706. break;
  2707. case C_FNCS:
  2708. r = bwb_FNCS( l );
  2709. break;
  2710. case C_FNEND:
  2711. r = bwb_FNEND( l );
  2712. break;
  2713. case C_FOR:
  2714. r = bwb_FOR( l );
  2715. break;
  2716. case C_FUNCTION:
  2717. r = bwb_FUNCTION( l );
  2718. break;
  2719. case C_GET:
  2720. r = bwb_GET( l );
  2721. break;
  2722. case C_GO:
  2723. r = bwb_GO( l );
  2724. break;
  2725. case C_GO_SUB:
  2726. r = bwb_GO_SUB( l );
  2727. break;
  2728. case C_GO_TO:
  2729. r = bwb_GO_TO( l );
  2730. break;
  2731. case C_GOODBYE:
  2732. r = bwb_GOODBYE( l );
  2733. break;
  2734. case C_GOSUB:
  2735. r = bwb_GOSUB( l );
  2736. break;
  2737. case C_GOTO:
  2738. r = bwb_GOTO( l );
  2739. break;
  2740. case C_HELP:
  2741. r = bwb_HELP( l );
  2742. break;
  2743. case C_IF:
  2744. r = bwb_IF( l );
  2745. break;
  2746. case C_IF_END:
  2747. r = bwb_IF_END( l );
  2748. break;
  2749. case C_IF_MORE:
  2750. r = bwb_IF_MORE( l );
  2751. break;
  2752. case C_IF8THEN:
  2753. r = bwb_IF8THEN( l );
  2754. break;
  2755. case C_IMAGE:
  2756. r = bwb_IMAGE( l );
  2757. break;
  2758. case C_INC:
  2759. r = bwb_INC( l );
  2760. break;
  2761. case C_INPUT:
  2762. r = bwb_INPUT( l );
  2763. break;
  2764. case C_INPUT_LINE:
  2765. r = bwb_INPUT_LINE( l );
  2766. break;
  2767. case C_LET:
  2768. r = bwb_LET( l );
  2769. break;
  2770. case C_LINE:
  2771. r = bwb_LINE( l );
  2772. break;
  2773. case C_LINE_INPUT:
  2774. r = bwb_LINE_INPUT( l );
  2775. break;
  2776. case C_LIST:
  2777. r = bwb_LIST( l );
  2778. break;
  2779. case C_LISTNH:
  2780. r = bwb_LISTNH( l );
  2781. break;
  2782. case C_LLIST:
  2783. r = bwb_LLIST( l );
  2784. break;
  2785. case C_LOAD:
  2786. r = bwb_LOAD( l );
  2787. break;
  2788. case C_LOCAL:
  2789. r = bwb_LOCAL( l );
  2790. break;
  2791. case C_LOOP:
  2792. r = bwb_LOOP( l );
  2793. break;
  2794. case C_LPRINT:
  2795. r = bwb_LPRINT( l );
  2796. break;
  2797. case C_LPRINTER:
  2798. r = bwb_LPRINTER( l );
  2799. break;
  2800. case C_LPT:
  2801. r = bwb_LPT( l );
  2802. break;
  2803. case C_LSET:
  2804. r = bwb_LSET( l );
  2805. break;
  2806. case C_MAINTAINER:
  2807. r = bwb_MAINTAINER( l );
  2808. break;
  2809. case C_MAINTAINER_CMDS:
  2810. r = bwb_MAINTAINER_CMDS( l );
  2811. break;
  2812. case C_MAINTAINER_CMDS_HTML:
  2813. r = bwb_MAINTAINER_CMDS_HTML( l );
  2814. break;
  2815. case C_MAINTAINER_CMDS_ID:
  2816. r = bwb_MAINTAINER_CMDS_ID( l );
  2817. break;
  2818. case C_MAINTAINER_CMDS_MANUAL:
  2819. r = bwb_MAINTAINER_CMDS_MANUAL( l );
  2820. break;
  2821. case C_MAINTAINER_CMDS_SWITCH:
  2822. r = bwb_MAINTAINER_CMDS_SWITCH( l );
  2823. break;
  2824. case C_MAINTAINER_CMDS_TABLE:
  2825. r = bwb_MAINTAINER_CMDS_TABLE( l );
  2826. break;
  2827. case C_MAINTAINER_DEBUG:
  2828. r = bwb_MAINTAINER_DEBUG( l );
  2829. break;
  2830. case C_MAINTAINER_DEBUG_OFF:
  2831. r = bwb_MAINTAINER_DEBUG_OFF( l );
  2832. break;
  2833. case C_MAINTAINER_DEBUG_ON:
  2834. r = bwb_MAINTAINER_DEBUG_ON( l );
  2835. break;
  2836. case C_MAINTAINER_FNCS:
  2837. r = bwb_MAINTAINER_FNCS( l );
  2838. break;
  2839. case C_MAINTAINER_FNCS_HTML:
  2840. r = bwb_MAINTAINER_FNCS_HTML( l );
  2841. break;
  2842. case C_MAINTAINER_FNCS_ID:
  2843. r = bwb_MAINTAINER_FNCS_ID( l );
  2844. break;
  2845. case C_MAINTAINER_FNCS_MANUAL:
  2846. r = bwb_MAINTAINER_FNCS_MANUAL( l );
  2847. break;
  2848. case C_MAINTAINER_FNCS_SWITCH:
  2849. r = bwb_MAINTAINER_FNCS_SWITCH( l );
  2850. break;
  2851. case C_MAINTAINER_FNCS_TABLE:
  2852. r = bwb_MAINTAINER_FNCS_TABLE( l );
  2853. break;
  2854. case C_MAINTAINER_MANUAL:
  2855. r = bwb_MAINTAINER_MANUAL( l );
  2856. break;
  2857. case C_MAINTAINER_STACK:
  2858. r = bwb_MAINTAINER_STACK( l );
  2859. break;
  2860. case C_MARGIN:
  2861. r = bwb_MARGIN( l );
  2862. break;
  2863. case C_MAT:
  2864. r = bwb_MAT( l );
  2865. break;
  2866. case C_MAT_GET:
  2867. r = bwb_MAT_GET( l );
  2868. break;
  2869. case C_MAT_INPUT:
  2870. r = bwb_MAT_INPUT( l );
  2871. break;
  2872. case C_MAT_PRINT:
  2873. r = bwb_MAT_PRINT( l );
  2874. break;
  2875. case C_MAT_PUT:
  2876. r = bwb_MAT_PUT( l );
  2877. break;
  2878. case C_MAT_READ:
  2879. r = bwb_MAT_READ( l );
  2880. break;
  2881. case C_MAT_WRITE:
  2882. r = bwb_MAT_WRITE( l );
  2883. break;
  2884. case C_MERGE:
  2885. r = bwb_MERGE( l );
  2886. break;
  2887. case C_MID4:
  2888. r = bwb_MID4( l );
  2889. break;
  2890. case C_MON:
  2891. r = bwb_MON( l );
  2892. break;
  2893. case C_NAME:
  2894. r = bwb_NAME( l );
  2895. break;
  2896. case C_NEW:
  2897. r = bwb_NEW( l );
  2898. break;
  2899. case C_NEXT:
  2900. r = bwb_NEXT( l );
  2901. break;
  2902. case C_OF:
  2903. r = bwb_OF( l );
  2904. break;
  2905. case C_OLD:
  2906. r = bwb_OLD( l );
  2907. break;
  2908. case C_ON:
  2909. r = bwb_ON( l );
  2910. break;
  2911. case C_ON_ERROR:
  2912. r = bwb_ON_ERROR( l );
  2913. break;
  2914. case C_ON_ERROR_GOSUB:
  2915. r = bwb_ON_ERROR_GOSUB( l );
  2916. break;
  2917. case C_ON_ERROR_GOTO:
  2918. r = bwb_ON_ERROR_GOTO( l );
  2919. break;
  2920. case C_ON_ERROR_RESUME:
  2921. r = bwb_ON_ERROR_RESUME( l );
  2922. break;
  2923. case C_ON_ERROR_RESUME_NEXT:
  2924. r = bwb_ON_ERROR_RESUME_NEXT( l );
  2925. break;
  2926. case C_ON_ERROR_RETURN:
  2927. r = bwb_ON_ERROR_RETURN( l );
  2928. break;
  2929. case C_ON_ERROR_RETURN_NEXT:
  2930. r = bwb_ON_ERROR_RETURN_NEXT( l );
  2931. break;
  2932. case C_ON_TIMER:
  2933. r = bwb_ON_TIMER( l );
  2934. break;
  2935. case C_OPEN:
  2936. r = bwb_OPEN( l );
  2937. break;
  2938. case C_OPTION:
  2939. r = bwb_OPTION( l );
  2940. break;
  2941. case C_OPTION_ANGLE:
  2942. r = bwb_OPTION_ANGLE( l );
  2943. break;
  2944. case C_OPTION_ANGLE_DEGREES:
  2945. r = bwb_OPTION_ANGLE_DEGREES( l );
  2946. break;
  2947. case C_OPTION_ANGLE_GRADIANS:
  2948. r = bwb_OPTION_ANGLE_GRADIANS( l );
  2949. break;
  2950. case C_OPTION_ANGLE_RADIANS:
  2951. r = bwb_OPTION_ANGLE_RADIANS( l );
  2952. break;
  2953. case C_OPTION_ARITHMETIC:
  2954. r = bwb_OPTION_ARITHMETIC( l );
  2955. break;
  2956. case C_OPTION_ARITHMETIC_DECIMAL:
  2957. r = bwb_OPTION_ARITHMETIC_DECIMAL( l );
  2958. break;
  2959. case C_OPTION_ARITHMETIC_FIXED:
  2960. r = bwb_OPTION_ARITHMETIC_FIXED( l );
  2961. break;
  2962. case C_OPTION_ARITHMETIC_NATIVE:
  2963. r = bwb_OPTION_ARITHMETIC_NATIVE( l );
  2964. break;
  2965. case C_OPTION_BASE:
  2966. r = bwb_OPTION_BASE( l );
  2967. break;
  2968. case C_OPTION_BUGS:
  2969. r = bwb_OPTION_BUGS( l );
  2970. break;
  2971. case C_OPTION_BUGS_BOOLEAN:
  2972. r = bwb_OPTION_BUGS_BOOLEAN( l );
  2973. break;
  2974. case C_OPTION_BUGS_OFF:
  2975. r = bwb_OPTION_BUGS_OFF( l );
  2976. break;
  2977. case C_OPTION_BUGS_ON:
  2978. r = bwb_OPTION_BUGS_ON( l );
  2979. break;
  2980. case C_OPTION_COMPARE:
  2981. r = bwb_OPTION_COMPARE( l );
  2982. break;
  2983. case C_OPTION_COMPARE_BINARY:
  2984. r = bwb_OPTION_COMPARE_BINARY( l );
  2985. break;
  2986. case C_OPTION_COMPARE_DATABASE:
  2987. r = bwb_OPTION_COMPARE_DATABASE( l );
  2988. break;
  2989. case C_OPTION_COMPARE_TEXT:
  2990. r = bwb_OPTION_COMPARE_TEXT( l );
  2991. break;
  2992. case C_OPTION_COVERAGE:
  2993. r = bwb_OPTION_COVERAGE( l );
  2994. break;
  2995. case C_OPTION_COVERAGE_OFF:
  2996. r = bwb_OPTION_COVERAGE_OFF( l );
  2997. break;
  2998. case C_OPTION_COVERAGE_ON:
  2999. r = bwb_OPTION_COVERAGE_ON( l );
  3000. break;
  3001. case C_OPTION_DATE:
  3002. r = bwb_OPTION_DATE( l );
  3003. break;
  3004. case C_OPTION_DIGITS:
  3005. r = bwb_OPTION_DIGITS( l );
  3006. break;
  3007. case C_OPTION_DISABLE:
  3008. r = bwb_OPTION_DISABLE( l );
  3009. break;
  3010. case C_OPTION_DISABLE_COMMAND:
  3011. r = bwb_OPTION_DISABLE_COMMAND( l );
  3012. break;
  3013. case C_OPTION_DISABLE_FUNCTION:
  3014. r = bwb_OPTION_DISABLE_FUNCTION( l );
  3015. break;
  3016. case C_OPTION_DISABLE_OPERATOR:
  3017. r = bwb_OPTION_DISABLE_OPERATOR( l );
  3018. break;
  3019. case C_OPTION_EDIT:
  3020. r = bwb_OPTION_EDIT( l );
  3021. break;
  3022. case C_OPTION_ENABLE:
  3023. r = bwb_OPTION_ENABLE( l );
  3024. break;
  3025. case C_OPTION_ENABLE_COMMAND:
  3026. r = bwb_OPTION_ENABLE_COMMAND( l );
  3027. break;
  3028. case C_OPTION_ENABLE_FUNCTION:
  3029. r = bwb_OPTION_ENABLE_FUNCTION( l );
  3030. break;
  3031. case C_OPTION_ENABLE_OPERATOR:
  3032. r = bwb_OPTION_ENABLE_OPERATOR( l );
  3033. break;
  3034. case C_OPTION_ERROR:
  3035. r = bwb_OPTION_ERROR( l );
  3036. break;
  3037. case C_OPTION_ERROR_GOSUB:
  3038. r = bwb_OPTION_ERROR_GOSUB( l );
  3039. break;
  3040. case C_OPTION_ERROR_GOTO:
  3041. r = bwb_OPTION_ERROR_GOTO( l );
  3042. break;
  3043. case C_OPTION_EXPLICIT:
  3044. r = bwb_OPTION_EXPLICIT( l );
  3045. break;
  3046. case C_OPTION_EXTENSION:
  3047. r = bwb_OPTION_EXTENSION( l );
  3048. break;
  3049. case C_OPTION_FILES:
  3050. r = bwb_OPTION_FILES( l );
  3051. break;
  3052. case C_OPTION_IMPLICIT:
  3053. r = bwb_OPTION_IMPLICIT( l );
  3054. break;
  3055. case C_OPTION_INDENT:
  3056. r = bwb_OPTION_INDENT( l );
  3057. break;
  3058. case C_OPTION_LABELS:
  3059. r = bwb_OPTION_LABELS( l );
  3060. break;
  3061. case C_OPTION_LABELS_OFF:
  3062. r = bwb_OPTION_LABELS_OFF( l );
  3063. break;
  3064. case C_OPTION_LABELS_ON:
  3065. r = bwb_OPTION_LABELS_ON( l );
  3066. break;
  3067. case C_OPTION_PROMPT:
  3068. r = bwb_OPTION_PROMPT( l );
  3069. break;
  3070. case C_OPTION_PUNCT:
  3071. r = bwb_OPTION_PUNCT( l );
  3072. break;
  3073. case C_OPTION_PUNCT_AT:
  3074. r = bwb_OPTION_PUNCT_AT( l );
  3075. break;
  3076. case C_OPTION_PUNCT_BYTE:
  3077. r = bwb_OPTION_PUNCT_BYTE( l );
  3078. break;
  3079. case C_OPTION_PUNCT_COMMENT:
  3080. r = bwb_OPTION_PUNCT_COMMENT( l );
  3081. break;
  3082. case C_OPTION_PUNCT_CURRENCY:
  3083. r = bwb_OPTION_PUNCT_CURRENCY( l );
  3084. break;
  3085. case C_OPTION_PUNCT_DOUBLE:
  3086. r = bwb_OPTION_PUNCT_DOUBLE( l );
  3087. break;
  3088. case C_OPTION_PUNCT_FILENUM:
  3089. r = bwb_OPTION_PUNCT_FILENUM( l );
  3090. break;
  3091. case C_OPTION_PUNCT_IMAGE:
  3092. r = bwb_OPTION_PUNCT_IMAGE( l );
  3093. break;
  3094. case C_OPTION_PUNCT_INPUT:
  3095. r = bwb_OPTION_PUNCT_INPUT( l );
  3096. break;
  3097. case C_OPTION_PUNCT_INTEGER:
  3098. r = bwb_OPTION_PUNCT_INTEGER( l );
  3099. break;
  3100. case C_OPTION_PUNCT_LONG:
  3101. r = bwb_OPTION_PUNCT_LONG( l );
  3102. break;
  3103. case C_OPTION_PUNCT_LPAREN:
  3104. r = bwb_OPTION_PUNCT_LPAREN( l );
  3105. break;
  3106. case C_OPTION_PUNCT_PRINT:
  3107. r = bwb_OPTION_PUNCT_PRINT( l );
  3108. break;
  3109. case C_OPTION_PUNCT_QUOTE:
  3110. r = bwb_OPTION_PUNCT_QUOTE( l );
  3111. break;
  3112. case C_OPTION_PUNCT_RPAREN:
  3113. r = bwb_OPTION_PUNCT_RPAREN( l );
  3114. break;
  3115. case C_OPTION_PUNCT_SINGLE:
  3116. r = bwb_OPTION_PUNCT_SINGLE( l );
  3117. break;
  3118. case C_OPTION_PUNCT_STATEMENT:
  3119. r = bwb_OPTION_PUNCT_STATEMENT( l );
  3120. break;
  3121. case C_OPTION_PUNCT_STRING:
  3122. r = bwb_OPTION_PUNCT_STRING( l );
  3123. break;
  3124. case C_OPTION_RECLEN:
  3125. r = bwb_OPTION_RECLEN( l );
  3126. break;
  3127. case C_OPTION_RENUM:
  3128. r = bwb_OPTION_RENUM( l );
  3129. break;
  3130. case C_OPTION_ROUND:
  3131. r = bwb_OPTION_ROUND( l );
  3132. break;
  3133. case C_OPTION_ROUND_BANK:
  3134. r = bwb_OPTION_ROUND_BANK( l );
  3135. break;
  3136. case C_OPTION_ROUND_MATH:
  3137. r = bwb_OPTION_ROUND_MATH( l );
  3138. break;
  3139. case C_OPTION_ROUND_TRUNCATE:
  3140. r = bwb_OPTION_ROUND_TRUNCATE( l );
  3141. break;
  3142. case C_OPTION_SCALE:
  3143. r = bwb_OPTION_SCALE( l );
  3144. break;
  3145. case C_OPTION_SLEEP:
  3146. r = bwb_OPTION_SLEEP( l );
  3147. break;
  3148. case C_OPTION_STDERR:
  3149. r = bwb_OPTION_STDERR( l );
  3150. break;
  3151. case C_OPTION_STDIN:
  3152. r = bwb_OPTION_STDIN( l );
  3153. break;
  3154. case C_OPTION_STDOUT:
  3155. r = bwb_OPTION_STDOUT( l );
  3156. break;
  3157. case C_OPTION_STRICT:
  3158. r = bwb_OPTION_STRICT( l );
  3159. break;
  3160. case C_OPTION_STRICT_OFF:
  3161. r = bwb_OPTION_STRICT_OFF( l );
  3162. break;
  3163. case C_OPTION_STRICT_ON:
  3164. r = bwb_OPTION_STRICT_ON( l );
  3165. break;
  3166. case C_OPTION_TERMINAL:
  3167. r = bwb_OPTION_TERMINAL( l );
  3168. break;
  3169. case C_OPTION_TERMINAL_ADM:
  3170. r = bwb_OPTION_TERMINAL_ADM( l );
  3171. break;
  3172. case C_OPTION_TERMINAL_ANSI:
  3173. r = bwb_OPTION_TERMINAL_ANSI( l );
  3174. break;
  3175. case C_OPTION_TERMINAL_NONE:
  3176. r = bwb_OPTION_TERMINAL_NONE( l );
  3177. break;
  3178. case C_OPTION_TIME:
  3179. r = bwb_OPTION_TIME( l );
  3180. break;
  3181. case C_OPTION_TRACE:
  3182. r = bwb_OPTION_TRACE( l );
  3183. break;
  3184. case C_OPTION_TRACE_OFF:
  3185. r = bwb_OPTION_TRACE_OFF( l );
  3186. break;
  3187. case C_OPTION_TRACE_ON:
  3188. r = bwb_OPTION_TRACE_ON( l );
  3189. break;
  3190. case C_OPTION_USING:
  3191. r = bwb_OPTION_USING( l );
  3192. break;
  3193. case C_OPTION_USING_ALL:
  3194. r = bwb_OPTION_USING_ALL( l );
  3195. break;
  3196. case C_OPTION_USING_COMMA:
  3197. r = bwb_OPTION_USING_COMMA( l );
  3198. break;
  3199. case C_OPTION_USING_DIGIT:
  3200. r = bwb_OPTION_USING_DIGIT( l );
  3201. break;
  3202. case C_OPTION_USING_DOLLAR:
  3203. r = bwb_OPTION_USING_DOLLAR( l );
  3204. break;
  3205. case C_OPTION_USING_EXRAD:
  3206. r = bwb_OPTION_USING_EXRAD( l );
  3207. break;
  3208. case C_OPTION_USING_FILLER:
  3209. r = bwb_OPTION_USING_FILLER( l );
  3210. break;
  3211. case C_OPTION_USING_FIRST:
  3212. r = bwb_OPTION_USING_FIRST( l );
  3213. break;
  3214. case C_OPTION_USING_LENGTH:
  3215. r = bwb_OPTION_USING_LENGTH( l );
  3216. break;
  3217. case C_OPTION_USING_LITERAL:
  3218. r = bwb_OPTION_USING_LITERAL( l );
  3219. break;
  3220. case C_OPTION_USING_MINUS:
  3221. r = bwb_OPTION_USING_MINUS( l );
  3222. break;
  3223. case C_OPTION_USING_PERIOD:
  3224. r = bwb_OPTION_USING_PERIOD( l );
  3225. break;
  3226. case C_OPTION_USING_PLUS:
  3227. r = bwb_OPTION_USING_PLUS( l );
  3228. break;
  3229. case C_OPTION_VERSION:
  3230. r = bwb_OPTION_VERSION( l );
  3231. break;
  3232. case C_OPTION_ZONE:
  3233. r = bwb_OPTION_ZONE( l );
  3234. break;
  3235. case C_PAUSE:
  3236. r = bwb_PAUSE( l );
  3237. break;
  3238. case C_PDEL:
  3239. r = bwb_PDEL( l );
  3240. break;
  3241. case C_POP:
  3242. r = bwb_POP( l );
  3243. break;
  3244. case C_PRINT:
  3245. r = bwb_PRINT( l );
  3246. break;
  3247. case C_PTP:
  3248. r = bwb_PTP( l );
  3249. break;
  3250. case C_PTR:
  3251. r = bwb_PTR( l );
  3252. break;
  3253. case C_PUT:
  3254. r = bwb_PUT( l );
  3255. break;
  3256. case C_QUIT:
  3257. r = bwb_QUIT( l );
  3258. break;
  3259. case C_READ:
  3260. r = bwb_READ( l );
  3261. break;
  3262. case C_RECALL:
  3263. r = bwb_RECALL( l );
  3264. break;
  3265. case C_REM:
  3266. r = bwb_REM( l );
  3267. break;
  3268. case C_RENAME:
  3269. r = bwb_RENAME( l );
  3270. break;
  3271. case C_RENUM:
  3272. r = bwb_RENUM( l );
  3273. break;
  3274. case C_RENUMBER:
  3275. r = bwb_RENUMBER( l );
  3276. break;
  3277. case C_REPEAT:
  3278. r = bwb_REPEAT( l );
  3279. break;
  3280. case C_REPLACE:
  3281. r = bwb_REPLACE( l );
  3282. break;
  3283. case C_RESET:
  3284. r = bwb_RESET( l );
  3285. break;
  3286. case C_RESTORE:
  3287. r = bwb_RESTORE( l );
  3288. break;
  3289. case C_RESUME:
  3290. r = bwb_RESUME( l );
  3291. break;
  3292. case C_RETURN:
  3293. r = bwb_RETURN( l );
  3294. break;
  3295. case C_RSET:
  3296. r = bwb_RSET( l );
  3297. break;
  3298. case C_RUN:
  3299. r = bwb_RUN( l );
  3300. break;
  3301. case C_RUNNH:
  3302. r = bwb_RUNNH( l );
  3303. break;
  3304. case C_SAVE:
  3305. r = bwb_SAVE( l );
  3306. break;
  3307. case C_SCRATCH:
  3308. r = bwb_SCRATCH( l );
  3309. break;
  3310. case C_SELECT:
  3311. r = bwb_SELECT( l );
  3312. break;
  3313. case C_SELECT_CASE:
  3314. r = bwb_SELECT_CASE( l );
  3315. break;
  3316. case C_STEP:
  3317. r = bwb_STEP( l );
  3318. break;
  3319. case C_STOP:
  3320. r = bwb_STOP( l );
  3321. break;
  3322. case C_STORE:
  3323. r = bwb_STORE( l );
  3324. break;
  3325. case C_SUB:
  3326. r = bwb_SUB( l );
  3327. break;
  3328. case C_SUB_END:
  3329. r = bwb_SUB_END( l );
  3330. break;
  3331. case C_SUB_EXIT:
  3332. r = bwb_SUB_EXIT( l );
  3333. break;
  3334. case C_SUBEND:
  3335. r = bwb_SUBEND( l );
  3336. break;
  3337. case C_SUBEXIT:
  3338. r = bwb_SUBEXIT( l );
  3339. break;
  3340. case C_SWAP:
  3341. r = bwb_SWAP( l );
  3342. break;
  3343. case C_SYSTEM:
  3344. r = bwb_SYSTEM( l );
  3345. break;
  3346. case C_TEXT:
  3347. r = bwb_TEXT( l );
  3348. break;
  3349. case C_THEN:
  3350. r = bwb_THEN( l );
  3351. break;
  3352. case C_TIMER:
  3353. r = bwb_TIMER( l );
  3354. break;
  3355. case C_TIMER_OFF:
  3356. r = bwb_TIMER_OFF( l );
  3357. break;
  3358. case C_TIMER_ON:
  3359. r = bwb_TIMER_ON( l );
  3360. break;
  3361. case C_TIMER_STOP:
  3362. r = bwb_TIMER_STOP( l );
  3363. break;
  3364. case C_TLOAD:
  3365. r = bwb_TLOAD( l );
  3366. break;
  3367. case C_TO:
  3368. r = bwb_TO( l );
  3369. break;
  3370. case C_TRACE:
  3371. r = bwb_TRACE( l );
  3372. break;
  3373. case C_TRACE_OFF:
  3374. r = bwb_TRACE_OFF( l );
  3375. break;
  3376. case C_TRACE_ON:
  3377. r = bwb_TRACE_ON( l );
  3378. break;
  3379. case C_TSAVE:
  3380. r = bwb_TSAVE( l );
  3381. break;
  3382. case C_TTY:
  3383. r = bwb_TTY( l );
  3384. break;
  3385. case C_TTY_IN:
  3386. r = bwb_TTY_IN( l );
  3387. break;
  3388. case C_TTY_OUT:
  3389. r = bwb_TTY_OUT( l );
  3390. break;
  3391. case C_UNTIL:
  3392. r = bwb_UNTIL( l );
  3393. break;
  3394. case C_USE:
  3395. r = bwb_USE( l );
  3396. break;
  3397. case C_VARS:
  3398. r = bwb_VARS( l );
  3399. break;
  3400. case C_WEND:
  3401. r = bwb_WEND( l );
  3402. break;
  3403. case C_WHILE:
  3404. r = bwb_WHILE( l );
  3405. break;
  3406. case C_WRITE:
  3407. r = bwb_WRITE( l );
  3408. break;
  3409. default:
  3410. WARN_INTERNAL_ERROR;
  3411. r = l;
  3412. break;
  3413. }
  3414. return r;
  3415. }
  3416. /* EOF */