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.
 
 
 
 
 
 

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