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.
 
 
 
 
 
 

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