1// This file is part of SmallBASIC
2//
3// This program is distributed under the terms of the GPL v2.0 or later
4// Download the GNU Public License (GPL) from www.gnu.org
5//
6// Copyright(C) 2000 Nicholas Christopoulos
7
8#include "common/sys.h"
9#include "common/kw.h"
10#include "common/var.h"
11#include "common/scan.h"
12
13/*
14 * functions without parameters
15 */
16bid_t kw_noarg_func_table[] = {
17 kwINKEY,
18 kwTIME,
19 kwDATE,
20 kwTICKS,
21 kwTIMER,
22 kwPROGLINE,
23 kwFREEFILE,
24 kwXPOS,
25 kwYPOS,
26 kwRND,
27 0
28};
29
30/*
31 * valid exit codes from eval
32 */
33int kw_check_evexit(code_t code) {
34 switch (code) {
35 case kwTYPE_EOC:
36 case kwTYPE_LINE:
37 case kwTYPE_SEP:
38 case kwFILLED:
39 case kwCOLOR:
40 case kwUSE:
41 case kwTO:
42 case kwIN:
43 case kwSTEP:
44 case kwFORSEP:
45 case kwINPUTSEP:
46 case kwINPUT:
47 case kwOUTPUTSEP:
48 case kwAPPENDSEP:
49 case kwAS:
50 case kwUSING:
51 case kwTHEN:
52 case kwDO:
53 case kwBACKG:
54 return 1;
55 default:
56 return 0;
57 }
58}
59
60int kw_getcmdname(code_t code, char *dest) {
61 int found = 0;
62
63 *dest = '\0';
64 for (int i = 0; keyword_table[i].name[0] != '\0'; i++) {
65 if (code == keyword_table[i].code) {
66 strcpy(dest, keyword_table[i].name);
67 found++;
68 break;
69 }
70 }
71 if (!found) {
72 sprintf(dest, "(%d)", (int) code);
73 }
74 return found;
75}
76
77int kw_getfuncname(bid_t code, char *dest) {
78 int found = 0;
79
80 *dest = '\0';
81 for (int i = 0; func_table[i].name[0] != '\0'; i++) {
82 if (code == func_table[i].fcode) {
83 strcpy(dest, func_table[i].name);
84 found++;
85 break;
86 }
87 }
88 if (!found) {
89 sprintf(dest, "(%d)", code);
90 }
91 return found;
92}
93
94int kw_getprocname(bid_t code, char *dest) {
95 int found = 0;
96
97 *dest = '\0';
98 for (int i = 0; proc_table[i].name[0] != '\0'; i++) {
99 if (code == proc_table[i].pcode) {
100 strcpy(dest, proc_table[i].name);
101 found++;
102 break;
103 }
104 }
105 if (!found) {
106 sprintf(dest, "(%d)", code);
107 }
108 return found;
109}
110
111int kw_noarg_func(bid_t code) {
112 for (int i = 0; kw_noarg_func_table[i] != 0; i++) {
113 if (kw_noarg_func_table[i] == code) {
114 return 1;
115 }
116 }
117 return 0;
118}
119
120