forked from nerun/bwbasic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbwb_fnc.c
4721 lines (4625 loc) · 92.7 KB
/
bwb_fnc.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_fnc.c Interpretation Routines
for Predefined Functions
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"
#ifndef RAND_MAX
#define RAND_MAX 32767
#endif /* RAND_MAX */
#ifndef PI
#define PI 3.14159265358979323846
#endif /* PI */
#define FromDegreesToRadians( X ) ( X * PI / 180.0 )
#define FromRadiansToDegrees( X ) ( X * 180.0 / PI )
#define FromGradiansToRadians( X ) ( X * PI / 200.0 )
#define FromRadiansToGradians( X ) ( X * 200.0 / PI )
static time_t t;
static struct tm *lt;
/* ORD() Table 1 */
/* ACRONYM */
typedef struct
{
const int Value;
const char *Name;
} Acronym;
#define NUM_ACRONYMS (34)
Acronym AcronymTable[NUM_ACRONYMS] = {
{0, "NUL"},
{1, "SOH"},
{2, "STX"},
{3, "ETX"},
{4, "EOT"},
{5, "ENQ"},
{6, "ACK"},
{7, "BEL"},
{8, "BS"},
{9, "HT"},
{10, "LF"},
{11, "VT"},
{12, "FF"},
{13, "CR"},
{14, "SO"},
{15, "SI"},
{16, "DLE"},
{17, "DC1"},
{18, "DC2"},
{19, "DC3"},
{20, "DC4"},
{21, "NAK"},
{22, "SYN"},
{23, "ETB"},
{24, "CAN"},
{25, "EM"},
{26, "SUB"},
{27, "ESC"},
{28, "FS"},
{29, "GS"},
{30, "RS"},
{31, "US"},
{32, "SP"},
{127, "DEL"}
};
/* ... ORD() */
extern VariableType *
IntrinsicFunction_execute (int argc, VariableType * argv,
IntrinsicFunctionType * f)
{
/* this is the generic handler for all intrinsic BASIC functions */
/* Follow the BASIC naming conventions, so the code is easier to read and maintain */
/* assign reasonable default values */
VariableType *argn;
/* Follow the BASIC naming conventions, so the code is easier to maintain */
char *S; /* S$ - STRING functions */
size_t s; /* LEN( S$ ) */
DoubleType N; /* N - NUMBER functions */
char *A; /* A$ - 1st STRING parameter */
size_t a; /* LEN( A$ ) */
char *B; /* B$ - 2nd STRING parameter */
size_t b; /* LEN( B$ ) */
#if FALSE /* keep third parameter */
char *C; /* C$ - 3rd STRING parameter */
size_t c; /* LEN( C$ ) */
#endif
DoubleType X; /* X - 1st NUMBER parameter */
IntegerType x; /* CINT( X ) */
DoubleType Y; /* Y - 2nd NUMBER parameter */
IntegerType y; /* CINT( Y ) */
#if FALSE /* keep third parameter */
DoubleType Z; /* Z - 3rd NUMBER parameter */
IntegerType z; /* CINT( Z ) */
#endif
assert (argc >= 0);
assert (argv != NULL);
assert (f != NULL);
assert(My != NULL);
assert(My->CurrentVersion != NULL);
assert(My->SYSOUT != NULL);
assert(My->SYSOUT->cfp != NULL);
assert(My->SYSPRN != NULL);
assert(My->SYSPRN->cfp != NULL);
assert(My->SYSIN != NULL);
assert(My->SYSIN->cfp != NULL);
S = NULL;
s = 0;
N = 0;
A = NULL;
a = 0;
B = NULL;
b = 0;
#if FALSE /* keep third parameter */
C = NULL;
c = 0;
#endif
X = 0;
x = 0;
Y = 0;
y = 0;
#if FALSE /* keep third parameter */
Z = 0;
z = 0;
#endif
if (f == NULL)
{
WARN_INTERNAL_ERROR;
return NULL;
}
if (argc < 0)
{
WARN_INTERNAL_ERROR;
return NULL;
}
/* the RETURN variable is the first variable in the 'argv' vaariable chain */
if (argv == NULL)
{
WARN_INTERNAL_ERROR;
return NULL;
}
if (VAR_IS_STRING (argv))
{
if (argv->Value.String == NULL)
{
WARN_INTERNAL_ERROR;
return NULL;
}
if (RESULT_BUFFER == NULL)
{
WARN_INTERNAL_ERROR;
return NULL;
}
RESULT_LENGTH = 0;
RESULT_BUFFER[RESULT_LENGTH] = NulChar;
}
else
{
if (argv->Value.Number == NULL)
{
WARN_INTERNAL_ERROR;
return NULL;
}
RESULT_NUMBER = 0;
}
argn = argv;
/* don't make a bad situation worse */
if (My->IsErrorPending /* Keep This */ )
{
/* An unrecognized NON-FATAL ERROR is pending. Just return a sane value. */
/* LET N = LOG(SQR(X)) ' X = -1 */
return argv;
}
/* so the following code is easier to read and maintain */
{
/* assign actual values */
if (f->ReturnTypeCode == StringTypeCode)
{
S = RESULT_BUFFER;
s = RESULT_LENGTH;
}
else
{
N = RESULT_NUMBER;
}
if (f->ParameterCount == 255 /* (...) */ )
{
/* ... VARIANT number of parameters */
}
else
{
int i;
int StrCount; /* count of STRING parameters - NEVER > 3 */
int NumCount; /* count of NUMBER parameters - NEVER > 3 */
ParamTestType ParameterTests;
StrCount = 0;
NumCount = 0;
ParameterTests = f->ParameterTests;
for (i = 0; i < argc && i < MAX_TESTS && My->IsErrorPending == FALSE;
i++)
{
argn = argn->next;
if (argn == NULL)
{
WARN_INTERNAL_ERROR;
return NULL;
}
if (VAR_IS_STRING (argn))
{
if (argn->Value.String == NULL)
{
WARN_INTERNAL_ERROR;
return NULL;
}
StrCount++;
switch (StrCount)
{
case 1:
/* 1st STRING parameter = A$ */
A = PARAM_BUFFER;
a = PARAM_LENGTH;
if (StringLengthCheck (ParameterTests, a))
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
A[a] = NulChar;
}
break;
case 2:
/* 2nd STRING parameter = B$ */
B = PARAM_BUFFER;
b = PARAM_LENGTH;
if (StringLengthCheck (ParameterTests, b))
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
B[b] = NulChar;
}
break;
#if FALSE /* keep third parameter */
case 3:
/* 3rd STRING parameter = C$ */
/* not currently used */
C = PARAM_BUFFER;
c = PARAM_LENGTH;
if (StringLengthCheck (ParameterTests, c))
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
C[c] = NulChar;
}
break;
#endif
default:
/* Nth STRING parameter = ERROR */
WARN_ILLEGAL_FUNCTION_CALL;
break;
}
}
else
{
if (argn->Value.Number == NULL)
{
WARN_INTERNAL_ERROR;
return NULL;
}
NumCount++;
switch (NumCount)
{
case 1:
/* 1st NUMBER parameter = X */
X = PARAM_NUMBER;
if (NumberValueCheck (ParameterTests, X))
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
DoubleType R;
R = bwb_rint (X);
if (R < INT_MIN || R > INT_MAX)
{
/* certainly not a
* classic BASIC
* integer */
}
else
{
/* Many classic BASIC
* intrinsic
* functions use the
* rounded integer
* value. */
x = (int) R;
}
}
break;
case 2:
/* 2nd NUMBER parameter = Y */
Y = PARAM_NUMBER;
if (NumberValueCheck (ParameterTests, Y))
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
DoubleType R;
R = bwb_rint (Y);
if (R < INT_MIN || R > INT_MAX)
{
/* certainly not a
* classic BASIC
* integer */
}
else
{
/* Many classic BASIC
* intrinsic
* functions use the
* rounded integer
* value. */
y = (int) R;
}
}
break;
#if FALSE /* keep third parameter */
case 3:
/* 3rd NUMBER parameter = Z */
/* not currently used */
Z = PARAM_NUMBER;
if (NumberValueCheck (ParameterTests, Z))
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
DoubleType R;
R = bwb_rint (Z);
if (R < INT_MIN || R > INT_MAX)
{
/* certainly not a
* classic BASIC
* integer */
}
else
{
/* Many classic BASIC
* intrinsic
* functions use the
* rounded integer
* value. */
z = (int) R;
}
}
break;
#endif
default:
/* Nth NUMBER parameter = ERROR */
WARN_ILLEGAL_FUNCTION_CALL;
break;
}
}
ParameterTests = ParameterTests >> 4;
}
}
}
if (My->IsErrorPending /* Keep This */ )
{
/* An unrecognized NON-FATAL ERROR is pending. Just return a sane value. */
/* LET N = LOG(SQR(X)) ' X = -1 */
return argv;
}
/*
**
** all parameters have been checked and are OK
** execute the intrinsic function
**
*/
switch (f->FunctionID)
{
/*
**
** ALL paramters have been checked
** for TYPE MISMATCH and INVALID RANGE.
** ONLY A HANDFUL OF ERRORS CAN OCCUR
**
*/
case 0:
{
/* INTERNAL ERROR */
WARN_INTERNAL_ERROR;
}
break;
case F_ARGC_N:
/* N = ARGC */
{
/* determine number of parameters to the current USER DEFINED FUNCTION */
int n;
n = 0;
if (My->StackHead != NULL)
{
int Loop;
StackType *StackItem;
Loop = TRUE;
for (StackItem = My->StackHead; StackItem != NULL && Loop == TRUE;
StackItem = StackItem->next)
{
if (StackItem->LoopTopLine != NULL)
{
switch (StackItem->LoopTopLine->cmdnum)
{
case C_FUNCTION:
case C_SUB:
/* we have checked all the way to a FUNCTION or SUB boundary */
/* FOUND */
{
VariableType *v;
for (v = StackItem->local_variable; v != NULL && Loop == TRUE;
v = v->next)
{
n++;
}
}
Loop = FALSE;
break;
}
}
}
}
n--; /* FUNCTION or SUB name */
N = n;
}
break;
case F_ARGT4_X_S:
/* S$ = ARGT$( X ) */
{
/* determine parameter type to the current USER DEFINED FUNCTION */
int Found;
int n;
Found = FALSE;
n = 0;
s = 0;
if (x < 1)
{
/* bad param number */
}
else if (My->StackHead != NULL)
{
int Loop;
StackType *StackItem;
Loop = TRUE;
for (StackItem = My->StackHead; StackItem != NULL && Loop == TRUE;
StackItem = StackItem->next)
{
if (StackItem->LoopTopLine != NULL)
{
switch (StackItem->LoopTopLine->cmdnum)
{
case C_FUNCTION:
case C_SUB:
/* we have checked all the way to a FUNCTION or SUB boundary */
/* FOUND */
{
VariableType *v;
for (v = StackItem->local_variable; v != NULL && Loop == TRUE;
v = v->next)
{
if (n == x)
{
char Char;
Char = TypeCode_to_Char (v->VariableTypeCode);
if (Char)
{
S[0] = Char;
s = 1;
Found = TRUE;
}
Loop = FALSE;
}
n++;
}
}
Loop = FALSE;
break;
}
}
}
}
if (Found == FALSE)
{
WARN_ILLEGAL_FUNCTION_CALL;
}
}
break;
case F_ARGV4_X_S:
/* S$ = ARGV$( X ) */
{
/* determine parameter value to the current
* USER DEFINED FUNCTION */
int Found;
int n;
Found = FALSE;
n = 0;
if (x < 1)
{
/* bad param number */
}
else if (My->StackHead != NULL)
{
int Loop;
StackType *StackItem;
Loop = TRUE;
for (StackItem = My->StackHead; StackItem != NULL && Loop == TRUE;
StackItem = StackItem->next)
{
if (StackItem->LoopTopLine != NULL)
{
switch (StackItem->LoopTopLine->cmdnum)
{
case C_FUNCTION:
case C_SUB:
/* we have checked all the way to a FUNCTION or SUB boundary */
/* FOUND */
{
VariableType *v;
for (v = StackItem->local_variable; v != NULL && Loop == TRUE;
v = v->next)
{
if (n == x)
{
if (VAR_IS_STRING (v))
{
s = v->Value.String->length;
bwb_memcpy (S, v->Value.String->sbuffer, s);
Found = TRUE;
}
else
{
}
Loop = FALSE;
}
n++;
}
}
Loop = FALSE;
break;
}
}
}
}
if (Found == FALSE)
{
WARN_ILLEGAL_FUNCTION_CALL;
}
}
break;
case F_ARGV_X_N:
/* S$ = ARGV( X ) */
{
/* determine parameter value to the current USER DEFINED FUNCTION */
int Found;
int n;
Found = FALSE;
n = 0;
if (x < 1)
{
/* bad param number */
}
else if (My->StackHead != NULL)
{
int Loop;
StackType *StackItem;
Loop = TRUE;
for (StackItem = My->StackHead; StackItem != NULL && Loop == TRUE;
StackItem = StackItem->next)
{
if (StackItem->LoopTopLine != NULL)
{
switch (StackItem->LoopTopLine->cmdnum)
{
case C_FUNCTION:
case C_SUB:
/* we have checked all the way to a FUNCTION or SUB boundary */
/* FOUND */
{
VariableType *v;
for (v = StackItem->local_variable; v != NULL && Loop == TRUE;
v = v->next)
{
if (n == x)
{
if (VAR_IS_STRING (v))
{
}
else
{
N = *v->Value.Number;
Found = TRUE;
}
Loop = FALSE;
}
n++;
}
}
Loop = FALSE;
break;
}
}
}
}
if (Found == FALSE)
{
WARN_ILLEGAL_FUNCTION_CALL;
}
}
break;
case F_BASE_N:
/* N = BASE */
{
/* PNONE */
N = My->CurrentVersion->OptionBaseInteger; /* implicit lower bound */
}
break;
case F_RESIDUE_N:
/* N = RESIDUE */
{
/* PNONE */
N = My->RESIDUE; /* Residue of the last integer divide */
}
case F_DIGITS_X_N:
/* N = DIGITS( X ) */
{
/* P1BYT */
if (x == 0)
{
/* default */
x = SIGNIFICANT_DIGITS;
}
if (x < MINIMUM_DIGITS || x > MAXIMUM_DIGITS)
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
My->OptionDigitsInteger = x;
}
}
break;
case F_SCALE_X_N:
case F_PRECISION_X_N:
/* N = SCALE( X ) */
/* N = PRECISION( X ) */
{
/* P1BYT */
if (x < MINIMUM_SCALE || x > MAXIMUM_SCALE)
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
My->OptionScaleInteger = x;
}
}
break;
case F_DIGITS_X_Y_N:
/* N = DIGITS( X, Y ) */
{
/* P1BYT | P2BYT */
if (x == 0)
{
/* default */
x = SIGNIFICANT_DIGITS;
}
if (x < MINIMUM_DIGITS || x > MAXIMUM_DIGITS)
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else if (y < MINIMUM_SCALE || y > MAXIMUM_SCALE)
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
My->OptionDigitsInteger = x;
My->OptionScaleInteger = y;
}
}
break;
case F_ASC_A_N:
case F_ASCII_A_N:
case F_CODE_A_N:
/* N = ASC( A$ ) */
/* N = ASCII( A$ ) */
/* N = CODE( A$ ) */
{
/* P1BYT */
N = A[0];
}
break;
case F_ASC_A_X_N:
/* N = ASC( A$, X ) */
{
/* P1BYT|P2POS */
x--; /* BASIC -> C */
if (x < a)
{
N = A[x];
}
else
{
WARN_ILLEGAL_FUNCTION_CALL;
}
}
break;
case F_CDBL_X_N:
/* N = CDBL( X ) */
{
/* P1DBL */
N = X;
}
break;
case F_CSNG_X_N:
/* N = CSNG( X ) */
{
/* P1FLT */
N = X;
}
break;
case F_CCUR_X_N:
/* N = CCUR( X ) */
{
/* P1CUR */
N = bwb_rint (X);
}
break;
case F_CLNG_X_N:
/* N = CLNG( X ) */
{
/* P1LNG */
N = bwb_rint (X);
}
break;
case F_CINT_X_N:
/* N = CINT( X ) */
{
/* P1INT */
N = bwb_rint (X);
}
break;
case F_MKD4_X_S:
/* S$ = MKD$( X ) */
{
/* P1DBL */
DoubleType x;
x = (DoubleType) X;
s = sizeof (DoubleType);
bwb_memcpy (S, &x, s);
}
break;
case F_MKS4_X_S:
/* S$ = MKS$( X ) */
{
/* P1FLT */
SingleType x;
x = (SingleType) X;
s = sizeof (SingleType);
bwb_memcpy (S, &x, s);
}
break;
case F_MKI4_X_S:
/* S$ = MKI$( X ) */
{
/* P1INT */
IntegerType x;
x = (IntegerType) bwb_rint (X);
s = sizeof (IntegerType);
bwb_memcpy (S, &x, s);
}
break;
case F_MKL4_X_S:
/* S$ = MKL$( X ) */
{
/* P1LNG */
LongType x;
x = (LongType) bwb_rint (X);
s = sizeof (LongType);
bwb_memcpy (S, &x, s);
}
break;
case F_MKC4_X_S:
/* S$ = MKC$( X ) */
{
/* P1CUR */
CurrencyType x;
x = (CurrencyType) bwb_rint (X);
s = sizeof (CurrencyType);
bwb_memcpy (S, &x, s);
}
break;
case F_CVD_A_N:
/* N = CVD( A$ ) */
{
/* P1DBL */
DoubleType n;
a = sizeof (DoubleType);
bwb_memcpy (&n, A, a);
N = n;
}
break;
case F_CVS_A_N:
/* N = CVS( X$ ) */
{
/* P1FLT */
SingleType n;
a = sizeof (SingleType);
bwb_memcpy (&n, A, a);
N = n;
}
break;
case F_CVI_A_N:
/* N = CVI( X$ ) */
{
/* P1INT */
IntegerType n;
a = sizeof (IntegerType);
bwb_memcpy (&n, A, a);
N = n;
}
break;
case F_CVL_A_N:
/* N = CVL( X$ ) */
{
/* P1LNG */
LongType n;
a = sizeof (LongType);
bwb_memcpy (&n, A, a);
N = n;
}
break;
case F_CVC_A_N:
/* N = CVC( X$ ) */
{
/* P1CUR */
CurrencyType n;
a = sizeof (CurrencyType);
bwb_memcpy (&n, A, a);
N = n;
}
break;
case F_ENVIRON4_A_S:
/* S$ = ENVIRON$( A$ ) */
{
/* P1BYT */
char *CharPointer;
CharPointer = getenv (A);
if (CharPointer == NULL)
{
/* empty string */
}
else
{
s = bwb_strlen (CharPointer);
if (s > MAXLEN)
{
WARN_STRING_TOO_LONG; /* F_ENVIRON4_A_S */
s = MAXLEN;
}
if (s == 0)
{
/* empty string */
}
else
{
bwb_memcpy (S, CharPointer, s);
}
}
}
break;
case F_ENVIRON_A_N:
/* ENVIRON A$ */
{
/* P1BYT */
char *CharPointer;
CharPointer = bwb_strchr (A, '=');
if (CharPointer == NULL)
{
/* missing required '=' */
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
if (putenv (A) == -1)
{
WARN_ILLEGAL_FUNCTION_CALL;
}
else
{
/* OK */
N = 0;
}
}
}
break;
case F_OPEN_A_X_B_Y_N:
/* OPEN "I"|"O"|"R"|"A", [#]n, filename [,rlen] */
{
/* P1STR|P2NUM|P3STR|P4NUM */
/* P1BYT|P2INT|P3BYT|P4INT */
while (*A == ' ')
{
A++; /* LTRIM$ */
}
bwb_file_open (*A, x, B, y);
}
break;
case F_OPEN_A_X_B_N:
/* default LEN is 128 for RANDOM, 0 for all others */
/* OPEN "I"|"O"|"R"|"A", [#]n, filename [,rlen] */
{
/* P1STR|P2NUM|P3STR|P4NUM */
/* P1BYT|P2INT|P3BYT|P4INT */
y = 0;
while (*A == ' ')
{