NrrdIoState * nrrdIoStateNew(void) { NrrdIoState *nio; nio = (NrrdIoState *)calloc(1, sizeof(NrrdIoState)); if (nio) { nio->path = NULL; nio->base = NULL; nio->line = NULL; nio->dataFNFormat = NULL; nio->dataFN = NULL; nio->headerStringRead = NULL; nio->headerStringWrite = NULL; void* pvoid = (void*)&(nio->dataFN); nio->dataFNArr = airArrayNew((void**)pvoid, NULL, sizeof(char *), NRRD_FILENAME_INCR); airArrayPointerCB(nio->dataFNArr, airNull, airFree); nio->format = nrrdFormatUnknown; nio->encoding = nrrdEncodingUnknown; nrrdIoStateInit(nio); } return nio; }
biffMsg * biffMsgNew(const char *key) { static const char me[]="biffMsgNew"; biffMsg *msg; if (!key) { fprintf(stderr, "%s: PANIC got NULL key\n", me); return NULL; /* exit(1); */ } msg = AIR_CALLOC(1, biffMsg); if (msg) { airPtrPtrUnion appu; msg->key = airStrdup(key); msg->err = NULL; msg->errNum = 0; appu.cp = &(msg->err); msg->errArr = airArrayNew(appu.v, &(msg->errNum), sizeof(char*), _MSG_INCR); if (msg->errArr) { airArrayPointerCB(msg->errArr, NULL, airFree); } } if (!( msg && msg->key && msg->errArr )) { fprintf(stderr, "%s: PANIC couldn't calloc new msg\n", me); return NULL; /* exit(1); */ } return msg; }
int tkwbReadFileToString(char **strP, int *hitEOF, FILE *file, char *stop) { char **all, line[AIR_STRLEN_HUGE]; airArray *allArr; unsigned int allLen; unsigned int lineLen, lineIdx, totalLen; _tkwbU uu; uu.pc = &all; allArr = airArrayNew(uu.v, &allLen, sizeof(char*), tkwbArrayIncr); airArrayPointerCB(allArr, airNull, airFree); lineLen = airOneLine(file, line, AIR_STRLEN_HUGE); totalLen = 0; while (lineLen && (!( airStrlen(stop) && !strcmp(line, stop) )) ) { lineIdx = airArrayLenIncr(allArr, 1); /* HEY error checking */ all[lineIdx] = (char *)calloc(strlen(line) + strlen("\n") + 1, sizeof(char)); sprintf(all[lineIdx], "%s\n", line); totalLen += strlen(line) + 1; lineLen = airOneLine(file, line, AIR_STRLEN_HUGE); } if (hitEOF) { *hitEOF = !lineLen; } *strP = (char*)calloc(totalLen+1, sizeof(char)); strcpy(*strP, ""); for (lineIdx=0; lineIdx<allLen; lineIdx++) { strcat(*strP, all[lineIdx]); } airArrayNuke(allArr); return 0; }
/* ******** nrrdNew() ** ** creates and initializes a Nrrd ** ** this does NOT use biff */ Nrrd * nrrdNew(void) { int ii; Nrrd *nrrd; nrrd = (Nrrd*)(calloc(1, sizeof(Nrrd))); if (!nrrd) { return NULL; } /* explicitly set pointers to NULL, since calloc isn't officially guaranteed to do that. */ nrrd->data = NULL; for (ii=0; ii<NRRD_DIM_MAX; ii++) { _nrrdAxisInfoNewInit(nrrd->axis + ii); } for (ii=0; ii<NRRD_SPACE_DIM_MAX; ii++) { nrrd->spaceUnits[ii] = NULL; } nrrd->content = NULL; nrrd->sampleUnits = NULL; /* create comment airArray (even though it starts empty) */ nrrd->cmt = NULL; void *pvoid = (void*)&(nrrd->cmt); nrrd->cmtArr = airArrayNew((void**)pvoid, NULL, sizeof(char *), NRRD_COMMENT_INCR); if (!nrrd->cmtArr) { return NULL; } airArrayPointerCB(nrrd->cmtArr, airNull, airFree); /* create key/value airArray (even thought it starts empty) */ nrrd->kvp = NULL; pvoid = &(nrrd->kvp); nrrd->kvpArr = airArrayNew((void**)pvoid, NULL, 2*sizeof(char *), NRRD_KEYVALUE_INCR); if (!nrrd->kvpArr) { return NULL; } /* key/value airArray uses no callbacks for now */ /* finish initializations */ nrrdInit(nrrd); return nrrd; }
echoScene * echoSceneNew(void) { echoScene *ret; ret = (echoScene *)calloc(1, sizeof(echoScene)); if (ret) { ret->cat = NULL; ret->catArr = airArrayNew((void**)&(ret->cat), NULL, sizeof(echoObject *), ECHO_LIST_OBJECT_INCR); airArrayPointerCB(ret->catArr, airNull, (void *(*)(void *))echoObjectNix); ret->rend = NULL; ret->rendArr = airArrayNew((void**)&(ret->rend), NULL, sizeof(echoObject *), ECHO_LIST_OBJECT_INCR); /* no callbacks set, renderable objecs are nixed from catArr */ ret->light = NULL; ret->lightArr = airArrayNew((void**)&(ret->light), NULL, sizeof(echoObject *), ECHO_LIST_OBJECT_INCR); /* no callbacks set; light objects are nixed from catArr */ ret->nrrd = NULL; ret->nrrdArr = airArrayNew((void**)&(ret->nrrd), NULL, sizeof(Nrrd *), ECHO_LIST_OBJECT_INCR); airArrayPointerCB(ret->nrrdArr, airNull, (void *(*)(void *))nrrdNuke); ret->envmap = NULL; ELL_3V_SET(ret->ambi, 1.0, 1.0, 1.0); ELL_3V_SET(ret->bkgr, 0.0, 0.0, 0.0); } return ret; }
/* ** _biffNewEntry() ** ** creates and initializes one new _biffEntry, returning a pointer to it ** panics and exit(1)s if there is a problem. */ _biffEntry * _biffNewEntry(const char *key) { char me[]="_biffInitEntry"; _biffEntry *ent; ent = (_biffEntry *)calloc(1, sizeof(_biffEntry)); if (!ent) { fprintf(stderr, "%s: couldn't make entry for new key \"%s\"\n", me, key); exit(1); } strcpy(ent->key, key); ent->AA = airArrayNew((void**)&(ent->err), &(ent->num), sizeof(char*), _BIFF_INCR); if (!ent->AA) { fprintf(stderr, "%s: couldn't make array for new key \"%s\"\n", me, key); exit(1); } airArrayPointerCB(ent->AA, NULL, airFree); return ent; }