void sreplace(char *s,char *orig,char *rep,char multi,long dsize){ char *p; memChunk *buffer,*string,*result; if (!(p = strstr (s, orig))) { return; } buffer = memReserve (dsize); string = memString (s); memCopy (buffer, string); snprintf (buffer->address + (p - s), buffer->size - (p - s), "%s%s", rep, p + strlen (orig)); result = memString (buffer->address); strcpy (s,result->address); //unsafe memFree (string); memFree (result); memFree (buffer); }
static void ResolveRelHintPath(char *file) { char *text = readText_b(file); char *p; int modified = 0; text = strrm(text, 128000000); // XXX p = text; while(p = strstrNext(p, "<HintPath>")) { if(startsWith(p, "..\\")) { char *trailer = strx(p); uint c; for(c = 0; c < UTIntoParentStep; c++) { *p++ = '.'; *p++ = '.'; *p++ = '\\'; } strcpy(p, trailer); memFree(trailer); p = strstrNext(p, "</HintPath>"); errorCase(!p); modified = 1; } } if(modified) writeOneLineNoRet_b(file, text); memFree(text); }
/* __gl_meshMakeEdge creates one edge, two vertices, and a loop (face). * The loop consists of the two new half-edges. */ GLUhalfEdge* __gl_meshMakeEdge(GLUmesh* mesh) { GLUvertex* newVertex1=allocVertex(); GLUvertex* newVertex2=allocVertex(); GLUface* newFace=allocFace(); GLUhalfEdge* e; /* if any one is null then all get freed */ if (newVertex1==NULL || newVertex2==NULL || newFace==NULL) { if (newVertex1!=NULL) { memFree(newVertex1); } if (newVertex2!=NULL) { memFree(newVertex2); } if (newFace!=NULL) { memFree(newFace); } return NULL; } e=MakeEdge(&mesh->eHead); if (e==NULL) { return NULL; } MakeVertex(newVertex1, e, &mesh->vHead); MakeVertex(newVertex2, e->Sym, &mesh->vHead); MakeFace(newFace, e, &mesh->fHead); return e; }
/* __gl_meshZapFace(fZap) destroys a face and removes it from the * global face list. All edges of fZap will have a NULL pointer as their * left face. Any edges which also have a NULL pointer as their right face * are deleted entirely (along with any isolated vertices this produces). * An entire mesh can be deleted by zapping its faces, one at a time, * in any order. Zapped faces cannot be used in further mesh operations! */ void __gl_meshZapFace(GLUface* fZap) { GLUhalfEdge* eStart=fZap->anEdge; GLUhalfEdge* e, *eNext, *eSym; GLUface* fPrev, *fNext; /* walk around face, deleting edges whose right face is also NULL */ eNext=eStart->Lnext; do { e=eNext; eNext=e->Lnext; e->Lface=NULL; if (e->Rface==NULL) { /* delete the edge -- see __gl_MeshDelete above */ if (e->Onext==e) { KillVertex(e->Org, NULL); } else { /* Make sure that e->Org points to a valid half-edge */ e->Org->anEdge=e->Onext; Splice(e, e->Oprev); } eSym=e->Sym; if (eSym->Onext==eSym) { KillVertex(eSym->Org, NULL); } else { /* Make sure that eSym->Org points to a valid half-edge */ eSym->Org->anEdge=eSym->Onext; Splice(eSym, eSym->Oprev); } KillEdge(e); } } while(e!=eStart); /* delete from circular doubly-linked list */ fPrev=fZap->prev; fNext=fZap->next; fNext->prev=fPrev; fPrev->next=fNext; memFree(fZap); }
static void Main2(char *tmplProject, char *tmplDir, int utFlag, int m2Flag) { char *project = nextArg(); errorCase(!existDir(tmplDir)); // 2bs ? errorCase_m(!lineExp("<1,30,__09AZaz>", project), "不正なプロジェクト名です。"); errorCase_m(existPath(project), "既に存在します。"); createDir(project); copyDir(tmplDir, project); addCwd(project); { coExecute("qq -f"); RenamePaths(tmplProject, project); addCwd(existDir(TESTER_PROJ_LDIR) ? TESTER_PROJ_LDIR : project); { ChangeAppIdent("Program.cs"); if(utFlag) { char *csprojFile = xcout("%s.csproj", project); if(existFile(csprojFile)) { ResolveRelHintPath(csprojFile); } memFree(csprojFile); } } unaddCwd(); removeFileIfExist("C:\\Factory\\tmp\\Sections.txt"); // 意図しない検索結果を trep しないように、念のため検索結果をクリア coExecute_x(xcout("Search.exe %s", tmplProject)); coExecute_x(xcout("trep.exe /F %s", project)); // execute("START ."); execute_x(xcout("%s.sln", project)); if(m2Flag) execute("START C:\\Dev\\CSharp\\Module2\\Module2"); } unaddCwd(); }
void sort0ByKeyIterative(Array<Tk> okey, Array<Tv> oval, bool isAscending) { // Get pointers and initialize original index locations Tk *okey_ptr = okey.get(); Tv *oval_ptr = oval.get(); typedef IndexPair<Tk, Tv> CurrentPair; dim_t size = okey.dims()[0]; size_t bytes = size * sizeof(CurrentPair); CurrentPair *pairKeyVal = (CurrentPair *)memAlloc<char>(bytes); for(dim_t w = 0; w < okey.dims()[3]; w++) { dim_t okeyW = w * okey.strides()[3]; dim_t ovalW = w * oval.strides()[3]; for(dim_t z = 0; z < okey.dims()[2]; z++) { dim_t okeyWZ = okeyW + z * okey.strides()[2]; dim_t ovalWZ = ovalW + z * oval.strides()[2]; for(dim_t y = 0; y < okey.dims()[1]; y++) { dim_t okeyOffset = okeyWZ + y * okey.strides()[1]; dim_t ovalOffset = ovalWZ + y * oval.strides()[1]; Tk *okey_col_ptr = okey_ptr + okeyOffset; Tv *oval_col_ptr = oval_ptr + ovalOffset; for(dim_t x = 0; x < size; x++) { pairKeyVal[x] = std::make_tuple(okey_col_ptr[x], oval_col_ptr[x]); } if(isAscending) { std::stable_sort(pairKeyVal, pairKeyVal + size, IPCompare<Tk, Tv, true>()); } else { std::stable_sort(pairKeyVal, pairKeyVal + size, IPCompare<Tk, Tv, false>()); } for(unsigned x = 0; x < size; x++) { okey_ptr[okeyOffset + x] = std::get<0>(pairKeyVal[x]); oval_ptr[ovalOffset + x] = std::get<1>(pairKeyVal[x]); } } } } memFree((char *)pairKeyVal); return; }
/*----------------------------------------------------------------------------- Name : frReloadFonts Description : reloads all of the currently loaded fonts with respect to the currently selected language. Inputs : none Outputs : none Return : void ----------------------------------------------------------------------------*/ void frReloadFonts(void) { sdword index; fonthandle curfont; char name[64]; char fullName[128]; curfont = fontCurrentGet(); for (index = FR_NumberFonts - 1; index >= 1; index--) { //for all of the registry if (frFontRegistry[index].name != NULL) { // free memory associated with the current font strcpy(name, frFontRegistry[index].name); memFree(frFontRegistry[index].name); //free previously allocated name frFontRegistry[index].name = NULL; //no longer registered fontDiscard(frFontRegistry[index].handle); //free the font frFontRegistry[index].name = memStringDupe(name);//duplicate name string strcpy(fullName, FR_PrependPath); //prepare file path if (strCurLanguage==languageEnglish) { strcat(fullName, FR_English); } else if (strCurLanguage==languageFrench) { strcat(fullName, FR_French); } else if (strCurLanguage==languageGerman) { strcat(fullName, FR_German); } else if (strCurLanguage==languageSpanish) { strcat(fullName, FR_Spanish); } else if (strCurLanguage==languageItalian) { strcat(fullName, FR_Italian); } strcat(fullName, name); frFontRegistry[index].fontdat = fontLoad(fullName); //load file frFontRegistry[index].handle = index; } } fontMakeCurrent(curfont); }
static void whoisReadReply(int fd, void *data) { WhoisState *p = data; StoreEntry *entry = p->entry; char *buf = memAllocate(MEM_4K_BUF); MemObject *mem = entry->mem_obj; int len; statCounter.syscalls.sock.reads++; len = FD_READ_METHOD(fd, buf, 4095); buf[len] = '\0'; debug(75, 3) ("whoisReadReply: FD %d read %d bytes\n", fd, len); debug(75, 5) ("{%s}\n", buf); if (len > 0) { if (0 == mem->inmem_hi) { http_reply *reply = mem->reply; storeBuffer(entry); httpReplySetHeaders(reply, HTTP_OK, "Gatewaying", "text/plain", -1, -1, -1); httpReplySwapOut(reply, entry); } fd_bytes(fd, len, FD_READ); kb_incr(&statCounter.server.all.kbytes_in, len); kb_incr(&statCounter.server.http.kbytes_in, len); storeAppend(entry, buf, len); storeBufferFlush(entry); commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read); } else if (len < 0) { debug(50, 2) ("whoisReadReply: FD %d: read failure: %s.\n", fd, xstrerror()); if (ignoreErrno(errno)) { commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read); } else { ErrorState *err; err = errorCon(ERR_READ_ERROR, HTTP_BAD_GATEWAY, p->fwd->request); err->xerrno = errno; fwdFail(p->fwd, err); comm_close(fd); } } else { storeTimestampsSet(entry); storeBufferFlush(entry); if (!EBIT_TEST(entry->flags, RELEASE_REQUEST)) storeSetPublicKey(entry); fwdComplete(p->fwd); debug(75, 3) ("whoisReadReply: Done: %s\n", storeUrl(entry)); comm_close(fd); } memFree(buf, MEM_4K_BUF); }
sdword aimProcessKamikaze(AITeam *team) { AITeamMove *thisMove = team->curMove; SelectCommand *selection = team->shipList.selection; if (selection->numShips == 0) { aiplayerLog((aiIndex,"Kamikaze Move, Zero Sized Team")); return TRUE; } if (!thisMove->processing) { if ((selection->numShips > 0) && (thisMove->params.kamikaze.ships->numShips > 0)) { if (aiuWrapSetTactics(selection,Aggressive)) { if (aiuWrapAttack(selection, thisMove->params.kamikaze.ships)) { aiuWrapSetKamikaze(selection); thisMove->processing = TRUE; } } } else { aiplayerLog((aiIndex,"Warning: no ships to kamikaze into")); thisMove->processing = TRUE; } return FALSE; } else { if ((selection->numShips == 0) || (thisMove->params.kamikaze.ships->numShips == 0) || (aiuShipsNoLongerAttacking(selection))) { // we're done memFree(thisMove->params.kamikaze.ships); thisMove->params.kamikaze.ships = NULL; return TRUE; } else { return FALSE; } } }
/* KillEdge( eDel ) destroys an edge (the half-edges eDel and eDel->Sym), * and removes from the global edge list. */ static void KillEdge( GLUhalfEdge *eDel ) { GLUhalfEdge *ePrev, *eNext; /* Half-edges are allocated in pairs, see EdgePair above */ if( eDel->Sym < eDel ) { eDel = eDel->Sym; } /* delete from circular doubly-linked list */ eNext = eDel->next; ePrev = eDel->Sym->next; eNext->Sym->next = ePrev; ePrev->Sym->next = eNext; memFree( eDel ); }
void db_destroy(DATA_BIN_PTR dbin) { FF_VALIDATE(dbin); if (dbin->eqn_info) { ee_free_einfo(dbin->eqn_info); dbin->eqn_info = NULL; } if (dbin->array_conduit_list) { ff_destroy_array_conduit_list(dbin->array_conduit_list); dbin->array_conduit_list = NULL; } if (dbin->table_list) { fd_destroy_format_data_list(dbin->table_list); dbin->table_list = NULL; } if (dbin->title) { memFree(dbin->title, "dbin->title"); dbin->title = NULL; } #ifdef FF_CHK_ADDR dbin->check_address = NULL; #endif memFree(dbin, "dbin"); return; }
static void httpHeaderEntryDestroy(HttpHeaderEntry * e) { assert(e); assert_eid(e->id); debug(55, 9) ("destroying entry %p: '%s: %s'\n", e, strBuf(e->name), strBuf(e->value)); /* clean name if needed */ if (e->id == HDR_OTHER) stringClean(&e->name); stringClean(&e->value); assert(Headers[e->id].stat.aliveCount); Headers[e->id].stat.aliveCount--; e->id = -1; memFree(e, MEM_HTTP_HDR_ENTRY); }
static void fragFree(Frag *f) { memFree(f->mem); if(f->state == FragLocalAlloc) { f->state = FragLocalFree; return; } lock(&freeList.lk); f->next = freeList.frag; freeList.frag = f; unlock(&freeList.lk); }
static void AddModule(char *module) { char *projFile; char *srcFile; char *hdrFile; autoList_t *lines; char *line; uint index; errorCase(!lineExp("<__09AZaz>", module)); projFile = GetProjFile(); srcFile = changeExt(module, "cpp"); hdrFile = changeExt(module, "h"); errorCase(existPath(srcFile)); errorCase(existPath(hdrFile)); lines = readLines(projFile); index = FindIndex(lines, 0, "<\t\t >Name=\"ソース ファイル\""); index = FindIndex(lines, index + 1, "<\t\t >>"); insertElement(lines, index + 1, (uint)xcout("<File RelativePath=\".\\%s\"></File>", srcFile)); index = FindIndex(lines, 0, "<\t\t >Name=\"ヘッダー ファイル\""); index = FindIndex(lines, index + 1, "<\t\t >>"); insertElement(lines, index + 1, (uint)xcout("<File RelativePath=\".\\%s\"></File>", hdrFile)); writeLines_xx(projFile, lines); addLine2File_cx("all.h", xcout("#include \"%s\"", hdrFile)); writeOneLine(srcFile, "#include \"all.h\""); createFile(hdrFile); // "all" ならここで all.h は空のファイルになる。 memFree(srcFile); memFree(hdrFile); }
/* really __gl_pqSortNewPriorityQ */ PriorityQ *pqNewPriorityQ( int (*leq)(PQkey key1, PQkey key2) ) { PriorityQ *pq = (PriorityQ *)memAlloc( sizeof( PriorityQ )); if (pq == NULL) return NULL; pq->heap = __gl_pqHeapNewPriorityQ( leq ); if (pq->heap == NULL) { memFree(pq); return NULL; } pq->keys = (PQHeapKey *)memAlloc( INIT_SIZE * sizeof(pq->keys[0]) ); if (pq->keys == NULL) { __gl_pqHeapDeletePriorityQ(pq->heap); memFree(pq); return NULL; } pq->size = 0; pq->max = INIT_SIZE; pq->initialized = FALSE; pq->leq = leq; return pq; }
void SCOTCH_graphMapExit ( const SCOTCH_Graph * const grafptr, SCOTCH_Mapping * const mappptr) { LibMapping * restrict lmapptr; lmapptr = (LibMapping *) mappptr; if (((lmapptr->flagval & LIBMAPPINGFREEPART) != 0) && /* If parttab must be freed */ (lmapptr->parttab != NULL)) /* And if exists */ memFree (lmapptr->parttab); /* Free it */ memSet (lmapptr, 0, sizeof (LibMapping)); }
/* glu_fastuidraw_gl_meshDeleteMesh( mesh ) will free all storage for any valid mesh. */ void glu_fastuidraw_gl_meshDeleteMesh( GLUmesh *mesh ) { GLUface *f, *fNext; GLUvertex *v, *vNext; GLUhalfEdge *e, *eNext; for( f = mesh->fHead.next; f != &mesh->fHead; f = fNext ) { fNext = f->next; memFree( f ); } for( v = mesh->vHead.next; v != &mesh->vHead; v = vNext ) { vNext = v->next; memFree( v ); } for( e = mesh->eHead.next; e != &mesh->eHead; e = eNext ) { /* One call frees both e and e->Sym (see EdgePair above) */ eNext = e->next; memFree( e ); } memFree( mesh ); }
CloakStruct *LoadCloakStruct(void) { SaveChunk *chunk; CloakStruct *cloakStruct; chunk = LoadNextChunk(); VerifyChunk(chunk,BASIC_STRUCTURE,sizeof(CloakStruct)); cloakStruct = memAlloc(sizeof(CloakStruct),"CloakStruct",0); memcpy(cloakStruct,chunkContents(chunk),sizeof(CloakStruct)); memFree(chunk); return cloakStruct; }
void interpret(char *cFile) { // 解譯器主程式 printf("interpret file:%s\n", cFile); char *cText = fileToStr(cFile); // 讀取檔案到 cText 字串中。 SymTable *symTable = SymTableNew(); Scanner *scanner = ScannerNew(cText); Tree *tree = parse(cText, symTable); // 剖析程式 (cText) 轉為語法樹 /* Interpreter *inter = InterNew(); inter->tree = parser->tree; char rzVar[100]; InterRun(inter, inter->tree, rzVar); InterFree(inter); */ TreeFree(tree); memFree(cText); ERROR(); }
DefenseStruct *LoadDefenseStruct(void) { SaveChunk *chunk; DefenseStruct *defenseStruct; chunk = LoadNextChunk(); VerifyChunk(chunk,BASIC_STRUCTURE,sizeof(DefenseStruct)); defenseStruct = memAlloc(sizeof(DefenseStruct),"DefenseStruct",0); memcpy(defenseStruct,chunkContents(chunk),sizeof(DefenseStruct)); memFree(chunk); return defenseStruct; }
void dofConstant ( Dof * const deofptr, const PASTIX_INT baseval, const PASTIX_INT nodenbr, const PASTIX_INT noddval) { deofptr->baseval = baseval; deofptr->nodenbr = nodenbr; if (deofptr->noddtab != NULL) { /* If DOF array already allocated */ memFree (deofptr->noddtab); /* It is no longer of use */ deofptr->noddtab = NULL; } deofptr->noddval = noddval; }
static void idnsGrokReply(const char *buf, size_t sz) { int n; int valid; rfc1035_rr *answers = NULL; unsigned short rid = 0xFFFF; idns_query *q; n = rfc1035AnswersUnpack(buf, sz, &answers, &rid); debug(78, 3) ("idnsGrokReply: ID %#hx, %d answers\n", rid, n); if (rid == 0xFFFF) { debug(78, 1) ("idnsGrokReply: Unknown error\n"); /* XXX leak answers? */ return; } q = idnsFindQuery(rid); if (q == NULL) { debug(78, 3) ("idnsGrokReply: Late response\n"); rfc1035RRDestroy(answers, n); return; } dlinkDelete(&q->lru, &lru_list); idnsRcodeCount(n, q->attempt); if (n < 0) { debug(78, 3) ("idnsGrokReply: error %d\n", rfc1035_errno); if (-2 == n && ++q->attempt < MAX_ATTEMPT) { /* * RCODE 2 is "Server failure - The name server was * unable to process this query due to a problem with * the name server." */ assert(NULL == answers); q->start_t = current_time; q->id = rfc1035RetryQuery(q->buf); idnsSendQuery(q); return; } } valid = cbdataValid(q->callback_data); cbdataUnlock(q->callback_data); if (valid) q->callback(q->callback_data, answers, n); rfc1035RRDestroy(answers, n); memFree(q, MEM_IDNS_QUERY); }
/** description: terminate a process returns: PcbPtr of process NULL if terminate failed */ PcbPtr terminatePcb(PcbPtr process) { if (kill(process->pid, SIGINT) < 0) { fprintf(stderr, "kill(SIGINT) error: %p\n", strerror(errno)); return NULL; } MabPtr tmpMab = NULL; tmpMab = memFree(process->memBlock); /*printf("free\n"); printMemTrace(); printf("-------\n");*/ return process; }
/*----------------------------------------------------------------------------- Name : navLightStaticInfoDelete Description : Delete the static info of a set of nav lights Inputs : staticInfo - array of navlight structures to free Outputs : unregisters the navlight textures, if any. Return : ----------------------------------------------------------------------------*/ void navLightStaticInfoDelete(NAVLightStaticInfo *staticInfo) { sdword i, num = staticInfo->numNAVLights; NAVLightStatic *navLightStatic = staticInfo->navlightstatics; dbgAssertOrIgnore(staticInfo != NULL); for( i=0 ; i < num ; i++, navLightStatic++) { if (navLightStatic->texturehandle != TR_InvalidHandle) { trTextureUnregister(navLightStatic->texturehandle); } } memFree(staticInfo); }
double GetCurrOptDouble(const int id, const double def) { char *value; double num; value = GetCurrOpt(g_cngplp_data, id, NULL); if(value != NULL){ setlocale (LC_NUMERIC, "C"); num = atof(value); setlocale (LC_NUMERIC, ""); memFree(value); return num; }else{ return def; } }
Baton::~Baton() { POSIX_BATON_DATA &p = *(POSIX_BATON_DATA *)m_data; #ifdef NDEBUG pthread_mutex_destroy( &p.m_mtx ); pthread_cond_destroy( &p.m_cv ); #else int res = pthread_mutex_destroy( &p.m_mtx ); fassert( res == 0 ); res = pthread_cond_destroy( &p.m_cv ); fassert( res == 0 ); #endif memFree( m_data ); }
static void gopherStateFree(int fdnotused, void *data) { GopherStateData *gopherState = data; if (gopherState == NULL) return; if (gopherState->entry) { storeUnlockObject(gopherState->entry); } if (gopherState->req) { requestUnlink(gopherState->req); } memFree(gopherState->buf, MEM_4K_BUF); gopherState->buf = NULL; cbdataFree(gopherState); }
void HFMXFree(void) { if (!loaded) return; memFree(HFMX->Ascent); memFree(HFMX->Descent); memFree(HFMX->LineGap); memFree(HFMX->CaretSlopeRise); memFree(HFMX->CaretSlopeRun); memFree(HFMX->CaretOffset); memFree(HFMX); HFMX = NULL; loaded = 0; }
int main(int argc, char **argv) { autoList_t *paths = readLines(FOUNDLISTFILE); char *path; uint index; char *outDir = makeFreeDir(); foreach(paths, path, index) { char *outPath = toCreatablePath(combine(outDir, getLocal(path)), getCount(paths) + 10); cout("< %s\n", path); cout("> %s\n", outPath); copyPath(path, outPath); memFree(outPath); }
/*----------------------------------------------------------------------------- Name : udLatestThingPush Description : Set the latest thing done so we can undo it later Inputs : function - function to call to perform the undo. userID - arbitrary ID to be passed to callback function userData - memory to duplicate and pass back. Ignored if length = 0 length - length of user memory to duplicate. If zero, no memory will be duplicated. Outputs : allocates and duplicates userData, plus copies the parameters to global variables Return : ??? ----------------------------------------------------------------------------*/ sdword udLatestThingPush(undofunc function, sdword userID, ubyte *userData, sdword length) { if (udUndoInfo.userData != NULL) { //if user data was previously allocated memFree(udUndoInfo.userData); //free it udUndoInfo.userData = NULL; //and set pointer to reflect nothing allocated } udUndoInfo.function = function; //save parameters udUndoInfo.userID = userID; udUndoInfo.length = length; if (length != 0) { //if we should duplicate RAM udUndoInfo.userData = memAlloc(length, "Undo buffer", 0); memcpy(udUndoInfo.userData, userData, length); } return(OKAY); }