forked from rileym65/Basic-02
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcnext.c
More file actions
57 lines (53 loc) · 1.76 KB
/
Copy pathcnext.c
File metadata and controls
57 lines (53 loc) · 1.76 KB
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
/*
*******************************************************************
*** This software is copyright 2021 by Michael H Riley ***
*** You have permission to use, modify, copy, and distribute ***
*** this software so long as this copyright notice is retained. ***
*** This software may not be used in commercial applications ***
*** without express written permission from the author. ***
*******************************************************************
*/
#include "header.h"
char* cnext(char* line) {
int pos;
word addr;
char hasVar;
char varname[256];
line = trim(line);
hasVar = 0;
if (*line == ':' || *line == 0) {
addr = 0;
}
else {
if (!(*line >= 'a' && *line <= 'z') && !(*line >= 'A' && *line <= 'Z')) {
showError("Invalid variable name");
exit(1);
}
pos = 0;
while ((*line >= 'a' && *line <= 'z') ||
(*line >= 'A' && *line <= 'Z') ||
(*line >= '0' && *line <= '9') ||
*line == '_') {
varname[pos++] = *line++;
}
varname[pos] = 0;
line = trim(line);
addr = getVariable(varname);
hasVar = -1;
}
if (hasVar == 0) {
Asm(" sep scall ; Call NEXT handler");
if (use32Bits) Asm(" dw next32");
else Asm(" dw next");
}
else {
sprintf(buffer," ldi v_%s.1 ; Get loop variable address",varname); Asm(buffer);
Asm(" phi rc");
sprintf(buffer," ldi v_%s.0",varname); Asm(buffer);
Asm(" plo rc");
Asm(" sep scall ; Call NEXT with var handler");
if (use32Bits) Asm(" dw nextvar32");
else Asm(" dw nextvar");
}
return line;
}