| 1267 |
push_sym(env, "["); |
push_sym(env, "["); |
| 1268 |
pack(env); if(env->err) return; |
pack(env); if(env->err) return; |
| 1269 |
} |
} |
| 1270 |
|
|
| 1271 |
|
/* Read a string */ |
| 1272 |
|
extern void readline(environment *env) { |
| 1273 |
|
char in_string[101]; |
| 1274 |
|
|
| 1275 |
|
fgets(in_string, 100, stdin); |
| 1276 |
|
push_cstring(&(env->head), in_string); |
| 1277 |
|
} |
| 1278 |
|
|
| 1279 |
|
/* Read a value and place on stack */ |
| 1280 |
|
extern void read(environment *env) { |
| 1281 |
|
const char symbform[]= "%[a-zA-Z0-9!$%*+./:<=>?@^_~-]%100c"; |
| 1282 |
|
const char strform[]= "\"%[^\"]\"%100c"; |
| 1283 |
|
const char intform[]= "%i%100c"; |
| 1284 |
|
const char blankform[]= "%*[ \t]%100c"; |
| 1285 |
|
const char ebrackform[]= "%*1[]]%100c"; |
| 1286 |
|
const char semicform[]= "%*1[;]%100c"; |
| 1287 |
|
const char bbrackform[]= "%*1[[]%100c"; |
| 1288 |
|
|
| 1289 |
|
int itemp, rerun= 0; |
| 1290 |
|
static int depth= 0; |
| 1291 |
|
char *rest, *match; |
| 1292 |
|
static char *in_string= NULL; |
| 1293 |
|
size_t inlength; |
| 1294 |
|
|
| 1295 |
|
if(in_string==NULL) { |
| 1296 |
|
readline(env); if(env->err) return; |
| 1297 |
|
|
| 1298 |
|
in_string= malloc(strlen(env->head->item->content.ptr)+1); |
| 1299 |
|
strcpy(in_string, env->head->item->content.ptr); |
| 1300 |
|
toss(env); if(env->err) return; |
| 1301 |
|
} |
| 1302 |
|
|
| 1303 |
|
inlength= strlen(in_string)+1; |
| 1304 |
|
match= malloc(inlength); |
| 1305 |
|
rest= malloc(inlength); |
| 1306 |
|
|
| 1307 |
|
if(sscanf(in_string, blankform, rest)) { |
| 1308 |
|
rerun= 1; |
| 1309 |
|
} else if(sscanf(in_string, intform, &itemp, rest) > 0) { |
| 1310 |
|
push_int(&(env->head), itemp); |
| 1311 |
|
} else if(sscanf(in_string, strform, match, rest) > 0) { |
| 1312 |
|
push_cstring(&(env->head), match); |
| 1313 |
|
} else if(sscanf(in_string, symbform, match, rest) > 0) { |
| 1314 |
|
push_sym(env, match); |
| 1315 |
|
} else if(sscanf(in_string, ebrackform, rest) > 0) { |
| 1316 |
|
push_sym(env, "["); |
| 1317 |
|
pack(env); if(env->err) return; |
| 1318 |
|
if(depth!=0) depth--; |
| 1319 |
|
} else if(sscanf(in_string, semicform, rest) > 0) { |
| 1320 |
|
push_sym(env, ";"); |
| 1321 |
|
} else if(sscanf(in_string, bbrackform, rest) > 0) { |
| 1322 |
|
push_sym(env, "["); |
| 1323 |
|
depth++; |
| 1324 |
|
} else { |
| 1325 |
|
free(rest); |
| 1326 |
|
rest= NULL; |
| 1327 |
|
rerun= 1; |
| 1328 |
|
} |
| 1329 |
|
|
| 1330 |
|
free(in_string); |
| 1331 |
|
free(match); |
| 1332 |
|
|
| 1333 |
|
in_string= rest; |
| 1334 |
|
|
| 1335 |
|
if(rerun || depth) |
| 1336 |
|
return read(env); |
| 1337 |
|
} |