/************************************************************************** * AEarthWindow :: ~AEarthWindow - Destructor for Earth window * **************************************************************************/ AEarthWindow :: ~AEarthWindow() { /*------------------------------------------------------------------------| | Tell earthWindowResizeHandler to stop handling events for AEarthWindow. | -------------------------------------------------------------------------*/ int i; earthWindowResizeHandler.stopHandlingEventsFor(this); for (i = 0; i < stars; i++) { starLines[i].orphanGeometry(); starLines[i].orphanBundle(); } for (i = 0; i <= atmosphereLayers; i++) { earthArc[i].orphanGeometry(); earthArc[i].orphanBundle(); } space.orphanGeometry(); space.orphanBundle(); IGraphicGroupIterator emptyCheck(&theGroup); while (emptyCheck.first()) theGroup.orphanFirst(); } /* end AEarthWindow :: ~AEarthWindow() */
int main(argc, argv) { Pilha pilha; int exit, op, data; printf("digite um comando invalido para sair\n"); do { menu(); exit=scanf("%d", &op); if (op==1) { startPilha(&pilha); } else if (op==2) { printf("qual número botar na pilha? "); scanf("%d", &data); push(&pilha, data); } else if (op==3) { if (emptyCheck(&pilha)) printf("pilha vazia!\n"); else printf("%d tirado da pilha!\n", pop(&pilha)); } else if (op==4) { printf("ainda não implementado!\n"); } } while (exit || op >4 || op<1); return 0; }
int pop(Pilha *pilha) { Node *temp=pilha->head; if(!emptyCheck(pilha)) { int dado = temp->data; pilha->head = temp->next; free(temp); return dado; } else return 0; }
void push(Pilha *pilha, int dado) { Node *noh = (Node*)malloc(sizeof(Node));//criou o apontamento noh->data = dado; if (emptyCheck(pilha) == 1) { pilha->head=noh; //se a pilha estiver vazia, joga o nó para a primeira posição } else { noh->next=pilha->head; //o novo nó recebe o endereço do nó que estava apontado pelo cabeçalho pilha->head=noh; //e o cabelhaço recebe o endereço do novo nó } }
bool AEarthWindow::paintWorld() { /*------------------------------------------------------------------------| | Clear out theGroup. | -------------------------------------------------------------------------*/ IGraphicGroupIterator emptyCheck(&theGroup); while (emptyCheck.first()) theGroup.orphanFirst(); /*------------------------------------------------------------------------| | Add the drawable objects to theGroup. | -------------------------------------------------------------------------*/ space.orphanGeometry(); space.adoptGeometry(&spaceDimensions); space.orphanBundle(); space.adoptBundle(&spaceBundle); theGroup.adoptLast(&space); for (int i=atmosphereLayers; i>=0; i--) { earthArc[i].orphanGeometry(); earthArc[i].adoptGeometry(&arcDimensions[i]); earthArc[i].orphanBundle(); earthArc[i].adoptBundle(&arcBundle[i]); theGroup.adoptLast(&earthArc[i]); } for (int k=0; k<stars ;k++ ) { starList[k].setPoint(star[k]); starLines[k].orphanGeometry(); starLines[k].adoptGeometry(&starList[k]); starLines[k].orphanBundle(); starLines[k].adoptBundle(&starBundle); theGroup.adoptLast(&starLines[k]); } return true; }
int openFile(){ //define a file that was previously opened and future file char* prevFile; prevFile = malloc(2408* sizeof(char)+1); char* prevLineNum; prevLineNum = malloc(2408* sizeof(char)+1); int lineCounter = 0; int count = 1; //while my linked list ain't empty while(emptyCheck(&fileList) == 0){ char* futureFileToOpen; futureFileToOpen = malloc((LINE_MAX* sizeof(char))+1); char* futureListEntry; futureListEntry = malloc(2408* sizeof(char)+1); char* listEntry; listEntry = malloc(2408* sizeof(char)+1); listEntry = grab(&fileList); //determine size to malloc these strings DONT NEED int b = 0; int fileCount = 0; for(b = 0; listEntry[b] != ':'; b++) { fileCount++; } //move past first : b++; int z = 0; int lineCount = 0; for(z = 0; listEntry[b] != '\0'; z++) { lineCount++; b++; } //declare variables for files and line numbers allocated correctly! char* fileToOpen; fileToOpen = malloc((LINE_MAX* sizeof(char))+1); char* lineNumber; lineNumber = malloc((LINE_MAX* sizeof(char))+1); //copy filetoopen int i = 0; while (listEntry[i]!= ':'){ fileToOpen[i] = listEntry[i]; i++; } //skip over the first : i++; //copy lineentry int j=0; while (listEntry[i]!= '\0'){ lineNumber[j] = listEntry[i]; i++; j++; } //declare file variables char* oneLine; oneLine = malloc((LINE_MAX* sizeof(char))+1); FILE *file; //if we're working with a new file, open it //and set line counter to the appropriate line number if(strcmp(fileToOpen, prevFile) != 0){ //if the previous file isn't empty, close it if (strlen(prevFile) != 0) fclose(file); file = fopen(fileToOpen, "r"); //firstEntry = 0; lineCounter = atoi(lineNumber); printf("\n=========================%s\n", fileToOpen); count = 1; } //if its anotehr instance in teh same file, //set linecounter to teh linenumber minus the linenumber from the last instance else{ lineCounter = atoi(lineNumber) - atoi(prevLineNum); //printf("line counter is %d\n", lineCounter); } //set a variable g to linecounter to print all lines before the match int g = lineCounter; //print all lines before the match while (g>1){ fgets(oneLine, LINE_MAX, file); if(numberedMode == 1) printf(" %d: %s", count, oneLine); else printf(" %s", oneLine); g--; count++; } //print the match fgets(oneLine, LINE_MAX, file); //Count how many instances of the word on the matching line for -w if (wordMode == 1){ int countPerLine = 0; char* wordString; wordString = malloc((LINE_MAX* sizeof(char))+1); wordString = strcasestr(oneLine, wordModeWord); while ((wordString = strcasestr(wordString, wordModeWord))){ wordString += strlen(wordModeWord); countPerLine++; } char* testString; testString = malloc((LINE_MAX* sizeof(char))+1); testString = strcasestr(oneLine, wordModeWord); while (countPerLine > 0){ char* copyString; copyString = malloc((LINE_MAX* sizeof(char))+1); //test string is the string starting with first match testString = strcasestr(testString, wordModeWord); //define length of full line minus area up to first match int x= strlen(oneLine) - strlen(testString); //copy oneline up to first match strncpy(copyString, oneLine, x); //add flag strcat(copyString, "\e[7m"); //copy the word strncat(copyString, oneLine+x,strlen(wordModeWord)); //add ending flag strcat(copyString, "\e[0m"); //copy the rest strcat(copyString, oneLine + x+strlen(wordModeWord)); strcpy(oneLine, copyString); testString += 4+strlen(wordModeWord); countPerLine--; } } if(numberedMode == 1) printf("MATCH!! %d: %s", count, oneLine); else printf("MATCH!! %s", oneLine); count++; //copy file to prevFile and prev line num strcpy(prevFile, fileToOpen); strcpy(prevLineNum, lineNumber); //pop the entry off my linked list pop(&fileList); //find future file that will be opened if(emptyCheck(&fileList) == 0){ futureListEntry = grab(&fileList); int v = 0; while (futureListEntry[v]!= ':'){ futureFileToOpen[v] = futureListEntry[v]; v++; } //printf("future file is %s\n", futureFileToOpen); } //if we're moving to a new file or our filelist is empty print rest of current file if(strcmp(fileToOpen, futureFileToOpen) != 0){ while (fgets(oneLine, LINE_MAX, file)){ if (numberedMode == 1) printf(" %d: %s", count, oneLine); else printf(" %s", oneLine); count++; } printf("\n"); } }