static DWORD ReadNextLine( FILE* fp, PSTR *output, PBOOLEAN pbEndOfFile ) { DWORD dwError = 0; DynamicArray buffer; const char nullTerm = '\0'; *pbEndOfFile = 0; *output = NULL; memset(&buffer, 0, sizeof(buffer)); dwError = LWSetCapacity(&buffer, 1, 100); BAIL_ON_MAC_ERROR(dwError); while(1) { if(fgets((char*)buffer.data + buffer.size, buffer.capacity - buffer.size, fp) == NULL) { if (feof(fp)) { *pbEndOfFile = 1; } else { dwError = errno; BAIL_ON_MAC_ERROR(dwError); } } buffer.size += strlen((char*)buffer.data + buffer.size); if(*pbEndOfFile) break; if(buffer.size == buffer.capacity - 1 && ((char *)buffer.data)[buffer.size - 1] != '\n') { dwError = LWSetCapacity(&buffer, 1, buffer.capacity * 2); BAIL_ON_MAC_ERROR(dwError); } else break; } dwError = LWArrayAppend(&buffer, 1, &nullTerm, 1); BAIL_ON_MAC_ERROR(dwError); *output = (PSTR)buffer.data; buffer.data = NULL; cleanup: ArrayFree(&buffer); return dwError; error: goto cleanup; }
AsmCode* AsmCodeNew(char *line) { AsmCode* code = ObjNew(AsmCode,1); char head[MAX_LEN]; strCut(line, "/", head, NULL); Array* tokens = split(head, " \t+[],", REMOVE_SPLITER); if (tokens->count == 0) { ArrayFree(tokens, strFree); ObjFree(code); return NULL; } code->line = strNew(head); strTrim(code->line, code->line, SPACE); code->tokens = tokens; int tokenIdx = 0; if (strTail(tokens->item[0], ":")) { code->label = ArrayGet(tokens, tokenIdx++); strTrim(code->label, code->label, ":"); } else code->label = NULL; code->op = ArrayGet(tokens, tokenIdx++); code->opCode = OP_NULL; code->argStart = tokenIdx; code->arg[0] = ArrayGet(tokens, tokenIdx++); code->arg[1] = ArrayGet(tokens, tokenIdx++); code->arg[2] = ArrayGet(tokens, tokenIdx++); // AsmCodePrintln(code); return code; }
bool ModelFree(Model* model) { if(model->parent) { ModelRemove(model->parent, model); model->parent = NULL; } while(ArrayLength(model->child)) { Model* child = (Model*)ArrayObjectAtIndex(model->child, 0); ModelRemove(model, child); child->parent = NULL; } ArrayFree(&model->child); free(model->mixColor); model->mixColor = NULL; free(model->color); model->color = NULL; free(model->matrix); model->matrix = NULL; free(model->matrixGlobal); model->matrixGlobal = NULL; return true; }
void AsmCodeFree(AsmCode *code) { strFree(code->line); ArrayFree(code->tokens, strFree); if (code->objCode != NULL) ObjFree(code->objCode); ObjFree(code); }
//////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // UDP Layer must be initialized // Shutdown should only happen if following is met: // Apps can call this function after they have shutdown message handlers (SDKs), // and verified there are no message handlers remaining. Calling the function // gsUdpEngineNoMoreMsgHandlers will do this. // Message handlers cannot call this function without checking if there no more // message handlers remaining and if there is no app (gsUdpEngineNoApp). GSUdpErrorCode gsUdpEngineShutdown() { GSUdpEngineObject *aUdp = gsUdpEngineGetEngine(); GS_ASSERT(aUdp->mInitialized); if (!aUdp->mInitialized) { gsDebugFormat(GSIDebugCat_Common, GSIDebugType_Network, GSIDebugLevel_Debug, "[Udp Engine] Engine not initialized\n"); return GS_UDP_NETWORK_ERROR; } gt2CloseSocket(aUdp->mSocket); ArrayFree(aUdp->mMsgHandlers); ArrayFree(aUdp->mRemotePeers); aUdp->mInitialized = gsi_false; return GS_UDP_NO_ERROR; }
void gpiDestroyPeer( GPConnection * connection, GPIPeer * peer ) { #ifndef NOFILE // Cleanup any transfers that use this peer. //////////////////////////////////////////// gpiTransferPeerDestroyed(connection, peer); #endif //shutdown(peer->sock, 2); //closesocket(peer->sock); freeclear(peer->inputBuffer.buffer); freeclear(peer->outputBuffer.buffer); if(peer->messages) { ArrayFree(peer->messages); peer->messages = NULL; } freeclear(peer); GSI_UNUSED(connection); }
void AsmPass1(Assembler *a, char *text) { // 第一階段的組譯 int i, address = 0, number; Array* lines = split(text, "\r\n", REMOVE_SPLITER); // 將組合語言分割成一行一行 ArrayEach(lines, strPrintln); // 印出以便觀察 printf("=================PASS1================\n"); for (i=0; i<lines->count; i++) { // 對於每一行 strReplace(lines->item[i], ";", '\0'); strReplace(lines->item[i], "\t", ' '); AsmCode *code = AsmCodeNew(lines->item[i]); // 建立指令物件 if (code == NULL) continue; code->address = address; // 設定該行的位址 Op *op = NULL; if (code->op != NULL) { op = HashTableGet(opTable, code->op); // 查詢運算碼 if (op != NULL) { // 如果查到 code->opCode = op->code; // 設定運算碼 code->type = op->type; // 設定型態 } } if (code->label != NULL) // 如果有標記符號 HashTablePut(a->symTable, code->label, code); // 加入符號表中 ArrayAdd(a->codes, code); // 建構指令物件陣列 AsmCodePrintln(code); // 印出觀察 code->size = AsmCodeSize(code); // 計算指令大小 address += code->size; // 計算下一個指令位址 } ArrayFree(lines, strFree); // 釋放記憶體 }
/* #ifndef __vstrf_defined #define __vstrf_defined char *vstrf(char *format,va_list ap) { int len; char *str,dummy[1]; len = vsnprintf(dummy,0,format,ap); str = ArrayAlloc(len,sizeof(char)); vsprintf(str,format,ap); return str; } #endif */ int WriteF(Stream *st,char *format,...) { va_list ap; char* str; int ret; va_start(ap, format); str = vstrf(format,ap); va_end(ap); ret = WriteArray(st,str); ArrayFree(str); return ret; }
static GPIBool gpiDisconnectCleanupProfile( GPConnection * connection, GPIProfile * profile, void * data ) { GPIConnection * iconnection = (GPIConnection*)*connection; GSI_UNUSED(data); // Even if we cache buddy/block info, free it up to get rid of mem // leaks, just don't remove the profile until we save the cache. ////////////////////////////////////////////////////////////////// if(profile->buddyStatus) { profile->buddyOrBlockCache = gsi_true; freeclear(profile->buddyStatus->statusString); freeclear(profile->buddyStatus->locationString); freeclear(profile->buddyStatus); } if (profile->buddyStatusInfo) { profile->buddyOrBlockCache = gsi_true; freeclear(profile->buddyStatusInfo->richStatus); freeclear(profile->buddyStatusInfo->gameType); freeclear(profile->buddyStatusInfo->gameVariant); freeclear(profile->buddyStatusInfo->gameMapName); if (profile->buddyStatusInfo->extendedInfoKeys) { ArrayFree(profile->buddyStatusInfo->extendedInfoKeys); profile->buddyStatusInfo->extendedInfoKeys = NULL; } freeclear(profile->buddyStatusInfo); } if (profile->blocked) profile->buddyOrBlockCache = gsi_true; freeclear(profile->authSig); freeclear(profile->peerSig); profile->requestCount = 0; // Remove Profile if: // (there is no info to cache) or // (we only cache buddies/blocked and the user is not a buddy or a block) if ((!profile->cache) || (iconnection->infoCachingBuddyAndBlockOnly==GPITrue && !profile->buddyOrBlockCache)) { gpiRemoveProfile(connection, profile); return GPIFalse; } return GPITrue; }
void TableFree(HashTable table) { int i; if(!table) gspyi.error("TableFree: table is NULL."); for (i = 0 ; i < table->nbuckets ; i++) { ArrayFree(table->buckets[i]); table->buckets[i] = NULL; } free(table->buckets); table->buckets = NULL; free(table); table = NULL; }
/* ** FUNCTION: ArrayTrim ** PURPOSE: Trim the tail of an array to a given length. ** INPUT: {ARRAY *a}, ** pointer to the array. ** {int n}, ** length of the final array. ** {void (*FreeElem)(void *)}, ** a function called before freeing each element. ** RETURN: {int}, ** always 0. ** SIDE EFFECT: ** NOTE: if the length of array is <= n, nothing happens. */ int ArrayTrim(ARRAY *a, int n) { DATA *p; void *pt; int i; if (!a) return 0; if (a->dim <= n) return 0; if (n == 0) { ArrayFree(a); return 0; } i = n; p = a->data; while (i >= a->block) { p = p->next; i -= a->block; } if (i == 0) { ArrayFreeData(a, p); p = NULL; } else { if (p->next) { ArrayFreeData(a, p->next); p->next = NULL; } if (p->dptr && a->FreeElem) { pt = ((char *) p->dptr) + i*(a->esize); for (; i < a->block; i++) { a->FreeElem(pt); pt = ((char *) pt) + a->esize; } } } a->dim = n; return 0; }
GPResult gpiDestroyNpBasic( GPConnection * connection ) { GPIConnection * iconnection = (GPIConnection*)*connection; // Explicitly destroy title context we used for lookup ////////////////////////////////////////////////////// if (iconnection->npLookupTitleCtxId >= 0) sceNpLookupDestroyTitleCtx(iconnection->npLookupTitleCtxId); // Do not destroy NpLookup or NpBasic if Game is using it ///////////////////////////////////////////////////////// if (!iconnection->npLookupGameInitialized) sceNpLookupTerm(); if (!iconnection->npBasicGameInitialized) { sceNpBasicUnregisterHandler(); // Obsolete? sceNpBasicTerm(); sceNpTerm(); } // Free up transaction list used for NP lookups /////////////////////////////////////////////// if (iconnection->npTransactionList) ArrayFree(iconnection->npTransactionList); iconnection->npInitialized = gsi_false; iconnection->npStatusRetrieved = gsi_false; return GP_NO_ERROR; }
//////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Message Handler DArray functions void gsUdpMsgHandlerFree(void *theMsgHandler) { GSUdpMsgHandler *aHandler= (GSUdpMsgHandler *)theMsgHandler; ArrayFree(aHandler->mPendingConnections); }
void cfac_free_coulomb(cfac_t *cfac) { ArrayFree(cfac->coulomb.dipole_array); free(cfac->coulomb.dipole_array); }
GPResult gpiDeleteBuddy( GPConnection * connection, GPProfile profile, GPIBool sendServerRequest ) { GPIProfile * pProfile; GPIConnection * iconnection = (GPIConnection*)*connection; int index; // Get the profile object. ////////////////////////// if(!gpiGetProfile(connection, profile, &pProfile)) Error(connection, GP_PARAMETER_ERROR, "Invalid profile."); // Check that this is a buddy. ////////////////////////////// // Removed - 092404 BED - User could be a buddy even though we don't have the status //if(!pProfile->buddyStatus) // Error(connection, GP_PARAMETER_ERROR, "Profile not a buddy."); // Send the request. //////////////////// if (GPITrue == sendServerRequest) { gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\delbuddy\\"); gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\sesskey\\"); gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, iconnection->sessKey); gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\delprofileid\\"); gpiAppendIntToBuffer(connection, &iconnection->outputBuffer, pProfile->profileId); gpiAppendStringToBuffer(connection, &iconnection->outputBuffer, "\\final\\"); } // Need to fix up the buddy indexes. //////////////////////////////////// if (pProfile->buddyStatus) { index = pProfile->buddyStatus->buddyIndex; assert(index >= 0); freeclear(pProfile->buddyStatus->statusString); freeclear(pProfile->buddyStatus->locationString); freeclear(pProfile->buddyStatus); if(gpiCanFreeProfile(pProfile)) gpiRemoveProfile(connection, pProfile); iconnection->profileList.numBuddies--; assert(iconnection->profileList.numBuddies >= 0); #ifndef _PS2 gpiProfileMap(connection, gpiFixBuddyIndices, (void *)(unsigned long)index); #else gpiProfileMap(connection, gpiFixBuddyIndices, (void *)index); #endif } if (pProfile->buddyStatusInfo) { index = pProfile->buddyStatusInfo->buddyIndex; assert(index >= 0); freeclear(pProfile->buddyStatusInfo->richStatus); freeclear(pProfile->buddyStatusInfo->gameType); freeclear(pProfile->buddyStatusInfo->gameVariant); freeclear(pProfile->buddyStatusInfo->gameMapName); freeclear(pProfile->buddyStatusInfo); if (pProfile->buddyStatusInfo->extendedInfoKeys) { ArrayFree(pProfile->buddyStatusInfo->extendedInfoKeys); pProfile->buddyStatusInfo->extendedInfoKeys = NULL; } if(gpiCanFreeProfile(pProfile)) gpiRemoveProfile(connection, pProfile); iconnection->profileList.numBuddies--; assert(iconnection->profileList.numBuddies >= 0); #ifndef _PS2 gpiProfileMap(connection, gpiFixBuddyIndices, (void *)(unsigned long)index); #else gpiProfileMap(connection, gpiFixBuddyIndices, (void *)index); #endif } return GP_NO_ERROR; }
int SaveIonization(cfac_t *cfac, int nb, int *b, int nf, int *f, char *fn) { int i, j, k; int ie, ip; FILE *file; LEVEL *lev1, *lev2; CI_RECORD r; CI_HEADER ci_hdr; F_HEADER fhdr; double delta, emin, emax, e, emax0; double qk[MAXNE], qku[MAXNUSR]; int nq, nqk; ARRAY subte; int isub, n_tegrid0, n_egrid0, n_usr0; int te_set, e_set, usr_set; double c, e0, e1; emin = 1E10; emax = 1E-10; k = 0; for (i = 0; i < nb; i++) { lev1 = GetLevel(cfac, b[i]); for (j = 0; j < nf; j++) { lev2 = GetLevel(cfac, f[j]); e = lev2->energy - lev1->energy; if (e > 0) k++; if (e < emin && e > 0) emin = e; if (e > emax) emax = e; } } if (k == 0) { return 0; } if (tegrid[0] < 0) { te_set = 0; } else { te_set = 1; } if (egrid[0] < 0) { e_set = 0; } else { e_set = 1; } if (usr_egrid[0] < 0) { usr_set = 0; } else { usr_set = 1; } n_tegrid0 = n_tegrid; n_egrid0 = n_egrid; n_usr0 = n_usr; if (egrid_limits_type == 0) { emax0 = 0.5*(emin + emax)*egrid_max; } else { emax0 = egrid_max; } ArrayInit(&subte, sizeof(double), 128, NULL, NULL); ArrayAppend(&subte, &emin); c = TE_MAX_MIN; if (!e_set || !te_set) { e = c*emin; while (e < emax) { ArrayAppend(&subte, &e); e *= c; } } ArrayAppend(&subte, &emax); egrid_type = 1; pw_type = 0; if (usr_egrid_type < 0) usr_egrid_type = 1; nqk = NPARAMS; r.params = malloc(sizeof(float)*nqk); fhdr.type = DB_CI; strcpy(fhdr.symbol, cfac_get_atomic_symbol(cfac)); fhdr.atom = cfac_get_atomic_number(cfac); ci_hdr.nele = GetNumElectrons(cfac, b[0]); ci_hdr.qk_mode = qk_mode; ci_hdr.nparams = nqk; ci_hdr.pw_type = pw_type; ci_hdr.egrid_type = egrid_type; ci_hdr.usr_egrid_type = usr_egrid_type; file = OpenFile(fn, &fhdr); e0 = emin*0.999; for (isub = 1; isub < subte.dim; isub++) { e1 = *((double *) ArrayGet(&subte, isub)); if (isub == subte.dim-1) e1 = e1*1.001; emin = e1; emax = e0; k = 0; for (i = 0; i < nb; i++) { lev1 = GetLevel(cfac, b[i]); for (j = 0; j < nf; j++) { lev2 = GetLevel(cfac, f[j]); e = lev2->energy - lev1->energy; if (e < e0 || e >= e1) continue; if (e < emin) emin = e; if (e > emax) emax = e; k++; } } if (k == 0) { e0 = e1; continue; } if (qk_mode == QK_CB) { SetIEGrid(1, emin, emax); } else { if (n_tegrid0 == 0) { n_tegrid = 3; } if (!te_set) { e = 2.0*(emax-emin)/(emax+emin); if (e < EPS3) { SetIEGrid(1, emin, emax); } else if (e < 0.5) { SetIEGrid(2, emin, emax); } else { if (k == 2) n_tegrid = 2; SetIEGrid(n_tegrid, emin, emax); } } } n_egrid = n_egrid0; n_usr = n_usr0; if (!usr_set) usr_egrid[0] = -1.0; if (!e_set) egrid[0] = -1.0; e = 0.5*(emin + emax); if (egrid_limits_type == 0) { emin = egrid_min*e; emax = egrid_max*e; } else { emin = egrid_min; emax = egrid_max; } if (emax < emax0) { emax = 50.0*e; if (emax > emax0) emax = emax0; } if (n_egrid <= 0) { n_egrid = 6; } if (egrid[0] < 0.0) { SetCIEGrid(n_egrid, emin, emax, e); } usr_different = 1; if (n_usr > 0 && usr_egrid[0] < 0.0) { SetUsrCIEGrid(n_usr, emin, emax, e); usr_egrid_type = 1; usr_different = 0; } if (n_usr <= 0) { SetUsrCIEGridDetail(n_egrid, egrid); usr_egrid_type = 1; usr_different = 0; } if (qk_mode != QK_CB) { SetTransitionOptions(cfac, G_BABUSHKIN, M_NR, 4, 4); SetRRTEGrid(1, e, e); SetPEGridLimits(egrid_min, egrid_max, egrid_limits_type); SetPEGridDetail(n_egrid, egrid); PrepRREGrids(e, emax0); } for (ie = 0; ie < n_egrid; ie++) { for (i = 0; i < n_tegrid; i++) { xegrid[i][ie] = egrid[ie]/tegrid[i]; if (egrid_type == 1) xegrid[i][ie] += 1.0; log_xegrid[i][ie] = log(xegrid[i][ie]); } } yegrid0[0] = log(1E-5); delta = (log(0.5) - yegrid0[0])/(NINT-1.0); for (i = 1; i < NINT; i++) { yegrid0[i] = yegrid0[i-1] + delta; } for (i = 0; i < NINT; i++) { yegrid0[i] = exp(yegrid0[i]); } if (pw_scratch.nkl == 0) { SetCIPWGrid(0, NULL, NULL); } r.strength = malloc(sizeof(float)*n_usr); ci_hdr.n_tegrid = n_tegrid; ci_hdr.n_egrid = n_egrid; ci_hdr.n_usr = n_usr; ci_hdr.tegrid = tegrid; ci_hdr.egrid = egrid; ci_hdr.usr_egrid = usr_egrid; InitFile(file, &fhdr, &ci_hdr); for (i = 0; i < nb; i++) { lev1 = GetLevel(cfac, b[i]); for (j = 0; j < nf; j++) { lev2 = GetLevel(cfac, f[j]); e = lev2->energy - lev1->energy; if (e < e0 || e >= e1) continue; nq = IonizeStrength(cfac, qku, qk, &e, b[i], f[j]); if (nq < 0) continue; r.b = b[i]; r.f = f[j]; r.kl = nq; for (ip = 0; ip < nqk; ip++) { r.params[ip] = (float) qk[ip]; } for (ie = 0; ie < n_usr; ie++) { r.strength[ie] = (float) qku[ie]; } WriteCIRecord(file, &r); } } DeinitFile(file, &fhdr); free(r.strength); ReinitRadial(cfac, 1); FreeRecQk(); FreeRecPk(); FreeIonizationQk(); e0 = e1; } free(r.params); ReinitRecombination(1); ReinitIonization(1); ArrayFree(&subte); CloseFile(file, &fhdr); return 0; }
bool ModelManagerShutdown(ModelManager* manager) { ArrayFree(&manager->touchArguments); return true; }
void AsmFree(Assembler *a) { ArrayFree(a->codes, (FuncPtr1) AsmCodeFree); HashTableFree(a->symTable); OpTableFree(); ObjFree(a); }