home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1994 March / Source_Code_CD-ROM_Walnut_Creek_March_1994.iso / compsrcs / misc / volume33 / bwbasic / part10 < prev    next >
Encoding:
Text File  |  1992-11-03  |  59.9 KB  |  1,916 lines

  1. Newsgroups: comp.sources.misc
  2. From: tcamp@acpub.duke.edu (Ted A. Campbell)
  3. Subject:  v33i046:  bwbasic - Bywater BASIC interpreter version 1.10, Part10/11
  4. Message-ID: <1992Nov5.041024.20880@sparky.imd.sterling.com>
  5. X-Md4-Signature: 1108c20fb309f84bbb936de803581217
  6. Date: Thu, 5 Nov 1992 04:10:24 GMT
  7. Approved: kent@sparky.imd.sterling.com
  8.  
  9. Submitted-by: tcamp@acpub.duke.edu (Ted A. Campbell)
  10. Posting-number: Volume 33, Issue 46
  11. Archive-name: bwbasic/part10
  12. Environment: ANSI-C
  13.  
  14. #! /bin/sh
  15. # This is a shell archive.  Remove anything before this line, then feed it
  16. # into a shell via "sh file" or similar.  To overwrite existing files,
  17. # type "sh file -c".
  18. # Contents:  bwb_mth.c bwbasic.h
  19. # Wrapped by kent@sparky on Wed Nov  4 21:34:29 1992
  20. PATH=/bin:/usr/bin:/usr/ucb:/usr/local/bin:/usr/lbin ; export PATH
  21. echo If this archive is complete, you will see the following message:
  22. echo '          "shar: End of archive 10 (of 11)."'
  23. if test -f 'bwb_mth.c' -a "${1}" != "-c" ; then 
  24.   echo shar: Will not clobber existing file \"'bwb_mth.c'\"
  25. else
  26.   echo shar: Extracting \"'bwb_mth.c'\" \(27902 characters\)
  27.   sed "s/^X//" >'bwb_mth.c' <<'END_OF_FILE'
  28. X/****************************************************************
  29. X
  30. X        bwb_mth.c       Mathematical Functions
  31. X                        for Bywater BASIC Interpreter
  32. X
  33. X                        Copyright (c) 1992, Ted A. Campbell
  34. X
  35. X                        Bywater Software
  36. X                        P. O. Box 4023
  37. X                        Duke Station
  38. X                        Durham, NC  27706
  39. X
  40. X                        email: tcamp@acpub.duke.edu
  41. X
  42. X        Copyright and Permissions Information:
  43. X
  44. X        All U.S. and international copyrights are claimed by the
  45. X        author. The author grants permission to use this code
  46. X        and software based on it under the following conditions:
  47. X        (a) in general, the code and software based upon it may be
  48. X        used by individuals and by non-profit organizations; (b) it
  49. X        may also be utilized by governmental agencies in any country,
  50. X        with the exception of military agencies; (c) the code and/or
  51. X        software based upon it may not be sold for a profit without
  52. X        an explicit and specific permission from the author, except
  53. X        that a minimal fee may be charged for media on which it is
  54. X        copied, and for copying and handling; (d) the code must be
  55. X        distributed in the form in which it has been released by the
  56. X        author; and (e) the code and software based upon it may not
  57. X        be used for illegal activities.
  58. X
  59. X****************************************************************/
  60. X
  61. X#include <stdio.h>
  62. X#include <stdlib.h>
  63. X#include <ctype.h>
  64. X#include <string.h>
  65. X#include <math.h>
  66. X#include <time.h>
  67. X
  68. X#include "bwbasic.h"
  69. X#include "bwb_mes.h"
  70. X
  71. Xunion un_integer
  72. X   {
  73. X   int the_integer;
  74. X   unsigned char the_chars[ sizeof( int ) ];
  75. X   } an_integer;
  76. X
  77. Xunion un_single
  78. X   {
  79. X   float the_float;
  80. X   unsigned char the_chars[ sizeof( float) ];
  81. X   } a_float;
  82. X
  83. Xunion un_double
  84. X   {
  85. X   double the_double;
  86. X   unsigned char the_chars[ sizeof( double ) ];
  87. X   } a_double;
  88. X
  89. X/***************************************************************
  90. X
  91. X        FUNCTION:       fnc_abs()
  92. X
  93. X        DESCRIPTION:    This C function implements the BASIC
  94. X                        predefined ABS function, returning the
  95. X                        absolute value of the argument.
  96. X
  97. X***************************************************************/
  98. X
  99. Xstruct bwb_variable *
  100. Xfnc_abs( int argc, struct bwb_variable *argv  )
  101. X   {
  102. X   static struct bwb_variable nvar;
  103. X   static int init = FALSE;
  104. X
  105. X   #if INTENSIVE_DEBUG
  106. X   sprintf( bwb_ebuf, "in fnc_abs(): entered function" );
  107. X   bwb_debug( bwb_ebuf );
  108. X   #endif
  109. X
  110. X   /* initialize the variable if necessary */
  111. X
  112. X   if ( init == FALSE )
  113. X      {
  114. X      init = TRUE;
  115. X      strncpy( nvar.name, "(abs var)", MAXVARNAMESIZE );
  116. X      #if INTENSIVE_DEBUG
  117. X      sprintf( bwb_ebuf, "in fnc_abs(): ready to make local variable <%s>",
  118. X         nvar.name );
  119. X      bwb_debug( bwb_ebuf );
  120. X      #endif
  121. X      var_make( &nvar, SINGLE );
  122. X      }
  123. X
  124. X   #if INTENSIVE_DEBUG
  125. X   sprintf( bwb_ebuf, "in fnc_abs(): received f_arg <%f> nvar type <%c>",
  126. X      var_getdval( &( argv[ 0 ] ) ), nvar.type );
  127. X   bwb_debug( bwb_ebuf );
  128. X   #endif
  129. X
  130. X   #if PROG_ERRORS
  131. X   if ( argc < 1 )
  132. X      {
  133. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function ABS().",
  134. X         argc );
  135. X      bwb_error( bwb_ebuf );
  136. X      return NULL;
  137. X      }
  138. X   else if ( argc > 1 )
  139. X      {
  140. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function ABS().",
  141. X         argc );
  142. X      bwb_error( bwb_ebuf );
  143. X      return NULL;
  144. X      }
  145. X   #else
  146. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  147. X      {
  148. X      return NULL;
  149. X      }
  150. X   #endif
  151. X
  152. X   /* assign values */
  153. X
  154. X   #if INTENSIVE_DEBUG
  155. X   sprintf( bwb_ebuf, "in fnc_abs(): nvar type <%c>; calling findval()",
  156. X      nvar.type );
  157. X   bwb_debug( bwb_ebuf );
  158. X   #endif
  159. X
  160. X   * var_findfval( &nvar, nvar.array_pos ) = 
  161. X      (float) fabs( var_getdval( &( argv[ 0 ] ) ) );
  162. X
  163. X   return &nvar;
  164. X
  165. X   }
  166. X
  167. X/***************************************************************
  168. X
  169. X        FUNCTION:       fnc_atn()
  170. X
  171. X        DESCRIPTION:    This C function implements the BASIC
  172. X
  173. X                        predefined ATN function, returning the
  174. X                        arctangent of the argument.
  175. X
  176. X***************************************************************/
  177. X
  178. Xstruct bwb_variable *
  179. Xfnc_atn( int argc, struct bwb_variable *argv  )
  180. X   {
  181. X   static struct bwb_variable nvar;
  182. X   static int init = FALSE;
  183. X
  184. X   /* initialize the variable if necessary */
  185. X
  186. X   if ( init == FALSE )
  187. X      {
  188. X      init = TRUE;
  189. X      var_make( &nvar, DOUBLE );
  190. X      }
  191. X
  192. X   #if INTENSIVE_DEBUG
  193. X   sprintf( bwb_ebuf, "in fnc_atn(): received f_arg <%f> ",
  194. X      var_getdval( &( argv[ 0 ] ) ) );
  195. X   bwb_debug( bwb_ebuf );
  196. X   #endif
  197. X
  198. X   #if PROG_ERRORS
  199. X   if ( argc < 1 )
  200. X      {
  201. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function ATN().",
  202. X         argc );
  203. X      bwb_error( bwb_ebuf );
  204. X      return NULL;
  205. X      }
  206. X   else if ( argc > 1 )
  207. X      {
  208. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function ATN().",
  209. X         argc );
  210. X      bwb_error( bwb_ebuf );
  211. X      return NULL;
  212. X      }
  213. X   #else
  214. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  215. X      {
  216. X      return NULL;
  217. X      }
  218. X   #endif
  219. X
  220. X   /* assign values */
  221. X
  222. X   * var_finddval( &nvar, nvar.array_pos ) 
  223. X      = atan( var_getdval( &( argv[ 0 ] ) ) );
  224. X
  225. X   return &nvar;
  226. X
  227. X   }
  228. X
  229. X/***************************************************************
  230. X
  231. X        FUNCTION:       fnc_cos()
  232. X
  233. X        DESCRIPTION:    This C function implements the BASIC
  234. X                        predefined COS function, returning the
  235. X                        cosine of the argument.
  236. X
  237. X***************************************************************/
  238. X
  239. Xstruct bwb_variable *
  240. Xfnc_cos( int argc, struct bwb_variable *argv  )
  241. X   {
  242. X   static struct bwb_variable nvar;
  243. X   static int init = FALSE;
  244. X
  245. X   /* initialize the variable if necessary */
  246. X
  247. X   if ( init == FALSE )
  248. X      {
  249. X      init = TRUE;
  250. X      var_make( &nvar, DOUBLE );
  251. X      }
  252. X
  253. X   #if INTENSIVE_DEBUG
  254. X   sprintf( bwb_ebuf, "in fnc_cos(): received f_arg <%f> ",
  255. X      var_getdval( &( argv[ 0 ] ) ) );
  256. X   bwb_debug( bwb_ebuf );
  257. X   #endif
  258. X
  259. X   #if PROG_ERRORS
  260. X   if ( argc < 1 )
  261. X      {
  262. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function COS().",
  263. X         argc );
  264. X      bwb_error( bwb_ebuf );
  265. X      return NULL;
  266. X      }
  267. X   else if ( argc > 1 )
  268. X      {
  269. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function COS().",
  270. X         argc );
  271. X      bwb_error( bwb_ebuf );
  272. X      return NULL;
  273. X      }
  274. X   #else
  275. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  276. X      {
  277. X      return NULL;
  278. X      }
  279. X   #endif
  280. X
  281. X   /* assign values */
  282. X
  283. X   * var_finddval( &nvar, nvar.array_pos ) 
  284. X      = cos( var_getdval( &( argv[ 0 ] ) ) );
  285. X
  286. X   return &nvar;
  287. X
  288. X   }
  289. X
  290. X/***************************************************************
  291. X
  292. X        FUNCTION:       fnc_log()
  293. X
  294. X        DESCRIPTION:    This C function implements the BASIC
  295. X                        predefined LOG function, returning the
  296. X                        natural logarithm of the argument.
  297. X
  298. X***************************************************************/
  299. X
  300. Xstruct bwb_variable *
  301. Xfnc_log( int argc, struct bwb_variable *argv  )
  302. X   {
  303. X   static struct bwb_variable nvar;
  304. X   static int init = FALSE;
  305. X
  306. X   /* initialize the variable if necessary */
  307. X
  308. X   if ( init == FALSE )
  309. X      {
  310. X      init = TRUE;
  311. X      var_make( &nvar, DOUBLE );
  312. X      }
  313. X
  314. X   #if INTENSIVE_DEBUG
  315. X   sprintf( bwb_ebuf, "in fnc_log(): received f_arg <%f> ",
  316. X      var_getdval( &( argv[ 0 ] ) ) );
  317. X   bwb_debug( bwb_ebuf );
  318. X   #endif
  319. X
  320. X   #if PROG_ERRORS
  321. X   if ( argc < 1 )
  322. X      {
  323. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function LOG().",
  324. X         argc );
  325. X      bwb_error( bwb_ebuf );
  326. X      return NULL;
  327. X      }
  328. X   else if ( argc > 1 )
  329. X      {
  330. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function LOG().",
  331. X         argc );
  332. X      bwb_error( bwb_ebuf );
  333. X      return NULL;
  334. X      }
  335. X   #else
  336. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  337. X      {
  338. X      return NULL;
  339. X      }
  340. X   #endif
  341. X
  342. X   /* assign values */
  343. X
  344. X   * var_finddval( &nvar, nvar.array_pos ) 
  345. X      = log( var_getdval( &( argv[ 0 ] ) ) );
  346. X
  347. X   return &nvar;
  348. X   }
  349. X
  350. X/***************************************************************
  351. X
  352. X        FUNCTION:       fnc_sin()
  353. X
  354. X        DESCRIPTION:    This C function implements the BASIC
  355. X                        predefined SIN function, returning
  356. X                        the sine of the argument.
  357. X
  358. X***************************************************************/
  359. X
  360. Xstruct bwb_variable *
  361. Xfnc_sin( int argc, struct bwb_variable *argv  )
  362. X   {
  363. X   static struct bwb_variable nvar;
  364. X   static int init = FALSE;
  365. X
  366. X   /* initialize the variable if necessary */
  367. X
  368. X   if ( init == FALSE )
  369. X      {
  370. X      init = TRUE;
  371. X      var_make( &nvar, DOUBLE );
  372. X      }
  373. X
  374. X   #if INTENSIVE_DEBUG
  375. X   sprintf( bwb_ebuf, "in fnc_sin(): received f_arg <%f> ",
  376. X      var_getdval( &( argv[ 0 ] ) ) );
  377. X   bwb_debug( bwb_ebuf );
  378. X   #endif
  379. X
  380. X   #if PROG_ERRORS
  381. X   if ( argc < 1 )
  382. X      {
  383. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function SIN().",
  384. X         argc );
  385. X      bwb_error( bwb_ebuf );
  386. X      return NULL;
  387. X      }
  388. X
  389. X   else if ( argc > 1 )
  390. X      {
  391. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function SIN().",
  392. X         argc );
  393. X      bwb_error( bwb_ebuf );
  394. X      return NULL;
  395. X      }
  396. X   #else
  397. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  398. X      {
  399. X      return NULL;
  400. X      }
  401. X   #endif
  402. X
  403. X   /* assign values */
  404. X
  405. X   * var_finddval( &nvar, nvar.array_pos ) 
  406. X      = sin( var_getdval( &( argv[ 0 ] ) ) );
  407. X
  408. X   return &nvar;
  409. X
  410. X   }
  411. X
  412. X
  413. X/***************************************************************
  414. X
  415. X        FUNCTION:       fnc_sqr()
  416. X
  417. X        DESCRIPTION:    This C function implements the BASIC
  418. X                        predefined SQR function, returning
  419. X                        the square root of the argument.
  420. X
  421. X***************************************************************/
  422. X
  423. Xstruct bwb_variable *
  424. Xfnc_sqr( int argc, struct bwb_variable *argv  )
  425. X   {
  426. X   static struct bwb_variable nvar;
  427. X   static int init = FALSE;
  428. X
  429. X   /* initialize the variable if necessary */
  430. X
  431. X   if ( init == FALSE )
  432. X      {
  433. X      init = TRUE;
  434. X      var_make( &nvar, DOUBLE );
  435. X      }
  436. X
  437. X   #if INTENSIVE_DEBUG
  438. X   sprintf( bwb_ebuf, "in fnc_sqr(): received f_arg <%f> ",
  439. X      var_getdval( &( argv[ 0 ] ) ) );
  440. X   bwb_debug( bwb_ebuf );
  441. X   #endif
  442. X
  443. X   #if PROG_ERRORS
  444. X   if ( argc < 1 )
  445. X      {
  446. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function SQR().",
  447. X         argc );
  448. X      bwb_error( bwb_ebuf );
  449. X      return NULL;
  450. X      }
  451. X   else if ( argc > 1 )
  452. X      {
  453. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function SQR().",
  454. X         argc );
  455. X      bwb_error( bwb_ebuf );
  456. X      return NULL;
  457. X      }
  458. X   #else
  459. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  460. X      {
  461. X      return NULL;
  462. X      }
  463. X   #endif
  464. X
  465. X   /* assign values */
  466. X
  467. X   * var_finddval( &nvar, nvar.array_pos ) 
  468. X      = sqrt( var_getdval( &( argv[ 0 ] ) ) );
  469. X
  470. X   return &nvar;
  471. X
  472. X   }
  473. X
  474. X/***************************************************************
  475. X
  476. X        FUNCTION:       fnc_tan()
  477. X
  478. X        DESCRIPTION:    This C function implements the BASIC
  479. X                        predefined TAN function, returning the
  480. X                        tangent of the argument.
  481. X
  482. X***************************************************************/
  483. X
  484. Xstruct bwb_variable *
  485. Xfnc_tan( int argc, struct bwb_variable *argv  )
  486. X   {
  487. X   static struct bwb_variable nvar;
  488. X   static int init = FALSE;
  489. X
  490. X   /* initialize the variable if necessary */
  491. X
  492. X   if ( init == FALSE )
  493. X      {
  494. X      init = TRUE;
  495. X      var_make( &nvar, DOUBLE );
  496. X      }
  497. X
  498. X   #if INTENSIVE_DEBUG
  499. X   sprintf( bwb_ebuf, "in fnc_tan(): received f_arg <%f> ",
  500. X      var_getdval( &( argv[ 0 ] ) ) );
  501. X   bwb_debug( bwb_ebuf );
  502. X   #endif
  503. X
  504. X   #if PROG_ERRORS
  505. X   if ( argc < 1 )
  506. X      {
  507. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function TAN().",
  508. X         argc );
  509. X      bwb_error( bwb_ebuf );
  510. X      return NULL;
  511. X      }
  512. X   else if ( argc > 1 )
  513. X      {
  514. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function TAN().",
  515. X         argc );
  516. X      bwb_error( bwb_ebuf );
  517. X      return NULL;
  518. X      }
  519. X   #else
  520. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  521. X      {
  522. X      return NULL;
  523. X      }
  524. X   #endif
  525. X
  526. X   /* assign values */
  527. X
  528. X   * var_finddval( &nvar, nvar.array_pos ) 
  529. X      = tan( var_getdval( &( argv[ 0 ] ) ) );
  530. X
  531. X   return &nvar;
  532. X
  533. X   }
  534. X
  535. X
  536. X/***************************************************************
  537. X
  538. X        FUNCTION:       fnc_sgn()
  539. X
  540. X        DESCRIPTION:    This C function implements the BASIC
  541. X                        predefined SGN function, returning 0
  542. X                        if the argument is 0, -1 if the argument
  543. X                        is less than 0, or 1 if the argument
  544. X                        is more than 0.
  545. X
  546. X***************************************************************/
  547. X
  548. Xstruct bwb_variable *
  549. Xfnc_sgn( int argc, struct bwb_variable *argv  )
  550. X   {
  551. X   static struct bwb_variable nvar;
  552. X   double dval;
  553. X   static int init = FALSE;
  554. X
  555. X   /* initialize the variable if necessary */
  556. X
  557. X   if ( init == FALSE )
  558. X      {
  559. X      init = TRUE;
  560. X      var_make( &nvar, INTEGER );
  561. X      }
  562. X
  563. X   #if INTENSIVE_DEBUG
  564. X   sprintf( bwb_ebuf, "in fnc_sgn(): received f_arg <%f> ",
  565. X      var_getdval( &( argv[ 0 ] ) ) );
  566. X   bwb_debug( bwb_ebuf );
  567. X   #endif
  568. X
  569. X   #if PROG_ERRORS
  570. X   if ( argc < 1 )
  571. X      {
  572. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function SGN().",
  573. X         argc );
  574. X      bwb_error( bwb_ebuf );
  575. X      return NULL;
  576. X      }
  577. X   else if ( argc > 1 )
  578. X      {
  579. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function SGN().",
  580. X         argc );
  581. X      bwb_error( bwb_ebuf );
  582. X      return NULL;
  583. X      }
  584. X   #else
  585. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  586. X      {
  587. X      return NULL;
  588. X      }
  589. X   #endif
  590. X
  591. X   /* assign values */
  592. X
  593. X   dval = var_getdval( &( argv[ 0 ] ));
  594. X
  595. X   if ( dval == 0.0 )
  596. X      {
  597. X      * var_findival( &nvar, nvar.array_pos ) = 0;
  598. X      }
  599. X   else if ( dval > 0.0 )
  600. X      {
  601. X      * var_findival( &nvar, nvar.array_pos ) = 1;
  602. X      }
  603. X   else
  604. X      {
  605. X      * var_findival( &nvar, nvar.array_pos ) = -1;
  606. X      }
  607. X
  608. X   return &nvar;
  609. X   }
  610. X
  611. X/***************************************************************
  612. X
  613. X        FUNCTION:       fnc_int()
  614. X
  615. X        DESCRIPTION:    This C function implements the BASIC
  616. X                        predefined INT function, returning an
  617. X                        less than or equal to the argument.
  618. X
  619. X***************************************************************/
  620. X
  621. Xstruct bwb_variable *
  622. Xfnc_int( int argc, struct bwb_variable *argv  )
  623. X   {
  624. X   static struct bwb_variable nvar;
  625. X   static int init = FALSE;
  626. X
  627. X   /* initialize the variable if necessary */
  628. X
  629. X   if ( init == FALSE )
  630. X      {
  631. X      init = TRUE;
  632. X      var_make( &nvar, SINGLE );
  633. X      }
  634. X
  635. X   #if INTENSIVE_DEBUG
  636. X   sprintf( bwb_ebuf, "in fnc_int(): received f_arg <%f> ",
  637. X      var_getdval( &( argv[ 0 ] ) ) );
  638. X   bwb_debug( bwb_ebuf );
  639. X   #endif
  640. X
  641. X   #if PROG_ERRORS
  642. X   if ( argc < 1 )
  643. X      {
  644. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function INT().",
  645. X         argc );
  646. X      bwb_error( bwb_ebuf );
  647. X      return NULL;
  648. X      }
  649. X   else if ( argc > 1 )
  650. X      {
  651. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function INT().",
  652. X         argc );
  653. X      bwb_error( bwb_ebuf );
  654. X      return NULL;
  655. X      }
  656. X   #else
  657. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  658. X      {
  659. X      return NULL;
  660. X      }
  661. X   #endif
  662. X
  663. X   /* assign values */
  664. X
  665. X   * var_findfval( &nvar, nvar.array_pos ) 
  666. X      = (float) floor( var_getdval( &( argv[ 0 ] ) ) );
  667. X
  668. X   return &nvar;
  669. X   }
  670. X
  671. X/***************************************************************
  672. X
  673. X        FUNCTION:       fnc_mki()
  674. X
  675. X        DESCRIPTION:    This C function implements the BASIC
  676. X                        predefined MKI$() function.
  677. X
  678. X***************************************************************/
  679. X
  680. Xstruct bwb_variable *
  681. Xfnc_mki( int argc, struct bwb_variable *argv  )
  682. X   {
  683. X   register int i;
  684. X   static struct bwb_variable nvar;
  685. X   bstring *b;
  686. X   static char tbuf[ sizeof( int ) ];
  687. X   static int init = FALSE;
  688. X
  689. X   /* initialize the variable if necessary */
  690. X
  691. X   if ( init == FALSE )
  692. X      {
  693. X      init = TRUE;
  694. X      var_make( &nvar, STRING );
  695. X      }
  696. X
  697. X   #if PROG_ERRORS
  698. X   if ( argc < 1 )
  699. X      {
  700. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function MKI$().",
  701. X         argc );
  702. X      bwb_error( bwb_ebuf );
  703. X      return NULL;
  704. X      }
  705. X   else if ( argc > 1 )
  706. X      {
  707. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function MKI$().",
  708. X         argc );
  709. X      bwb_error( bwb_ebuf );
  710. X      return NULL;
  711. X      }
  712. X   #else
  713. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  714. X      {
  715. X      return NULL;
  716. X      }
  717. X   #endif
  718. X
  719. X   /* assign values */
  720. X
  721. X   an_integer.the_integer = var_getival( &( argv[ 0 ] ) );
  722. X
  723. X   for ( i = 0; i < sizeof( int ); ++i )
  724. X      {
  725. X      tbuf[ i ] = an_integer.the_chars[ i ];
  726. X      }
  727. X   b = var_getsval( &nvar );
  728. X   b->length = sizeof( int );
  729. X   b->buffer = tbuf;
  730. X   b->rab = FALSE;   
  731. X
  732. X   return &nvar;
  733. X   }
  734. X
  735. X/***************************************************************
  736. X
  737. X        FUNCTION:       fnc_mkd()
  738. X
  739. X        DESCRIPTION:    This C function implements the BASIC
  740. X                        predefined MKD$() function.
  741. X
  742. X***************************************************************/
  743. X
  744. Xstruct bwb_variable *
  745. Xfnc_mkd( int argc, struct bwb_variable *argv  )
  746. X   {
  747. X   register int i;
  748. X   static struct bwb_variable nvar;
  749. X   bstring *b;
  750. X   char tbuf[ sizeof ( double ) ];
  751. X   static int init = FALSE;
  752. X
  753. X   /* initialize the variable if necessary */
  754. X
  755. X   if ( init == FALSE )
  756. X      {
  757. X      init = TRUE;
  758. X      var_make( &nvar, STRING );
  759. X      }
  760. X
  761. X   #if PROG_ERRORS
  762. X   if ( argc < 1 )
  763. X      {
  764. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function MKD$().",
  765. X         argc );
  766. X      bwb_error( bwb_ebuf );
  767. X      return NULL;
  768. X      }
  769. X   else if ( argc > 1 )
  770. X      {
  771. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function MKD$().",
  772. X         argc );
  773. X      bwb_error( bwb_ebuf );
  774. X      return NULL;
  775. X      }
  776. X   #else
  777. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  778. X      {
  779. X      return NULL;
  780. X      }
  781. X   #endif
  782. X
  783. X   /* assign values */
  784. X
  785. X   a_double.the_double = var_getdval( &( argv[ 0 ] ) );
  786. X
  787. X   for ( i = 0; i < sizeof ( double ); ++i )
  788. X      {
  789. X      tbuf[ i ] = a_double.the_chars[ i ];
  790. X      tbuf[ i + 1 ] = '\0';
  791. X      }
  792. X   b = var_getsval( &nvar );
  793. X   b->length = sizeof( double );
  794. X   b->buffer = tbuf;
  795. X   b->rab = FALSE;
  796. X
  797. X   return &nvar;
  798. X   }
  799. X
  800. X/***************************************************************
  801. X
  802. X        FUNCTION:       fnc_mks()
  803. X
  804. X        DESCRIPTION:    This C function implements the BASIC
  805. X                        predefined MKS$() function.
  806. X
  807. X***************************************************************/
  808. X
  809. Xstruct bwb_variable *
  810. Xfnc_mks( int argc, struct bwb_variable *argv  )
  811. X   {
  812. X   register int i;
  813. X   static struct bwb_variable nvar;
  814. X   static unsigned char tbuf[ 5 ];
  815. X   bstring *b;
  816. X   static int init = FALSE;
  817. X
  818. X   /* initialize the variable if necessary */
  819. X
  820. X   if ( init == FALSE )
  821. X      {
  822. X      init = TRUE;
  823. X      var_make( &nvar, STRING );
  824. X      }
  825. X
  826. X   #if PROG_ERRORS
  827. X   if ( argc < 1 )
  828. X      {
  829. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function MKS$().",
  830. X         argc );
  831. X      bwb_error( bwb_ebuf );
  832. X      return NULL;
  833. X      }
  834. X   else if ( argc > 1 )
  835. X      {
  836. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function MKS$().",
  837. X         argc );
  838. X      bwb_error( bwb_ebuf );
  839. X      return NULL;
  840. X      }
  841. X   #else
  842. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  843. X      {
  844. X      return NULL;
  845. X      }
  846. X   #endif
  847. X
  848. X   /* assign values */
  849. X
  850. X   a_float.the_float = var_getfval( &( argv[ 0 ] ) );
  851. X
  852. X   for ( i = 0; i < sizeof( float ); ++i )
  853. X      {
  854. X      tbuf[ i ] = a_float.the_chars[ i ];
  855. X      }
  856. X   b = var_getsval( &nvar );
  857. X   b->length = sizeof( float );
  858. X   b->buffer = tbuf;
  859. X   b->rab = FALSE;
  860. X
  861. X   #if INTENSIVE_DEBUG
  862. X   sprintf( bwb_ebuf, "in fnc_mks(): string <%s> hex vals <%X><%X><%X><%X>",
  863. X      tbuf, tbuf[ 0 ], tbuf[ 1 ], tbuf[ 2 ], tbuf[ 3 ] );
  864. X   bwb_debug( bwb_ebuf );
  865. X   #endif
  866. X
  867. X   return &nvar;
  868. X   }
  869. X
  870. X/***************************************************************
  871. X
  872. X        FUNCTION:       fnc_cvi()
  873. X
  874. X        DESCRIPTION:    This C function implements the BASIC
  875. X                        predefined CVI() function.
  876. X
  877. X***************************************************************/
  878. X
  879. Xstruct bwb_variable *
  880. Xfnc_cvi( int argc, struct bwb_variable *argv  )
  881. X   {
  882. X   register int i;
  883. X   struct bwb_variable *v;
  884. X   bstring *b;
  885. X   static struct bwb_variable nvar;
  886. X   static int init = FALSE;
  887. X
  888. X   /* initialize the variable if necessary */
  889. X
  890. X   if ( init == FALSE )
  891. X      {
  892. X      init = TRUE;
  893. X      var_make( &nvar, INTEGER );
  894. X      }
  895. X
  896. X   #if PROG_ERRORS
  897. X   if ( argc < 1 )
  898. X      {
  899. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function CVI().",
  900. X         argc );
  901. X      bwb_error( bwb_ebuf );
  902. X      return NULL;
  903. X      }
  904. X   else if ( argc > 1 )
  905. X      {
  906. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function CVI().",
  907. X         argc );
  908. X      bwb_error( bwb_ebuf );
  909. X      return NULL;
  910. X      }
  911. X   #else
  912. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  913. X      {
  914. X      return NULL;
  915. X      }
  916. X   #endif
  917. X
  918. X   /* assign values */
  919. X
  920. X   v = &( argv[ 0 ] );
  921. X   b = var_findsval( v, v->array_pos );
  922. X
  923. X   for ( i = 0; i < sizeof( int ); ++i )
  924. X      {
  925. X      an_integer.the_chars[ i ] = b->buffer[ i ];
  926. X      }
  927. X
  928. X   * var_findival( &nvar, nvar.array_pos ) = an_integer.the_integer;
  929. X
  930. X   return &nvar;
  931. X   }
  932. X
  933. X/***************************************************************
  934. X
  935. X        FUNCTION:       fnc_cvd()
  936. X
  937. X        DESCRIPTION:    This C function implements the BASIC
  938. X                        predefined CVD() function.
  939. X
  940. X***************************************************************/
  941. X
  942. Xstruct bwb_variable *
  943. Xfnc_cvd( int argc, struct bwb_variable *argv  )
  944. X   {
  945. X   register int i;
  946. X   struct bwb_variable *v;
  947. X   bstring *b;
  948. X   static struct bwb_variable nvar;
  949. X   static int init = FALSE;
  950. X
  951. X   /* initialize the variable if necessary */
  952. X
  953. X   if ( init == FALSE )
  954. X      {
  955. X      init = TRUE;
  956. X      var_make( &nvar, DOUBLE );
  957. X      }
  958. X
  959. X   #if PROG_ERRORS
  960. X   if ( argc < 1 )
  961. X      {
  962. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function CVD().",
  963. X         argc );
  964. X      bwb_error( bwb_ebuf );
  965. X      return NULL;
  966. X      }
  967. X   else if ( argc > 1 )
  968. X      {
  969. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function CVD().",
  970. X         argc );
  971. X      bwb_error( bwb_ebuf );
  972. X      return NULL;
  973. X      }
  974. X   #else
  975. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  976. X      {
  977. X      return NULL;
  978. X      }
  979. X   #endif
  980. X
  981. X   /* assign values */
  982. X
  983. X   v = &( argv[ 0 ] );
  984. X   b = var_findsval( v, v->array_pos );
  985. X
  986. X   for ( i = 0; i < sizeof( double ); ++i )
  987. X      {
  988. X      a_double.the_chars[ i ] = b->buffer[ i ];
  989. X      }
  990. X
  991. X   * var_finddval( &nvar, nvar.array_pos ) = a_double.the_double;
  992. X
  993. X   return &nvar;
  994. X
  995. X   }
  996. X
  997. X/***************************************************************
  998. X
  999. X        FUNCTION:       fnc_cvs()
  1000. X
  1001. X        DESCRIPTION:    This C function implements the BASIC
  1002. X                        predefined CVS() function.
  1003. X
  1004. X***************************************************************/
  1005. X
  1006. Xstruct bwb_variable *
  1007. Xfnc_cvs( int argc, struct bwb_variable *argv  )
  1008. X   {
  1009. X   register int i;
  1010. X   struct bwb_variable *v;
  1011. X   bstring *b;
  1012. X   static struct bwb_variable nvar;
  1013. X   static int init = FALSE;
  1014. X
  1015. X   /* initialize the variable if necessary */
  1016. X
  1017. X   if ( init == FALSE )
  1018. X      {
  1019. X      init = TRUE;
  1020. X      var_make( &nvar, SINGLE );
  1021. X      }
  1022. X
  1023. X   #if PROG_ERRORS
  1024. X   if ( argc < 1 )
  1025. X      {
  1026. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function CVS().",
  1027. X         argc );
  1028. X      bwb_error( bwb_ebuf );
  1029. X      return NULL;
  1030. X      }
  1031. X   else if ( argc > 1 )
  1032. X      {
  1033. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function CVS().",
  1034. X         argc );
  1035. X      bwb_error( bwb_ebuf );
  1036. X      return NULL;
  1037. X      }
  1038. X   #else
  1039. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  1040. X      {
  1041. X      return NULL;
  1042. X      }
  1043. X   #endif
  1044. X
  1045. X   /* assign values */
  1046. X
  1047. X   v = &( argv[ 0 ] );
  1048. X   b = var_findsval( v, v->array_pos );
  1049. X
  1050. X   for ( i = 0; i < sizeof( float ); ++i )
  1051. X      {
  1052. X      a_float.the_chars[ i ] = b->buffer[ i ];
  1053. X      }
  1054. X
  1055. X   #if INTENSIVE_DEBUG
  1056. X   sprintf( bwb_ebuf, "in fnc_cvs(): string <%s> hex vals <%X><%X><%X><%X>",
  1057. X      a_float.the_chars, a_float.the_chars[ 0 ], a_float.the_chars[ 1 ], 
  1058. X      a_float.the_chars[ 2 ], a_float.the_chars[ 3 ] );
  1059. X   bwb_debug( bwb_ebuf );
  1060. X   #endif
  1061. X
  1062. X   * var_findfval( &nvar, nvar.array_pos ) = a_float.the_float;
  1063. X
  1064. X   return &nvar;
  1065. X
  1066. X   }
  1067. X
  1068. X/***************************************************************
  1069. X
  1070. X        FUNCTION:       fnc_csng()
  1071. X
  1072. X        DESCRIPTION:    
  1073. X
  1074. X***************************************************************/
  1075. X
  1076. Xstruct bwb_variable *
  1077. Xfnc_csng( int argc, struct bwb_variable *argv )
  1078. X   {
  1079. X   static struct bwb_variable nvar;
  1080. X   static int init = FALSE;
  1081. X
  1082. X   /* initialize the variable if necessary */
  1083. X
  1084. X   if ( init == FALSE )
  1085. X      {
  1086. X      init = TRUE;
  1087. X      var_make( &nvar, SINGLE );
  1088. X      }
  1089. X
  1090. X   /* check parameters */
  1091. X
  1092. X   #if PROG_ERRORS
  1093. X   if ( argc < 1 )
  1094. X      {
  1095. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function CINT().",
  1096. X         argc );
  1097. X      bwb_error( bwb_ebuf );
  1098. X      return NULL;
  1099. X      }
  1100. X   else if ( argc > 1 )
  1101. X      {
  1102. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function CINT().",
  1103. X         argc );
  1104. X      bwb_error( bwb_ebuf );
  1105. X      return NULL;
  1106. X      }
  1107. X   #else
  1108. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  1109. X      {
  1110. X      return NULL;
  1111. X      }
  1112. X   #endif
  1113. X
  1114. X   /* get truncated integer value */
  1115. X
  1116. X   * var_findfval( &nvar, nvar.array_pos )
  1117. X      = (float) var_getfval( &( argv[ 0 ] ) );
  1118. X
  1119. X   return &nvar;
  1120. X   }
  1121. X
  1122. X/***************************************************************
  1123. X
  1124. X        FUNCTION:       fnc_exp()
  1125. X
  1126. X        DESCRIPTION:    
  1127. X
  1128. X***************************************************************/
  1129. X
  1130. Xstruct bwb_variable *
  1131. Xfnc_exp( int argc, struct bwb_variable *argv )
  1132. X   {
  1133. X   static struct bwb_variable nvar;
  1134. X   static int init = FALSE;
  1135. X
  1136. X   /* initialize the variable if necessary */
  1137. X
  1138. X   if ( init == FALSE )
  1139. X      {
  1140. X      init = TRUE;
  1141. X      var_make( &nvar, DOUBLE );
  1142. X      }
  1143. X
  1144. X   #if PROG_ERRORS
  1145. X   if ( argc < 1 )
  1146. X      {
  1147. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function EXP().",
  1148. X         argc );
  1149. X      bwb_error( bwb_ebuf );
  1150. X      return NULL;
  1151. X      }
  1152. X
  1153. X   else if ( argc > 1 )
  1154. X      {
  1155. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function EXP().",
  1156. X         argc );
  1157. X      bwb_error( bwb_ebuf );
  1158. X      return NULL;
  1159. X      }
  1160. X   #else
  1161. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  1162. X      {
  1163. X      return NULL;
  1164. X      }
  1165. X   #endif
  1166. X
  1167. X   /* assign values */
  1168. X
  1169. X   * var_finddval( &nvar, nvar.array_pos ) 
  1170. X      = exp( var_getdval( &( argv[ 0 ] ) ) );
  1171. X
  1172. X   return &nvar;
  1173. X   }
  1174. X
  1175. X/***************************************************************
  1176. X
  1177. X        FUNCTION:       fnc_cint()
  1178. X
  1179. X        DESCRIPTION:
  1180. X
  1181. X***************************************************************/
  1182. X
  1183. Xstruct bwb_variable *
  1184. Xfnc_cint( int argc, struct bwb_variable *argv )
  1185. X   {
  1186. X   static struct bwb_variable nvar;
  1187. X   static int init = FALSE;
  1188. X
  1189. X   /* initialize the variable if necessary */
  1190. X
  1191. X   if ( init == FALSE )
  1192. X      {
  1193. X      init = TRUE;
  1194. X      var_make( &nvar, SINGLE );
  1195. X      }
  1196. X
  1197. X   /* check parameters */
  1198. X
  1199. X   #if PROG_ERRORS
  1200. X   if ( argc < 1 )
  1201. X      {
  1202. X      sprintf( bwb_ebuf, "Not enough parameters (%d) to function CINT().",
  1203. X         argc );
  1204. X      bwb_error( bwb_ebuf );
  1205. X      return NULL;
  1206. X      }
  1207. X   else if ( argc > 1 )
  1208. X      {
  1209. X      sprintf( bwb_ebuf, "Too many parameters (%d) to function CINT().",
  1210. X         argc );
  1211. X      bwb_error( bwb_ebuf );
  1212. X      return NULL;
  1213. X      }
  1214. X   #else
  1215. X   if ( fnc_checkargs( argc, argv, 1, 1 ) == FALSE )
  1216. X      {
  1217. X      return NULL;
  1218. X      }
  1219. X   #endif
  1220. X
  1221. X   /* get truncated integer value */
  1222. X
  1223. X   * var_findfval( &nvar, nvar.array_pos )
  1224. X      = (float) trnc_int( (double) var_getfval( &( argv[ 0 ] )) );
  1225. X
  1226. X   return &nvar;
  1227. X   }
  1228. X
  1229. Xdouble
  1230. Xtrnc_int( double x )
  1231. X   {
  1232. X   double sign;
  1233. X
  1234. X   if ( x < 0.0 )
  1235. X      {
  1236. X      sign = -1.0;
  1237. X      }
  1238. X   else
  1239. X      {
  1240. X      sign = 1.0;
  1241. X      }
  1242. X
  1243. X   return ( floor( fabs( x )) * sign );
  1244. X   }
  1245. X
  1246. X
  1247. END_OF_FILE
  1248.   if test 27902 -ne `wc -c <'bwb_mth.c'`; then
  1249.     echo shar: \"'bwb_mth.c'\" unpacked with wrong size!
  1250.   fi
  1251.   # end of 'bwb_mth.c'
  1252. fi
  1253. if test -f 'bwbasic.h' -a "${1}" != "-c" ; then 
  1254.   echo shar: Will not clobber existing file \"'bwbasic.h'\"
  1255. else
  1256.   echo shar: Extracting \"'bwbasic.h'\" \(29508 characters\)
  1257.   sed "s/^X//" >'bwbasic.h' <<'END_OF_FILE'
  1258. X/***************************************************************
  1259. X
  1260. X        bwbasic.h       Header File
  1261. X                        for Bywater BASIC Interpreter
  1262. X
  1263. X                        Copyright (c) 1992, Ted A. Campbell
  1264. X
  1265. X                        Bywater Software
  1266. X                        P. O. Box 4023
  1267. X                        Duke Station
  1268. X                        Durham, NC  27706
  1269. X
  1270. X                        email: tcamp@acpub.duke.edu
  1271. X
  1272. X        Copyright and Permissions Information:
  1273. X
  1274. X        All U.S. and international copyrights are claimed by the
  1275. X        author. The author grants permission to use this code
  1276. X        and software based on it under the following conditions:
  1277. X        (a) in general, the code and software based upon it may be
  1278. X        used by individuals and by non-profit organizations; (b) it
  1279. X        may also be utilized by governmental agencies in any country,
  1280. X        with the exception of military agencies; (c) the code and/or
  1281. X        software based upon it may not be sold for a profit without
  1282. X        an explicit and specific permission from the author, except
  1283. X        that a minimal fee may be charged for media on which it is
  1284. X        copied, and for copying and handling; (d) the code must be
  1285. X        distributed in the form in which it has been released by the
  1286. X        author; and (e) the code and software based upon it may not
  1287. X        be used for illegal activities.
  1288. X
  1289. X***************************************************************/
  1290. X
  1291. X
  1292. X#ifndef TRUE
  1293. X#define TRUE    -1
  1294. X#define FALSE   0
  1295. X#endif
  1296. X
  1297. X/* Version number */
  1298. X
  1299. X#define VERSION         "1.10"          /* Current version number */
  1300. X
  1301. X/* Definitions controlling program features */
  1302. X
  1303. X#define DIRECTORY_CMDS    TRUE         /* implement CHDIR, MKDIR, and RMDIR */
  1304. X                    /* requires chdir() mkdir() rmdir() */
  1305. X#define COMMAND_SHELL   TRUE        /* allow command shell processing */
  1306. X
  1307. X/* definitions controlling debugging options */
  1308. X
  1309. X#define DEBUG           FALSE         /* current debugging */
  1310. X#define PROG_ERRORS     FALSE        /* identify serious programming errors */
  1311. X                    /* and print extensive error messages */
  1312. X                    /* This will override messages defined in */
  1313. X                    /* bwb_mes.h, and almost all messages will be in English */
  1314. X#define CHECK_RECURSION FALSE        /* check for recursion violation in expression parser */
  1315. X#define INTENSIVE_DEBUG FALSE           /* old debugging; might be useful later */
  1316. X#define REDIRECT_STDERR FALSE           /* Redirect stderr to file ERRFILE */
  1317. X#define TEST_BSTRING    FALSE        /* test bstring integrity */
  1318. X#define ERRFILE         "err.out"       /* Filename for redirected error messages */
  1319. X
  1320. X/* define number of commands */
  1321. X
  1322. X#define CMDS_BASE       55              /* number of base commands defined */
  1323. X#if DIRECTORY_CMDS
  1324. X#define CMDS_DIR    3
  1325. X#else
  1326. X#define CMDS_DIR    0
  1327. X#endif
  1328. X#if DEBUG
  1329. X#define CMDS_DEBUG      3               /* number of debugging cmds */
  1330. X#else
  1331. X#define CMDS_DEBUG      0               /* no debugging cmds */
  1332. X#endif
  1333. X#define COMMANDS        (CMDS_BASE+CMDS_DEBUG+CMDS_DIR)    /* total number of cmds */
  1334. X
  1335. X#define FUNCS_BASE      43              /* number of basic functions */
  1336. X#ifdef DEBUG
  1337. X#define FUNCS_DEBUG    1        /* number of debugging functions */
  1338. X#else
  1339. X#define FUNCS_DEBUG    0        /* number of debugging functions */
  1340. X#endif
  1341. X#define FUNCTIONS    (FUNCS_BASE+FUNCS_DEBUG)    /* total number of functions implemented */
  1342. X
  1343. X#define MAXARGSIZE      128             /* maximum size of argument */
  1344. X#define MAXREADLINESIZE 256             /* size of read_line buffer */
  1345. X#define MAXCMDNAMESIZE  64              /* maximum size for command name */
  1346. X#define MAXLINENO       32767           /* maximum line number */
  1347. X#define MAXVARNAMESIZE  40              /* maximum size for variable name */
  1348. X#define MAXFILENAMESIZE 40              /* maximum size for file name */
  1349. X#define MAXSTRINGSIZE   255             /* maximum string length */
  1350. X#define GOSUBLEVELS     36              /* GOSUB stack levels */
  1351. X#define WHILELEVELS     36              /* WHILE stack levels */
  1352. X#define FORLEVELS       36              /* FOR stack levels */
  1353. X#define MAX_GOLINES     12              /* Maximum # of lines for ON...GOTO statements */
  1354. X#define MAX_FARGS       4               /* maximum # arguments to function */
  1355. X#define MAX_DIMS    64        /* maximum # of dimensions */
  1356. X#define ESTACKSIZE      64              /* elements in expression stack */
  1357. X#define UFNCSTACKSIZE   64              /* elements in user-defined function stack */
  1358. X#define XLSTACKSIZE     16              /* elements in xline stack */
  1359. X#define XTXTSTACKSIZE   16              /* elements in eXecute TeXT stack */
  1360. X#define N_OPERATORS     24              /* number of operators defined */
  1361. X#define N_ERRORS    23        /* number of errors defined */
  1362. X#define MAX_PRECEDENCE  19              /* highest (last) level of precedence */
  1363. X#define MININTSIZE      -32767          /* minimum integer size */
  1364. X#define MAXINTSIZE       32767          /* maximum integer size */
  1365. X#define DEF_SUBSCRIPT   11              /* default subscript */
  1366. X#define DEF_DEVICES     16              /* default number of devices available */
  1367. X#define DEF_WIDTH    128        /* default width for devices */
  1368. X#define PRN_TAB        0x02        /* send TAB followed by col number to output device */
  1369. X
  1370. X#if DEBUG
  1371. X#define PERMANENT_DEBUG TRUE
  1372. X#else
  1373. X#define PERMANENT_DEBUG FALSE
  1374. X#endif
  1375. X
  1376. X/* define variable types based on first character */
  1377. X
  1378. X#define INTEGER         '%'
  1379. X#define DOUBLE          '#'
  1380. X#define SINGLE          '!'
  1381. X#define STRING          '$'
  1382. X
  1383. X/* define mathematical operations */
  1384. X
  1385. X#define MULTIPLY        '*'
  1386. X#define DIVIDE          '/'
  1387. X#define ADD             '+'
  1388. X#define SUBTRACT        '-'
  1389. X#define ARGUMENT        'A'
  1390. X
  1391. X/* absence of one of these marks denotes a single-precision
  1392. X   (i.e., float) variable */
  1393. X
  1394. X/* Operations defined */
  1395. X
  1396. X#define OP_ERROR        -255        /* operation error (break out) */
  1397. X#define OP_NULL         0               /* null: operation not defined yet */
  1398. X#define NUMBER          1               /* number held as internal variable in uvar */
  1399. X#define CONST_STRING    2               /* string constant */
  1400. X#define CONST_NUMERICAL 3               /* numerical constant */
  1401. X#define FUNCTION        4               /* function header */
  1402. X#define VARIABLE        5               /* external variable pointed to by xvar */
  1403. X#define PARENTHESIS     6               /* begin parenthetical expression */
  1404. X#define OP_ADD          7               /* addition sign '+' */
  1405. X#define OP_SUBTRACT     8               /* subtraction sign '-' */
  1406. X#define OP_MULTIPLY     9               /* multiplication sign '*' */
  1407. X#define OP_DIVIDE       10              /* division sign '/' */
  1408. X#define OP_MODULUS      11              /* modulus "MOD" */
  1409. X#define OP_EXPONENT     12              /* exponentiation '^' */
  1410. X#define OP_INTDIVISION  13              /* integer division sign '\' */
  1411. X#define OP_NEGATION     14              /* negation '-' ??? */
  1412. X#define OP_STRJOIN      15              /* string join ';' */
  1413. X#define OP_STRTAB       16              /* string tab ',' */
  1414. X#define OP_EQUALS       17              /* either logical equal operator */
  1415. X#define OP_ASSIGN       18              /* assignment operator */
  1416. X#define OP_NOTEQUAL     20              /* inequality */
  1417. X#define OP_LESSTHAN     21              /* less than */
  1418. X#define OP_GREATERTHAN  22              /* greater than */
  1419. X#define OP_LTEQ         23              /* less than or equal to */
  1420. X#define OP_GTEQ         24              /* greater than or equal to */
  1421. X#define OP_NOT          25              /* negation */
  1422. X#define OP_AND          26              /* conjunction */
  1423. X#define OP_OR           27              /* disjunction */
  1424. X#define OP_XOR          28              /* exclusive or */
  1425. X#define OP_IMPLIES      29              /* implication */
  1426. X#define OP_EQUIV        30              /* equivalence */
  1427. X#define OP_TERMINATE    31              /* terminate expression parsing */
  1428. X
  1429. X/* Device input/output modes */
  1430. X
  1431. X#define DEVMODE_AVAILABLE  -1
  1432. X#define DEVMODE_CLOSED     0
  1433. X#define DEVMODE_OUTPUT     1
  1434. X#define DEVMODE_INPUT      2
  1435. X#define DEVMODE_APPEND     3
  1436. X#define DEVMODE_RANDOM     4
  1437. X
  1438. Xextern char bwb_progfile[ MAXARGSIZE ];
  1439. Xextern char *bwb_ebuf;
  1440. Xextern int bwb_trace;
  1441. Xextern int bwb_number;            /* current line number */
  1442. Xextern struct bwb_line *bwb_l;        /* current line pointer */
  1443. Xextern int exp_esc;            /* expression stack counter */
  1444. Xextern int dim_base;            /* set by OPTION BASE */
  1445. X
  1446. X/* Typdef structure for strings under Bywater BASIC */
  1447. X
  1448. Xstruct bstr
  1449. X   {
  1450. X   unsigned char length;        /* length of string */
  1451. X   char *buffer;            /* pointer to string buffer */
  1452. X   int rab;                /* is it a random-access buffer? */
  1453. X   #if TEST_BSTRING
  1454. X   char name[ MAXVARNAMESIZE + 1 ];    /* name for test purposes */
  1455. X   #endif
  1456. X   };
  1457. X
  1458. Xtypedef struct bstr bstring;
  1459. X
  1460. X/* Structure used for all variables under Bywater BASIC */
  1461. X
  1462. Xstruct bwb_variable
  1463. X   {
  1464. X   char name[ MAXVARNAMESIZE + 1 ];    /* name */
  1465. X   int type;                            /* type, i.e., STRING, DOUBLE,
  1466. X                                           SINGLE, or INTEGER */
  1467. X   char *array;                /* pointer to array memory */
  1468. X   size_t array_units;            /* total number of units of memory */
  1469. X   int  *array_sizes;            /* pointer to array of <dimensions>
  1470. X                                           integers, with sizes of each
  1471. X                                           dimension */
  1472. X   int *array_pos;                      /* current position in array */
  1473. X   int dimensions;                      /* number of dimensions,
  1474. X                                           0 = not an array */
  1475. X   struct bwb_variable *next;           /* next variable in chain */
  1476. X   int common;                /* should this variable be common to chained programs? */
  1477. X   };
  1478. X
  1479. Xextern struct bwb_variable var_start, var_end;
  1480. X
  1481. X/* Structure to represent program lines under Bywater BASIC */
  1482. X
  1483. Xstruct bwb_line
  1484. X   {
  1485. X   struct bwb_line *next;               /* pointer to next line in chain */
  1486. X   int number;                          /* line number */
  1487. X   char *buffer;            /* buffer to hold the line */
  1488. X   int position;                        /* current position in line */
  1489. X   int lnpos;                           /* line number position in buffer */
  1490. X   int lnum;                            /* line number read from buffer */
  1491. X   int cmdpos;                          /* command position in buffer */
  1492. X   int cmdnum;                          /* number of command in command table
  1493. X                                           read from buffer */
  1494. X   int startpos;                        /* start of rest of line read from buffer */
  1495. X   int marked;                          /* has line been checked yet? */
  1496. X   };
  1497. X
  1498. Xextern struct bwb_line bwb_start, bwb_end;
  1499. Xextern struct bwb_line *data_line;      /* current line to read data */
  1500. X
  1501. X/* Structure defining user-defined function in Bywater BASIC:
  1502. X   note that this structure is appended to an existing bwb_function
  1503. X   structure (see below) and cannot be used apart from its host
  1504. X   bwb_function structure. */
  1505. X
  1506. Xstruct user_fnc
  1507. X   {
  1508. X   char user_vns[ MAX_FARGS ][ MAXVARNAMESIZE + 1 ]; /* array of variable names: user_vns[ 0 ] is argv[ 0 ], etc. */
  1509. X   struct bwb_line *line;        /* line on which the function definition occurs */
  1510. X   char int_line[ MAXSTRINGSIZE + 1 ];    /* line to be interpreted */
  1511. X   };
  1512. X
  1513. X/* Structure used for all functions under Bywater BASIC.  Note that
  1514. X   user-defined functions should have an attached user_fnc structure
  1515. X   pointed to by the ufnc field; if ufnc is set to NULL, then the
  1516. X   function is predefined. */
  1517. X
  1518. Xstruct bwb_function
  1519. X   {
  1520. X   char name[ MAXVARNAMESIZE + 1 ];     /* name */
  1521. X   int type;                            /* type, i.e., STRING, DOUBLE,
  1522. X                                           SINGLE, or INTEGER */
  1523. X   int arguments;                       /* number of args passed */
  1524. X   struct user_fnc *ufnc;               /* pointer to structure for a user-defined function (or NULL) */
  1525. X   struct bwb_variable * (*vector) ( int argc, struct bwb_variable *argv );  /* vector to function to call */
  1526. X   struct bwb_function *next;           /* next function in chain */
  1527. X   };
  1528. X
  1529. Xextern struct bwb_function fnc_start, fnc_end;
  1530. Xextern struct bwb_function * fnc_find();
  1531. X
  1532. Xextern int data_pos;                    /* position in data_line */
  1533. X
  1534. X/* Structure to represent all command statements under Bywater BASIC */
  1535. X
  1536. Xstruct bwb_command
  1537. X   {
  1538. X   char name[ MAXCMDNAMESIZE + 1 ];
  1539. X   struct bwb_line * (*vector) (struct bwb_line *);
  1540. X   int arg_offset;
  1541. X   };
  1542. X
  1543. Xextern struct bwb_command bwb_cmdtable[ COMMANDS ];
  1544. X
  1545. X/* Structure to define device stack for Bywater BASIC */
  1546. X
  1547. Xstruct dev_element
  1548. X   {
  1549. X   int mode;                            /* DEVMODE_ item */
  1550. X   int width;                /* width for output control */
  1551. X   int col;                /* current column */
  1552. X   int reclen;                          /* record length for random access */
  1553. X   int next_record;            /* next record to read/write */
  1554. X   int loc;                /* location in file */
  1555. X   char filename[ MAXFILENAMESIZE + 1 ];/* filename */
  1556. X   FILE *cfp;                           /* C file pointer for this device */
  1557. X   char *buffer;            /* pointer to character buffer for random access */
  1558. X   };
  1559. X
  1560. Xextern struct dev_element *dev_table;          /* table of devices */
  1561. X
  1562. X/* Structure to define expression stack elements under Bywater BASIC */
  1563. X
  1564. Xstruct exp_ese
  1565. X   {
  1566. X   int operation;                       /* operation at this level */
  1567. X   char type;                /* type of operation at this level:
  1568. X                          STRING, INTEGER, SINGLE, or DOUBLE */
  1569. X   bstring sval;            /* string */
  1570. X   int ival;                /* integer value */
  1571. X   float fval;                /* float value */
  1572. X   double dval;                /* double value */
  1573. X   char string[ MAXSTRINGSIZE + 1 ];     /* string for writing */
  1574. X   struct bwb_variable *xvar;           /* pointer to external variable */
  1575. X   struct bwb_function *function;       /* pointer to function structure */
  1576. X   int array_pos[ MAX_DIMS ];        /* array for variable positions */
  1577. X   int pos_adv;                         /* position advanced in string */
  1578. X   int rec_pos;                         /* position marker for recursive calls */
  1579. X   };
  1580. X
  1581. X/* Structure to define user-defined function stack elements */
  1582. X
  1583. Xstruct ufsel                            /* user function stack element */
  1584. X   {
  1585. X   char args[ MAX_FARGS ][ MAXARGSIZE + 1 ];
  1586. X   char l_buffer[ MAXSTRINGSIZE + 1 ];
  1587. X   int position;
  1588. X   };
  1589. X
  1590. X/* Structure to define FOR-NEXT stack elements */
  1591. X
  1592. Xstruct fse                                           /* FOR stack element */
  1593. X   {
  1594. X   struct bwb_line     *nextline;                       /* next line after FOR */
  1595. X   struct bwb_variable *variable;                       /* variable to be incremented */
  1596. X   int                 target;                          /* target value */
  1597. X   int                 step;                            /* step increment */
  1598. X   int                 position;                        /* position for reset */
  1599. X   };
  1600. X
  1601. X/* Structure to define GOSUB-RETURN stack elements */
  1602. X
  1603. Xstruct gsse                                           /* GOSUB stack element */
  1604. X   {
  1605. X   int                 position;                        /* position marker */
  1606. X   };
  1607. X
  1608. Xextern FILE *errfdevice;                /* output device for error messages */
  1609. X
  1610. Xextern struct exp_ese *exp_es;      /* expression stack */
  1611. Xextern struct ufsel *ufs;                  /* user function stack */
  1612. Xextern struct fse *fs;                  /* FOR stack */
  1613. Xextern struct gsse *bwb_gss;            /* GOSUB stack */
  1614. X
  1615. Xextern int bwb_gssc;                    /* GOSUB stack counter */
  1616. Xextern int ufsc;                        /* user function stack counter */
  1617. Xextern int ws_counter;                  /* WHILE stack counter */
  1618. Xextern int fs_counter;                  /* FOR stack counter */
  1619. Xextern int err_line;            /* line in which error occurred */
  1620. Xextern int err_number;            /* number of last error */
  1621. Xextern int err_gosubn;            /* number for error GOSUB */
  1622. Xextern char *err_table[ N_ERRORS ];    /* table of error messages */
  1623. X
  1624. X/* Operator Table */
  1625. X
  1626. Xstatic struct
  1627. X   {
  1628. X   char symbol[ 8 ];                    /* BASIC symbol for the operator */
  1629. X   int operation;                       /* internal code for the operator */
  1630. X   int precedence;                      /* level of precedence, 0 = highest */
  1631. X   } exp_ops[ N_OPERATORS ] =
  1632. X   {
  1633. X   { "NOT",     OP_NOT,         12 },   /* multiple-character operators */
  1634. X   { "AND",     OP_AND,         13 },   /* should be tested first because */
  1635. X   { "OR",      OP_OR,          14 },   /* e.g. a ">=" would be matched */
  1636. X   { "XOR",     OP_XOR,         15 },   /* as "=" if the single-character */
  1637. X   { "IMP",     OP_IMPLIES,     16 },   /* operator came first */
  1638. X   { "EQV",     OP_EQUIV,       17 },
  1639. X   { "MOD",     OP_MODULUS,     4  },
  1640. X   { "<>",      OP_NOTEQUAL,    7  },
  1641. X   { "<=",      OP_LTEQ,        10 },
  1642. X   { "=<",      OP_LTEQ,        10 },   /* allow either form */
  1643. X   { ">=",      OP_GTEQ,        11 },
  1644. X   { "=>",      OP_GTEQ,        11 },   /* allow either form */
  1645. X   { "<",       OP_LESSTHAN,    8  },
  1646. X   { ">",       OP_GREATERTHAN, 9  },
  1647. X   { "^",       OP_EXPONENT,    0  },
  1648. X   { "*",       OP_MULTIPLY,    2  },
  1649. X   { "/",       OP_DIVIDE,      2  },
  1650. X   { "\\",      OP_INTDIVISION, 3  },
  1651. X   { "+",       OP_ADD,         5  },
  1652. X   { "-",       OP_SUBTRACT,    5  },
  1653. X   { "=",       OP_EQUALS,      6  },
  1654. X   { "=",       OP_ASSIGN,      6  },   /* don't worry: OP_EQUALS will be converted to OP_ASSIGN if necessary */
  1655. X   { ";",       OP_STRJOIN,     18 },
  1656. X   { ",",       OP_STRTAB,      19 }
  1657. X   };
  1658. X
  1659. X/* Prototypes for publicly available functions and data */
  1660. X
  1661. Xextern int bwb_fload( FILE *file );
  1662. Xextern int bwb_ladd( char *buffer, int replace );
  1663. Xextern int bwb_findcmd( int argc, int a, struct bwb_line *l );
  1664. Xextern struct bwb_line *bwb_xtxtline( char *buffer );
  1665. Xextern struct bwb_line *bwb_xline( struct bwb_line *l );
  1666. Xextern int bwb_gets( char *buffer );
  1667. Xextern int bwb_error( char *message );
  1668. Xextern void break_handler( void );
  1669. Xextern void break_mes( int x );
  1670. Xextern struct bwb_line *bwb_null( struct bwb_line *l );
  1671. Xextern struct bwb_line *bwb_rem( struct bwb_line *l );
  1672. Xextern struct bwb_line *bwb_lerror( struct bwb_line *l );
  1673. Xextern struct bwb_line *bwb_run( struct bwb_line *l );
  1674. Xextern struct bwb_line *bwb_let( struct bwb_line *l );
  1675. Xextern struct bwb_line *bwb_load( struct bwb_line *l );
  1676. Xextern struct bwb_line *bwb_merge( struct bwb_line *l );
  1677. Xextern struct bwb_line *bwb_chain( struct bwb_line *l );
  1678. Xextern struct bwb_line *bwb_common( struct bwb_line *l );
  1679. Xextern struct bwb_line *bwb_xload( struct bwb_line *l );
  1680. Xextern struct bwb_line *bwb_new( struct bwb_line *l );
  1681. Xextern struct bwb_line *bwb_save( struct bwb_line *l );
  1682. Xextern struct bwb_line *bwb_list( struct bwb_line *l );
  1683. Xextern struct bwb_line *bwb_xlist( struct bwb_line *l, FILE *file );
  1684. Xextern struct bwb_line *bwb_goto( struct bwb_line *l );
  1685. Xextern struct bwb_line *bwb_gosub( struct bwb_line *l );
  1686. Xextern struct bwb_line *bwb_return( struct bwb_line *l );
  1687. Xextern struct bwb_line *bwb_xend( struct bwb_line *l );
  1688. Xextern struct bwb_line *bwb_system( struct bwb_line *l );
  1689. Xextern struct bwb_line *bwb_tron( struct bwb_line *l );
  1690. Xextern struct bwb_line *bwb_troff( struct bwb_line *l );
  1691. Xextern struct bwb_line *bwb_randomize( struct bwb_line *l );
  1692. Xextern struct bwb_line *bwb_stop( struct bwb_line *l );
  1693. Xextern struct bwb_line *bwb_data( struct bwb_line *l );
  1694. Xextern struct bwb_line *bwb_read( struct bwb_line *l );
  1695. Xextern struct bwb_line *bwb_restore( struct bwb_line *l );
  1696. Xextern struct bwb_line *bwb_delete( struct bwb_line *l );
  1697. Xextern struct bwb_line *bwb_if( struct bwb_line *l );
  1698. Xextern struct bwb_line *bwb_while( struct bwb_line *l );
  1699. Xextern struct bwb_line *bwb_wend( struct bwb_line *l );
  1700. Xextern struct bwb_line *bwb_for( struct bwb_line *l );
  1701. Xextern struct bwb_line *bwb_next( struct bwb_line *l );
  1702. Xextern struct bwb_line *bwb_dim( struct bwb_line *l );
  1703. Xextern struct bwb_line *bwb_option( struct bwb_line *l );
  1704. Xextern struct bwb_line *bwb_open( struct bwb_line *l );
  1705. Xextern struct bwb_line *bwb_close( struct bwb_line *l );
  1706. Xextern struct bwb_line *bwb_get( struct bwb_line *l );
  1707. Xextern struct bwb_line *bwb_put( struct bwb_line *l );
  1708. Xextern struct bwb_line *bwb_rmdir( struct bwb_line *l );
  1709. Xextern struct bwb_line *bwb_chdir( struct bwb_line *l );
  1710. Xextern struct bwb_line *bwb_mkdir( struct bwb_line *l );
  1711. Xextern struct bwb_line *bwb_kill( struct bwb_line *l );
  1712. Xextern struct bwb_line *bwb_name( struct bwb_line *l );
  1713. Xextern struct bwb_line *bwb_rset( struct bwb_line *l );
  1714. Xextern struct bwb_line *bwb_lset( struct bwb_line *l );
  1715. Xextern struct bwb_line *bwb_field( struct bwb_line *l );
  1716. Xextern struct bwb_line *bwb_on( struct bwb_line *l );
  1717. Xextern struct bwb_line *bwb_line( struct bwb_line *l );
  1718. Xextern struct bwb_line *bwb_ddbl( struct bwb_line *l );
  1719. Xextern struct bwb_line *bwb_dint( struct bwb_line *l );
  1720. Xextern struct bwb_line *bwb_dsng( struct bwb_line *l );
  1721. Xextern struct bwb_line *bwb_dstr( struct bwb_line *l );
  1722. Xextern struct bwb_line *bwb_clear( struct bwb_line *l );
  1723. Xextern struct bwb_line *bwb_erase( struct bwb_line *l );
  1724. Xextern struct bwb_line *bwb_swap( struct bwb_line *l );
  1725. Xextern struct bwb_line *bwb_environ( struct bwb_line *l );
  1726. Xextern struct bwb_line *bwb_width( struct bwb_line *l );
  1727. Xextern struct bwb_line *bwb_write( struct bwb_line *l );
  1728. Xextern int bwb_getcnd( char *lb, char *lhs, char *rhs, char *op, int *n );
  1729. Xextern int bwb_getlhs( char *lb, char *lhs, int *n );
  1730. Xextern int bwb_getop( char *lb, char *op, int *n );
  1731. Xextern int bwb_getrhs( char *lb, char *rhs, int *n );
  1732. Xextern int bwb_evalcnd( char *lhs, char *rhs, char *op );
  1733. Xextern int bwb_isstr( char *b );
  1734. Xextern int eval_int( int l, int r, char *op );
  1735. Xextern int eval_sng( float l, float r, char *op );
  1736. Xextern int eval_dbl( double l, double r, char *op );
  1737. Xextern struct exp_ese *bwb_exp( char *expression, int assignment, int *position );
  1738. Xextern int exp_getvfname( char *source, char *destination );
  1739. Xextern int exp_operation( int entry_level );
  1740. Xextern int inc_esc( void );
  1741. Xextern int dec_esc( void );
  1742. Xextern int fnc_init( void );
  1743. Xextern struct bwb_function *fnc_find( char *buffer );
  1744. Xextern struct bwb_variable *fnc_intufnc( int argc, struct bwb_variable *argv,
  1745. X   struct bwb_function *f );
  1746. Xextern struct bwb_line *bwb_deffn( struct bwb_line *l );
  1747. Xextern int bwb_getargs( char *buffer );
  1748. Xextern int bwb_stripcr( char *s );
  1749. Xextern int bwb_numseq( char *buffer, int *start, int *end );
  1750. Xextern int bwb_freeline( struct bwb_line *l );
  1751. Xextern struct bwb_line *bwb_print( struct bwb_line *l );
  1752. Xextern int bwb_xprint( struct bwb_line *l, FILE *f );
  1753. Xextern int bwb_eltype( char *l_buffer, int p );
  1754. Xextern int var_init( void );
  1755. Xextern int var_delcvars( void );
  1756. Xextern int bwb_strel( char *lb, char *sb, int *n );
  1757. Xextern struct bwb_variable *bwb_numel( char *lb, int *n );
  1758. Xextern int bwb_const( char *lb, char *sb, int *n );
  1759. Xextern int bwb_getvarname( char *lb, char *sb, int *n );
  1760. Xextern struct bwb_variable *var_find( char *buffer );
  1761. Xextern int bwb_isvar( char *buffer );
  1762. Xextern struct bwb_line *bwb_input( struct bwb_line *l );
  1763. Xextern int inp_adv( char *b, int *c );
  1764. Xextern double var_getdval( struct bwb_variable *nvar );
  1765. Xextern float var_getfval( struct bwb_variable *nvar );
  1766. Xextern int var_getival( struct bwb_variable *nvar );
  1767. Xextern bstring *var_getsval( struct bwb_variable *nvar );
  1768. Xextern bstring *var_findsval( struct bwb_variable *v, int *pp );
  1769. Xextern int *var_findival( struct bwb_variable *v, int *pp );
  1770. Xextern float *var_findfval( struct bwb_variable *v, int *pp );
  1771. Xextern double *var_finddval( struct bwb_variable *v, int *pp );
  1772. Xextern int var_make( struct bwb_variable *v, int type );
  1773. Xextern int dim_getparams( char *buffer, int *pos, int *n_params, int **pp );
  1774. Xextern double exp_getdval( struct exp_ese *e );
  1775. Xextern float exp_getfval( struct exp_ese *e );
  1776. Xextern int exp_getival( struct exp_ese *e );
  1777. Xextern bstring * exp_getsval( struct exp_ese *e );
  1778. Xextern double * exp_finddval( struct exp_ese *e );
  1779. Xextern float * exp_findfval( struct exp_ese *e );
  1780. Xextern int * exp_findival( struct exp_ese *e );
  1781. Xextern int is_numconst( char *buffer );
  1782. Xextern int adv_element( char *buffer, int *pos, char *element );
  1783. Xextern int adv_ws( char *buffer, int *pos );
  1784. Xextern int line_start( char *buffer, int *pos, int *lnpos, int *lnum,
  1785. X   int *cmdpos, int *cmdnum, int *startpos );
  1786. Xextern int is_cmd( char *buffer, int *cmdnum );
  1787. Xextern int is_let( char *buffer, int *cmdnum );
  1788. Xextern int int_qmdstr( char *buffer_a, char *buffer_b );
  1789. Xextern struct bwb_line * cnd_xpline( struct bwb_line *l, char *buffer );
  1790. X
  1791. Xextern int prn_precision( struct bwb_variable *v );
  1792. Xextern int * prn_getcol( FILE *f );
  1793. Xextern int prn_getwidth( FILE *f );
  1794. Xextern int xprintf( FILE *f, char *buffer );
  1795. Xextern int bwb_strtoupper( char *buffer );
  1796. Xextern int getcmdnum( char *cmdstr );
  1797. X
  1798. Xextern struct bwb_variable * fnc_tab( int argc, struct bwb_variable *argv );
  1799. Xextern struct bwb_variable * fnc_spc( int argc, struct bwb_variable *argv );
  1800. Xextern struct bwb_variable * fnc_space( int argc, struct bwb_variable *argv );
  1801. Xextern struct bwb_variable * fnc_environ( int argc, struct bwb_variable *argv );
  1802. Xextern struct bwb_variable * fnc_pos( int argc, struct bwb_variable *argv );
  1803. Xextern struct bwb_variable * fnc_err( int argc, struct bwb_variable *argv );
  1804. Xextern struct bwb_variable * fnc_erl( int argc, struct bwb_variable *argv );
  1805. Xextern struct bwb_variable * fnc_loc( int argc, struct bwb_variable *argv );
  1806. Xextern struct bwb_variable * fnc_lof( int argc, struct bwb_variable *argv );
  1807. Xextern struct bwb_variable * fnc_eof( int argc, struct bwb_variable *argv );
  1808. Xextern struct bwb_variable * fnc_csng( int argc, struct bwb_variable *argv );
  1809. Xextern struct bwb_variable * fnc_exp( int argc, struct bwb_variable *argv );
  1810. Xextern struct bwb_variable * fnc_instr( int argc, struct bwb_variable *argv );
  1811. Xextern struct bwb_variable * fnc_str( int argc, struct bwb_variable *argv );
  1812. Xextern int str_btoc( char *buffer, bstring *s );
  1813. Xextern int str_btob( bstring *d, bstring *s );
  1814. Xextern int str_ctob( bstring *s, char *buffer );
  1815. Xextern int str_cmp( bstring *s, bstring *t );
  1816. Xextern char * str_cat( bstring *s, bstring *t );
  1817. Xextern int exp_findop( char *expression );
  1818. Xextern int exp_isop( char *expression );
  1819. Xextern int exp_isfn( char *expression );
  1820. Xextern int exp_isnc( char *expression );
  1821. Xextern int exp_isvn( char *expression );
  1822. Xextern int exp_iscmd( char *expression );
  1823. Xextern int exp_paren( char *expression );
  1824. Xextern int exp_strconst( char *expression );
  1825. Xextern int exp_numconst( char *expression );
  1826. Xextern int exp_function( char *expression );
  1827. Xextern int exp_variable( char *expression );
  1828. Xextern int exp_validarg( char *expression );
  1829. Xextern int ln_asbuf( struct bwb_line *l, char *s );
  1830. Xextern int xputc( FILE *f, char c );
  1831. X
  1832. X#if DEBUG
  1833. Xextern int bwb_debug( char *message );
  1834. Xextern struct bwb_line *bwb_cmds( struct bwb_line *l );
  1835. Xextern struct bwb_line *bwb_vars( struct bwb_line *l );
  1836. Xextern struct bwb_line *bwb_fncs( struct bwb_line *l );
  1837. X#endif
  1838. X
  1839. X#ifdef ALLOW_RENUM
  1840. Xextern struct bwb_line *bwb_renum( struct bwb_line *l );
  1841. X#endif
  1842. X
  1843. X#if DIRECTORY_CMDS
  1844. Xextern int rmdir( char *path );
  1845. Xextern int chdir( char *path );
  1846. Xextern int mkdir( char *path );
  1847. X#endif
  1848. X
  1849. X/* declarations of function commands */
  1850. X
  1851. Xextern struct bwb_variable *fnc_null( int argc, struct bwb_variable *argv );
  1852. Xextern struct bwb_variable *fnc_abs( int argc, struct bwb_variable *argv );
  1853. Xextern struct bwb_variable *fnc_date( int argc, struct bwb_variable *argv );
  1854. Xextern struct bwb_variable *fnc_time( int argc, struct bwb_variable *argv );
  1855. Xextern struct bwb_variable *fnc_atn( int argc, struct bwb_variable *argv );
  1856. Xextern struct bwb_variable *fnc_cos( int argc, struct bwb_variable *argv );
  1857. Xextern struct bwb_variable *fnc_log( int argc, struct bwb_variable *argv );
  1858. Xextern struct bwb_variable *fnc_sin( int argc, struct bwb_variable *argv );
  1859. Xextern struct bwb_variable *fnc_sqr( int argc, struct bwb_variable *argv );
  1860. Xextern struct bwb_variable *fnc_tan( int argc, struct bwb_variable *argv );
  1861. Xextern struct bwb_variable *fnc_sgn( int argc, struct bwb_variable *argv );
  1862. Xextern struct bwb_variable *fnc_int( int argc, struct bwb_variable *argv );
  1863. Xextern struct bwb_variable *fnc_rnd( int argc, struct bwb_variable *argv );
  1864. Xextern struct bwb_variable *fnc_chr( int argc, struct bwb_variable *argv );
  1865. Xextern struct bwb_variable *fnc_mid( int argc, struct bwb_variable *argv );
  1866. Xextern struct bwb_variable *fnc_left( int argc, struct bwb_variable *argv );
  1867. Xextern struct bwb_variable *fnc_right( int argc, struct bwb_variable *argv );
  1868. Xextern struct bwb_variable *fnc_timer( int argc, struct bwb_variable *argv );
  1869. Xextern struct bwb_variable *fnc_val( int argc, struct bwb_variable *argv );
  1870. Xextern struct bwb_variable *fnc_len( int argc, struct bwb_variable *argv );
  1871. Xextern struct bwb_variable *fnc_hex( int argc, struct bwb_variable *argv );
  1872. Xextern struct bwb_variable *fnc_oct( int argc, struct bwb_variable *argv );
  1873. Xextern struct bwb_variable *fnc_cint( int argc, struct bwb_variable *argv );
  1874. Xextern struct bwb_variable *fnc_asc( int argc, struct bwb_variable *argv );
  1875. Xextern struct bwb_variable *fnc_mkd( int argc, struct bwb_variable *argv );
  1876. Xextern struct bwb_variable *fnc_mki( int argc, struct bwb_variable *argv );
  1877. Xextern struct bwb_variable *fnc_mks( int argc, struct bwb_variable *argv );
  1878. Xextern struct bwb_variable *fnc_cvi( int argc, struct bwb_variable *argv );
  1879. Xextern struct bwb_variable *fnc_cvd( int argc, struct bwb_variable *argv );
  1880. Xextern struct bwb_variable *fnc_cvs( int argc, struct bwb_variable *argv );
  1881. Xextern struct bwb_variable *fnc_string( int argc, struct bwb_variable *argv );
  1882. Xextern double trnc_int( double x );
  1883. Xextern int fnc_checkargs( int argc, struct bwb_variable *argv,
  1884. X   int min, int max );
  1885. Xextern int ufsc;            /* user function stack counter */
  1886. X
  1887. X#if DEBUG
  1888. Xextern struct bwb_variable *fnc_test( int argc, struct bwb_variable *argv );
  1889. X#endif
  1890. X
  1891. X
  1892. X
  1893. END_OF_FILE
  1894.   if test 29508 -ne `wc -c <'bwbasic.h'`; then
  1895.     echo shar: \"'bwbasic.h'\" unpacked with wrong size!
  1896.   fi
  1897.   # end of 'bwbasic.h'
  1898. fi
  1899. echo shar: End of archive 10 \(of 11\).
  1900. cp /dev/null ark10isdone
  1901. MISSING=""
  1902. for I in 1 2 3 4 5 6 7 8 9 10 11 ; do
  1903.     if test ! -f ark${I}isdone ; then
  1904.     MISSING="${MISSING} ${I}"
  1905.     fi
  1906. done
  1907. if test "${MISSING}" = "" ; then
  1908.     echo You have unpacked all 11 archives.
  1909.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  1910. else
  1911.     echo You still must unpack the following archives:
  1912.     echo "        " ${MISSING}
  1913. fi
  1914. exit 0
  1915. exit 0 # Just in case...
  1916.