void drawgames(int pos) { int selected_game = 0; if (games[pos].status != GAME_FREE) { selected_game = pos; } else selected_game = 0; dispmultiframe(); xt_par0(XT_CH_NORMAL); int c = 0; int useroffsettotal = 0; int ioffset = 0; while (2 * ioffset + useroffsettotal + (games[numgames - c].status == GAME_FREE ? 0 : games[numgames - c].slots_filled) < ROWS - 20){ useroffsettotal += games[numgames - c].status == GAME_FREE ? 0 : games[numgames - c].slots_filled; c++; } int i = selected_game - c; int ii; useroffsettotal = 1; int useroffset = 1; if (i < 0) i = 0; for (; i < MAX_GAMES; i++) { if (games[i].status == GAME_FREE) continue; printgame(5 + 2 * ioffset + useroffsettotal, i == selected_game, games[i]); for (ii = 0; ii < games[i].slots_filled; ii++) { if (games[i].players[ii] == EMPTY_SLOT) continue; SETPOS(6 + 2 * ioffset + useroffsettotal, 8); printf("%s", users[games[i].players[ii]].username); useroffset++; useroffsettotal++; } useroffset = 1; i++; ioffset++; } SETPOS(2, 3); printf("Open Lobbies (Up/Down to select, %sJ%soin, %sC%sreate, %sQ%suit, %sH%selp)", XT_CH_UNDERLINE, XT_CH_NORMAL, XT_CH_UNDERLINE, XT_CH_NORMAL, XT_CH_UNDERLINE, XT_CH_NORMAL, XT_CH_UNDERLINE, XT_CH_NORMAL); xt_par0(XT_CH_BOLD); SETPOS(3, 3); printf("terminvaders MuLtIpLaYeR Lobby"); xt_par0(XT_CH_DEFAULT); }
//Creates the text representation of myuiscreen by using ASCII art. void setup() { //print using myui (stat) xt_par0(XT_CLEAR_SCREEN); setStat(); xt_par2(XT_SET_ROW_COL_POS, row = 1, col = 1); xt_par0(XT_CH_GREEN); printf("-------------------------------------------------------LifeTracker------------------------------------------------------"); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 2, col = 25); printf("Number of Records: %s | Authors: %s | Version: %s ", data[3].value, data[2].value, data[1].value); xt_par2(XT_SET_ROW_COL_POS,row = 3, col = 24); if (maxRecord != 0) printf("First Record Time: %s | Last Record Time: %s", data[4].value, data[5].value); else printf(" First Record Time: (NULL) | Last Record Time: (NULL)"); xt_par2(XT_SET_ROW_COL_POS, row = 4, col = 1); printf("------------------------------------------------------------------------------------------------------------------------"); xt_par2(XT_SET_ROW_COL_POS, row = 5, col = 1); xt_par0(XT_CH_BLUE); if(screen == 0) printf("------------UP/Down-Scroll between Subjects/Records/Search Left/Right-Toggle between Subjects/Records/Search------------"); else if(screen == 1 || screen == 2) printf("-------------------------------------UP/Down-Switch rows Left/Right-Switch columns--------------------------------------"); else printf("------------------------------------------------------------------------------------------------------------------------"); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, row = 7, col = 21); }
//Displays the screen for deleting a record. User will only be able to delete a record //after pressing F3 two times, to ascertain that she wants to delete the record. void deleteScreen(){ setup(); for(i = 0; i < 12; i++){ xt_par2(XT_SET_ROW_COL_POS, row = 11+i, col = 24); printf("|"); xt_par2(XT_SET_ROW_COL_POS, row = 11+i, col = 96); printf("|"); } xt_par2(XT_SET_ROW_COL_POS, row = 11, col = 25); printf("-----------------------------------------------------------------------"); xt_par0(XT_CH_GREEN); xt_par2(XT_SET_ROW_COL_POS, row = 12, col = 25); printf("Record - (---------- --:--:--)"); //print the record number and time using myui1 xt_par2(XT_SET_ROW_COL_POS, row = 13, col = 25); printf("Category:"); xt_par2(XT_SET_ROW_COL_POS, row = 15, col = 25); printf("Title:"); xt_par2(XT_SET_ROW_COL_POS, row = 18, col = 25); printf("Body:"); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, row = 22, col = 25); printf("-------------------------------F3-Delete-------------------------------"); xt_par2(XT_SET_ROW_COL_POS, row = 28, col = 1); xt_par0(XT_CH_BLUE); printf("-------------------------------------------------------F9-EXIT----------------------------------------------------------"); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS,row = 14, col = 25); }
//Clears the search after the user exits from that portion of the screen. void clearSearch(){ //insert code for resetting Title, Category, and Body (for some reason we have several versions of this) int trow, tcol; xt_par2(XT_SET_ROW_COL_POS, trow = 8, tcol = 95); xt_par0(XT_CH_GREEN); printf("Category:"); xt_par2(XT_SET_ROW_COL_POS, trow = 11, tcol = 95); printf("Title:"); xt_par2(XT_SET_ROW_COL_POS, trow = 15, tcol = 95); printf("Body:"); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, trow = 9, tcol = 95); printf("------------------"); xt_par2(XT_SET_ROW_COL_POS, trow = 12, tcol = 95); printf("-------"); xt_par2(XT_SET_ROW_COL_POS, trow = 13, tcol = 95); printf("------------------"); for(i = 0; i < 5; i++){ xt_par2(XT_SET_ROW_COL_POS, trow = 16+i, tcol = 95); printf("-------------------------"); } xt_par2(XT_SET_ROW_COL_POS, trow = 16 + 5, tcol = 95); printf("---------------"); xt_par2(XT_SET_ROW_COL_POS, row, col); }
void main() { int c, row, col; int i, j; xt_par2(XT_BG_BLUE,row=1,col=1); row = col = 1; xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS,row=24,col=1); printf("%s", greeting); xt_par2(XT_SET_ROW_COL_POS,row=1,col=1); for (i = 0; i < 23; i++) { for (j = 0; j < 80; j++) { Board[i][j] = ' '; } Board[i][80] = '\0'; } while (1) { while ((c = getkey()) == KEY_NOTHING) ; if(c == KEY_F9) break; else if (c == KEY_F3) startRipple(); else if (c == KEY_UP && row > 3) xt_par2(XT_SET_ROW_COL_POS,--row,col); else if (c == KEY_DOWN && row < 21) xt_par2(XT_SET_ROW_COL_POS,++row,col); else if (c == KEY_RIGHT && col < 78) xt_par2(XT_SET_ROW_COL_POS,row,++col); else if (c == KEY_LEFT && col > 3) xt_par2(XT_SET_ROW_COL_POS,row,--col); else if (c == KEY_ENTER) xt_par2(XT_SET_ROW_COL_POS,++row,col=1); else if (c == KEY_BACKSPACE && col > 1) { xt_par2(XT_SET_ROW_COL_POS,row,--col); putchar(' '); Board[row - 1][col - 1] = ' '; xt_par2(XT_SET_ROW_COL_POS,row,col); } else if (c == KEY_DELETE) { Board[row - 1][col - 1] = ' '; putchar(' '); xt_par2(XT_SET_ROW_COL_POS,row,col); } else if (c >= '1' && c <= '9') { putchar(c); Board[row-1][col-1] = c; if (col < 80) { ++col; } else if (row < 23) { xt_par2(XT_SET_ROW_COL_POS,++row,col=1); } else { xt_par2(XT_SET_ROW_COL_POS,row,col); } } } getkey_terminate(); xt_par2(XT_BG_DEFAULT,row=1,col=1); xt_par0(XT_CLEAR_SCREEN); }
//The function to loop through dataStorage to determine the records that match //the input parameters for T, B, and C in Search. void searchResults(int range){ free(catStorage); int trow, tcol; char TempBodyA[71]; char TempBodyB[71]; int r; int i; removeBlanks(); for(i = 6; i <= 25; i++){ xt_par2(XT_SET_ROW_COL_POS,trow=i,tcol=20); printf(" "); } tempCounter = 0; //struct ArrayRecords *catStorage; catStorage = (struct ArrayRecords*)malloc((maxRecord) * sizeof(struct ArrayRecords)); for(i = 0; i < maxRecord; i++){ if(strstr(dataStorage[i].subject, Title) != NULL && strstr(dataStorage[i].body, Body) != NULL && strstr(dataStorage[i].category, Category) != NULL) { catStorage[tempCounter] = dataStorage[i]; tempCounter++; } } i = 0; //printf("Is there anything in catStorage? %s\n", catStorage[1].body); for(r = range; r < 4+range; r++){ if(r < tempCounter){ int k = 0; while(k != 70) { TempBodyA[k] = ' '; TempBodyB[k] = ' '; k++; } TempBodyA[70] = '\0'; TempBodyB[70] = '\0'; k = 0; xt_par2(XT_SET_ROW_COL_POS, trow = 7+5*i, tcol = 20); xt_par0(XT_CH_GREEN); printf("Record %d (%s)", r+1, catStorage[r].timedate); //get the time using myui1 xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, trow = 8+5*i, tcol = 20); int j = 0; while(catStorage[r].body[j] != '\0'){ if(j < 70) TempBodyA[j] = catStorage[r].body[j]; else if(j < 140) TempBodyB[j%70] = catStorage[r].body[j]; j++; } xt_par0(XT_CH_GREEN); printf("%s", catStorage[r].subject); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, trow = 9+5*i, tcol = 20); printf("%s", TempBodyA); xt_par2(XT_SET_ROW_COL_POS, trow = 10+5*i, tcol = 20); printf("%s", TempBodyB); i++; } } xt_par2(XT_SET_ROW_COL_POS,row,col); }
static void drawDoodler(Doodler d) { xt_par2(XT_SET_ROW_COL_POS,1,1); xt_par2(XT_SET_ROW_COL_POS,d.y,d.x); xt_par0(XT_BG_RED); //printf("doodler"); puts(DOODLER_SHAPE); xt_par0(XT_BG_DEFAULT); }
//Function to update the screen by displaying the correct records when the user scrolls //up and down. The maximum number of records displayed at any time is four, from range to //range + four. void updateRecords(int range){ free(catStorage); int trow, tcol; char TempBodyA[71]; char TempBodyB[71]; int r; int i; for(i = 6; i <= 25; i++){ xt_par2(XT_SET_ROW_COL_POS,trow=i,tcol=20); printf(" "); } tempCounter = 0; //struct ArrayRecords *catStorage; catStorage = (struct ArrayRecords*)malloc((maxRecord) * sizeof(struct ArrayRecords)); for(i = 0; i < maxRecord; i++){ if(strcmp(dataStorage[i].category, categoryList[CATEGORY-8].category) == 0){ catStorage[tempCounter] = dataStorage[i]; tempCounter++; } } i = 0; for(r = range; r < 4+range; r++){ if(r < tempCounter){ int k = 0; while(k != 70) { TempBodyA[k] = ' '; TempBodyB[k] = ' '; k++; } TempBodyA[70] = '\0'; TempBodyB[70] = '\0'; k = 0; xt_par2(XT_SET_ROW_COL_POS, trow = 7+5*i, tcol = 20); xt_par0(XT_CH_GREEN); printf("Record %d (%s)", r+1, catStorage[r].timedate); //get the time using myui1 xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, trow = 8+5*i, tcol = 20); int j = 0; while(catStorage[r].body[j] != '\0'){ if(j < 70) TempBodyA[j] = catStorage[r].body[j]; else if(j < 140) TempBodyB[j%70] = catStorage[r].body[j]; j++; } xt_par0(XT_CH_GREEN); printf("%s", catStorage[r].subject); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS, trow = 9+5*i, tcol = 20); printf("%s", TempBodyA); xt_par2(XT_SET_ROW_COL_POS, trow = 10+5*i, tcol = 20); printf("%s", TempBodyB); i++; } } xt_par2(XT_SET_ROW_COL_POS,row,col); }
void addRecord(){ saveOption = 0; subjInput = (char*)malloc(31 * sizeof(char)); bodyInput = (char*)malloc(141 * sizeof(char)); subjPos = bodyPos = 0; xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS, 1, 1); xt_par0(XT_CH_BOLD); printf("Welcome to MyStore.\n"); xt_par0(XT_CH_NORMAL); setUpAddEditScreen(); addEditKeyboardControl(); }
//display functions int displayUIElement(Area window,struct displayText ui, ...) { int row = 0; int col = 0; int len = strlen(ui.text); va_list args; va_start(args,ui); row = verticalMargin(ui.verticalMargin,window); if(ui.verticalMargin > 0) { row = window.top + ui.verticalMargin; } else if (ui.verticalMargin < 0) { row = window.bot + ui.verticalMargin; } if(ui.alignment == TEXT_ALIGN_LEFT) { col = window.left; } else if (ui.alignment == TEXT_ALIGN_CENTER) { col = (window.right - window.left - len) / 2; } else if (ui.alignment == TEXT_ALIGN_RIGHT) { col = window.right - len; } xt_par2(XT_SET_ROW_COL_POS,row,col); xt_par0(ui.color); vprintf(ui.text,args); va_end(args); return row; }
void main(){ xt_par0(XT_CLEAR_SCREEN); int score = 0; int highscore = 0; xt_par2(XT_SET_ROW_COL_POS, 1,1); printf("Welcome to Pacman! Press any arrow key to start a new game.\n# are walls\n* are pellets to eat\n"); printf("Objective: Collect all the pellets in as few moves as possible.\n"); printf("Press F3 to restart. Press F2 to quit.\n"); while (1){ while ((c = getkey()) == KEY_NOTHING); if (c == KEY_LEFT || c == KEY_RIGHT || c == KEY_UP || c == KEY_DOWN) play(); break; } getkey_terminate(); xt_par0(XT_CLEAR_SCREEN); }
void dispmultiframe(){ xt_par0(XT_CLEAR_SCREEN); SETPOS(10,10); xt_par0(XT_CH_NORMAL); int cursor_r = 1, cursor_c = 1; SETPOS(1, 1); int test = 0; int lim = 3; while (cursor_c <= COLS) { cursor_r = 1; SETPOS(cursor_r, cursor_c); printf("~"); cursor_r = ROWS; SETPOS(cursor_r, cursor_c); printf("~"); cursor_c++; if (test == lim){ fflush(stdout); test = 0; } test++; } cursor_r = 2; while (cursor_r < ROWS) { cursor_c = 1; SETPOS(cursor_r, cursor_c); printf("#"); cursor_c = COLS - 20; SETPOS(cursor_r, cursor_c); putchar('|'); cursor_c = COLS; SETPOS(cursor_r, cursor_c); printf("#"); cursor_r++; if (test == lim){ fflush(stdout); test = 0; } test++; } }
void editRecord(){ saveOption = 1; subjInput = (char*)malloc(31 * sizeof(char)); bodyInput = (char*)malloc(141 * sizeof(char)); subjPos = bodyPos = 0; char strRecordNum[10]; sprintf(strRecordNum, "%d", recordNum); ReadMystoreFromChild("display", strRecordNum, NULL, NULL); ParseInput(); strcpy(subjInput,pairs[3].value); strcpy(bodyInput,pairs[4].value); xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS, 1, 1); xt_par0(XT_CH_BOLD); printf("Welcome to MyStore.\n"); xt_par0(XT_CH_NORMAL); printf("This is the EDIT Page.\n"); printf("Added/edited text shows up in RED.\n"); setUpAddEditScreen(); addEditKeyboardControl(); }
void ClearBoard() { int i,j; for (i = 0; i < 23; i++) { for (j = 0; j < 80; j++) { Board[i][j] = ' '; } } xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS,24,1); printf("%s",greeting); xt_par2(XT_SET_ROW_COL_POS,1,1); }
void setUpAddEditScreen(){ row = col = 10; screenPos = 1; printf("Use up and down arrow keys to scroll between subject and body.\n"); printf("When you are totally finished, press 'ENTER' on the save button.\n"); printf("Alternatively, press F3 to return to the display screen without saving\n"); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 10,1); printf("SUBJECT: "); xt_par0(XT_CH_DEFAULT); printf("%s", subjInput); xt_par2(XT_SET_ROW_COL_POS,15,1); printf("BODY: %s", bodyInput); xt_par2(XT_SET_ROW_COL_POS, 20, 10); printf("SAVE"); xt_par2(XT_SET_ROW_COL_POS, 10,10); }
void raiseScreen(){ if (screenPos == 1){ xt_par2(XT_SET_ROW_COL_POS, 10, 1); printf("SUBJECT: "); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 20, 10); printf("SAVE"); xt_par0(XT_CH_DEFAULT); screenPos = 3; } else if (screenPos == 2){ xt_par2(XT_SET_ROW_COL_POS, 15, 1); printf("BODY: "); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 10, 1); printf("SUBJECT: "); xt_par0(XT_CH_DEFAULT); row = 10; col = 10; subjPos = 0; screenPos = 1; } else { xt_par2(XT_SET_ROW_COL_POS, 20, 10); printf("SAVE"); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 15, 1); printf("BODY: "); xt_par0(XT_CH_DEFAULT); row = 15; col = 7; bodyPos = 0; screenPos = 2; } }
void endGame(){ xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS, 1, 1); if (numMoves < bestScore) bestScore = numMoves; printf("CONGRATULATIONS! You finished in %d moves!\n\n\n", numMoves); printf("Would you like to play again?\nIf so, press the LEFT arrow key. If not, press the RIGHT arrow key.\n"); while (1){ while((c=getkey()) == KEY_NOTHING); if (c == KEY_LEFT){ play(); break; } else if (c == KEY_RIGHT) break; } }
//Function for printing the main screen (everything on the main screne) void lifeTracker() { setup(); for(i = 0; i < 20; i++){ xt_par2(XT_SET_ROW_COL_POS, row = i+7, col = 1); printf("|"); xt_par2(XT_SET_ROW_COL_POS, row = i+7, col = 16); printf("|"); xt_par2(XT_SET_ROW_COL_POS, row = i+7, col = 19); printf("|"); xt_par2(XT_SET_ROW_COL_POS, row = i+7, col = 91); printf("|"); xt_par2(XT_SET_ROW_COL_POS, row = i+7, col = 94); printf("|"); xt_par2(XT_SET_ROW_COL_POS, row = i+7, col = 120); printf("|"); } xt_par2(XT_SET_ROW_COL_POS, row = 7, col = 2); fillCategory(); xt_par0(XT_CH_GREEN); printf("--Categories--"); xt_par0(XT_CH_WHITE); if(sort == 0) bubbleSortTime(); else if (sort == 1) bubbleSort(); xt_par2(XT_SET_ROW_COL_POS, row = 26, col = 2); xt_par0(XT_CH_BLUE); printf("---F6-Sort----"); updateRecords(0); xt_par2(XT_SET_ROW_COL_POS, row = 26, col = 20); xt_par0(XT_CH_BLUE); printf("-----------------------F2-Add F3-Delete F4-Edit------------------------"); xt_par0(XT_CH_GREEN); xt_par2(XT_SET_ROW_COL_POS, row = 7, col = 95); printf("---------Search----------"); clearSearch(); //also delete the code in between these lines xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, row = 26, col = 95); printf("--------F7-Search--------"); xt_par2(XT_SET_ROW_COL_POS, row = 28, col = 1); xt_par0(XT_CH_BLUE); printf("---------------------------------------------------------F9-EXIT--------------------------------------------------------"); xt_par0(XT_CH_WHITE); xt_par2(XT_SET_ROW_COL_POS,row=CATEGORY,col=2); }
int lobby() { char* buffer; int option, command; int flags = fcntl(sockfd, F_GETFL, 0); int j; for (j = 0; j < MAX_CLIENTS; j++) users[j].id = j; for (j = 0; j < MAX_GAMES; j++) games[j].id = j; while (1) { if (transmit(sockfd, CMD_LOBBY_INFO, NULL) < 0) return 0; if (receive(sockfd, &command, &buffer) < 0) return 0; switch (command) { case CMD_LOBBY_INFO: { int ii; unserialize_lobby_info(buffer, &users[0], &games[0]); numgames = 0; for (ii = 0; ii < MAX_GAMES; ii++) { if (games[ii].status != GAME_FREE) numgames++; } break; } case CMD_QUIT: case CMD_ERROR: return 0; } free(buffer); fcntl(sockfd, F_SETFL, flags | O_NONBLOCK); option = game(); //game() calls the actual multiplayer lobby logic. fcntl(sockfd, F_SETFL, flags); switch (option) { case MENU_QUIT: xt_par0(XT_CH_NORMAL); return 0; } usleep(1000000 / 5); } }
void setUpBoard(){ xt_par0(XT_CLEAR_SCREEN); printscores(); xt_par2(XT_SET_ROW_COL_POS,row=1,col=1); FILE *fp; fp = fopen("pacman.txt", "r"); int i; for (i = 0; i < 25; i++){ char line[25]; (fgets(line, 25, fp)); strcpy(data[i], line); printf("%s",data[i]); } fclose(fp); xt_par2(XT_SET_ROW_COL_POS, row=19, col=12); putchar('<'); xt_par2(XT_SET_ROW_COL_POS, row=19, col=12); }
void lowerScreen(){ if (screenPos == 1){ xt_par2(XT_SET_ROW_COL_POS, 10, 1); printf("SUBJECT: "); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 15, 1); printf("BODY: "); xt_par0(XT_CH_DEFAULT); row = 15; col = 7; //xt_par0(XT_CH_RED); // bodyInput = enterInput(0); bodyPos = 0; screenPos = 2; } else if (screenPos == 2){ xt_par2(XT_SET_ROW_COL_POS, 15, 1); printf("BODY: "); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 20, 10); printf ("SAVE"); xt_par0(XT_CH_DEFAULT); screenPos = 3; } else { xt_par2(XT_SET_ROW_COL_POS, 20, 10); printf("SAVE"); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 10, 1); printf("SUBJECT: "); xt_par0(XT_CH_DEFAULT); row = 10; col = 10; // subjInput = enterInput(1); subjPos = 0; screenPos = 1; } }
void addEditKeyboardControl(){ while (1){ while ((c = getkey()) == KEY_NOTHING); //temp testing code /* xt_par2(XT_SET_ROW_COL_POS, 20, 1); xt_par0(XT_ERASE_LINE); xt_par2(XT_SET_ROW_COL_POS, 21, 1); xt_par0(XT_ERASE_LINE); xt_par2(XT_SET_ROW_COL_POS, 20, 1); printf("subject test: %s\n", subjInput); printf("body test: %s\n", bodyInput); xt_par2(XT_SET_ROW_COL_POS, row, col); */ //end temp testing code if (c == KEY_ENTER){ if (screenPos == 3){ if (strlen(subjInput) > 0 && strlen(bodyInput) > 0){ save(); break; } } } else if (c == KEY_DOWN){ lowerScreen(); } else if (c == KEY_UP){ raiseScreen(); } else if (c >= ' ' && c <= '~'){ xt_par0(XT_CH_RED); if (screenPos == 1){ //row = 10; //col = 10; size = 31; xt_par2(XT_SET_ROW_COL_POS, row, col); if (subjPos < size - 1){ if (subjInput[subjPos] == '\0') subjInput[subjPos + 1] = '\0'; subjInput[subjPos++] = c; // subjInput[++subjPos] = '\0'; putchar(c); col++; } } else if (screenPos == 2){ //row = 15; //col = 7; size = 141; if (bodyPos < size - 1){ if (bodyInput[bodyPos] == '\0') bodyInput[bodyPos + 1] = '\0'; bodyInput[bodyPos++] = c; // bodyInput[++bodyPos] = '\0'; putchar(c); col++; if (col > 80){ xt_par2(XT_SET_ROW_COL_POS, row=16, col=1); } } } xt_par0(XT_CH_DEFAULT); } else if (c == KEY_BACKSPACE){ if (screenPos == 1){ if (subjPos > 0){ if (subjInput[subjPos] == '\0') subjInput[--subjPos] = '\0'; else subjInput[--subjPos] = ' '; xt_par2(XT_SET_ROW_COL_POS, row, --col); putchar(' '); xt_par2(XT_SET_ROW_COL_POS, row, col); } } else if (screenPos == 2){ if (bodyPos > 0){ if (bodyInput[bodyPos] == '\0') bodyInput[--bodyPos] = '\0'; else bodyInput[--bodyPos] = ' '; if (row == 16 && col == 1) xt_par2(XT_SET_ROW_COL_POS, row=15, col=80); else xt_par2(XT_SET_ROW_COL_POS, row, --col); putchar(' '); xt_par2(XT_SET_ROW_COL_POS, row, col); } } } else if (c == KEY_DELETE){ if (screenPos == 1){ if (subjInput[subjPos] != '\0') subjInput[subjPos] = ' '; putchar(' '); xt_par2(XT_SET_ROW_COL_POS, row, col); } else if (screenPos == 2){ if (bodyInput[bodyPos] != '\0') bodyInput[bodyPos] = ' '; putchar(' '); xt_par2(XT_SET_ROW_COL_POS, row, col); } } else if (c == KEY_LEFT){ if (screenPos == 1){ if (subjPos > 0){ subjPos --; xt_par2(XT_SET_ROW_COL_POS, row, --col); } } else if (screenPos == 2){ if (bodyPos > 0){ bodyPos --; if (row == 16 && col == 1) xt_par2(XT_SET_ROW_COL_POS, row=15, col=80); else xt_par2(XT_SET_ROW_COL_POS, row, --col); } } } else if (c == KEY_RIGHT){ if (screenPos == 1){ if (subjInput[subjPos] != '\0'){ subjPos++; xt_par2(XT_SET_ROW_COL_POS, row, ++col); } } else if (screenPos == 2){ if (bodyInput[bodyPos] != '\0'){ bodyPos++; if (row == 15 && col == 80) xt_par2(XT_SET_ROW_COL_POS, row=16, col=1); else xt_par2(XT_SET_ROW_COL_POS, row, ++col); } } } else if (c == KEY_F3){ // recordNum = 1; display(); break; } } getkey_terminate(); }
void viewFoundRecordsHelper(){ while (1){ while ((c=getkey()) == KEY_NOTHING); // xt_par2(XT_SET_ROW_COL_POS, 18, 1); // xt_par0(XT_ERASE_LINE); if (c == KEY_LEFT){ if (numFoundRecords != 1){ fi--; if (fi < 0) fi = numFoundRecords-1; displayFoundRecords(); break; } } else if (c == KEY_RIGHT){ if (numFoundRecords != 1){ fi++; if (fi == numFoundRecords) fi = 0; displayFoundRecords(); break; } } else if (c == KEY_F3){ if (numFoundRecords > 0){ int tempRecordCounter = numRecords; deleteRecordHelper(); calculateNumRecords(); if (numRecords < tempRecordCounter) numFoundRecords--; //numRecords --; if (fi == numRecords) fi--; displayFoundRecords(); break; } else{ xt_par2(XT_SET_ROW_COL_POS, 18, 1); xt_par0(XT_ERASE_LINE); printf("No record to delete."); } } else if (c == KEY_F4){ if (numRecords > 0) recordNum = 1; display(); break; } else if (c == KEY_F5){ findInputScreen(); break; } else if (c == KEY_F6){ if (numFoundRecords > 0){ editRecord(); //displayFoundRecords(); break; } else{ xt_par2(XT_SET_ROW_COL_POS, 18, 1); xt_par0(XT_ERASE_LINE); printf("No record to edit."); } } } getkey_terminate(); }
void deleteRecordHelper(){ xt_par2(XT_SET_ROW_COL_POS,23,1); xt_par0(XT_CH_BOLD); printf("Are you sure you wish to delete current record?"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS,24,20); printf("YES"); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 24, 40); printf("NO"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS,24,80); int curSelect = 1; while(1){ while ((c=getkey()) == KEY_NOTHING); if(c == KEY_LEFT){ curSelect = 0; xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS,24,20); printf("YES"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS, 24, 40); printf("NO"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS,24,80); } else if(c == KEY_RIGHT){ curSelect = 1; xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS,24,20); printf("YES"); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 24, 40); printf("NO"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS,24,80); } else if(c == KEY_ENTER){ xt_par2(XT_SET_ROW_COL_POS,23,1); xt_par0(XT_ERASE_LINE); xt_par2(XT_SET_ROW_COL_POS,24,1); xt_par0(XT_ERASE_LINE); if(curSelect == 0){ char del[5]; sprintf(del, "%d", recordNum); ReadMystoreFromChild("delete",del,NULL,NULL); if(recordNum == numRecords) recordNum--; numRecords--; } break; } } }
void deleteAllRecords(){ xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS, 10,1); xt_par0(XT_CH_BOLD); printf("Are you sure you want to delete ALL records?"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS, 11, 20); printf("YES"); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 11, 40); printf("NO"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS,24,80); int curSelect = 1; int key; while(1){ while ((key=getkey()) == KEY_NOTHING); if(key == KEY_LEFT){ curSelect = 0; xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 11, 20); printf("YES"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS, 11, 40); printf("NO"); xt_par2(XT_SET_ROW_COL_POS,24,80); } else if(key == KEY_RIGHT){ curSelect = 1; xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS, 11, 20); printf("YES"); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 11, 40); printf("NO"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS,24,80); } else if(key == KEY_ENTER){ if(curSelect == 0){ char del[2]; del[0] = '1'; del[1] = '\0'; recordNum = 1; while(numRecords > 0){ //printf("%d\n", numRecords); ReadMystoreFromChild("delete",del,NULL,NULL); --numRecords; } //while(1); } break; } } }
void display(){ xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS, 1, 1); xt_par0(XT_CH_BOLD); printf("Welcome to MyStore.\n"); xt_par0(XT_CH_NORMAL); printf("Scroll through records using left and right arrow keys.\n\n"); printf("Press F2 to add a new record\n"); printf("Press F3 to delete current record\n"); printf("Press F4 to return to welcome screen\n"); printf("Press F5 to delete all records\n"); printf("Press F6 to edit\n"); printf("Press F7 to SEARCH for a key word\n"); printf("Press F9 to jump to first record\n"); if (numRecords == 0){ xt_par0(XT_CH_BOLD); printf("\n\n\nNO RECORDS AS OF YET"); xt_par0(XT_CH_NORMAL); viewRecordHelper(); } else{ char strRecordNum[10]; sprintf(strRecordNum, "%d", recordNum); ReadMystoreFromChild("display", strRecordNum, NULL, NULL); setNumStructsNeeded(); ParseInput(); char *date = (char *)malloc(100 * sizeof(char)); date = pairs[2].value; char *subject = (char *)malloc(30 * sizeof(char)); subject = pairs[3].value; char *body = (char *)malloc(141 * sizeof(char)); body = pairs[4].value; xt_par2(XT_SET_ROW_COL_POS, 15, 1); xt_par0(XT_CH_BOLD); printf("ITEM #: "); xt_par0(XT_CH_NORMAL); printf("%d\n", recordNum); xt_par2(XT_SET_ROW_COL_POS, 16, 1); xt_par0(XT_CH_BOLD); printf("SUBJECT: "); xt_par0(XT_CH_NORMAL); printf("%s", subject); xt_par2(XT_SET_ROW_COL_POS, 17,1); xt_par0(XT_CH_BOLD); printf("BODY: "); xt_par0(XT_CH_NORMAL); printf("%s", body); xt_par2(XT_SET_ROW_COL_POS, 19, 1); xt_par0(XT_CH_BOLD); printf("TIME ADDED: "); xt_par0(XT_CH_NORMAL); printf("%s", date); viewRecordHelper(); } }
void findInputScreen(){ int vertPos = 0; int subjOrBod = 0; char* search = (char*)malloc(141 * sizeof(char)); int searchPos = 0; int row = 10; int col = 13; xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS, 1, 1); printf("Please indicate what key word you would like to search for.\n"); printf("Then, please Indicate if you would like to search through SUBJECTS or BODIES.\n"); printf("To return to the previous screen, press F4."); xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 10, 1); printf("Search for:"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS, 20, 20); printf("SUBJECTS"); xt_par2(XT_SET_ROW_COL_POS, 20, 55); printf("BODIES"); xt_par2(XT_SET_ROW_COL_POS, 10, 13); while (1){ while ((c=getkey()) == KEY_NOTHING); // xt_par2(XT_SET_ROW_COL_POS, 15, 1); // xt_par0(XT_ERASE_LINE); //printf("%s", search); if (c == KEY_DOWN){ if (vertPos == 0){ xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS, 10, 1); printf("Search for:"); if (subjOrBod == 0){ xt_par2(XT_SET_ROW_COL_POS, 20, 20); xt_par0(XT_CH_BLUE); printf("SUBJECTS"); xt_par2(XT_SET_ROW_COL_POS, 20, 55); xt_par0(XT_CH_NORMAL); printf("BODIES"); xt_par2(XT_SET_ROW_COL_POS, 24, 80); xt_par0(XT_CH_NORMAL); } else{ xt_par2(XT_SET_ROW_COL_POS, 20, 20); xt_par0(XT_CH_NORMAL); printf("SUBJECTS"); xt_par2(XT_SET_ROW_COL_POS, 20, 55); xt_par0(XT_CH_BLUE); printf("BODIES"); xt_par2(XT_SET_ROW_COL_POS, 24, 80); xt_par0(XT_CH_NORMAL); } vertPos = 1; } } else if (c == KEY_UP){ if (vertPos == 1){ xt_par0(XT_CH_BLUE); xt_par2(XT_SET_ROW_COL_POS, 10, 1); printf("Search for:"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS, 20, 20); printf("SUBJECTS"); xt_par2(XT_SET_ROW_COL_POS, 20, 55); printf("BODIES"); xt_par2(XT_SET_ROW_COL_POS, 10, 13); vertPos = 0; } } else if (c == KEY_LEFT){ if (vertPos == 1 && subjOrBod == 1){ xt_par2(XT_SET_ROW_COL_POS, 20, 20); xt_par0(XT_CH_BLUE); printf("SUBJECTS"); xt_par2(XT_SET_ROW_COL_POS, 20, 55); xt_par0(XT_CH_NORMAL); printf("BODIES"); xt_par2(XT_SET_ROW_COL_POS, 24, 80); subjOrBod = 0; } else if (vertPos == 0){ if (searchPos > 0){ searchPos --; if (row == 11 && col == 1) xt_par2(XT_SET_ROW_COL_POS, row = 10, col=80); else xt_par2(XT_SET_ROW_COL_POS, row, --col); } } } else if (c == KEY_RIGHT){ if (vertPos == 1 && subjOrBod == 0){ xt_par2(XT_SET_ROW_COL_POS, 20, 20); xt_par0(XT_CH_NORMAL); printf("SUBJECTS"); xt_par2(XT_SET_ROW_COL_POS, 20, 55); xt_par0(XT_CH_BLUE); printf("BODIES"); xt_par2(XT_SET_ROW_COL_POS, 24, 80); xt_par0(XT_CH_NORMAL); subjOrBod = 1; } else if (vertPos == 0){ if (search[searchPos] != '\0'){ searchPos++; if (row == 10 && col == 80) xt_par2(XT_SET_ROW_COL_POS, row=11, col=1); else xt_par2(XT_SET_ROW_COL_POS, row, ++col); } } } else if (c >= ' ' && c <= '~'){ if (vertPos == 0){ xt_par2(XT_SET_ROW_COL_POS, row, col); xt_par0(XT_CH_RED); if (searchPos < 140){ if (search[searchPos] == '\0') search[searchPos + 1] = '\0'; search[searchPos++] = c; putchar(c); col ++; if (col > 80){ xt_par2(XT_SET_ROW_COL_POS, row=11, col=1); } } } xt_par0(XT_CH_DEFAULT); } else if (c == KEY_BACKSPACE){ if (vertPos == 0){ if (searchPos > 0){ if (search[searchPos] == '\0') search[--searchPos] = '\0'; else search[--searchPos] = ' '; if (row == 11 && col == 1) xt_par2(XT_SET_ROW_COL_POS, row=10, col=80); else xt_par2(XT_SET_ROW_COL_POS, row, --col); putchar(' '); xt_par2(XT_SET_ROW_COL_POS, row, col); } } } else if (c == KEY_DELETE){ if (vertPos == 0){ if (search[searchPos] != '\0') search[searchPos] = ' '; putchar(' '); xt_par2(XT_SET_ROW_COL_POS, row, col); } } else if (c == KEY_ENTER){ if (vertPos == 1 && strlen(search) > 0){ findRecords(search, subjOrBod); xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS, 1, 14); xt_par0(XT_CH_BOLD); printf("%s",search); xt_par0(XT_CH_NORMAL); printf(" in "); xt_par0(XT_CH_BOLD); if (subjOrBod == 0) printf("subject"); else printf("body"); xt_par0(XT_CH_NORMAL); displayFoundRecords(); break; } } else if (c == KEY_F4){ display(); break; } } getkey_terminate(); }
void viewRecordHelper(){ while (1){ while ((c=getkey()) == KEY_NOTHING); if (c == KEY_LEFT){ if (numRecords != 1){ recordNum --; if (recordNum <= 0) recordNum = numRecords; display(); break; } } else if (c == KEY_RIGHT){ if (numRecords != 1){ recordNum ++; if (recordNum == (numRecords + 1)){ if (numRecords > 0) recordNum = 1; else recordNum = 0; } display(); break; } } else if (c == KEY_F2){ addRecord(); break; } else if (c == KEY_F3){ if (recordNum > 0){ deleteRecordHelper(); display(); break; } else{ xt_par2(XT_SET_ROW_COL_POS, 18, 1); xt_par0(XT_ERASE_LINE); printf("No record to delete."); } } else if (c == KEY_F4){ welcomeScreen(); break; } else if (c == KEY_F5){ if (recordNum > 0){ deleteAllRecords(); display(); break; } else{ xt_par2(XT_SET_ROW_COL_POS, 18, 1); xt_par0(XT_ERASE_LINE); printf("No records to delete."); } } else if (c == KEY_F6){ if (numRecords > 0){ editRecord(); // display(); break; } else{ xt_par2(XT_SET_ROW_COL_POS, 18, 1); xt_par0(XT_ERASE_LINE); printf("No record to edit."); } } else if (c == KEY_F7){ if (numRecords > 0){ findInputScreen(); break; } else{ xt_par2(XT_SET_ROW_COL_POS, 18, 1); xt_par0(XT_ERASE_LINE); printf("No records to search through."); } } else if (c == KEY_F9){ if (numRecords > 0){ recordNum = 1; display(); break; } else{ xt_par2(XT_SET_ROW_COL_POS, 18, 1); xt_par0(XT_ERASE_LINE); printf("There is no first record yet!"); } } } getkey_terminate(); }
void displayFoundRecords(){ xt_par2(XT_SET_ROW_COL_POS, 15, 1); xt_par0(XT_ERASE_LINE); xt_par2(XT_SET_ROW_COL_POS, 16, 1); xt_par0(XT_ERASE_LINE); xt_par2(XT_SET_ROW_COL_POS, 17, 1); xt_par0(XT_ERASE_LINE); xt_par2(XT_SET_ROW_COL_POS, 18, 1); xt_par0(XT_ERASE_LINE); xt_par2(XT_SET_ROW_COL_POS, 19, 1); xt_par0(XT_ERASE_LINE); xt_par2(XT_SET_ROW_COL_POS, 20, 1); xt_par0(XT_ERASE_LINE); xt_par2(XT_SET_ROW_COL_POS, 1, 1); printf("Records with \n"); printf("Scroll through found records using left and right arrow keys.\n\n"); printf("Press F3 to delete current record\n"); printf("Press F4 to return to all records\n"); printf("Press F5 to input a new SEARCH\n"); printf("Press F6 to edit current record\n"); recordNum = foundRecords[fi]; if (numFoundRecords == 0){ printf("\n\n\nNO MATCHING RECORDS FOUND"); viewFoundRecordsHelper(); } else{ char strRecordNum[10]; sprintf(strRecordNum, "%d", recordNum); ReadMystoreFromChild("display", strRecordNum, NULL, NULL); setNumStructsNeeded(); ParseInput(); char *date = (char*)malloc(100 * sizeof(char)); date = pairs[2].value; char *subject = (char *)malloc(31 * sizeof(char)); subject = pairs[3].value; char *body = (char *)malloc(141 * sizeof(char)); body = pairs[4].value; xt_par2(XT_SET_ROW_COL_POS, 10, 1); xt_par2(XT_SET_ROW_COL_POS, 15, 1); xt_par0(XT_CH_BOLD); printf("ITEM #: "); xt_par0(XT_CH_NORMAL); printf("%d\n", recordNum); xt_par2(XT_SET_ROW_COL_POS, 16, 1); xt_par0(XT_CH_BOLD); printf("SUBJECT: "); xt_par0(XT_CH_NORMAL); printf("%s", subject); xt_par2(XT_SET_ROW_COL_POS, 17,1); xt_par0(XT_CH_BOLD); printf("BODY: "); xt_par0(XT_CH_NORMAL); printf("%s", body); xt_par2(XT_SET_ROW_COL_POS, 19, 1); xt_par0(XT_CH_BOLD); printf("TIME ADDED: "); xt_par0(XT_CH_NORMAL); printf("%s", date); viewFoundRecordsHelper(); } }
void welcomeScreen(){ xt_par0(XT_CLEAR_SCREEN); xt_par0(XT_CH_NORMAL); xt_par0(XT_CH_BOLD); xt_par0(XT_CH_UNDERLINE); xt_par2(XT_SET_ROW_COL_POS,1,1); printf("WELCOME TO MYSTORE!!!"); xt_par2(XT_SET_ROW_COL_POS,5,1); xt_par0(XT_CH_NORMAL); printf("Mystore Back End designed and developed by "); xt_par0(XT_CH_BOLD); printf("Peter Brooks.\n"); xt_par0(XT_CH_NORMAL); printf("Mystore Front End designed and developed by "); xt_par0(XT_CH_BOLD); printf("Justin Duda"); xt_par0(XT_CH_NORMAL); printf(" and "); xt_par0(XT_CH_BOLD); printf("Jeremy Karson.\n\n\n"); printf("System Level Programming\n"); printf("Fall 2013\n"); printf("Period 5\n"); xt_par0(XT_CH_NORMAL); xt_par2(XT_SET_ROW_COL_POS, 20, 20); xt_par0(XT_CH_BLUE); printf("CONTINUE"); xt_par2(XT_SET_ROW_COL_POS, 20, 55); xt_par0(XT_CH_NORMAL); printf("EXIT"); xt_par2(XT_SET_ROW_COL_POS, 24, 80); int screenPos = 1; while(1){ while ((c=getkey()) == KEY_NOTHING); if (c == KEY_LEFT){ if (screenPos == 2){ xt_par2(XT_SET_ROW_COL_POS, 20, 20); xt_par0(XT_CH_BLUE); printf("CONTINUE"); xt_par2(XT_SET_ROW_COL_POS, 20, 55); xt_par0(XT_CH_NORMAL); printf("EXIT"); xt_par2(XT_SET_ROW_COL_POS, 24, 80); screenPos = 1; } } else if (c == KEY_RIGHT){ if (screenPos == 1){ xt_par2(XT_SET_ROW_COL_POS, 20, 20); xt_par0(XT_CH_NORMAL); printf("CONTINUE"); xt_par2(XT_SET_ROW_COL_POS, 20, 55); xt_par0(XT_CH_BLUE); printf("EXIT"); xt_par2(XT_SET_ROW_COL_POS, 24, 80); xt_par0(XT_CH_NORMAL); screenPos = 2; } } else if (c == KEY_ENTER){ if (screenPos == 1){ display(); break; } else{ xt_par0(XT_CLEAR_SCREEN); xt_par2(XT_SET_ROW_COL_POS,1,1); break; } } } getkey_terminate(); }