home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / DevTools / COWS / Code / COWSStateNode.m < prev    next >
Encoding:
Text File  |  1994-03-05  |  2.0 KB  |  116 lines

  1. /*
  2.     Copyright (C) 1994 Sean Luke
  3.  
  4.     COWSStateNode.m
  5.     Version 1.0
  6.     Sean Luke
  7.     
  8. */
  9.  
  10.  
  11.  
  12.  
  13. #import "COWSStateNode.h"
  14. #import "COWSInterpreter.h"
  15.  
  16. @implementation COWSStateNode
  17.  
  18. - init
  19.     {
  20.     id returnval=[super init];
  21.     dictionary=[[HashTable alloc] initKeyDesc:"*"valueDesc:"*"];
  22.     arguments=[[COWSArgumentList alloc] init];
  23.     pos=0;
  24.     return returnval;
  25.     }
  26.  
  27. - free
  28.     {
  29.     [dictionary freeObjects];
  30.     [dictionary free];
  31.     [arguments free];
  32.     return [super free];
  33.     }
  34.     
  35. - (int) pos
  36.     {
  37.     return pos;
  38.     }
  39.     
  40. - setPos:(int) this
  41.     {
  42.     pos=this;
  43.     return self;
  44.     }
  45.  
  46. - (COWSArgumentList*) arguments
  47.     {
  48.     return arguments;
  49.     }
  50.     
  51.     
  52. - (HashTable*) dictionary
  53.     {
  54.     return dictionary;
  55.     }
  56.  
  57. - printContents
  58.     {
  59.     id value_node;
  60.     const char *value;
  61.     const void *key;
  62.     NXHashState state=[dictionary initState];
  63.     printf ("\tARGS/VARS\n");
  64.     while ([dictionary nextState: &state key: &key value: (void*) &value_node])
  65.         {
  66.         char* temp=(char*)key;
  67.         value=[value_node string];
  68.         printf ("\tKEY:   #%s#\n\tVALUE: #%s#  %d  %d\n",(char*) key, 
  69.             (const char*) value,strlen(temp),
  70.                 (unsigned int)(temp[strlen(temp)-1]));
  71.         }
  72.     printf ("\tPOS:  %d\n",pos);
  73.     printf ("\tARG LIST\n");
  74.     [arguments printContents];
  75.     return self; 
  76.     }
  77.     
  78. - setArguments:this
  79.     {
  80.     [arguments free];
  81.     arguments=this;
  82.     return self;
  83.     }    
  84.     
  85. - setStringNoCopy:(char*) this_string
  86.     {
  87.     if (string!=NULL) free(string);
  88.     string=this_string;
  89.     return self;
  90.     }
  91.     
  92. - copy
  93.     {
  94.     const void*key;
  95.     void*value;
  96.     NXHashState state=[dictionary initState];
  97.     id copy_node=[[COWSStateNode alloc] init];
  98.     id new_dictionary;
  99.     
  100.     [copy_node setPos:[self pos]];
  101.     [copy_node setString:string];
  102.     [copy_node setError:error];
  103.     [copy_node setArguments:[arguments copy]];
  104.     new_dictionary=[copy_node dictionary];
  105.     while ([dictionary nextState:&state key: &key value: &value])
  106.         {
  107.         char* old_key=(char*) key;
  108.         id old_val=(COWSStringNode*) value;
  109.         id new_val=[[COWSStringNode alloc] init];
  110.         [new_val setString:[old_val string]];
  111.         [new_dictionary insertKey:newstr(old_key) value:(void*)new_val];
  112.         }
  113.     return copy_node;
  114.     }
  115.     
  116. @end