/* * Return a processed source line list for the next line of the file. * The source line list may have several entries if the line is an * includer directive or requires a continuation. */ SrcLineList includeLine(FileName fn, FILE *fin, int *plineno, InclIsContinuedFun iscont) { SrcLineList r; inclBuffer = bufNew(); localAssertList = globalAssertList; fileState.curDir = osCurDirName(); fileState.curFile = strCopy(fnameUnparseStatic(fn)); fileState.curFname = fn; fileState.infile = fin; fileState.fileCodes = 0; fileState.fileNames = 0; fileState.lineNumber= *plineno; ifState = NoIf; r = 0; inclLine(&r, iscont); r = listNReverse(SrcLine)(r); /* Leave the assert list and included files for the next call. */ globalAssertList = localAssertList; bufFree(inclBuffer); /* strFree(fileState.curFile); !!This is held on to by the srclines.*/ listFree(Hash) (fileState.fileCodes); listFree(String)(fileState.fileNames); *plineno = fileState.lineNumber; inclFileLineNo = fileState.lineNumber; return r; }
void compPhaseSave(EmitInfo finfo, Foam foam, Stab stab) { SymeList symes = 0; AbSyn macs; phStart(PH_PutIntermed); macs = macexGetMacros(); if (emitIsOutputNeededOrWarn(finfo, FTYPENO_SYMEEXPR)) { symes = emitCollectIntermedSymes(stab, foam); emitTheSymbolExpr(finfo, symes, macs); listFree(Syme)(symes); } if (emitIsOutputNeededOrWarn(finfo, FTYPENO_INTERMED)) { symes = emitCollectIntermedSymes(stab, foam); emitTheIntermed(finfo, symes, foam, macs); listFree(Syme)(symes); phLibStats(emitFileName(finfo, FTYPENO_INTERMED)); if (emitDependsWanted()) emitTheDependencies(finfo); } if (emitIsOutputNeededOrWarn(finfo, FTYPENO_FOAMEXPR)) { emitTheFoamExpr(finfo, foam); } phEnd((PhPrFun) 0, (PhPrFun) 0, (Pointer) NULL); }
/* * Return a processed source line list of the file contents. */ SrcLineList includeFile(FileName fname) { String fnameString; SrcLineList r; inclSerialLineNo = 0; fnameString = strCopy(fnameUnparseStatic(fname)); inclBuffer = bufNew(); includedFileCodes = 0; localAssertList = listCopy(String)(globalAssertList); fileState.curDir = osCurDirName(); fileState.fileCodes = 0; fileState.fileNames = 0; r = listNReverse(SrcLine)( inclFile(fnameString, false, true, &inclFileLineNo)); strFree(fnameString); bufFree(inclBuffer); listFree(String)(localAssertList); listFree(Hash)(includedFileCodes); return r; }
void routeFree(Route** route) { if (route != NULL && *route != NULL) { listFree((*route)->links); listFree((*route)->stations); free(*route); *route = NULL; } }
int cmdArguments(int argi0, int argc, String *argv) { int opt, i, j; String arg; StringList sl; /* * Initialize default values. */ cmdFileCount = argc - 1; cmdIncDirs = cmdLibDirs = cmdLibKeys = 0; _dont_assert = true; /* Disable assertions by default. */ /* * Handle the options. */ for (i = argi0, j = 0; ; ) { opt = cmdGetOption(argc, argv, &i, &j, &arg); if (!opt) break; if (cmdIsArgOption(opt) && !arg) cmdUseError(ALDOR_F_CmdBadOption, argv[i-1]); cmdHandleOption(opt, arg); } /* * After some sequence of -O and -Q do we still want cc -O ? */ ccSetOptimize(optIsCcFNonStdWanted(),optIsCcOptimizeWanted()); /* * Push directories etc in correct order. */ for (sl = cmdIncDirs; sl; sl = cdr(sl)) fileAddIncludeDirectory(car(sl)); for (sl = cmdLibDirs; sl; sl = cdr(sl)) fileAddLibraryDirectory(car(sl)); for (sl = cmdLibKeys; sl; sl = cdr(sl)) { String id, key, s; int rc; s = scmdScanLibraryOption(car(sl), &id, &key); rc = s ? scmdHandleLibrary(id, key) : -1; if (rc < 0) cmdUseError(ALDOR_F_CmdBadOption, "-l"); } listFree(String)(cmdIncDirs); listFree(String)(cmdLibDirs); listFree(String)(cmdLibKeys); /* * Determine number of arguments consumed. */ if (i + cmdFileCount > argc) cmdFileCount = argc - i; return i; }
BOOL DLLCALL msgQueueFree(msg_queue_t* q) { if(q==NULL) return(FALSE); listFree(&q->in); listFree(&q->out); if(q->flags&MSG_QUEUE_MALLOC) free(q); return(TRUE); }
void stFree(SYMBOL_TABLE_PTR st){ if(!st) return; BT_Free(&st->start.symbols); BT_Free(&st->functions); listFree(&st->start.staticValues); listFree(&st->start.instructions); st->start.calledCount = 0; st->curr = NULL; }
/** * @brief Remove a video filter. * * @param vf video filter to be removed */ static void remove_vf(char *vf) { if (vf_settings) { int i = 0; while (vf_settings[i].name) { if (strcmp(vf_settings[i].name, vf) == 0) { int j; mp_msg(MSGT_GPLAYER, MSGL_INFO, MSGTR_GUI_MSG_RemovingVideoFilter, vf); free(vf_settings[i].name); listFree(&vf_settings[i].attribs); j = i + 1; while (vf_settings[j].name) j++; memmove(&vf_settings[i], &vf_settings[i + 1], (j - i) * sizeof(*vf_settings)); break; } i++; } } }
void aboutInit() { char buf[128]; list_t* txt; listItem* it; FILE* fp = android_fopen("data/about.txt", "r"); if(!fp) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open data/about.txt"); return; } txt = listInit(NULL); while( fgets(buf, 128, fp ) ) { int l = strlen(buf); it = listAppendData(txt, malloc( l+1 ) ); strcpy( (char*)(it->data), buf ); } numLines = txt->count; lines = malloc( sizeof(char*)*numLines ); listAddToArray((void*)lines,txt); listFree(txt); }
Foam fboxMake(FoamBox fbox) { Foam newFoam; int i=0; FoamList l; if (fbox->l == 0) { if (fbox->initial) return fbox->initial; else return foamNewEmpty(fbox->tag, int0); } newFoam = foamNewEmpty(fbox->tag, fbox->argc + foamNaryStart(fbox->tag)); if (fbox->initial) for(i=0; i<foamArgc(fbox->initial); i++) foamArgv(newFoam)[i].code = foamArgv(fbox->initial)[i].code; fbox->l = listNReverse(Foam)(fbox->l); for (l = fbox->l; l; l = cdr(l), i++) foamArgv(newFoam)[i].code = car(l); if (fbox->initial) foamFreeNode(fbox->initial); listFree(Foam)(fbox->l); stoFree(fbox); return newFoam; }
void testRemoval() { LList *list = newList( comparisonFunction ); const int numElements = 1000; // Insert elements for( int i = 0; i < numElements; i++ ) { listInsert( list, mallocInt(i) ); } // Remove the elements and ensure that the right elements were removed for( int i = 0; i < numElements; i++ ) { int *elementToRemove = mallocInt(i); int *removedElement = listRemove( list, elementToRemove ); assertNotNull( removedElement, "removedElement is null!\n" ); int comparisonResult = list->comparisonFunction( elementToRemove, removedElement ); assertTrue( comparisonResult == 0, "compare(%d, %d) != 0\n", *elementToRemove, *removedElement ); free( elementToRemove ); free( removedElement ); } // Free the list listFree( list ); }
void testListFind() { LList *list = newList( comparisonFunction ); const int numElements = 1000; // Insert the elements for( int i = 0; i < numElements; i++ ) { listInsert( list, mallocInt(i) ); } // Find the elements for( int i = 0; i < numElements; i++ ) { int *intToFind = mallocInt(i); // Ensure that the find didn't return null ListNode *findResult = listFind( list, intToFind ); assertNotNull( findResult, "find(i) should not be NULL!\n" ); // Ensure that the elements are equal int comparisonResult = list->comparisonFunction( intToFind, findResult->data ); assertTrue( comparisonResult == 0, "find(%d)->data != %d\n", i, i ); free( intToFind ); } // Free the list listFree( list ); }
static void externalServerDelete(externalServer_t* pServer) { if (pServer) { if (pServer->serverName) { FREE(pServer->serverName); } if (pServer->serverIP) { FREE(pServer->serverIP); } // all these lists should be empty as we are just deleting the // head and not all the objects inside the list listFree(pServer->activeConnections); listFree(pServer->freeConnections); listFree(pServer->unassignedRequests); FREE(pServer); } }
// GLUT callback for keyboard activity. // 1 - 9 to change the degree of the polynomial. // 0 to change between bezier and b-spline. // C to clear the control points. // ESC to quit. // U to switch between uniform and nonuniform bspline curves. void keyboard(unsigned char key, int x, int y) { if (key >= '1' && key <= '9') order = (int)key - 48; else if (key == '0') bezier = !bezier; else if (key == 'c' || key == 'C') { selected = 0; listFree(l); l = 0; count = 0; } else if ((int)key == 27) { glutDestroyWindow(glutGetWindow()); exit(0); } else if ((key == 'u' || key == 'U') && !bezier) uniform = !uniform; if (!bezier) { free(knot); if (uniform) knot = computeUniformKnot(order + 1, count - 1); else knot = computeNonUniformKnot(order + 1, count - 1); } glutPostRedisplay(); return; }
void cmdInsert(heap *ops, bool print) { if(print) printf("String: "); char *buf = NULL; list *strbuf = listCreate(); for(;;) { buf = malloc(sizeof(*buf)); fread(buf, sizeof(*buf), 1, stdin); if(*buf == '\n') break; listInsert(strbuf, buf); } free(buf); int listsize = listSize(strbuf), i; buf = malloc(sizeof(char[listsize + 1])); memset(buf, 0, sizeof(char[listsize + 1])); for(i = 0, listMoveBack(strbuf); i < listsize; i++, listMoveBack(strbuf)) { char *tmp = listGetCurrent(strbuf); buf[i] = *tmp; free(tmp); } listFree(strbuf); hpAdd(ops, buf); }
void aboutInit() { char buf[128]; list_t* txt; listItem* it; FILE* fp = fopen( DATADIR"data/about.txt", "r"); if(!fp) { printf("Couldn't open "DATADIR"data/about.txt\n"); return; } txt = listInit(NULL); while( fgets(buf, 128, fp ) ) { int l = strlen(buf); it = listAppendData(txt, malloc( l+1 ) ); strcpy( (char*)(it->data), buf ); } numLines = txt->count; lines = malloc( sizeof(char*)*numLines ); listAddToArray((void*)lines,txt); listFree(txt); }
int main(void) { LISTA *l = NULL; int listSize = 0; int i = 0; int randVal = 0; int val = 0; clock_t s,f; printf("Informe o tamanho da lista: "); scanf("%i", &listSize); srand(time(NULL)); for(i=0; i<listSize; i++) { randVal = rand()%100; push(&l, randVal); } printf("\n"); printf("Lista desordenada: "); imprimeLista(l); s = clock(); LISTA *ord = insertionSortList(l); f = clock(); printf("\n"); printf("Lista ordenada: "); imprimeLista(ord); float t = (f-s)*1000/CLOCKS_PER_SEC; printf("\nTempo: %.2f\n", t); printf("\n Informe o valor a ser buscado: "); scanf("%i", &val); if(binarySearch(ord, val) == 0) { printf("\n O valor: %i, esta na lista.\n", val); } else { printf("\n Valor nao encontrado!\n"); } listFree(l); listFree(ord); return 0; }
void vpFree(VarPool pool) { int i; for(i=0; i < FOAM_LIMIT; i++) listFree(AInt)(pool->vars[i]); stoFree(pool); }
int freeEventList() { size_t i ; for(i = 0 ;i < EVENT_COUNT ; ++i) { if(events[i]) listFree(events[i]); } return E_OK; }
void listFree( node* head ){ if ( NULL == head ) return; if ( NULL != head->next) { listFree( head->next ); } free(head); }
void arClose(Archive ar) { fnameFree(ar->name); if (ar->hasFile) fclose(ar->file); listFreeDeeply(ArEntry)(ar->members, arFreeEntry); listFree(Syme)(ar->symes); stoFree((Pointer) ar); }
/** * @brief Set string list to @a entry. * * @param list pointer to the string list * @param entry the new (and only) element of the list * * @note Actually, a new list will be created and the old list will be freed. */ void listSet(char ***list, const char *entry) { listFree(list); *list = malloc(2 * sizeof(char *)); if (*list) { (*list)[0] = gstrdup(entry); (*list)[1] = NULL; } }
void listFreeAll(felist *l, BOOLE freenodes) { felist *tmp, *tmp2; tmp = l; while (tmp != NULL) { if (freenodes && (listNode(tmp) != NULL)) free(listNode(tmp)); tmp2 = listNext(tmp); listFree(tmp); tmp = tmp2; } }
void testListCreation() { // Create the list LList *list = newList( comparisonFunction ); // Test the initial conditions of the list assertNotNull( list, "List should not be null!\n" ); assertNotNull( list->head, "List head not be null!\n" ); assertNotNull( list->comparisonFunction, "List comparisonFunction not be null!\n" ); assertTrue( list->size == 0, "List size should be zero!\n" ); // Free the list listFree( list ); }
/* * tl is one element of the cross product get(v,k)...get(v,n-1) */ local void tposs0Multi(TPoss tp,Length k,TFormList tl,Length n,Pointer v,TPossGetter get) { if (k == 0) tpossCons(tp, tfMultiFrList(tl)); else { TPoss tpk = get(v, k-1); TPossIterator tpi; tl = listCons(TForm)(NULL, tl); for (tpossITER(tpi,tpk); tpossMORE(tpi); tpossSTEP(tpi)) { TForm t = tpossELT(tpi); t = tfFollowOnly(t); setcar(tl, t); tposs0Multi(tp, k-1, tl, n, v, get); } listFreeCons(TForm)(tl); tpossFree(tpk); } } TPoss tpossMulti(Length argc, Pointer argv, TPossGetter get) { TPoss tp = tpossEmpty(); tposs0Multi(tp, argc, listNil(TForm), argc, argv, get); return tp; } TPoss tpossAdd1(TPoss tp, TForm t) { t = tfFollowOnly(t); if (! tpossHas(tp, t)) tpossCons(tp, t); return tp; } TPoss tpossRefer(TPoss tp) { if (tp != NULL) ++tp->refc; return tp; } TPoss tpossCopy(TPoss tp) { TPoss np; if (tp == NULL) return NULL; np = tpossAlloc(); np->possl = listCopy(TForm)(tp->possl); np->possc = tp->possc; np->refc = 1; return np; } int tpossCount(TPoss tp) { if (tp) return tp->possc; else return 0; } int debugflag = 0; /* Don't want "clever" C compiler's dead coding this */ void tpossFree(TPoss tp) { if (tp == NULL) return; if (--tp->refc > 0) return; if (!debugflag) { listFree(TForm)(tp->possl); stoFree((Pointer) tp); } debugflag = 0; }
void testInserts() { // Create the list LList *list = newList( comparisonFunction ); const int numElements = 100; int prevSize = list->size; // Insert a bunch of elements into the list for( int i = 1; i <= numElements; i++ ) { listInsert( list, mallocInt(i) ); assertTrue( (prevSize + 1) == list->size, "List size should have increased by 1\n" ); prevSize++; } // Assert that the right number of elements are present in the list assertTrue( numElements == list->size, "List should now have %d elements, has %d\n", numElements, list->size ); // Check that the ordering invariant holds ListNode *current = list->head; ComparisonFunction compare = list->comparisonFunction; int numElementsCompared = 0; while( current->next != NULL ) { void *nodeData = current->data; void *nextNodeData = current->next->data; // Segfault prevention check if( nodeData != NULL && nextNodeData != NULL ) { int comparisonResult = compare(nodeData, nextNodeData); assertTrue( comparisonResult < 0, "Assert comparisonResult < 0 failed! (Was %d)\n", comparisonResult ); numElementsCompared++; } current = current->next; } // Ensure that we made some value comparisons throughout the the loop assertTrue( numElementsCompared != 0, "Should haven't compared more than 0 elements!\n" ); // Test insert at beginning listInsert( list, mallocInt( -1 ) ); // Test insert at end listInsert( list, mallocInt( 1000 ) ); // Free the list listFree( list ); }
long DLLCALL listDettach(link_list_t* list) { int refs; if(list==NULL || list->refs<1) return(-1); listLock(list); if((refs=--list->refs)==0) listFree(list); else listUnlock(list); return(refs); }
const Status File::allocatePage(int& pageNo) { Page header; Status status; if ((status = intread(0, &header)) != OK) return status; // If free list has pages on it, take one from there // and adjust free list accordingly. if (DBP(header).nextFree != -1) { // free list exists? // Return first page on free list to the caller, // adjust free list accordingly. pageNo = DBP(header).nextFree; Page firstFree; if ((status = intread(pageNo, &firstFree)) != OK) return status; DBP(header).nextFree = DBP(firstFree).nextFree; } else { // no free list, have to extend file // Extend file -- the current number of pages will be // the page number of the page to be returned. pageNo = DBP(header).numPages; Page newPage; memset(&newPage, 0, sizeof newPage); if ((status = intwrite(pageNo, &newPage)) != OK) return status; DBP(header).numPages++; if (DBP(header).firstPage == -1) // first user page in file? DBP(header).firstPage = pageNo; } if ((status = intwrite(0, &header)) != OK) return status; #ifdef DEBUGFREE listFree(); #endif return OK; }
FreeVar fvFrSymes(SymeList symes) { FreeVar fv; if (symes == listNil(Syme)) fv = fvEmpty(); else if (cdr(symes) == listNil(Syme)) { fv = fvSingleton(car(symes)); listFree(Syme)(symes); } else fv = fvFrTheSymes(symes); return fv; }
int main() { //new a new list node *p,*head; int d,deld,insertd; p = head = NULL; while( scanf("%d",&d) ) { if( 0 == d ) break; node *n = (node*) malloc(sizeof(node)); n->data = d; n->next = NULL; if (NULL == head) p = head = n; p->next = n; p = n; } listLen( head ); listPrint( head ); printf("del?"); scanf("%d",&deld); head = delByData(head, deld); listPrint( head ); printf("insert?"); scanf("%d",&insertd); head = insert(head, insertd); listPrint( head ); printf("reverse\n"); head = reverse (head ); listPrint( head ); printf("sort\n"); //head = selSort( head ); head = bubbleSort( head ); listPrint( head ); listFree( head ); return 0; }