162 |
return 1; |
return 1; |
163 |
} |
} |
164 |
|
|
165 |
|
void printerr(const char* in_string) { |
166 |
|
fprintf(stderr, "Err: %s\n", in_string); |
167 |
|
} |
168 |
|
|
169 |
/* Discard the top element of the stack. */ |
/* Discard the top element of the stack. */ |
170 |
extern void toss(stackitem** stack_head) |
extern void toss(stackitem** stack_head) |
171 |
{ |
{ |
172 |
stackitem* temp= *stack_head; |
stackitem* temp= *stack_head; |
173 |
|
|
174 |
if((*stack_head)==NULL) |
if((*stack_head)==NULL) { |
175 |
|
printerr("Stack empty"); |
176 |
return; |
return; |
177 |
|
} |
178 |
|
|
179 |
if((*stack_head)->type==string) |
if((*stack_head)->type==string) |
180 |
free((*stack_head)->content.ptr); |
free((*stack_head)->content.ptr); |
192 |
/* Prints the top element of the stack. */ |
/* Prints the top element of the stack. */ |
193 |
void print_(stackitem** stack_head) |
void print_(stackitem** stack_head) |
194 |
{ |
{ |
195 |
if((*stack_head)==NULL) |
if((*stack_head)==NULL) { |
196 |
|
printerr("Stack empty"); |
197 |
return; |
return; |
198 |
|
} |
199 |
|
|
200 |
switch((*stack_head)->type) { |
switch((*stack_head)->type) { |
201 |
case value: |
case value: |
238 |
if(*stack_head != NULL) { |
if(*stack_head != NULL) { |
239 |
print_st(*stack_head, 1); |
print_st(*stack_head, 1); |
240 |
printf("\n"); |
printf("\n"); |
241 |
|
} else { |
242 |
|
printerr("Stack empty"); |
243 |
} |
} |
244 |
} |
} |
245 |
|
|
249 |
{ |
{ |
250 |
funcp in_func; |
funcp in_func; |
251 |
|
|
252 |
if((*stack_head)==NULL || (*stack_head)->type!=ref) |
if((*stack_head)==NULL || (*stack_head)->type!=ref) { |
253 |
|
printerr("Stack empty or not a reference"); |
254 |
return; |
return; |
255 |
|
} |
256 |
|
|
257 |
if(((stackitem*)(*stack_head)->content.ptr)->type==func) { |
if(((stackitem*)(*stack_head)->content.ptr)->type==func) { |
258 |
in_func= (funcp)((stackitem*)(*stack_head)->content.ptr)->content.ptr; |
in_func= (funcp)((stackitem*)(*stack_head)->content.ptr)->content.ptr; |
259 |
toss(stack_head); |
toss(stack_head); |
260 |
(*in_func)(stack_head); |
(*in_func)(stack_head); |
261 |
return; |
return; |
262 |
} |
} else |
263 |
|
printerr("Not a function"); |
264 |
} |
} |
265 |
|
|
266 |
/* Parse input. */ |
/* Parse input. */ |
323 |
void* delimiter; |
void* delimiter; |
324 |
stackitem *iterator, *temp, *pack; |
stackitem *iterator, *temp, *pack; |
325 |
|
|
326 |
if((*stack_head)==NULL) /* No delimiter */ |
if((*stack_head)==NULL) { |
327 |
|
printerr("Stack empty"); |
328 |
return; |
return; |
329 |
|
} |
330 |
|
|
331 |
delimiter= (*stack_head)->content.ptr; /* Get delimiter */ |
delimiter= (*stack_head)->content.ptr; /* Get delimiter */ |
332 |
toss(stack_head); |
toss(stack_head); |
359 |
stackitem *temp, *new_head; |
stackitem *temp, *new_head; |
360 |
|
|
361 |
/* Is top element a list? */ |
/* Is top element a list? */ |
362 |
if((*stack_head)==NULL || (*stack_head)->type!=list) |
if((*stack_head)==NULL || (*stack_head)->type!=list) { |
363 |
|
printerr("Stack empty or not a list"); |
364 |
return; |
return; |
365 |
|
} |
366 |
|
|
367 |
/* The first list element is the new stack head */ |
/* The first list element is the new stack head */ |
368 |
new_head= temp= (*stack_head)->content.ptr; |
new_head= temp= (*stack_head)->content.ptr; |
382 |
{ |
{ |
383 |
stackitem* temp= (*stack_head); |
stackitem* temp= (*stack_head); |
384 |
|
|
385 |
if((*stack_head)==NULL || (*stack_head)->next==NULL) |
if((*stack_head)==NULL) { |
386 |
|
printerr("Stack empty"); |
387 |
|
return; |
388 |
|
} |
389 |
|
|
390 |
|
if((*stack_head)->next==NULL) |
391 |
return; |
return; |
392 |
|
|
393 |
*stack_head= (*stack_head)->next; |
*stack_head= (*stack_head)->next; |
401 |
void *left, *right; |
void *left, *right; |
402 |
int result; |
int result; |
403 |
|
|
404 |
if((*stack_head)==NULL || (*stack_head)->next==NULL) |
if((*stack_head)==NULL || (*stack_head)->next==NULL) { |
405 |
|
printerr("Not enough elements to compare"); |
406 |
return; |
return; |
407 |
|
} |
408 |
|
|
409 |
left= (*stack_head)->content.ptr; |
left= (*stack_head)->content.ptr; |
410 |
swap(stack_head); |
swap(stack_head); |
420 |
{ |
{ |
421 |
int value; |
int value; |
422 |
|
|
423 |
if((*stack_head)==NULL || (*stack_head)->type!=value) |
if((*stack_head)==NULL || (*stack_head)->type!=value) { |
424 |
|
printerr("Stack empty or element is not a value"); |
425 |
return; |
return; |
426 |
|
} |
427 |
|
|
428 |
value= (*stack_head)->content.val; |
value= (*stack_head)->content.val; |
429 |
toss(stack_head); |
toss(stack_head); |
444 |
stackitem *temp, *value; |
stackitem *temp, *value; |
445 |
|
|
446 |
if(*stack_head==NULL || (*stack_head)->next==NULL |
if(*stack_head==NULL || (*stack_head)->next==NULL |
447 |
|| (*stack_head)->type!=ref) |
|| (*stack_head)->type!=ref) { |
448 |
|
printerr("Define what?"); |
449 |
return; |
return; |
450 |
|
} |
451 |
|
|
452 |
temp= (*stack_head)->content.ptr; |
temp= (*stack_head)->content.ptr; |
453 |
value= (*stack_head)->next; |
value= (*stack_head)->next; |