LIST * compile_setexec( PARSE *parse, LOL *args, int *jmp ) { RULE *rule = bindrule( parse->string ); LIST *bindlist = (*parse->left->func)( parse->left, args, jmp ); /* Free old one, if present */ if( rule->actions ) { freestr( rule->actions ); list_free( rule->bindlist ); } rule->actions = copystr( parse->string1 ); rule->bindlist = bindlist; rule->flags = parse->num; /* commented out so jamgram.y can compile #ifdef OPT_ACTION_MAXTARGETS_EXT */ rule->maxline = parse->num2; rule->maxtargets = parse->num3; /* commented out so jamgram.y can compile #endif */ return L0; }
void freefargs( /* free object arguments */ FUNARGS *fa ) { int i; if (fa->nsargs) { for (i = 0; i < fa->nsargs; i++) freestr(fa->sarg[i]); free((void *)fa->sarg); fa->sarg = NULL; fa->nsargs = 0; } #ifdef IARGS if (fa->niargs) { free((void *)fa->iarg); fa->iarg = NULL; fa->niargs = 0; } #endif if (fa->nfargs) { free((void *)fa->farg); fa->farg = NULL; fa->nfargs = 0; } }
static void setivar( /* set an intermediate variable */ char *vname, char *fname, char *definition ) { IVAR ivbeg; register IVAR *iv; scompile(definition, fname, 0); /* compile the string */ ivbeg.next = ivhead; for (iv = &ivbeg; iv->next != NULL; iv = iv->next) if (!strcmp(vname, iv->next->name)) { iv = iv->next; freestr(iv->dfn); iv->dfn = savestr(definition); return; } iv->next = (IVAR *)emalloc(sizeof(IVAR)); iv = iv->next; iv->name = savestr(vname); iv->dfn = savestr(definition); iv->next = NULL; ivhead = ivbeg.next; }
void epfree( /* free a parse tree */ EPNODE *epar ) { EPNODE *ep; switch (epar->type) { case VAR: varfree(epar->v.ln); break; case SYM: freestr(epar->v.name); break; case NUM: case CHAN: case ARG: case CLKT: break; default: while ((ep = epar->v.kid) != NULL) { epar->v.kid = ep->sibling; epfree(ep); } break; } efree((char *)epar); }
int yyline() { struct include * i = incp; if ( !incp ) return EOF; /* Once we start reading from the input stream, we reset the include * insertion point so that the next include file becomes the head of the * list. */ /* If there is more data in this line, return it. */ if ( *i->string ) return *i->string++; /* If we are reading from an internal string list, go to the next string. */ if ( i->strings ) { if ( *i->strings ) { ++i->line; i->string = *(i->strings++); return *i->string++; } } else { /* If necessary, open the file. */ if ( !i->file ) { FILE * f = stdin; if ( strcmp( i->fname, "-" ) && !( f = fopen( i->fname, "r" ) ) ) perror( i->fname ); i->file = f; } /* If there is another line in this file, start it. */ if ( i->file && fgets( i->buf, sizeof( i->buf ), i->file ) ) { ++i->line; i->string = i->buf; return *i->string++; } } /* This include is done. Free it up and return EOF so yyparse() returns to * parse_file(). */ incp = i->next; /* Close file, free name. */ if ( i->file && ( i->file != stdin ) ) fclose( i->file ); freestr( i->fname ); BJAM_FREE( (char *)i ); return EOF; }
/* * actions_free() - release a reference to the given actions */ void actions_free(rule_actions* a) { if (--a->reference_count <= 0) { freestr(a->command); list_free(a->bindlist); free(a); } }
void upb_fielddef_setdefault(upb_fielddef *f, upb_value value) { assert(f->type_is_set_); assert(!upb_fielddef_isfrozen(f)); assert(!upb_fielddef_isstring(f) && !upb_fielddef_issubmsg(f)); if (f->default_is_string) { str_t *s = upb_value_getptr(f->defaultval); assert(s); freestr(s); } f->defaultval = value; f->default_is_string = false; }
/* print a CExoString field */ void print_exostr(void) { unsigned i; CExoString str = getstr(); for (i = 0; i < str.Size; i++) { putchar(str.Str[i]); } freestr(str); putchar('\n'); }
void call_bind_rule( char* target_, char* boundname_ ) { LIST* bind_rule = var_get( "BINDRULE" ); if( bind_rule ) { /* No guarantee that target is an allocated string, so be on the * safe side */ char* target = copystr( target_ ); /* Likewise, don't rely on implementation details of newstr.c: allocate * a copy of boundname */ char* boundname = copystr( boundname_ ); if( boundname && target ) { /* Prepare the argument list */ FRAME frame[1]; frame_init( frame ); /* First argument is the target name */ lol_add( frame->args, list_new( L0, target ) ); lol_add( frame->args, list_new( L0, boundname ) ); if( lol_get( frame->args, 1 ) ) evaluate_rule( bind_rule->string, frame ); /* Clean up */ frame_free( frame ); } else { if( boundname ) freestr( boundname ); if( target ) freestr( target ); } } }
void add_env_include_dirs(HSCPRC *hp) { STRPTR incp = getenv(ENV_HSCINCLUDE); if(NULL != incp) { STRPTR s = strclone(incp); STRPTR t = strtok(s,PATHL_SEPARATOR); hsc_add_include_directory(hp,t); while(NULL != (t = strtok(NULL,PATHL_SEPARATOR))) { hsc_add_include_directory(hp,t); } freestr(s); } }
void fargs( /* free any arguments p has */ register PRIMITIVE *p ) { if (p->args != NULL) { freestr(p->args); p->args = NULL; } }
/* * global_rule() - given a rule, produce the corresponding entry in the global module */ static RULE* global_rule( RULE* r ) { if ( r->module == root_module() ) { return r; } else { char* name = global_rule_name( r ); RULE* result = define_rule( r->module, name, root_module() ); freestr(name); return result; } }
static bool checksetdefault(upb_fielddef *f, upb_fieldtype_t type) { if (!f->type_is_set_ || upb_fielddef_isfrozen(f) || upb_fielddef_type(f) != type) { assert(false); return false; } if (f->default_is_string) { str_t *s = f->defaultval.bytes; assert(s); freestr(s); } f->default_is_string = false; return true; }
void parse_free( PARSE *p ) { if( --p->refs ) return; if( p->string ) freestr( p->string ); if( p->string1 ) freestr( p->string1 ); if( p->left ) parse_free( p->left ); if( p->right ) parse_free( p->right ); if( p->third ) parse_free( p->third ); #ifdef OPT_IMPROVED_MEMUSE_EXT mempool_free(parse_pool, p); #else free( (char *)p ); #endif }
static void undefine( /* undefine a variable */ register VARIABLE *vp ) { if (vp == NULL || !(vp->flags & DEFINED)) return; switch (vp->type) { case REAL: case FUNCTION: dremove(vp->name); freestr(vp->v.dfn); break; case STRING: freestr(vp->v.s); break; case DATA: efree((char *)vp->v.d.data); break; } vp->flags &= ~DEFINED; }
void freemesh(MESH *ms) /* free mesh data */ { MESH mhead; MESH *msp; if (ms == NULL) return; if (ms->nref <= 0) error(CONSISTENCY, "unreferenced mesh in freemesh"); ms->nref--; if (ms->nref) /* still in use */ return; /* else remove from list */ mhead.next = mlist; for (msp = &mhead; msp->next != NULL; msp = msp->next) if (msp->next == ms) { msp->next = ms->next; ms->next = NULL; break; } if (ms->next != NULL) /* can't be in list anymore */ error(CONSISTENCY, "unlisted mesh in freemesh"); mlist = mhead.next; /* free mesh data */ freestr(ms->name); octfree(ms->mcube.cutree); lu_done(&ms->lut); if (ms->npatches > 0) { MESHPATCH *pp = ms->patch + ms->npatches; while (pp-- > ms->patch) { if (pp->j2tri != NULL) free((void *)pp->j2tri); if (pp->j1tri != NULL) free((void *)pp->j1tri); if (pp->tri != NULL) free((void *)pp->tri); if (pp->uv != NULL) free((void *)pp->uv); if (pp->norm != NULL) free((void *)pp->norm); if (pp->xyz != NULL) free((void *)pp->xyz); } free((void *)ms->patch); } if (ms->pseudo != NULL) free((void *)ms->pseudo); free((void *)ms); }
void rule_free( RULE* r ) { freestr( r->name ); r->name = ""; parse_free( r->procedure ); r->procedure = 0; if ( r->arguments ) args_free( r->arguments ); r->arguments = 0; if ( r->actions ) actions_free( r->actions ); r->actions = 0; }
LIST * list_new( LIST *head, const char *string, int copy ) { LIST *l; if( DEBUG_LISTS ) printf( "list > %s <\n", string ); /* Copy/newstr as needed */ string = copy ? copystr( string ) : newstr( string ); /* Get list struct from freelist, if one available. */ /* Otherwise allocate. */ /* If from freelist, must free string first */ if( freelist ) { l = freelist; freestr( l->string ); freelist = freelist->next; } else { #ifdef OPT_IMPROVED_MEMUSE_EXT if (!list_pool) { list_pool = mempool_create("LIST", sizeof(LIST)); } l = mempool_alloc(list_pool); #else l = (LIST *)malloc( sizeof( *l ) ); #endif } /* If first on chain, head points here. */ /* If adding to chain, tack us on. */ /* Tail must point to this new, last element. */ if( !head ) head = l; else head->tail->next = l; head->tail = l; l->next = 0; l->string = string; return head; }
void freesettings( SETTINGS *v ) { while( v ) { SETTINGS *n = v->next; freestr( v->symbol ); list_free( v->value ); free( (char *)v ); v = n; } }
void pfree( /* free a primitive */ register PRIMITIVE *p ) { if (p->args != NULL) { freestr(p->args); p->args = NULL; } push(p, &freelist); nalloc--; }
void mgclearall(void) /* clear all variable settings */ { int j; register IVAR *iv; register int i; for (iv = ivhead; iv != NULL; iv = iv->next) { dremove(iv->name); freestr(iv->name); freestr(iv->dfn); efree((char *)iv); } ivhead = NULL; for (i = 0; i < NVARS; i++) if (gparam[i].flags & DEFINED) undefine(&gparam[i]); for (j = 0; j < MAXCUR; j++) for (i = 0; i < NCVARS; i++) if (cparam[j][i].flags & DEFINED) undefine(&cparam[j][i]); }
void typestr::allocstr(size_t size) { freestr(); if (size <= buffersize) { m_str = m_buffer; m_size = buffersize; } else { m_str = (char *) malloc(size); m_size = size; } *m_str = '\0'; }
void freesettings( SETTINGS *v ) { while( v ) { SETTINGS *n = v->next; freestr( v->symbol ); list_free( v->value ); v->next = settings_freelist; settings_freelist = v; v = n; } }
// Rule formatted string init void typestr::rulestr(const char *s) { if (!s || !*s || !*(s + 1)) { freestr(); return; } int i=1, j=0; allocstr(strlen(s) + 1); while(s[i]) { switch(s[i]) { case '$' : if (s[i+1]=='$') m_str[j++] = s[++i]; else m_str[j++] = START_OF_FIELD; ++i; break; case '\\' : // hex value ++i; if (s[i]=='\\' || s[i]=='$') m_str[j++]=s[i++]; else { int d=s[i++]; int u=s[i++]; if (d>='0' && d<='9') d-='0'; else if (d>='A' && d<='F') d-='A'-10; else if (d>='a' && d<='f') d-='a'-10; if (u>='0' && u<='9') u-='0'; else if (u>='A' && u<='F') u-='A'-10; else if (u>='a' && u<='f') u-='a'-10; m_str[j++]=16*d+u; } break; default : m_str[j++]=s[i++]; } } m_str[j-1]=0; }
bool upb_fielddef_setdefaultstr(upb_fielddef *f, const void *str, size_t len, upb_status *s) { assert(upb_fielddef_isstring(f) || f->type_ == UPB_TYPE_ENUM); if (f->type_ == UPB_TYPE_ENUM && !upb_isident(str, len, false, s)) return false; if (f->default_is_string) { str_t *s = upb_value_getptr(f->defaultval); assert(s); freestr(s); } else { assert(f->type_ == UPB_TYPE_ENUM); } str_t *str2 = newstr(str, len); upb_value_setptr(&f->defaultval, str2); f->default_is_string = true; return true; }
void plfree( /* free a primitive list */ register PLIST *pl ) { register PRIMITIVE *p; for (p = pl->ptop; p != NULL; p = p->pnext) { if (p->args != NULL) { freestr(p->args); p->args = NULL; } nalloc--; } append(pl, &freelist); pl->ptop = pl->pbot = NULL; }
char* typestr::str(const char *str, size_t maxlen /*= 0*/) { if (!str) { freestr(); return NULL; } size_t needed = 1 + (maxlen > 0 ? maxlen : strlen(str)); if (m_size < needed) { allocstr(needed); } if (maxlen > 0) { strncpy(m_str, str, maxlen); m_str[maxlen] = '\0'; } else strcpy(m_str, str); return m_str; }
bool upb_fielddef_resolveenumdefault(upb_fielddef *f, upb_status *s) { if (!upb_fielddef_default_is_symbolic(f)) return true; str_t *str = upb_value_getptr(f->defaultval); const upb_enumdef *e = upb_downcast_enumdef(upb_fielddef_subdef(f)); assert(str); // Points to either a real default or the empty string. assert(e); if (str->len == 0) { // The "default default" for an enum is the first defined value. upb_value_setint32(&f->defaultval, e->defaultval); } else { int32_t val = 0; if (!upb_enumdef_ntoi(e, str->str, &val)) { upb_status_seterrf(s, "enum default not found in enum (%s)", str->str); return false; } upb_value_setint32(&f->defaultval, val); } f->default_is_string = false; freestr(str); return true; }
LIST * list_new( LIST *head, char *string ) { LIST *l; if( DEBUG_LISTS ) printf( "list > %s <\n", string ); /* Get list struct from freelist, if one available. */ /* Otherwise allocate. */ /* If from freelist, must free string first */ if( freelist ) { l = freelist; freestr( l->string ); freelist = freelist->next; } else { l = (LIST *)malloc( sizeof( *l ) ); } /* If first on chain, head points here. */ /* If adding to chain, tack us on. */ /* Tail must point to this new, last element. */ if( !head ) head = l; else head->tail->next = l; head->tail = l; l->next = 0; l->string = string; return head; }
LIST * compile_setexec( PARSE *parse, LOL *args, int *jmp ) { RULE *rule = bindrule( parse->string ); LIST *bindlist = (*parse->left->func)( parse->left, args, jmp ); /* Free old one, if present */ if( rule->actions ) { freestr( rule->actions ); list_free( rule->bindlist ); } rule->actions = copystr( parse->string1 ); rule->bindlist = bindlist; rule->flags = parse->num; return L0; }