void rememberExtensions(const char *module, const PL_extension *e) { ExtensionCell cell = PL_malloc(sizeof *cell); cell->extensions = dupExtensions(e); cell->next = NULL; cell->module = dupStr(module); if ( ext_tail ) { ext_tail->next = cell; ext_tail = cell; } else { ext_head = ext_tail = cell; } }
DLLEXPORT(const char*) lookupStr(const char *s) { StrItem *t; unsigned int h = hashStr(s); if ((t = strTbl[h]) != 0) { do { if (qstricmp(t->s,s) == 0) { t->refCnt++; return t->s; } t = t->next; } while (t); } s = dupStr(s,0); strTbl[h] = newStrItem(s,strTbl[h]); return s; }
VObject* addGroup(VObject *o, const char *g) { /* a.b.c --> prop(c) prop(VCGrouping=b) prop(VCGrouping=a) */ char *dot = strrchr(g,'.'); if (dot) { VObject *p, *t; char *gs, *n = dot+1; gs = dupStr(g,0); /* so we can write to it. */ /* used to be * t = p = addProp_(o,lookupProp_(n)); */ t = p = addProp_(o,lookupProp(n)); dot = strrchr(gs,'.'); if (dot) { *dot = 0; do { dot = strrchr(gs,'.'); if (dot) { n = dot+1; *dot=0; } else n = gs; /* property(VCGroupingProp=n); * and the value may have VCGrouping property */ t = addProp(t,VCGroupingProp); setVObjectStringZValue(t,lookupProp_(n)); } while (n != gs); } else { t = addProp(t,VCGroupingProp); setVObjectStringZValue(t,lookupProp_(n)); } deleteStr(gs); return p; } else return addProp_(o,lookupProp(g)); }
const char* lookupStr(const char *s) { char *newS; StrItem *t; unsigned int h = hashStr(s); if ((t = strTbl[h]) != 0) { do { if (strcasecmp(t->s,s) == 0) { t->refCnt++; return t->s; } t = t->next; } while (t); } newS = dupStr(s,0); strTbl[h] = newStrItem(newS,strTbl[h]); return newS; }
static PL_extension * dupExtensions(const PL_extension *e) { int i; PL_extension *dup, *o; int len = 0; while(e[len++].predicate_name) ; o = dup = PL_malloc(len*sizeof(*e)); for ( i=0; i<len; i++, o++, e++) { o->predicate_name = dupStr(e->predicate_name); o->arity = e->arity; o->function = e->function; o->flags = e->flags; } return dup; }
vector * split(char * str, char * delim){ vector * v = createVector(); char *token; int count = 0; token = strtok(str, delim); while( token != NULL ) { token = strtok(NULL, delim); count++; } v->size=count; v->ar = calloc(sizeof(char*),count); token = str; for (int i = 0; i < count;i++) { ((char **)v->ar)[i] = dupStr(token); token += strlen(token) + 1; // get the next token by skipping past the '\0' token += strspn(token, delim); // then skipping any starting delimiters } return v; }
// returns HRESULT(ERROR_ALREADY_ASSIGNED) if the error has already been defined DrError AddEntry(DrExitCode code, const char *pszDescription) { DrError err = DrError_Fail; Lock(); if (FindEntry(code) != NULL) { err = HRESULT_FROM_WIN32( ERROR_ALREADY_ASSIGNED ); goto done; } int i = IndexOf(code); ExitCodeHashEntry *p = new ExitCodeHashEntry; LogAssert(p != NULL); p->value = code; p->pszDescription = dupStr(pszDescription); p->pNext = m_pBucket[i]; m_pBucket[i] = p; err = DrError_OK; done: Unlock(); return err; }
DLLEXPORT(VObject*) addPropSizedValue(VObject *o, const char *p, const char *v, unsigned int size) { return addPropSizedValue_(o,p,dupStr(v,size),size); }
DLLEXPORT(VObject*) setValueWithSize(VObject *prop, void *val, unsigned int size) { void *p = dupStr((const char *)val,size); return setValueWithSize_(prop,p,p?size:0); }
DLLEXPORT(void) setVObjectStringZValue(VObject *o, const char *s) { STRINGZ_VALUE_OF(o) = dupStr(s,0); VALUE_TYPE(o) = VCVT_STRINGZ; }
VObject* setValueWithSize(VObject *prop, void *val, unsigned int size) { void *p = dupStr(val,size); return setValueWithSize_(prop,p,p?size:0); }
void setVObjectUStringZValue(VObject *o, const wchar_t *s) { USTRINGZ_VALUE_OF(o) = (wchar_t*) dupStr((char*)s,(unsigned)(uStrLen(s)+1)*2); VALUE_TYPE(o) = VCVT_USTRINGZ; }
void setVObjectUStringZValue(VObject *o, const wchar_t *s) { size_t size = (size_t)((uStrLen(s)+1)*sizeof(wchar_t)); USTRINGZ_VALUE_OF(o) = (wchar_t*) dupStr((char*)s,size); VALUE_TYPE(o) = VCVT_USTRINGZ; }
static char *lexStr() { return dupStr(lexBuf.strs, lexBuf.strsLen + 1); }