-
Notifications
You must be signed in to change notification settings - Fork 3
/
commandsReadOld.cpp
161 lines (133 loc) · 3.95 KB
/
commandsReadOld.cpp
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
#include <vector>
#include <proto/exec.h>
#include <proto/dos.h>
#include "stack.h"
#include "amosKittens.h"
#include "commands.h"
#include "engine.h"
#include "debug.h"
#include "errors.h"
extern int last_var;
extern struct globalVar globalVars[];
extern int _last_var_index; // we need to know what index was to keep it.
extern int _set_var_index; // we need to resore index
char *_setVar( struct glueCommands *data, int nextToken );
char *_cmdRead( struct glueCommands *data, int nextToken );
char *FinderTokenInBuffer( char *ptr, unsigned short token , unsigned short token_eof1, unsigned short token_eof2, char *_eof_ );
void read_from_data()
{
unsigned short token;
int _len;
bool neg = false;
if (data_read_pointers[proc_stack_frame])
{
bool try_next_token;
do
{
try_next_token = false;
token = *((short *) data_read_pointers[proc_stack_frame]);
switch (token)
{
case 0x0404: // data
data_read_pointers[proc_stack_frame]+=4; // token + data size 2
neg = false;
try_next_token = true;
break;
case 0xFFCA: // negative number.
data_read_pointers[proc_stack_frame] +=2;
neg = true;
try_next_token = true;
break;
case 0x003E: // num
{
int num = *((int *) (data_read_pointers[proc_stack_frame] + 2));
setStackNum ( neg ? -num : num );
}
data_read_pointers[proc_stack_frame] +=6;
break;
case 0x0026: // string
_len = *((unsigned short *) (data_read_pointers[proc_stack_frame] + 2));
_len = _len + (_len & 1);
if (kittyStack[__stack].str) free(kittyStack[__stack].str);
kittyStack[__stack].str = strndup( data_read_pointers[proc_stack_frame] + 4, _len );
kittyStack[__stack].len = strlen( kittyStack[__stack].str );
data_read_pointers[proc_stack_frame] +=4 + _len;
break;
case 0x000c: // label
{
struct reference *ref = (struct reference *) (data_read_pointers[proc_stack_frame] + 2);
data_read_pointers[proc_stack_frame] += 2 + sizeof(struct reference) + ref -> length;
}
try_next_token = true;
break;
case 0x005C: // comma
data_read_pointers[proc_stack_frame] +=2;
neg = false;
try_next_token = true;
break;
case 0x0000: // new line
data_read_pointers[proc_stack_frame] +=4;
try_next_token = true;
break;
default:
printf("SHIT unkown token\n");
getchar();
data_read_pointers[proc_stack_frame] = FinderTokenInBuffer( data_read_pointers[proc_stack_frame], 0x0404 , -1, -1, _file_end_ );
try_next_token = true;
}
if (data_read_pointers[proc_stack_frame] == 0x0000) break;
} while ( try_next_token );
}
}
void _read_arg( struct nativeCommand *cmd, char *tokenBuffer )
{
int args = 0;
int num = 0;
double des = -1.0f;
struct glueCommands data;
proc_names_printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
if (cmd == NULL)
{
args =__stack - cmdTmp[cmdStack].stack + 1;
}
else
{
if (cmdStack) if (cmdTmp[cmdStack-1].cmd == _cmdRead)
{
args =__stack - cmdTmp[cmdStack-1].stack + 1;
}
}
if (last_var)
{
_set_var_index = globalVars[last_var -1].var.index;
read_from_data();
}
data.lastVar = last_var;
_setVar( &data,0 );
}
char *_cmdRead( struct glueCommands *data, int nextToken )
{
proc_names_printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
int args =__stack - data -> stack +1;
_read_arg( NULL, NULL );
popStack(__stack - data -> stack );
do_input[parenthesis_count] = do_std_next_arg;
do_breakdata = NULL;
return NULL;
}
char *cmdRead(struct nativeCommand *cmd, char *tokenBuffer )
{
proc_names_printf("%s:%s:%d\n",__FILE__,__FUNCTION__,__LINE__);
if (data_read_pointers[proc_stack_frame] == 0x0000)
{
printf("we are here\n");
setError( 25, tokenBuffer);
}
else
{
do_input[parenthesis_count] = _read_arg;
do_breakdata = NULL;
stackCmdNormal( _cmdRead, tokenBuffer );
}
return tokenBuffer;
}