Browse code

Flagged functions as static

neauoire authored on 28/06/2021 21:42:36
Showing 4 changed files
... ...
@@ -29,4 +29,3 @@ BRK
29 29
 		DUP #09 GTH ,&above JCN #30 ADD RTN &above #09 SUB #60 ADD RTN
30 30
 
31 31
 RTN
32
-
... ...
@@ -39,21 +39,19 @@ Program p;
39 39
 
40 40
 /* clang-format off */
41 41
 
42
-char ops[][4] = {
42
+static char ops[][4] = {
43 43
 	"BRK", "LIT", "NOP", "POP", "DUP", "SWP", "OVR", "ROT",
44 44
 	"EQU", "NEQ", "GTH", "LTH", "JMP", "JCN", "JSR", "STH",
45 45
 	"LDZ", "STZ", "LDR", "STR", "LDA", "STA", "DEI", "DEO",
46 46
 	"ADD", "SUB", "MUL", "DIV", "AND", "ORA", "EOR", "SFT"
47 47
 };
48 48
 
49
-int   scin(char *s, char c) { int i = 0; while(s[i]) if(s[i++] == c) return i - 1; return -1; } /* string char index */
50
-int   scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i] && i < len) if(!a[i++]) return 1; return 0; } /* string compare */
51
-int   sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')) return 0; return i > 1; } /* string is hexadecimal */
52
-int   ssin(char *s, char *ss) { int a = 0, b = 0; while(s[a]) { if(s[a] == ss[b]) { if(!ss[b + 1]) return a - b; b++; } else b = 0; a++; } return -1; } /* string substring index */
53
-int   shex(char *s) { int n = 0, i = 0; char c; while((c = s[i++])) if(c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if(c >= 'a' && c <= 'f') n = n * 16 + 10 + (c - 'a'); return n; } /* string to num */
54
-int   slen(char *s) { int i = 0; while(s[i] && s[++i]) ; return i; } /* string length */
55
-char *scpy(char *src, char *dst, int len) { int i = 0; while((dst[i] = src[i]) && i < len - 2) i++; dst[i + 1] = '\0'; return dst; } /* string copy */
56
-char *scat(char *dst, const char *src) { char *ptr = dst + slen(dst); while(*src) *ptr++ = *src++; *ptr = '\0'; return dst; } /* string cat */
49
+static int   scmp(char *a, char *b, int len) { int i = 0; while(a[i] == b[i] && i < len) if(!a[i++]) return 1; return 0; } /* string compare */
50
+static int   sihx(char *s) { int i = 0; char c; while((c = s[i++])) if(!(c >= '0' && c <= '9') && !(c >= 'a' && c <= 'f')) return 0; return i > 1; } /* string is hexadecimal */
51
+static int   shex(char *s) { int n = 0, i = 0; char c; while((c = s[i++])) if(c >= '0' && c <= '9') n = n * 16 + (c - '0'); else if(c >= 'a' && c <= 'f') n = n * 16 + 10 + (c - 'a'); return n; } /* string to num */
52
+static int   slen(char *s) { int i = 0; while(s[i] && s[++i]) ; return i; } /* string length */
53
+static char *scpy(char *src, char *dst, int len) { int i = 0; while((dst[i] = src[i]) && i < len - 2) i++; dst[i + 1] = '\0'; return dst; } /* string copy */
54
+static char *scat(char *dst, const char *src) { char *ptr = dst + slen(dst); while(*src) *ptr++ = *src++; *ptr = '\0'; return dst; } /* string cat */
57 55
 
58 56
 #pragma mark - Helpers
59 57
 
... ...
@@ -61,7 +59,7 @@ char *scat(char *dst, const char *src) { char *ptr = dst + slen(dst); while(*src
61 59
 
62 60
 #pragma mark - I/O
63 61
 
64
-void
62
+static void
65 63
 pushbyte(Uint8 b, int lit)
66 64
 {
67 65
 	if(lit) pushbyte(0x01, 0);
... ...
@@ -69,7 +67,7 @@ pushbyte(Uint8 b, int lit)
69 67
 	p.length = p.ptr;
70 68
 }
71 69
 
72
-void
70
+static void
73 71
 pushshort(Uint16 s, int lit)
74 72
 {
75 73
 	if(lit) pushbyte(0x21, 0);
... ...
@@ -77,7 +75,7 @@ pushshort(Uint16 s, int lit)
77 75
 	pushbyte(s & 0xff, 0);
78 76
 }
79 77
 
80
-void
78
+static void
81 79
 pushword(char *s)
82 80
 {
83 81
 	int i = 0;
... ...
@@ -85,7 +83,7 @@ pushword(char *s)
85 83
 	while((c = s[i++])) pushbyte(c, 0);
86 84
 }
87 85
 
88
-Macro *
86
+static Macro *
89 87
 findmacro(char *name)
90 88
 {
91 89
 	int i;
... ...
@@ -95,7 +93,7 @@ findmacro(char *name)
95 93
 	return NULL;
96 94
 }
97 95
 
98
-Label *
96
+static Label *
99 97
 findlabel(char *name)
100 98
 {
101 99
 	int i;
... ...
@@ -105,7 +103,7 @@ findlabel(char *name)
105 103
 	return NULL;
106 104
 }
107 105
 
108
-Uint8
106
+static Uint8
109 107
 findopcode(char *s)
110 108
 {
111 109
 	int i;
... ...
@@ -130,7 +128,7 @@ findopcode(char *s)
130 128
 	return 0;
131 129
 }
132 130
 
133
-char *
131
+static char *
134 132
 sublabel(char *src, char *scope, char *name)
135 133
 {
136 134
 	return scat(scat(scpy(scope, src, 64), "/"), name);
... ...
@@ -138,14 +136,14 @@ sublabel(char *src, char *scope, char *name)
138 136
 
139 137
 #pragma mark - Parser
140 138
 
141
-int
139
+static int
142 140
 error(char *name, char *id)
143 141
 {
144 142
 	fprintf(stderr, "Error: %s[%s]\n", name, id);
145 143
 	return 0;
146 144
 }
147 145
 
148
-int
146
+static int
149 147
 makemacro(char *name, FILE *f)
150 148
 {
151 149
 	Macro *m;
... ...
@@ -170,7 +168,7 @@ makemacro(char *name, FILE *f)
170 168
 	return 1;
171 169
 }
172 170
 
173
-int
171
+static int
174 172
 makelabel(char *name, Uint16 addr)
175 173
 {
176 174
 	Label *l;
... ...
@@ -187,7 +185,7 @@ makelabel(char *name, Uint16 addr)
187 185
 	return 1;
188 186
 }
189 187
 
190
-int
188
+static int
191 189
 skipblock(char *w, int *cap, char a, char b)
192 190
 {
193 191
 	if(w[0] == b) {
... ...
@@ -199,7 +197,7 @@ skipblock(char *w, int *cap, char a, char b)
199 197
 	return 0;
200 198
 }
201 199
 
202
-int
200
+static int
203 201
 walktoken(char *w)
204 202
 {
205 203
 	Macro *m;
... ...
@@ -226,7 +224,7 @@ walktoken(char *w)
226 224
 	return error("Unknown label in first pass", w);
227 225
 }
228 226
 
229
-int
227
+static int
230 228
 parsetoken(char *w)
231 229
 {
232 230
 	Label *l;
... ...
@@ -285,7 +283,7 @@ parsetoken(char *w)
285 283
 	return error("Invalid token", w);
286 284
 }
287 285
 
288
-int
286
+static int
289 287
 pass1(FILE *f)
290 288
 {
291 289
 	int ccmnt = 0;
... ...
@@ -316,7 +314,7 @@ pass1(FILE *f)
316 314
 	return 1;
317 315
 }
318 316
 
319
-int
317
+static int
320 318
 pass2(FILE *f)
321 319
 {
322 320
 	int ccmnt = 0, cmacr = 0;
... ...
@@ -348,7 +346,7 @@ pass2(FILE *f)
348 346
 	return 1;
349 347
 }
350 348
 
351
-void
349
+static void
352 350
 cleanup(char *filename)
353 351
 {
354 352
 	int i;
... ...
@@ -19,14 +19,14 @@ WITH REGARD TO THIS SOFTWARE.
19 19
 
20 20
 static Device *devconsole;
21 21
 
22
-int
22
+static int
23 23
 error(char *msg, const char *err)
24 24
 {
25 25
 	printf("Error %s: %s\n", msg, err);
26 26
 	return 0;
27 27
 }
28 28
 
29
-void
29
+static void
30 30
 printstack(Stack *s)
31 31
 {
32 32
 	Uint8 x, y;
... ...
@@ -42,14 +42,14 @@ printstack(Stack *s)
42 42
 
43 43
 #pragma mark - Devices
44 44
 
45
-void
45
+static void
46 46
 console_talk(Device *d, Uint8 b0, Uint8 w)
47 47
 {
48 48
 	if(w && b0 == 0x8)
49 49
 		write(1, (char *)&d->dat[0x8], 1);
50 50
 }
51 51
 
52
-void
52
+static void
53 53
 file_talk(Device *d, Uint8 b0, Uint8 w)
54 54
 {
55 55
 	Uint8 read = b0 == 0xd;
... ...
@@ -70,7 +70,7 @@ file_talk(Device *d, Uint8 b0, Uint8 w)
70 70
 	}
71 71
 }
72 72
 
73
-void
73
+static void
74 74
 datetime_talk(Device *d, Uint8 b0, Uint8 w)
75 75
 {
76 76
 	time_t seconds = time(NULL);
... ...
@@ -89,7 +89,7 @@ datetime_talk(Device *d, Uint8 b0, Uint8 w)
89 89
 	(void)w;
90 90
 }
91 91
 
92
-void
92
+static void
93 93
 nil_talk(Device *d, Uint8 b0, Uint8 w)
94 94
 {
95 95
 	(void)d;
... ...
@@ -99,7 +99,7 @@ nil_talk(Device *d, Uint8 b0, Uint8 w)
99 99
 
100 100
 #pragma mark - Generics
101 101
 
102
-int
102
+static int
103 103
 start(Uxn *u)
104 104
 {
105 105
 	if(!evaluxn(u, PAGE_PROGRAM))
... ...
@@ -33,15 +33,15 @@ static Device *devscreen, *devmouse, *devctrl, *devaudio0, *devconsole;
33 33
 
34 34
 #define PAD 16
35 35
 
36
-Uint8 zoom = 0, debug = 0, reqdraw = 0, bench = 0;
36
+static Uint8 zoom = 0, debug = 0, reqdraw = 0, bench = 0;
37 37
 
38
-int
38
+static int
39 39
 clamp(int val, int min, int max)
40 40
 {
41 41
 	return (val >= min) ? (val <= max) ? val : max : min;
42 42
 }
43 43
 
44
-int
44
+static int
45 45
 error(char *msg, const char *err)
46 46
 {
47 47
 	fprintf(stderr, "Error %s: %s\n", msg, err);
... ...
@@ -59,7 +59,7 @@ audio_callback(void *u, Uint8 *stream, int len)
59 59
 	(void)u;
60 60
 }
61 61
 
62
-void
62
+static void
63 63
 redraw(Uxn *u)
64 64
 {
65 65
 	if(debug)
... ...
@@ -73,14 +73,14 @@ redraw(Uxn *u)
73 73
 	reqdraw = 0;
74 74
 }
75 75
 
76
-void
76
+static void
77 77
 toggledebug(Uxn *u)
78 78
 {
79 79
 	debug = !debug;
80 80
 	redraw(u);
81 81
 }
82 82
 
83
-void
83
+static void
84 84
 togglezoom(Uxn *u)
85 85
 {
86 86
 	zoom = zoom == 3 ? 1 : zoom + 1;
... ...
@@ -88,7 +88,7 @@ togglezoom(Uxn *u)
88 88
 	redraw(u);
89 89
 }
90 90
 
91
-void
91
+static void
92 92
 screencapture(void)
93 93
 {
94 94
 	const Uint32 format = SDL_PIXELFORMAT_ARGB8888;
... ...
@@ -102,7 +102,7 @@ screencapture(void)
102 102
 	fprintf(stderr, "Saved screenshot.bmp\n");
103 103
 }
104 104
 
105
-void
105
+static void
106 106
 quit(void)
107 107
 {
108 108
 	free(ppu.fg.pixels);
... ...
@@ -120,7 +120,7 @@ quit(void)
120 120
 	exit(0);
121 121
 }
122 122
 
123
-int
123
+static int
124 124
 init(void)
125 125
 {
126 126
 	SDL_AudioSpec as;
... ...
@@ -163,7 +163,7 @@ init(void)
163 163
 	return 1;
164 164
 }
165 165
 
166
-void
166
+static void
167 167
 domouse(SDL_Event *event)
168 168
 {
169 169
 	Uint8 flag = 0x00;
... ...
@@ -185,7 +185,7 @@ domouse(SDL_Event *event)
185 185
 	}
186 186
 }
187 187
 
188
-void
188
+static void
189 189
 doctrl(Uxn *u, SDL_Event *event, int z)
190 190
 {
191 191
 	Uint8 flag = 0x00;
... ...
@@ -219,7 +219,7 @@ doctrl(Uxn *u, SDL_Event *event, int z)
219 219
 
220 220
 #pragma mark - Devices
221 221
 
222
-void
222
+static void
223 223
 system_talk(Device *d, Uint8 b0, Uint8 w)
224 224
 {
225 225
 	if(!w) {
... ...
@@ -232,14 +232,14 @@ system_talk(Device *d, Uint8 b0, Uint8 w)
232 232
 	(void)b0;
233 233
 }
234 234
 
235
-void
235
+static void
236 236
 console_talk(Device *d, Uint8 b0, Uint8 w)
237 237
 {
238 238
 	if(w && b0 == 0x8)
239 239
 		write(1, (char *)&d->dat[0x8], 1);
240 240
 }
241 241
 
242
-void
242
+static void
243 243
 screen_talk(Device *d, Uint8 b0, Uint8 w)
244 244
 {
245 245
 	if(w && b0 == 0xe) {
... ...
@@ -258,7 +258,7 @@ screen_talk(Device *d, Uint8 b0, Uint8 w)
258 258
 	}
259 259
 }
260 260
 
261
-void
261
+static void
262 262
 file_talk(Device *d, Uint8 b0, Uint8 w)
263 263
 {
264 264
 	Uint8 read = b0 == 0xd;
... ...
@@ -300,7 +300,7 @@ audio_talk(Device *d, Uint8 b0, Uint8 w)
300 300
 	}
301 301
 }
302 302
 
303
-void
303
+static void
304 304
 datetime_talk(Device *d, Uint8 b0, Uint8 w)
305 305
 {
306 306
 	time_t seconds = time(NULL);
... ...
@@ -319,7 +319,7 @@ datetime_talk(Device *d, Uint8 b0, Uint8 w)
319 319
 	(void)w;
320 320
 }
321 321
 
322
-void
322
+static void
323 323
 nil_talk(Device *d, Uint8 b0, Uint8 w)
324 324
 {
325 325
 	(void)d;
... ...
@@ -329,7 +329,7 @@ nil_talk(Device *d, Uint8 b0, Uint8 w)
329 329
 
330 330
 #pragma mark - Generics
331 331
 
332
-int
332
+static int
333 333
 start(Uxn *u)
334 334
 {
335 335
 	evaluxn(u, 0x0100);