forked from nerun/bwbasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbwb_cnd.c
1937 lines (1624 loc) · 40.7 KB
/
bwb_cnd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************
bwb_cnd.c Conditional Expressions and Commands
for Bywater BASIC Interpreter
Copyright (c) 1993, Ted A. Campbell
Bywater Software
email: [email protected]
Copyright and Permissions Information:
All U.S. and international rights are claimed by the author,
Ted A. Campbell.
This software is released under the terms of the GNU General
Public License (GPL), which is distributed with this software
in the file "COPYING". The GPL specifies the terms under
which users may copy and use the software in this distribution.
A separate license is available for commercial distribution,
for information on which you should contact the author.
***************************************************************/
/*---------------------------------------------------------------*/
/* NOTE: Modifications marked "JBV" were made by Jon B. Volkoff, */
/* 11/1995 ([email protected]). */
/* */
/* Those additionally marked with "DD" were at the suggestion of */
/* Dale DePriest ([email protected]). */
/* */
/* Version 3.00 by Howard Wulf, AF5NE */
/* */
/* Version 3.10 by Howard Wulf, AF5NE */
/* */
/* Version 3.20 by Howard Wulf, AF5NE */
/* */
/*---------------------------------------------------------------*/
#include "bwbasic.h"
static LineType *bwb_then_else (LineType * l, int Value);
static LineType *bwb_if_file (LineType * l, int ThenValue);
static int FindTopLineOnStack (LineType * l);
static int for_limit_check (DoubleType Value, DoubleType Target,
DoubleType Step);
static int IsTypeMismatch (char LeftTypeCode, char RightTypeCode);
/*
--------------------------------------------------------------------------------------------
EXIT
--------------------------------------------------------------------------------------------
*/
LineType *
bwb_EXIT (LineType * l)
{
assert (l != NULL);
WARN_SYNTAX_ERROR;
return (l);
}
/*
--------------------------------------------------------------------------------------------
SELECT
--------------------------------------------------------------------------------------------
*/
LineType *
bwb_SELECT (LineType * l)
{
assert (l != NULL);
WARN_SYNTAX_ERROR;
return (l);
}
/*
--------------------------------------------------------------------------------------------
FUNCTION - END FUNCTION
--------------------------------------------------------------------------------------------
*/
/***************************************************************
FUNCTION: bwb_FUNCTION()
DESCRIPTION: This function implements the BASIC
FUNCTION command, introducing a named
function.
SYNTAX: FUNCTION subroutine-name
...
[ EXIT FUNCTION ]
...
END FUNCTION
***************************************************************/
LineType *
bwb_FUNCTION (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
/* check current exec level */
assert(My != NULL);
assert(My->StackHead != NULL);
if (My->StackHead->next == NULL)
{
/* skip over the entire function definition */
l = l->OtherLine; /* line of END SUB */
l = l->next; /* line after END SUB */
l->position = 0;
return l;
}
/* we are being executed via IntrinsicFunction_deffn() */
/* if this is the first time at this SUB statement, note it */
if (My->StackHead->LoopTopLine != l)
{
if (bwb_incexec ())
{
/* OK */
My->StackHead->LoopTopLine = l;
}
else
{
/* ERROR */
WARN_OUT_OF_MEMORY;
return My->EndMarker;
}
}
line_skip_eol (l);
return (l);
}
LineType *
bwb_EXIT_FUNCTION (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
/* check integrity of SUB commmand */
if (FindTopLineOnStack (l->OtherLine))
{
/* FOUND */
LineType *r;
bwb_decexec ();
r = l->OtherLine; /* line of FUNCTION */
r = r->OtherLine; /* line of END FUNCTION */
r = r->next; /* line after END FUNCTION */
r->position = 0;
return r;
}
/* NOT FOUND */
WARN_EXIT_FUNCTION_WITHOUT_FUNCTION;
return (l);
}
LineType *
bwb_END_FUNCTION (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
/* check integrity of SUB commmand */
if (FindTopLineOnStack (l->OtherLine) == FALSE)
{
/* NOT FOUND */
WARN_END_FUNCTION_WITHOUT_FUNCTION;
return (l);
}
/* decrement the stack */
bwb_decexec ();
/* and return next from old line */
assert(My != NULL);
assert(My->StackHead != NULL);
My->StackHead->line->next->position = 0;
return My->StackHead->line->next;
}
LineType *
bwb_FNEND (LineType * l)
{
assert (l != NULL);
return bwb_END_FUNCTION (l);
}
LineType *
bwb_FEND (LineType * l)
{
assert (l != NULL);
return bwb_END_FUNCTION (l);
}
/*
--------------------------------------------------------------------------------------------
SUB - END SUB
--------------------------------------------------------------------------------------------
*/
/***************************************************************
FUNCTION: bwb_sub()
DESCRIPTION: This function implements the BASIC
SUB command, introducing a named
subroutine.
SYNTAX: SUB subroutine-name
...
[ EXIT SUB ]
...
END SUB
***************************************************************/
LineType *
bwb_SUB (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
/* check current exec level */
assert(My != NULL);
assert(My->StackHead != NULL);
if (My->StackHead->next == NULL)
{
/* skip over the entire function definition */
l = l->OtherLine; /* line of END SUB */
l = l->next; /* line after END SUB */
l->position = 0;
return l;
}
/* we are being executed via IntrinsicFunction_deffn() */
/* if this is the first time at this SUB statement, note it */
if (My->StackHead->LoopTopLine != l)
{
if (bwb_incexec ())
{
/* OK */
My->StackHead->LoopTopLine = l;
}
else
{
/* ERROR */
WARN_OUT_OF_MEMORY;
return My->EndMarker;
}
}
line_skip_eol (l);
return (l);
}
LineType *
bwb_EXIT_SUB (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
/* check integrity of SUB commmand */
if (FindTopLineOnStack (l->OtherLine))
{
/* FOUND */
LineType *r;
bwb_decexec ();
r = l->OtherLine; /* line of FUNCTION */
r = r->OtherLine; /* line of END FUNCTION */
r = r->next; /* line after END FUNCTION */
r->position = 0;
return r;
}
/* NOT FOUND */
WARN_EXIT_SUB_WITHOUT_SUB;
return (l);
}
LineType *
bwb_SUBEXIT (LineType * l)
{
assert (l != NULL);
return bwb_EXIT_SUB (l);
}
LineType *
bwb_SUB_EXIT (LineType * l)
{
assert (l != NULL);
return bwb_EXIT_SUB (l);
}
LineType *
bwb_END_SUB (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
/* check integrity of SUB commmand */
if (FindTopLineOnStack (l->OtherLine) == FALSE)
{
/* NOT FOUND */
WARN_END_SUB_WITHOUT_SUB;
return (l);
}
/* decrement the stack */
bwb_decexec ();
/* and return next from old line */
assert(My != NULL);
assert(My->StackHead != NULL);
My->StackHead->line->next->position = 0;
return My->StackHead->line->next;
}
LineType *
bwb_SUBEND (LineType * l)
{
assert (l != NULL);
return bwb_END_SUB (l);
}
LineType *
bwb_SUB_END (LineType * l)
{
assert (l != NULL);
return bwb_END_SUB (l);
}
/*
--------------------------------------------------------------------------------------------
IF - END IF
--------------------------------------------------------------------------------------------
*/
/***************************************************************
FUNCTION: bwb_IF()
DESCRIPTION: This function handles the BASIC IF
statement, standard flavor.
standard
SYNTAX: IF expression THEN line [ELSE line]
IF END # file THEN line [ELSE line]
IF MORE # file THEN line [ELSE line]
***************************************************************/
LineType *
bwb_IF (LineType * l)
{
/* classic IF */
/* IF expression THEN 100 */
/* IF expression THEN 100 ELSE 200 */
int Value;
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
if (line_read_integer_expression (l, &Value) == FALSE)
{
WARN_SYNTAX_ERROR;
return (l);
}
return bwb_then_else (l, Value);
}
LineType *
bwb_IF_END (LineType * l)
{
/* IF END #1 THEN 100 */
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
assert(My != NULL);
assert(My->CurrentVersion != NULL);
if (My->CurrentVersion->OptionVersionValue & (C77))
{
/* sets a linenumber to branch to on EOF */
int FileNumber = 0;
int LineNumber = 0;
if (line_read_integer_expression (l, &FileNumber) == FALSE)
{
WARN_BAD_FILE_NUMBER;
return (l);
}
if (FileNumber <= 0)
{
WARN_BAD_FILE_NUMBER;
return (l);
}
if (line_skip_word (l, "THEN") == FALSE)
{
WARN_SYNTAX_ERROR;
return (l);
}
if (line_read_integer_expression (l, &LineNumber) == FALSE)
{
WARN_UNDEFINED_LINE;
return (l);
}
if (LineNumber < 0)
{
WARN_UNDEFINED_LINE;
return (l);
}
/* now, we are ready to create the file */
My->CurrentFile = find_file_by_number (FileNumber);
if (My->CurrentFile == NULL)
{
My->CurrentFile = file_new ();
My->CurrentFile->FileNumber = FileNumber;
}
My->CurrentFile->EOF_LineNumber = LineNumber;
return (l);
}
/* branch to the line if we are currently at EOF */
return bwb_if_file (l, TRUE);
}
LineType *
bwb_IF_MORE (LineType * l)
{
/* IF MORE #1 THEN 100 */
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
/* branch to the line if we are not currently at EOF */
return bwb_if_file (l, FALSE);
}
/***************************************************************
FUNCTION: bwb_IF8THEN()
DESCRIPTION: This function handles the BASIC IF
statement, structured flavor.
SYNTAX: IF expression THEN
...
ELSEIF expression
...
ELSE
...
END IF
***************************************************************/
LineType *
bwb_IF8THEN (LineType * l)
{
/* structured IF */
LineType *else_line;
int Value;
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
/* evaluate the expression */
if (line_read_integer_expression (l, &Value) == FALSE)
{
WARN_SYNTAX_ERROR;
return (l);
}
if (Value)
{
/* expression is TRUE */
l->next->position = 0;
return l->next;
}
/*
RESUME knows we iterate thru the various ELSEIF commands, and restarts at the IF THEN command.
RESUME NEXT knows we iterate thru the various ELSEIF commands, and restarts at the END IF command.
*/
for (else_line = l->OtherLine; else_line->cmdnum == C_ELSEIF;
else_line = else_line->OtherLine)
{
else_line->position = else_line->Startpos;
/* evaluate the expression */
if (line_read_integer_expression (else_line, &Value) == FALSE)
{
WARN_SYNTAX_ERROR;
return (l);
}
if (Value)
{
/* expression is TRUE */
else_line->next->position = 0;
return else_line->next;
}
}
/* ELSE or END IF */
else_line->next->position = 0;
return else_line->next;
}
LineType *
bwb_ELSEIF (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
for (l = l->OtherLine; l->OtherLine != NULL; l = l->OtherLine);
l = l->next; /* line after END IF */
l->position = 0;
return l;
}
LineType *
bwb_ELSE (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
for (l = l->OtherLine; l->OtherLine != NULL; l = l->OtherLine);
l = l->next; /* line after END IF */
l->position = 0;
return l;
}
LineType *
bwb_END_IF (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
return (l);
}
/*
--------------------------------------------------------------------------------------------
SELECT CASE - END SELECT
--------------------------------------------------------------------------------------------
*/
/***************************************************************
FUNCTION: bwb_select()
DESCRIPTION: This C function handles the BASIC SELECT
statement.
SYNTAX: SELECT CASE expression ' examples:
CASE value ' CASE 5
CASE min TO max ' CASE 1 TO 10
CASE IF relationaloperator value ' CASE IF > 5
CASE IS relationaloperator value ' CASE IS > 5
CASE ELSE
END SELECT
***************************************************************/
LineType *
bwb_SELECT_CASE (LineType * l)
{
VariantType selectvalue;
VariantType *e;
LineType *else_line;
assert (l != NULL);
e = &selectvalue;
CLEAR_VARIANT (e);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
/* evaluate the expression */
if (line_read_expression (l, e) == FALSE) /* bwb_SELECT_CASE */
{
WARN_SYNTAX_ERROR;
return (l);
}
/*
**
** RESUME knows we iterate thru the various CASE commands, and restarts at the SELECT CASE command.
** RESUME NEXT knows we iterate thru the various CASE commands, and restarts at the END SELECT command.
**
*/
for (else_line = l->OtherLine; else_line->cmdnum == C_CASE;
else_line = else_line->OtherLine)
{
else_line->position = else_line->Startpos;
do
{
/* evaluate the expression */
if (line_skip_word (else_line, "IF")
|| line_skip_word (else_line, "IS"))
{
/* CASE IS < 10 */
/* CASE IF < "DEF" */
/* CASE IS > 7 */
/* CASE IS > "ABC" */
char *tbuf;
int tlen;
size_t n; /* number of characters we want to put in tbuf */
int position;
VariantType casevalue;
VariantType *r;
assert(My != NULL);
assert(My->ConsoleOutput != NULL);
assert(MAX_LINE_LENGTH > 1);
tbuf = My->ConsoleOutput;
tlen = MAX_LINE_LENGTH;
n = 0;
r = &casevalue;
CLEAR_VARIANT (r);
/*
**
** Available choices:
** 1. Parse every possible operator combination, depending upon the BASIC flavor.
** 2. Jump into the middle of the expression parser, by exposing the parser internals.
** 3. Limit the length of the expression. This is the choice I made.
**
*/
if (e->VariantTypeCode == StringTypeCode)
{
/* STRING */
n += bwb_strlen (e->Buffer);
if (n > tlen)
{
WARN_STRING_FORMULA_TOO_COMPLEX; /* bwb_SELECT_CASE */
return (l);
}
/* OK , everything will fit */
bwb_strcpy (tbuf, e->Buffer);
}
else
{
/* NUMBER */
FormatBasicNumber (e->Number, tbuf);
n += bwb_strlen (tbuf);
if (n > tlen)
{
WARN_STRING_FORMULA_TOO_COMPLEX; /* bwb_SELECT_CASE */
return (l);
}
/* OK , everything will fit */
}
{
char *Space;
Space = " ";
n += bwb_strlen (Space);
if (n > tlen)
{
WARN_STRING_FORMULA_TOO_COMPLEX; /* bwb_SELECT_CASE */
return (l);
}
/* OK , everything will fit */
bwb_strcat (tbuf, Space);
}
{
n += bwb_strlen (&(else_line->buffer[else_line->position]));
if (n > tlen)
{
WARN_STRING_FORMULA_TOO_COMPLEX; /* bwb_SELECT_CASE */
return (l);
}
/* OK , everything will fit */
bwb_strcat (tbuf, &(else_line->buffer[else_line->position]));
}
position = 0;
if (buff_read_expression (tbuf, &position, r) == FALSE) /* bwb_SELECT_CASE */
{
WARN_SYNTAX_ERROR;
return (l);
}
if (r->VariantTypeCode == StringTypeCode)
{
RELEASE_VARIANT (r);
WARN_TYPE_MISMATCH;
return (l);
}
if (r->Number)
{
/* expression is TRUE */
else_line->next->position = 0;
return else_line->next;
}
/* condition is FALSE */
/* proceed to next CASE line if there is one */
}
else
{
/* CASE 7 */
/* CASE 7 TO 10 */
/* CASE "ABC" */
/* CASE "ABC" TO "DEF" */
VariantType minvalue;
VariantType *minval;
minval = &minvalue;
CLEAR_VARIANT (minval);
/* evaluate the MIN expression */
if (line_read_expression (else_line, minval) == FALSE) /* bwb_SELECT_CASE */
{
WARN_SYNTAX_ERROR;
return (l);
}
if (IsTypeMismatch (e->VariantTypeCode, minval->VariantTypeCode))
{
RELEASE_VARIANT (minval);
WARN_TYPE_MISMATCH;
return (l);
}
if (line_skip_word (else_line, "TO"))
{
/* CASE 7 TO 10 */
/* CASE "ABC" TO "DEF" */
VariantType maxvalue;
VariantType *maxval;
maxval = &maxvalue;
CLEAR_VARIANT (maxval);
/* evaluate the MAX expression */
if (line_read_expression (else_line, maxval) == FALSE) /* bwb_SELECT_CASE */
{
WARN_SYNTAX_ERROR;
return (l);
}
if (IsTypeMismatch (e->VariantTypeCode, maxval->VariantTypeCode))
{
RELEASE_VARIANT (maxval);
WARN_TYPE_MISMATCH;
return (l);
}
if (e->VariantTypeCode == StringTypeCode)
{
/* STRING */
if (bwb_strcmp (e->Buffer, minval->Buffer) >= 0
&& bwb_strcmp (e->Buffer, maxval->Buffer) <= 0)
{
/* expression is TRUE */
RELEASE_VARIANT (maxval);
else_line->next->position = 0;
return else_line->next;
}
RELEASE_VARIANT (maxval);
}
else
{
/* NUMBER */
if (e->Number >= minval->Number && e->Number <= maxval->Number)
{
/* expression is TRUE */
else_line->next->position = 0;
return else_line->next;
}
}
}
else
{
/* CASE 7 */
/* CASE "ABC" */
if (e->VariantTypeCode == StringTypeCode)
{
/* STRING */
if (bwb_strcmp (e->Buffer, minval->Buffer) == 0)
{
/* expression is TRUE */
RELEASE_VARIANT (minval);
else_line->next->position = 0;
return else_line->next;
}
RELEASE_VARIANT (minval);
}
else
{
/* NUMBER */
if (e->Number == minval->Number)
{
/* expression is TRUE */
else_line->next->position = 0;
return else_line->next;
}
}
}
/* condition is FALSE */
/* proceed to next CASE line if there is one */
}
}
while (line_skip_seperator (else_line));
}
/* CASE_ELSE or END_SELECT */
RELEASE_VARIANT (e);
else_line->next->position = 0;
return else_line->next;
}
LineType *
bwb_CASE (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
for (l = l->OtherLine; l->OtherLine != NULL; l = l->OtherLine);
l = l->next; /* line after END SELECT */
l->position = 0;
return l;
}
LineType *
bwb_CASE_ELSE (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
for (l = l->OtherLine; l->OtherLine != NULL; l = l->OtherLine);
l = l->next; /* line after END SELECT */
l->position = 0;
return l;
}
LineType *
bwb_END_SELECT (LineType * l)
{
assert (l != NULL);
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
return (l);
}
/*
--------------------------------------------------------------------------------------------
DO - LOOP
--------------------------------------------------------------------------------------------
*/
/***************************************************************
FUNCTION: bwb_DO()
DESCRIPTION: This C function implements the ANSI BASIC
DO statement.
SYNTAX: DO [UNTIL|WHILE condition]
...
[EXIT DO]
...
LOOP [UNTIL|WHILE condition]
***************************************************************/
LineType *
bwb_DO (LineType * l)
{
LineType *r;
int Value;
assert (l != NULL);
/* DO ' forever */
/* DO UNTIL ' exits when != 0 */
/* DO WHILE ' exits when == 0 */
if (l->LineFlags & (LINE_USER))
{
WARN_ILLEGAL_DIRECT;
return (l);
}
do
{
/* evaluate the expression */
if (line_is_eol (l))
{
break; /* exit 'do' */
}
else if (line_skip_word (l, "UNTIL"))
{
/* DO UNTIL */