/*Will free the entire buffer*/ void FreeBuffer(list *FileBuffer){ node *p; p = FileBuffer->head; if (p == NULL) return; while (p){ p = p->next; free(FileBuffer->head); FileBuffer->head = p; } InitialiseBuffer(FileBuffer); }
/*!***************************************************************************************************************************************** @Function main @Input argc Number of arguments passed to the application, ignored. @Input argv Command line strings passed to the application, ignored. @Return Result code to send to the Operating System @Description Main function of the program, executes other functions. *******************************************************************************************************************************************/ int main(int /*argc*/, char **/*argv*/) { // X11 variables Display* nativeDisplay = NULL; Window nativeWindow = 0; // EGL variables EGLDisplay eglDisplay = NULL; EGLConfig eglConfig = NULL; EGLSurface eglSurface = NULL; EGLContext eglContext = NULL; // A vertex buffer object to store our model data. GLuint vertexBuffer = 0; // Get access to a native display if (!CreateNativeDisplay(&nativeDisplay)) { goto cleanup; } // Setup the windowing system, create a window if (!CreateNativeWindow(nativeDisplay, &nativeWindow)) { goto cleanup; } // Create and Initialise an EGLDisplay from the native display if (!CreateEGLDisplay(nativeDisplay, eglDisplay)) { goto cleanup; } // Choose an EGLConfig for the application, used when setting up the rendering surface and EGLContext if (!ChooseEGLConfig(eglDisplay, eglConfig)) { goto cleanup; } // Create an EGLSurface for rendering from the native window if (!CreateEGLSurface(nativeWindow, eglDisplay, eglConfig, eglSurface)) { goto cleanup; } // Setup the EGL Context from the other EGL constructs created so far, so that the application is ready to submit OpenGL ES commands if (!SetupEGLContext(eglDisplay, eglConfig, eglSurface, eglContext)) { goto cleanup; } // Initialise the vertex data in the application if (!InitialiseBuffer(vertexBuffer)) { goto cleanup; } // Renders a triangle for 800 frames using the state setup in the previous function for (int i = 0; i < 800; ++i) { if (!RenderScene(eglDisplay, eglSurface, nativeDisplay)) { break; } } // Release any resources we created in the Initialise functions DeInitialiseBuffer(vertexBuffer); cleanup: // Release the EGL State ReleaseEGLState(eglDisplay); // Release the windowing system resources ReleaseNativeResources(nativeDisplay, nativeWindow); // Destroy the eglWindow return 0; }
/*!***************************************************************************************************************************************** @Function WinMain @Input applicationInstance Application instance created by the Operating System @Input previousInstance Always NULL @Input commandLineString Command line string passed from the Operating System, ignored. @Input showCommand Specifies how the window is to be shown, ignored. @Return Result code to send to the Operating System @Description Main function of the program, executes other functions. *******************************************************************************************************************************************/ int WINAPI WinMain(HINSTANCE applicationInstance, HINSTANCE previousInstance, TCHAR* /*commandLineString*/, int /*showCommand*/) { // Windows variables HWND nativeWindow = NULL; HDC deviceContext = NULL; // EGL variables EGLDisplay eglDisplay = NULL; EGLConfig eglConfig = NULL; EGLSurface eglSurface = NULL; EGLContext eglContext = NULL; // A vertex buffer object to store our model data. GLuint vertexBuffer = 0; // Setup the windowing system, getting a window and a display if (!CreateWindowAndDisplay(applicationInstance, nativeWindow, deviceContext)) { goto cleanup; } // Create and Initialise an EGLDisplay from the native display if (!CreateEGLDisplay(deviceContext, eglDisplay)) { goto cleanup; } // Choose an EGLConfig for the application, used when setting up the rendering surface and EGLContext if (!ChooseEGLConfig(eglDisplay, eglConfig)) { goto cleanup; } // Create an EGLSurface for rendering from the native window if (!CreateEGLSurface(nativeWindow, eglDisplay, eglConfig, eglSurface)) { goto cleanup; } // Setup the EGL Context from the other EGL constructs created so far, so that the application is ready to submit OpenGL ES commands if (!SetupEGLContext(eglDisplay, eglConfig, eglSurface, eglContext, nativeWindow)) { goto cleanup; } // Initialise the vertex data in the application if (!InitialiseBuffer(vertexBuffer, nativeWindow)) { goto cleanup; } // Renders a triangle for 800 frames using the state setup in the previous function for (int i = 0; i < 800; ++i) { if (!RenderScene(eglDisplay, eglSurface, nativeWindow)) { break; } } // Release any resources we created in the Initialise functions DeInitialiseBuffer(vertexBuffer); cleanup: // Release the EGL State ReleaseEGLState(eglDisplay); // Release the windowing system resources ReleaseWindowAndDisplay(nativeWindow, deviceContext); // Destroy the eglWindow return 0; }
//Edits the current file void MenuEdit(list *FileBuffer, WINDOW *my_menu_win){ //Printing the existing file in the buffer to the window PrintBuffer(FileBuffer, my_menu_win); int x = 0, y = 2, c, choice = 0; int ymax = 2; //Creating temporary buffers char str[100][MAXCHAR], string[MAXCHAR]; int i = 0, j = 0; char ch; int ln = 2; node *p; //Copying the contents of the buffer into the 2D temporary buffer p = FileBuffer->head; while(p){ strcpy(&str[ln][0], p->string); p = p->next; ln++; } //If the buffer was non-empty, the contents of the temp buffer will be rewritten FreeBuffer(FileBuffer); InitialiseBuffer(FileBuffer); ymax = ln; y = ymax; x = 0; //Taking input from the user while((c = wgetch(my_menu_win)) != KEY_F(6) ||(c = wgetch(my_menu_win)) != KEY_F(3) ){ switch(c){ case KEY_UP: if (y > 2){ y--; wmove(my_menu_win, y, x); ln--; } break; case KEY_DOWN: y++; if (y > ymax) ymax = y; wmove(my_menu_win, y, x); ln++; break; case KEY_LEFT: if (x > 0){ x--; wmove(my_menu_win, y, x); i--; } break; case KEY_RIGHT: if (x < MAXCHAR){ x++; wmove(my_menu_win, y, x); i++; } break; case KEY_BACKSPACE: case 8: if (x > 0){ x--; wmove(my_menu_win, y, x); i--; } mvwprintw(my_menu_win, y, x, " "); str[y][x] = ' '; break; case 10: case 13: str[y][x] = '\n'; y++; ln++; if (y > ymax) ymax = y; x = 0; wmove(my_menu_win, y, x); break; //Escape case 27: choice = 1; break; default: str[y][x] = c; //Printing the character read to the screen mvwprintw(my_menu_win, y, x, "%c", c); x++; wmove(my_menu_win, y, x); break; } //If the user has pressed escape if (choice) break; } //Copying from temp buffer to permanent buffer for (i = 2; i < ymax ; i++){ //for each character that was read for (j = 0; str[i][j] != '\n'; j++){ string[j] = str[i][j]; } string[j] = '\0'; //Reinserting the strings from the temp buffer to the file buffer AppendtoBuffer(FileBuffer, string); } }
int main(){ WINDOW *my_win, *menu_win, *my_menu_win; ITEM **my_items; MENU *my_menu; list *FileBuffer; int height, width, startx, starty, exit = 0; int highlight = 1; int ch, c, choice = 0, i, j; char str[81]; FileBuffer = (list *)malloc(sizeof(list)); if (FileBuffer == NULL) return; InitialiseBuffer(FileBuffer); initscr(); clear(); noecho(); cbreak(); start_color(); /*Checking whether the terminal supports colors*/ if (has_colors() == FALSE){ endwin(); printf("Your terminal does not support colors\n"); } keypad(stdscr, TRUE); height = 3; width = 10; starty = (LINES - height)/2; startx = (COLS - width) / 2; refresh(); my_win = Create_NewWindow(height, width, starty, startx); mvwhline(my_win, 5, 1, ACS_HLINE, width - 1); init_pair(1, COLOR_RED, COLOR_BLACK); init_pair(2, COLOR_CYAN, COLOR_BLACK); /* Create items */ my_items = (ITEM **)calloc(nchoices, sizeof(ITEM *)); for(i = 0; i < nchoices; ++i) my_items[i] = new_item(menu_options[i], menu_options[i]); /* Create menu */ my_menu = new_menu((ITEM **)my_items); /* Set menu option not to show the description */ menu_opts_off(my_menu, O_SHOWDESC); /* Create the window to be associated with the menu */ my_menu_win = newwin(0, 0, 0, 0); keypad(my_menu_win, TRUE); /* Set main window and sub window */ set_menu_win(my_menu, my_menu_win); set_menu_sub(my_menu, derwin(my_menu_win, 0, 0, 0, 0)); set_menu_format(my_menu, 1, 6); set_menu_mark(my_menu, " * "); /* Post the menu */ post_menu(my_menu); wrefresh(my_menu_win); i = 0; mvwhline(my_menu_win, 1, 0, ACS_HLINE, COLS); mvwprintw(my_menu_win, LINES - 1, 0, "Press F3 to go to the menu, F6 to exit", c); while(1){ choice = ToggleMenu(my_menu_win, my_menu, i); i = choice; switch(choice){ case 0: MenuOpen(FileBuffer, my_menu_win); break; case 1: MenuNew(FileBuffer, my_menu_win, my_menu); break; case 2: MenuSave(FileBuffer, my_menu_win); break; case 3: MenuSaveAs(FileBuffer, my_menu_win); break; case 4: MenuEdit(FileBuffer, my_menu_win); break; case 5: MenuExit(FileBuffer, my_menu_win); exit = 1; break; default: break; } if (exit) break; } /*Assertion: the user wants to exit the program*/ /* Unpost and free all the memory taken up */ unpost_menu(my_menu); free_menu(my_menu); for(j = 0; j < nchoices; ++j) free_item(my_items[j]); clrtoeol(); refresh(); /*Ending curses mode*/ endwin(); return 0; }