home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright (C) 1994 Sean Luke
-
- COWSStringNode.m
- Version 1.0
- Sean Luke
-
- */
-
-
-
-
- #import "COWSStringNode.h"
- #import "COWSInterpreter.h"
- #import <string.h>
- #import <stdlib.h>
-
-
- @implementation COWSStringNode
-
- - init
- {
- id returnval=[super init];
- string= string=newstr("");
- error=NO;
- return returnval;
- }
-
- - (const char*) string
- {
- return string;
- }
-
- - setString:(const char*) this
- {
- if (this==NULL)
- {
- if (string!=NULL) free(string);
- string=NULL;
- return self;
- }
-
- if (string!=NULL)
- {
- if (strlen(this)<=strlen(string)) // needn't allocate more space
- {
- strcpy(string,this);
- return self;
- }
- // otherwise...
- free(string);
- }
- string=newstr(this);
- return self;
- }
-
- - setString:(const char*) this size:(int)this_size
- {
- if (this==NULL)
- {
- if (string!=NULL) free(string);
- string=NULL;
- return self;
- }
-
- if (string!=NULL)
- {
- if (this_size+1<=strlen(string)) // needn't allocate more space
- {
- strncpy(string,this,this_size);
- string[this_size]='\0'; // terminates it.
- return self;
- }
- // otherwise...
- free(string);
- }
- string=newstrn(this,this_size);
- return self;
- }
-
- - free
- {
- if (string!=NULL)
- {
- free(string);
- }
- return [super free];
- }
-
- - printContents
- {
- printf ("\t#%s#\n",string);
- return self;
- }
-
- - setError:(BOOL)true_or_false
- {
- error=true_or_false;
- return self;
- }
-
-
- - (BOOL) error
- {
- return error;
- }
-
- @end