/[cvs]/stack/stack.c
ViewVC logotype

Diff of /stack/stack.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.82 by masse, Thu Feb 14 19:49:48 2002 UTC revision 1.83 by masse, Thu Feb 14 22:44:49 2002 UTC
# Line 8  Line 8 
8  #include <dlfcn.h>  #include <dlfcn.h>
9  /* strcmp, strcpy, strlen, strcat, strdup */  /* strcmp, strcpy, strlen, strcat, strdup */
10  #include <string.h>  #include <string.h>
11    /* mtrace, muntrace */
12    #include <mcheck.h>
13    
14  #define HASHTBLSIZE 2048  #define HASHTBLSIZE 2048
15    
# Line 111  void free_val(value *val){ Line 113  void free_val(value *val){
113        free(val->content.ptr);        free(val->content.ptr);
114        break;        break;
115      }      }
116      free(val);          /* Free the actual list value */      free(val);          /* Free the actual value structure */
117    }    }
118  }  }
119    
# Line 177  void push_int(environment *env, int in_v Line 179  void push_int(environment *env, int in_v
179        
180    new_value->content.val= in_val;    new_value->content.val= in_val;
181    new_value->type= integer;    new_value->type= integer;
182    new_value->refcount= 1;    new_value->refcount= 0;
183    
184    push_val(env, new_value);    push_val(env, new_value);
185  }  }
# Line 190  void push_cstring(environment *env, cons Line 192  void push_cstring(environment *env, cons
192    new_value->content.ptr= malloc(strlen(in_string)+1);    new_value->content.ptr= malloc(strlen(in_string)+1);
193    strcpy(new_value->content.ptr, in_string);    strcpy(new_value->content.ptr, in_string);
194    new_value->type= string;    new_value->type= string;
195    new_value->refcount= 1;    new_value->refcount= 0;
196    
197    push_val(env, new_value);    push_val(env, new_value);
198  }  }
# Line 609  extern void pack(environment *env) Line 611  extern void pack(environment *env)
611    pack= malloc(sizeof(value));    pack= malloc(sizeof(value));
612    pack->type= list;    pack->type= list;
613    pack->content.ptr= temp;    pack->content.ptr= temp;
614    pack->refcount= 1;    pack->refcount= 0;
615    
616    push_val(env, pack);    push_val(env, pack);
617    rev(env);    rev(env);
# Line 738  extern void def(environment *env) Line 740  extern void def(environment *env)
740    
741  extern void clear(environment *);  extern void clear(environment *);
742  void forget_sym(symbol **);  void forget_sym(symbol **);
743    extern void words(environment *);
744    
745  /* Quit stack. */  /* Quit stack. */
746  extern void quit(environment *env)  extern void quit(environment *env)
# Line 745  extern void quit(environment *env) Line 748  extern void quit(environment *env)
748    long i;    long i;
749    
750    clear(env);    clear(env);
751    
752      words(env);
753    
754    if (env->err) return;    if (env->err) return;
755    for(i= 0; i<HASHTBLSIZE; i++) {    for(i= 0; i<HASHTBLSIZE; i++) {
756      while(env->symbols[i]!= NULL) {      while(env->symbols[i]!= NULL) {
# Line 752  extern void quit(environment *env) Line 758  extern void quit(environment *env)
758      }      }
759      env->symbols[i]= NULL;      env->symbols[i]= NULL;
760    }    }
761    
762      words(env);
763    
764      if(env->free_string!=NULL)
765        free(env->free_string);
766      
767      muntrace();
768    
769    exit(EXIT_SUCCESS);    exit(EXIT_SUCCESS);
770  }  }
771    
# Line 826  int main() Line 840  int main()
840  {  {
841    environment myenv;    environment myenv;
842    
843      mtrace();
844    
845    init_env(&myenv);    init_env(&myenv);
846    
847    while(1) {    while(1) {
# Line 1201  extern void to(environment *env) { Line 1217  extern void to(environment *env) {
1217    
1218    temp_val= malloc(sizeof(value));    temp_val= malloc(sizeof(value));
1219    temp_val->content.ptr= env->head;    temp_val->content.ptr= env->head;
1220    temp_val->refcount= 1;    temp_val->refcount= 0;
1221    temp_val->type= list;    temp_val->type= list;
1222    env->head= temp_head;    env->head= temp_head;
1223    push_val(env, temp_val);    push_val(env, temp_val);
# Line 1227  extern void read(environment *env) { Line 1243  extern void read(environment *env) {
1243    
1244    int itemp, readlength= -1;    int itemp, readlength= -1;
1245    static int depth= 0;    static int depth= 0;
1246    char *rest, *match;    char *match;
1247    size_t inlength;    size_t inlength;
1248    
1249    if(env->in_string==NULL) {    if(env->in_string==NULL) {
# Line 1244  extern void read(environment *env) { Line 1260  extern void read(environment *env) {
1260        
1261    inlength= strlen(env->in_string)+1;    inlength= strlen(env->in_string)+1;
1262    match= malloc(inlength);    match= malloc(inlength);
   rest= malloc(inlength);  
1263    
1264    if(sscanf(env->in_string, blankform, &readlength)!=EOF    if(sscanf(env->in_string, blankform, &readlength)!=EOF
1265       && readlength != -1) {       && readlength != -1) {
# Line 1272  extern void read(environment *env) { Line 1287  extern void read(environment *env) {
1287    } else {    } else {
1288      free(env->free_string);      free(env->free_string);
1289      env->in_string = env->free_string = NULL;      env->in_string = env->free_string = NULL;
     free(match);  
1290    }    }
1291    if ( env->in_string != NULL) {    if ( env->in_string != NULL) {
1292      env->in_string += readlength;      env->in_string += readlength;
1293    }    }
1294    
1295      free(match);
1296    
1297    if(depth)    if(depth)
1298      return read(env);      return read(env);
1299  }  }

Legend:
Removed from v.1.82  
changed lines
  Added in v.1.83

root@recompile.se
ViewVC Help
Powered by ViewVC 1.1.26