#include "display.h" #include "global.h" #include "highlevel.h" #include "main.h" #include "dataops.h" //the following block of globals are used in multiple functions spanning files //there are in many cases corresponding "Get" and "Set" functions struct menuitems{ char menuString[150]; int width; } menuSelections [NUM_MODE_MENUS]; //the different menu items int selection = NULL; //indicates current selection cccmenuopts currMenu = NONE; //indicates current menu stringline menuArray[7] = {NULL}; window tempwin = NULL, iowindow = NULL; //reusable window pointer window tmpMsgWin[2] = {NULL}; mode currMode = NO_FILE; //the current mode menuModeCode currSelection = PROG_MA; //the current combination of mode and menu DLnkNodePtr entry[MAX_ENTRY]; //the list for movie and category listing int fincount=0, msgWinID; menuModeCode menuMode[NUM_MENUS+1][NUM_MODES]; //array of mode/menu combinations DLnkNodePtr WorkingMovie; //the node that is used when jumping lists short lineIndex = 0, middle, highError, highHelp, length[2], helpCode[2]; //menu settings int middleByte, longest, startWinY[2], startWinX[2], looping, start[2] = {FIRST}, end[2], winHeight[2], width[2], msgNumber; //more menu settings messageLine currMsgLine = {NULL}; winMsgLine currErrMess[MAXNUMMESWINLINES] = {NULL}, currHlpMess[MAXNUMMESWINLINES] = {NULL}; bool scrollable[2] = {false}; int * widthptr[2] = {&width[0], &width[1]}; cccwindows currWinType; int reviews=0; //this holds reviews for MainHandler DLnkNodePtr SelNode=NULL; //the currently selected item in the lists typedef void (*FunPtr)(); //This is typedefing FunPtr to be a void Fn. Pointer (menu ops.) FunPtr menu_options[13][NUM_MODES]; //array for menu operations short oldMsgNum = NULL; int displayFirst = NULL; char scrollChar = NULL; mode currentMode = NO_FILE; DLnkNodePtr head=NULL; /********************************************************************** * * Function: InitMenus * * Input: void * * Returns: void * * Description: * Sets up the menus for use. Lets the menu configuration be in one location. * * Variables: none * * Called by: Main * * Calls: none * * Author: Glenn Rioux/Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ void InitMenus(void) { strcpy(menuSelections[PROG_MA].menuString, "About Help F1"); menuSelections[PROG_MA].width = 9; strcpy(menuSelections[FILE_M0].menuString, "New... Ctrl-N Open... Ctrl-O Quit Ctrl-Q "); menuSelections[FILE_M0].width = 16; strcpy(menuSelections[FILE_M123].menuString, "New... Ctrl-N Open... Ctrl-O Save Ctrl-S Save As... Ctrl-A Close Ctrl-L Quit Ctrl-Q "); menuSelections[FILE_M123].width = 19; menuSelections[EDIT_M03].width = 111; strcpy(menuSelections[EDIT_M1].menuString, "Category..."); menuSelections[EDIT_M1].width = 11; strcpy(menuSelections[EDIT_M2].menuString, "Title... Rating... Filename..."); menuSelections[EDIT_M2].width = 11; menuSelections[CCC_M03].width = 123; strcpy(menuSelections[CCC_M1].menuString, "Add Category... Ins Delete Category... Del "); menuSelections[CCC_M1].width = 24; strcpy(menuSelections[CCC_M2].menuString, "Include Review... Ins Erase Review... Del "); menuSelections[CCC_M2].width = 23; menuSelections[VIEW_M0].width = 109; strcpy(menuSelections[VIEW_M1].menuString, "Category Movie "); menuSelections[VIEW_M1].width = 9; strcpy(menuSelections[VIEW_M23].menuString, "Category Movie Review "); menuSelections[VIEW_M23].width = 9; menuSelections[SEARCH_M0].width = 112; strcpy(menuSelections[SEARCH_M123].menuString, "Name... Title... Filename..."); menuSelections[SEARCH_M123].width = 12; menuMode[PROG_MENU][NO_FILE] = PROG_MA; menuMode[PROG_MENU][CAT_VIEW] = PROG_MA; menuMode[PROG_MENU][MOV_VIEW] = PROG_MA; menuMode[PROG_MENU][REV_VIEW] = PROG_MA; menuMode[FILE_MENU][NO_FILE] = FILE_M0; menuMode[FILE_MENU][CAT_VIEW] = FILE_M123; menuMode[FILE_MENU][MOV_VIEW] = FILE_M123; menuMode[FILE_MENU][REV_VIEW] = FILE_M123; menuMode[EDIT_MENU][NO_FILE] = EDIT_M03; menuMode[EDIT_MENU][CAT_VIEW] = EDIT_M1; menuMode[EDIT_MENU][MOV_VIEW] = EDIT_M2; menuMode[EDIT_MENU][REV_VIEW] = EDIT_M03; menuMode[CCC_MENU][NO_FILE] = CCC_M03; menuMode[CCC_MENU][CAT_VIEW] = CCC_M1; menuMode[CCC_MENU][MOV_VIEW] = CCC_M2; menuMode[CCC_MENU][REV_VIEW] = CCC_M03; menuMode[VIEW_MENU][NO_FILE] = VIEW_M0; menuMode[VIEW_MENU][CAT_VIEW] = VIEW_M1; menuMode[VIEW_MENU][MOV_VIEW] = VIEW_M23; menuMode[VIEW_MENU][REV_VIEW] = VIEW_M23; menuMode[SRCH_MENU][NO_FILE] = SEARCH_M0; menuMode[SRCH_MENU][CAT_VIEW] = SEARCH_M123; menuMode[SRCH_MENU][MOV_VIEW] = SEARCH_M123; menuMode[SRCH_MENU][REV_VIEW] = SEARCH_M123; menu_options[PROG_MA][1] = &ShowStart; menu_options[PROG_MA][2] = &DisplayMessage; menu_options[FILE_M0][1] = &ReadVRS; menu_options[FILE_M0][2] = &ReadMRS; menu_options[FILE_M0][3] = &Quit; menu_options[FILE_M123][1] = &ReadVRS; menu_options[FILE_M123][2] = &ReadMRS; menu_options[FILE_M123][3] = &Save; menu_options[FILE_M123][4] = &SaveAs; menu_options[FILE_M123][5] = &Close; menu_options[FILE_M123][6] = &Quit; menu_options[EDIT_M1][1] = &ModFileTitle; menu_options[EDIT_M2][1] = &ModFileTitle; menu_options[EDIT_M2][2] = &ModStarRating; menu_options[EDIT_M2][3] = &ModFileName; menu_options[CCC_M1][1] = &Add; menu_options[CCC_M1][2] = &Delete; menu_options[CCC_M2][1] = &Add; menu_options[CCC_M2][2] = &Delete; menu_options[SEARCH_M123][1] = &NYA; menu_options[SEARCH_M123][2] = &NYA; menu_options[SEARCH_M123][3] = &NYA; } /********************************************************************** * * Function: DisplayMessage * * Input: void * * Returns: void * * Description: * Handles messages from a message file. * * Variables: none * * Called by: Main * * Calls: GetMsgNum * Add2Win * CreateWin * SetMsgNum * Response * GetMsgMode * SetMsgMode * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ void DisplayMessage(void) { msgNumber = GetMsgNum(); if(msgNumber == 0) { beep(); return; } if(displayFirst == 0) displayFirst = 1; if(displayFirst == 2) displayFirst = 4; if(msgNumber < 0) { currWinType = ERRWIN; SetMsgMode(1); } else { currWinType = HELPWIN; if(GetMsgMode() == 1) SetMsgMode(2); else SetMsgMode(1); } if(msgNumber != 32767) { fstream messageFile; messageFile.open("ccc.messages",ios::in | ios::binary); messageFile.seekg(0, ios::beg); messageFile.read((char *)&longest, 8); messageFile.read((char *)&middle, 4); messageFile.read((char *)&highError, 4); messageFile.read((char *)&highHelp, 4); middleByte = (longest*(middle-1))+20; messageFile.seekg(middleByte, ios::beg); messageFile.seekg((longest*(msgNumber)), ios::cur); messageFile.read((char *)&currMsgLine,longest); messageFile.close(); } else // major file error!! { currMsgLine.width = 45; currMsgLine.helpCode = 0; currMsgLine.messageNo = 0; strcpy(currMsgLine.holdLine, "There has been a file error. The required message file 'ccc.messages' is not present. This file is necessary to the operation of this program. Please ensure that the file is present before this software is executed again."); } if(((msgNumber < highError) || (msgNumber > highHelp)) && (msgNumber != 32767)) { beep(); Response(JUST_ENTER, 1, "Attempted message outside bounds, Please press 'ENTER' to continue"); return; } if(msgNumber < 0) { msgWinID = 0; } else { msgWinID = 1; } width[msgWinID] = currMsgLine.width; SetMsgNum(currMsgLine.helpCode); if(!msgWinID) //error windows { length[0] = FormatWindow((char *)currMsgLine.holdLine, currErrMess, widthptr[0]); } else //help windows { length[1] = FormatWindow((char *)currMsgLine.holdLine, currHlpMess, widthptr[1]); } if(length[msgWinID] > (short)MAXMSGWINLINE - 2) { winHeight[msgWinID] = MAXMSGWINLINE; end[msgWinID] = MAXMSGWINLINE - 2; scrollable[msgWinID] = true; } else { winHeight[msgWinID] = length[msgWinID] + 2; end[msgWinID] = length[msgWinID]; scrollable[msgWinID] = false; } startWinY[msgWinID] = FIRST + ((int)((USEABLEWINY - winHeight[msgWinID]) / 2)); startWinX[msgWinID] = BEGINWINX + ((int)((USEABLEWINX - width[msgWinID]) / 2)); tmpMsgWin[msgWinID] = GetWindow(currWinType); delwin(tmpMsgWin[msgWinID]); CreateWin(currWinType, (winHeight[msgWinID]), (width[msgWinID] + 2), startWinY[msgWinID], startWinX[msgWinID]); tmpMsgWin[msgWinID] = GetWindow(currWinType); if(!msgWinID) //error message { for(looping = FIRST; looping <= (end[msgWinID]) ; looping++) { Add2Win(currWinType, looping, 1, currErrMess[looping]); } } else // help message { for(looping = FIRST; looping <= (end[msgWinID]) ; looping++) { Add2Win(currWinType, looping, 1, currHlpMess[looping]); } } touchwin(tmpMsgWin[msgWinID]); wrefresh(tmpMsgWin[msgWinID]); if(scrollable[msgWinID]) { start[msgWinID] = FIRST; end[msgWinID] = MAXMSGWINLINE; char scrollChar = 25; mvwaddrawch(tmpMsgWin[msgWinID], 0, (width[msgWinID] + 1), scrollChar); touchwin(tmpMsgWin[msgWinID]); wrefresh(tmpMsgWin[msgWinID]); }//end if }//end DisplayMessage() /********************************************************************** * * Function: FormatWindow * * Input: char* string - the string to format * stringline array[] - the array of menu items * int width - the maximum width/width of menus * * Returns: int looping - number of items on menu * * Description: * Builds the menu window * * Variables: char* tempptr - points to the string * int stringlen - the length of the string * int looping - the number of items on menu * int terminator - the original width * * Called by: Main * * Calls: none * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ int FormatWindow(char * string, stringline array[], int width) { char * tempptr = string; int stringlen = strlen(string); int looping = 1; do{ strncpy(array[looping], tempptr, width); if((stringlen-(width*looping)) > 0) tempptr += width; else return(looping); while((*tempptr != SPACE) && (*tempptr != NULL)) { tempptr--; } looping++; tempptr++; }while((width*looping) <= stringlen + 1); return(looping); } /********************************************************************** * * Function: FormatWindow * * Input: char* string - the string to format * winMsgLine array[] - the array of menu items * int width - the maximum width/width of menus * * Returns: int looping - number of items on menu * * Description: * Builds the menu window * * Variables: char* tempptr - points to the string * int stringlen - the length of the string * int looping - the number of items on menu * int terminator - the original width * int endWidth - ending width * * Called by: Main * * Calls: none * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ int FormatWindow(char * string, winMsgLine array[], int * width) { char * tempptr = string; int stringlen = strlen(string); int looping = 1, terminator = 0, endWidth = 0, innerLoop = 0, middle = 0, tempLoop = 0; bool done = false, newLine = false, center = false; winMsgLine tempLine = {NULL}; char * charptr = NULL; do{ strncpy(array[looping], tempptr, *width); for(innerLoop = 0; ((innerLoop < *width) && (!done)) && (!newLine); innerLoop++) { terminator++; if(*tempptr == '~') //new line { array[looping][innerLoop] = SPACE; newLine = true; } if(*tempptr == '^') //center the line { array[looping][innerLoop] = SPACE; center = true; } tempptr++; if(*tempptr == NULL) done = true; } if(center) { array[looping][terminator] = NULL; strncpy(tempLine, array[looping], terminator); tempLine[(terminator + 1)] = NULL; middle = ((int)((*width - terminator) / 2)); for(tempLoop = 0; tempLoop < middle; tempLoop++) array[looping][tempLoop] = SPACE; charptr = &array[looping][tempLoop]; strcpy(charptr, tempLine); terminator += middle; center = false; } if(!done) { while((*tempptr != SPACE) && (*tempptr != NULL) && (*tempptr != '~')) { tempptr--; terminator--; } } array[looping][terminator] = NULL; terminator++; if(terminator > endWidth) endWidth = terminator; terminator = 0; looping++; tempptr++; newLine = false; }while(tempptr-string < stringlen); looping--; *width = endWidth; return(looping); } /********************************************************************** * * Function: DrawMenu * * Input: cccmenuopts menuCode - the menu that is being changed * stringline currMenuString - the current menu string * int width - used for monitoring the width * * Returns: void * * Description: * Draws the menu window * * Variables: int p - a looping variable * int terminator - the original width * * Called by: UpdateDisplay * * Calls: none * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ void DrawMenu(cccmenuopts menuCode, int * length) { currMenu = menuCode; for(int p = 0; p <= 7 ; p++) { for(int q = 0 ; q <= 120 ; q++) menuArray[p][q] = NULL; } currMode = GetMode(); currSelection = menuMode[menuCode][currMode]; tempwin = GetWindow(MENUOPTWIN); delwin(tempwin); int width = 0; *length = 0; stringline currMenuString = {NULL}; if(menuSelections[currSelection].width <= 100) { strcpy(currMenuString, menuSelections[currSelection].menuString); width = menuSelections[currSelection].width; *length = FormatWindow(currMenuString, menuArray, width); CreateWin(MENUOPTWIN, (*length+2), (width+2), 1, ((int)menuCode-1)*10); tempwin = GetWindow(MENUOPTWIN); wattron(tempwin, A_REVERSE); Add2Win(MENUOPTWIN, FIRST, 1, menuArray[FIRST]); wattron(tempwin, A_REVERSE); for(int i = 2; i <= *length ; i++) { Add2Win(MENUOPTWIN, i, 1, menuArray[i]); } } else { width = menuSelections[currSelection].width -100; CreateWin(MENUOPTWIN, (*length+2), (width+2), 1, ((int)menuCode-1)*10); } } /********************************************************************** * * Function: DrawMenu * * Input: int current - currently selected item * * Returns: void * * Description: * Draws the menu window with a new selection * * Variables: none * * Called by: MainHandler * * Calls: Add2Win * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ void DrawMenu(int current) { currMode = GetMode(); currSelection = menuMode[currMenu][currMode]; selection = current; tempwin = GetWindow(MENUOPTWIN); Add2Win(MENUOPTWIN, selection, 1, menuArray[selection]); } /********************************************************************** * * Function: DrawMenu * * Input: cccmenuopts menuCode - the new menu to work on * int selection - currently selected item * * Returns: void * * Description: * Draws the menu window with a new selection/menu * * Variables: none * * Called by: MainHandler * * Calls: Add2Win * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ void DrawMenu(cccmenuopts menuCode, int selection) { currMode = GetMode(); currSelection = menuMode[menuCode][currMode]; tempwin = GetWindow(MENUOPTWIN); wattron(tempwin, A_REVERSE); Add2Win(MENUOPTWIN, selection, 1, menuArray[selection]); wattron(tempwin, A_REVERSE); } /********************************************************************** * * Function: MsgWinKeyOpts * * Input: int & key - current keystroke * * Returns: void * * Description: * Processes keystrokes * * Variables: index temporary for filling window * msgMode temporary for checking message mode * * Called by: MainHandler * CommandLineInterface * Response * * Calls: GetMsgMode * SetMsgMode * Add2Win * SUDS * UpdateDisplay * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ void MsgWinKeyOpts(int &key) { int index; // temporary varible for filling msg windows int msgMode = GetMsgMode(); if(scrollable[msgWinID]) { switch(key) { case UP_ARROW: if(end[msgWinID] == length[msgWinID] + 2) scrollChar = 18; if(start[msgWinID] != FIRST) { start[msgWinID] -= 1; end[msgWinID] -= 1; if(start[msgWinID] == FIRST) scrollChar = 25; else scrollChar = 18; } else // already at top { scrollChar = 25; beep(); } break; case DOWN_ARROW: if(start[msgWinID] == FIRST) scrollChar = 18; if(end[msgWinID] != (length[msgWinID] + 2)) { start[msgWinID] += 1; end[msgWinID] += 1; if(end[msgWinID] == (length[msgWinID] + 2)) scrollChar = 24; else scrollChar = 18; } else // already at bottom { scrollChar = 24; beep(); } break; case PG_UP: if(end[msgWinID] == length[msgWinID] + 2) scrollChar = 18; if(start[msgWinID] != FIRST) { if(start[msgWinID] < MAXMSGWINLINE) //within one page of top { start[msgWinID] = FIRST; end[msgWinID] = MAXMSGWINLINE; scrollChar = 25; } else //more than one page from top { start[msgWinID] -= MAXMSGWINLINE - 2; end[msgWinID] -= MAXMSGWINLINE - 2; scrollChar = 18; } } else //already at top { scrollChar = 25; beep(); } break; case PG_DN: if(start[msgWinID] == FIRST) scrollChar = 18; if(end[msgWinID] != length[msgWinID] + 2) { if((length[msgWinID] - end[msgWinID]) < MAXMSGWINLINE) //within one page of bottom { start[msgWinID] = length[msgWinID] - MAXMSGWINLINE + 3; end[msgWinID] = length[msgWinID] + 2; scrollChar = 24; } else //more than one page from bottom { start[msgWinID] += MAXMSGWINLINE - 2; end[msgWinID] += MAXMSGWINLINE - 2; scrollChar = 18; } } else //already at bottom { scrollChar = 24; beep(); } break; case HOME_KEY: if(start[msgWinID] != FIRST) { start[msgWinID] = FIRST; end[msgWinID] = MAXMSGWINLINE; scrollChar = 25; } else //already at top { scrollChar = 25; beep(); } break; case END_KEY: if(end[msgWinID] != length[msgWinID] + 2) { start[msgWinID] = length[msgWinID] - MAXMSGWINLINE + 3; end[msgWinID] = length[msgWinID] + 2; scrollChar = 24; } else //already at bottom { scrollChar = 24; beep(); } break; case ESCAPE: msgMode -= 1; SetMsgMode(msgMode); key = NULL; if(msgMode) SUDS(0,1,1,0,0,0,0,0,1,0); else SUDS(0,1,1,0,0,0,0,0,0,0); if(displayFirst == 4) displayFirst = 2; if(displayFirst == 1) displayFirst = 0; UpdateDisplay(); return; default: beep(); key = NULL; }//end case mvwclrtobot(tmpMsgWin[msgWinID], FIRST, FIRST); box(tmpMsgWin[msgWinID], C_V, C_H ) ; mvwaddrawch(tmpMsgWin[msgWinID], 0, (width[msgWinID] + 1), scrollChar); if(!msgWinID) //error message { for(looping = (start[msgWinID]); looping <= (end[msgWinID] - 2) ; looping++) { index = looping - start[msgWinID] + 1; Add2Win(currWinType, index, FIRST, currErrMess[looping]); } } else // help message { for(looping = (start[msgWinID]); looping <= (end[msgWinID] - 2) ; looping++) { index = looping - start[msgWinID] + 1; Add2Win(currWinType, index, FIRST, currHlpMess[looping]); } } } else // not scrollable window { switch(key) { case ESCAPE: msgMode -= 1; SetMsgMode(msgMode); key = NULL; if(msgMode) SUDS(0,1,1,0,0,0,0,0,1,0); else SUDS(0,1,1,0,0,0,0,0,0,0); if(displayFirst == 4) displayFirst = 2; if(displayFirst == 1) displayFirst = 0; UpdateDisplay(); return; default: beep(); key = NULL; }//end case } touchwin(tmpMsgWin[msgWinID]); wrefresh(tmpMsgWin[msgWinID]); }//end MsgWinKeyOpts /********************************************************************** * * Function: CommandLineInterface * * Input: char inputString string to be filled * int maxInpStrLen max length of input * char displayString string to be displayed on io line * * Returns: void * * Description: * gets string input while handling message keystrokes * * Variables: index temporary for filling window * msgMode temporary for checking message mode * * Called by: MainHandler * CommandLineInterface * Response * * Calls: GetMsgMode * MsgWinKeyOpts * SetMsgMode * SetMsgNum * Add2Win * SUDS * UpdateDisplay * GetWindow * Curses * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ void CommandLineInterface(char inputString[], int maxInpStrLen, char displayString[]) { int holdIndex = NULL; int messageLength = NULL; int response = NULL; int temp = NULL; int msgMode = GetMsgMode(); short msgNumber = GetMsgNum(); bool done = false; if(msgNumber < 0) { beep(); beep(); return; } if(displayFirst == 0) displayFirst = 3; if(displayFirst == 1) displayFirst = 2; iowindow=GetWindow(IOWIN); keypad(iowindow, TRUE); werase(iowindow); SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); if(displayString) { Add2Win(IOWIN, 0, 1, displayString); messageLength = strlen(displayString); } mvwaddrawch(iowindow, 0, (messageLength + 1), SPACE); SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); curson(); do { msgMode = GetMsgMode(); response = wgetch(iowindow); if((response == ESCAPE) && ((displayFirst == 0) || (displayFirst == 2) || (displayFirst == 3))) { inputString[0] = NULL; response = NULL; done = true; } if((msgMode) && ((response == UP_ARROW) || (response == DOWN_ARROW) || (response == PG_UP) || (response == PG_DN) || (response == HOME_KEY) || (response == END_KEY) || (response == ESCAPE))) { MsgWinKeyOpts(response); response = NULL; } if((msgMode) && (displayFirst >=3) && (response != NULL)) { MsgWinKeyOpts(response); response = NULL; } if(response == F1_KEY) { temp = GetMsgNum(); DisplayMessage(); SetMsgNum(temp); } if((response >= 32) && (response <= 126)) //check for printable { if(((int)response != 34) && // ensure char is legal for filename ((int)response != 42) && ((int)response != 47) && ((int)response != 60) && ((int)response != 62) && ((int)response != 63) && ((int)response != 124)) { inputString[holdIndex] = response; holdIndex += 1; waddch(iowindow, response); SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); } } if(holdIndex >= maxInpStrLen) { response = BKSPACE; beep(); } if((response == BKSPACE) && (holdIndex > 0)) { holdIndex -= 1; waddch(iowindow, response); waddch(iowindow, SPACE); waddch(iowindow, response); SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); } if(response == ENTER) { done = true; } inputString[holdIndex] = '\0'; SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); }while(!done); if(GetMsgMode()) { msgMode -= 1; SetMsgMode(msgMode); if(msgMode) SUDS(0,1,1,0,0,0,0,0,1,0); else SUDS(0,1,1,0,0,0,0,0,0,0); } cursoff(); displayFirst = 0; werase(iowindow); SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); } /********************************************************************** * * Function: WaitMessage * * Input: bool state used to turn message on or off * * Returns: void * * Description: * Displays wait message * * Variables: iowindow used to act on io window * * Called by: MainHandler * CommandLineInterface * Response * * Calls: GetMsgMode * SetMsgMode * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ void WaitMessage(bool state) { iowindow=GetWindow(IOWIN); if(state) { werase(iowindow); Add2Win(IOWIN, 0, FIRST, "Please wait..... Processing"); SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); } else { werase(iowindow); SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); } } /********************************************************************** * * Function: Response * * Input: char responses string on responses to look for * int numResponses number of responses to look for * char displayString string to be displayed on io line * * Returns: void * * Description: * Processes keystrokes * * Variables: index temporary for filling window * msgMode temporary for checking message mode * messageLength used for displaying of messages * * Called by: MainHandler * CommandLineInterface * Response * * Calls: GetMsgMode * SetMsgMode * SetMsgNum * Add2Win * SUDS * UpdateDisplay * GetWindow * Curses * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ int Response(const char responses[], int numResponses, char displayString[]) { int messageLength = NULL; int response = NULL; int msgMode = GetMsgMode(); bool done = false, match = false; if(displayFirst == 0) displayFirst = 3; if(displayFirst == 1) displayFirst = 2; iowindow=GetWindow(IOWIN); keypad(iowindow, TRUE); werase(iowindow); Add2Win(IOWIN, 0, 1, displayString); messageLength = strlen(displayString); mvwaddrawch(iowindow, 0, (messageLength + 1), SPACE); SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); curson(); do { msgMode = GetMsgMode(); response = wgetch(iowindow); response = tolower(response); if((msgMode) && ((response == UP_ARROW) || (response == DOWN_ARROW) || (response == PG_UP) || (response == PG_DN) || (response == HOME_KEY) || (response == END_KEY) || (response == ESCAPE))) { MsgWinKeyOpts(response); response = NULL; } if((msgMode) && (displayFirst >=3) && (response != NULL)) { MsgWinKeyOpts(response); response = NULL; } if(response == F1_KEY) { DisplayMessage(); response = NULL; } if(response != NULL) { for(looping = 0; looping < numResponses; looping++) { if(responses[looping] == response) { match = true; done = true; } } // end for if(!match) { response = BKSPACE; beep(); } } // end if SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); }while(!done); if(GetMsgMode()) { msgMode -= 1; SetMsgMode(msgMode); if(msgMode) SUDS(0,0,1,0,0,0,0,0,1,0); else SUDS(0,0,1,0,0,0,0,0,0,0); if ((currentMode) && (currentMode != 3)) SUDS(0,1,0,0,0,0,0,0,0,0); } cursoff(); displayFirst = 0; werase(iowindow); SUDS(0,0,0,1,0,0,0,0,0,0); UpdateDisplay(); if(match) return(response); else return(NULL); } /********************************************************************** * * Function: MakeMessage * * Input: char insertMessage string to add * int insertWidth preferred message width * * Returns: int messageNumber * * Description: * Processes keystrokes * * Variables: index temporary for filling window * msgMode temporary for checking message mode * messageLength used for displaying of messages * * Called by: MainHandler * CommandLineInterface * Response * * Calls: GetMsgMode * SetMsgMode * SetMsgNum * Add2Win * SUDS * UpdateDisplay * GetWindow * Curses * * Author: Glenn Rioux * Revisions: none * * Version: 1.0 * * **********************************************************************/ int MakeMessage(char * insertMessage, int insertWidth) { fstream messageFile; messageFile.open("ccc.messages",ios::in | ios::out | ios::binary); messageFile.seekg(0, ios::beg); messageFile.read((char *)&longest, 8); messageFile.read((char *)&middle, 4); messageFile.read((char *)&highError, 4); messageFile.read((char *)&highHelp, 4); strcpy(currMsgLine.holdLine, insertMessage); highHelp++; currMsgLine.messageNo = highHelp; currMsgLine.helpCode = 0; currMsgLine.width = insertWidth; messageFile.seekg(0, ios::beg); messageFile.write((char *)&longest, 8); messageFile.write((char *)&middle, 4); messageFile.write((char *)&highError, 4); messageFile.write((char *)&highHelp, 4); messageFile.close(); messageFile.open("ccc.messages",ios::in | ios::out | ios::binary | ios::app); messageFile.write((char *)&currMsgLine,longest); messageFile.close(); return(highHelp); } void MakeMessage(void) { fstream messageFile; messageFile.open("ccc.messages",ios::in | ios::out | ios::binary); messageFile.seekg(0, ios::beg); messageFile.read((char *)&longest, 8); messageFile.read((char *)&middle, 4); messageFile.read((char *)&highError, 4); messageFile.read((char *)&highHelp, 4); highHelp--; messageFile.seekg(0, ios::beg); messageFile.write((char *)&longest, 8); messageFile.write((char *)&middle, 4); messageFile.write((char *)&highError, 4); messageFile.write((char *)&highHelp, 4); messageFile.close(); } /********************************************************************** * * Function: List * * Input: void * * Returns: void * * Description: * Lists the nodes in segments of 20. * * Variables: char possFileName - the name of the file to remove * char filetype - the type of the file to add * char response - the reply from the user * int temp - the length of the string * DLnkNodePtr CurrPtr - Keeps the pointer for the list * int winsel - the selected item * int selected - selected item * int start - first displayed item * int finish - last displayed item * int looper - a looping element * int loop - a looping element * * Called by: MainHandler * ReadVRS * ReadMRS * Category * * Calls: GetNextLink * GetPrevLink * GetList * GetWindow * Add2Win * GetDispParams * GetMovieCounter * SetSelNode * SetDispParams * SUDS * UpdateDisplay * * * Author: Glenn Rioux * Revisions: Tim McGaughey - Major overhaul to display only the * categories, use curses, and be able * to handle scrolling and use other * display charicteristics of MainHandler * * Version: 2.0 * * **********************************************************************/ void List(int winsel) { DLnkNodePtr TempLine=NULL; char line[80]; int maxdispnum=-1; TempLine=GetList(); if(TempLine==NULL) { Response(JUST_ENTER, 1, "The list is Empty! Please press 'ENTER' to continue."); return; } WaitMessage(true); if (head) { DLnkNodePtr TempNext=NULL; while (GetNextLink(head)) { head=GetNextLink(head); } while (GetPrevLink(head)) { head=GetPrevLink(head); TempNext=GetNextLink(head); FreeNode(TempNext); } FreeNode(head); } while(TempLine) { if(TempLine->Item.filetype=='M') { Insert(head,TempLine->Item.filename,TRUE,TempLine->Item.movieindex); head->Item.filetype=TempLine->Item.filetype; head->Item.verified=TempLine->Item.verified; head->Item.revieworrating=TempLine->Item.revieworrating; strcpy(head->Item.title,TempLine->Item.title); maxdispnum++; } TempLine=GetNextLink(TempLine); } while (GetPrevLink(head)) head=GetPrevLink(head); tempwin=GetWindow(TITLEWIN); werase(tempwin); Add2Win(TITLEWIN,0,0," Category Reviews"); int selected; int start; int finish; GetDispParams(selected, start, finish); TempLine=head; int looper=0; if (GetMovieCounter()>20) { if (start<0) { start=0; finish=start+20; winsel=start-1; } if (finish>maxdispnum--) { finish=maxdispnum; start=finish-20; winsel=finish+1; } if (finish<20) finish=20; if (winsel0) { finish--; start--; } } if(winsel>finish) { if (finish+1<=maxdispnum) { finish++; start++; } } for (looper=0;((looper<=finish)&&(GetNextLink(TempLine)));looper++) TempLine=GetNextLink(TempLine); for (looper=20;looper>=0;looper--) { entry[looper]=TempLine; TempLine=GetPrevLink(TempLine); } } else { looper=0; while (TempLine) { entry[looper]=TempLine; TempLine=GetNextLink(TempLine); looper++; } //head=TempLine; while (looper<20) { entry[looper]=NULL; looper++; } finish=GetMovieCounter()-1; start=0; if (start<0) { start=0; finish=start+20; winsel=start-1; } if (finish>maxdispnum--) { finish=maxdispnum; start=finish-20; winsel=finish+1; } } tempwin=GetWindow(DISPLAYWIN); werase(tempwin); looper=0; if (winselfinish) { winsel=finish; beep(); } while (entry[looper]) { line[0]='\0'; char temp[6]; temp[0]='\0'; int loop=0; //this is to add the title and format it. strcat(line,entry[looper]->Item.title); for (loop=1;loop<=29-abs(strlen(entry[looper]->Item.title));loop++) strcat(line," "); //here comes the number of reviews itoa(entry[looper]->Item.revieworrating,temp,10); for (loop=1;loop<=5-abs(strlen(temp));loop++) strcat(line," "); strcat(line,temp); if (looper==(winsel-start)) { DLnkNodePtr BigTemp=GetList(); BinarySearch(BigTemp,entry[looper]->Item.filename); SetSelNode(GetSrchPtr()); wattron(tempwin, A_REVERSE); Add2Win(DISPLAYWIN,looper,0,line); wattron(tempwin, A_REVERSE); } else { Add2Win(DISPLAYWIN,looper,0,line); } looper++; } tempwin=GetWindow(STATUS3WIN); werase(tempwin); SetDispParams(winsel,start,finish); SUDS(0,1,1,0,0,0,1,0,0,0); SetMode(CAT_VIEW); UpdateDisplay(); WaitMessage(false); } /********************************************************************** * * Function: ListMovie * * Input: DLnkNodePtr Category - The category that was selected * * Returns: void * * Description: * Lists the reviews for a category in segments of 20. * * Variables: DLnkNodePtr TempLine - Temporary position in list * DLnkNodePtr head - sets a new head for the new list * char line[80] - the string to output to the display * int winsel - the selected item * int selected - selected item * int start - first displayed item * int finish - last displayed item * int looper - a looping element * int loop - a looping element * * Called by: MainHandler * Movie * * Calls: GetNextLink * GetPrevLink * GetList * GetWindow * Add2Win * GetDispParams * GetMovieCounter * SetSelNode * SetDispParams * SUDS * UpdateDisplay * SetReviewNum * * * Author: Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ void ListMovie(DLnkNodePtr Category) { DLnkNodePtr TempLine=NULL; char line[80]; int winsel=0; char WorkingFileName[35]; int WorkingMovieIndex=Category->Item.movieindex; TempLine=GetList(); while (GetPrevLink(TempLine)) { TempLine=GetPrevLink(TempLine); } strcpy(WorkingFileName, Category->Item.filename); tempwin=GetWindow(DISPLAYWIN); werase(tempwin); SUDS(0,0,1,0,0,0,0,0,0,0); UpdateDisplay(); tempwin=GetWindow(TITLEWIN); werase(tempwin); if(TempLine==NULL) { Response(JUST_ENTER, 1, "The list is Empty! Please press 'ENTER' to continue."); return; } WaitMessage(true); if (head) { DLnkNodePtr TempNext=NULL; while (GetNextLink(head)) { head=GetNextLink(head); } while (GetPrevLink(head)) { head=GetPrevLink(head); TempNext=GetNextLink(head); FreeNode(TempNext); } FreeNode(head); } int reviewnum=0; while (TempLine) { if((TempLine->Item.filetype=='R')&&(TempLine->Item.movieindex==WorkingMovieIndex)) { Insert(head,TempLine->Item.filename,TRUE,TempLine->Item.movieindex); head->Item.filetype=TempLine->Item.filetype; head->Item.verified=TempLine->Item.verified; head->Item.revieworrating=TempLine->Item.revieworrating; strcpy(head->Item.title,TempLine->Item.title); reviewnum++; } TempLine=GetNextLink(TempLine); } SetReviewNum(reviewnum); while (GetPrevLink(head)) head=GetPrevLink(head); Add2Win(TITLEWIN,0,0," Title Rating File Name"); int selected; int start; int finish; GetDispParams(selected, start, finish); TempLine=head; int looper; winsel=selected; if (reviewnum>20) { if (start<0) { start=0; finish=start+20; winsel=start-1; } if (finish>reviewnum--) { finish=reviewnum; start=finish-20; winsel=finish+1; } if (finish<20) finish=20; if (winsel0) { finish--; start--; } } if(winsel>finish) { if (finish+1<=reviewnum) { finish++; start++; } } for (looper=0;((looper<=finish)&&(GetNextLink(TempLine)));looper++) TempLine=GetNextLink(TempLine); for (looper=20;looper>=0;looper--) { entry[looper]=TempLine; TempLine=GetPrevLink(TempLine); } } else { looper=0; while (TempLine) { entry[looper]=TempLine; TempLine=GetNextLink(TempLine); looper++; } while (looper<20) { entry[looper]=NULL; looper++; } finish=reviewnum-1; start=0; } looper=0; if (winselfinish) { winsel=finish; beep(); } while ((entry[looper])&&(looper<=MAX_ENTRY)) { line[0]='\0'; char temp[6]; temp[0]='\0'; strcat(line,entry[looper]->Item.title); for (int loop=1;loop<=29-abs(strlen(entry[looper]->Item.title));loop++) strcat(line," "); itoa(entry[looper]->Item.revieworrating,temp,10); for (loop=1;loop<=4-abs(strlen(temp));loop++) strcat(line," "); int length; length=strlen(temp); temp[length]=temp[length-1]; temp[length-1]='.'; temp[length+1]='\0'; strcat(line,temp); strcat(line," "); strcat(line,entry[looper]->Item.filename); for (loop=1;loop<=35-abs(strlen(entry[looper]->Item.filename));loop++) strcat(line," "); if (looper==(winsel-start)) { DLnkNodePtr BigTemp=GetList(); BinarySearch(BigTemp,entry[looper]->Item.filename); SetSelNode(GetSrchPtr()); tempwin=GetWindow(DISPLAYWIN); wattron(tempwin, A_REVERSE); Add2Win(DISPLAYWIN,looper,0,line); wattron(tempwin, A_REVERSE); } else { Add2Win(DISPLAYWIN,looper,0,line); } looper++; } tempwin=GetWindow(STATUS3WIN); werase(tempwin); line[0]='\0'; DLnkNodePtr TempNode=GetList(); BinarySearch(TempNode, WorkingFileName); WorkingMovie=GetSrchPtr(); for (int loop=1;loop<=25-abs(strlen(WorkingMovie->Item.title));loop++) strcat(line," "); strcat(line,WorkingMovie->Item.title); Add2Win(STATUS3WIN,0,0,line); SUDS(0,1,1,0,0,0,1,0,0,0); SetMode(MOV_VIEW); UpdateDisplay(); WaitMessage(false); } /********************************************************************** * * Function: ListMovie * * Input: int winsel - The number of the item that was selected * * Returns: void * * Description: * Lists the reviews for a category in segments of 20. * * Variables: DLnkNodePtr TempLine - Temporary position in list * DLnkNodePtr head - sets a new head for the new list * char line[80] - the string to output to the display * int winsel - the selected item * int selected - selected item * int start - first displayed item * int finish - last displayed item * int looper - a looping element * int loop - a looping element * * Called by: MainHandler * Movie * * Calls: GetNextLink * GetPrevLink * GetList * GetWindow * Add2Win * GetDispParams * GetMovieCounter * SetSelNode * SetDispParams * SUDS * UpdateDisplay * SetReviewNum * * * Author: Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ void ListMovie(int winsel) { DLnkNodePtr TempLine=NULL; char line[80]; TempLine=GetList(); if(TempLine==NULL) { Response(JUST_ENTER, 1, "The list is Empty! Please press 'ENTER' to continue."); return; } WaitMessage(true); if (head) { DLnkNodePtr TempNext=NULL; while (GetNextLink(head)) { head=GetNextLink(head); } while (GetPrevLink(head)) { head=GetPrevLink(head); TempNext=GetNextLink(head); FreeNode(TempNext); } FreeNode(head); } int reviewnum=0; while (TempLine) { if((TempLine->Item.filetype=='R')&&(TempLine->Item.movieindex==WorkingMovie->Item.movieindex)) { Insert(head,TempLine->Item.filename,TRUE,TempLine->Item.movieindex); head->Item.filetype=TempLine->Item.filetype; head->Item.verified=TempLine->Item.verified; head->Item.revieworrating=TempLine->Item.revieworrating; strcpy(head->Item.title,TempLine->Item.title); reviewnum++; } TempLine=GetNextLink(TempLine); } SetReviewNum(reviewnum); while (GetPrevLink(head)) head=GetPrevLink(head); Add2Win(TITLEWIN,0,0," Title Rating File Name"); int selected; int start; int finish; GetDispParams(selected, start, finish); TempLine=head; int looper; selected=winsel; tempwin=GetWindow(DISPLAYWIN); werase(tempwin); if (reviewnum>20) { if (start<0) { start=0; finish=start+20; winsel=start-1; } if (finish>reviewnum--) { finish=reviewnum; start=finish-20; winsel=finish+1; } if (finish<20) finish=20; if (winsel0) { finish--; start--; } } if(winsel>finish) { if (finish+1<=reviewnum) { finish++; start++; } } for (looper=0;((looper<=finish)&&(GetNextLink(TempLine)));looper++) TempLine=GetNextLink(TempLine); for (looper=20;looper>=0;looper--) { entry[looper]=TempLine; TempLine=GetPrevLink(TempLine); } } else { looper=0; while (TempLine) { entry[looper]=TempLine; TempLine=GetNextLink(TempLine); looper++; } while (looper<20) { entry[looper]=NULL; looper++; } finish=reviewnum-1; start=0; } looper=0; if (winselfinish) { winsel=finish; beep(); } while ((entry[looper])&&(looper<=MAX_ENTRY)) { line[0]='\0'; char temp[6]; temp[0]='\0'; strcat(line,entry[looper]->Item.title); for (int loop=1;loop<=29-abs(strlen(entry[looper]->Item.title));loop++) strcat(line," "); itoa(entry[looper]->Item.revieworrating,temp,10); for (loop=1;loop<=4-abs(strlen(temp));loop++) strcat(line," "); int length; length=strlen(temp); temp[length]=temp[length-1]; temp[length-1]='.'; temp[length+1]='\0'; strcat(line,temp); strcat(line," "); strcat(line,entry[looper]->Item.filename); for (loop=1;loop<=35-abs(strlen(entry[looper]->Item.filename));loop++) strcat(line," "); if (looper==(winsel-start)) { DLnkNodePtr BigTemp=GetList(); BinarySearch(BigTemp,entry[looper]->Item.filename); SetSelNode(GetSrchPtr()); tempwin=GetWindow(DISPLAYWIN); wattron(tempwin, A_REVERSE); Add2Win(DISPLAYWIN,looper,0,line); wattron(tempwin, A_REVERSE); } else { Add2Win(DISPLAYWIN,looper,0,line); } looper++; } tempwin=GetWindow(STATUS3WIN); werase(tempwin); line[0]='\0'; for (int loop=1;loop<=25-abs(strlen(WorkingMovie->Item.title));loop++) strcat(line," "); strcat(line,WorkingMovie->Item.title); SetDispParams(winsel, start, finish); Add2Win(STATUS3WIN,0,0,line); SUDS(0,1,1,0,0,0,1,0,0,0); SetMode(MOV_VIEW); UpdateDisplay(); WaitMessage(false); } /********************************************************************** * * Function: GetEntry * * Input: int index - the index number for the array * * Returns: DLnkNodePtr* * * Description: * Returns the Node for the item in the entry list * * Variables: none * * Called by: MainHandler * * Calls: none * * Author: Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ DLnkNode* GetEntry(int index) { if (index<=MAX_ENTRY) return entry[index]; else return NULL; } /********************************************************************** * * Function: Execute * * Input: cccmenuopts menuCode - the menu being used * mode currentMode - the current mode being used * int selection - the current selection * * Returns: void * * Description: * Executes an item from the menus by calling the correct function pointer * * Variables: menuModeCode configuration - holds the menu and mode * * Called by: MainHandler * * Calls: Category * Movie * ViewFile * menu_options[configuration][selection] - function pointer 2D array * * Author: Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ void Execute(cccmenuopts menuCode,mode currentMode, int selection) { menuModeCode configuration; configuration=menuMode[menuCode][currentMode]; if ((configuration==VIEW_M1)||(configuration==VIEW_M23)) { switch(selection) { case 1: Category(); break; case 2: Movie(); break; case 3: ViewFile(); break; } } else { if (menuCode==SRCH_MENU) NYA(); else menu_options[configuration][selection](); } } /********************************************************************** * * Function: SetSelNode * * Input: DLnkNodePtr SomeNode - the node to set to * * Returns: void * * Description: * Sets the currently selected node to the one provided * * Variables: none * * Called by: List * ListMovie * * Calls: none * * Author: Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ void SetSelNode(DLnkNodePtr SomeNode) { SelNode=SomeNode; } /********************************************************************** * * Function: GetSelNode * * Input: void * * Returns: DLnkNodePtr - the currently selected node * * Description: * Gets the currently selected node and returns it * * Variables: none * * Called by: MainHandler * Movie * Category * * Calls: none * * Author: Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ DLnkNodePtr GetSelNode(void) { return SelNode; } /********************************************************************** * * Function: SetReviewNum * * Input: int reviewnum * * Returns: void * * Description: * Sets the current review number * * Variables: none * * Called by: ListMovie * * Calls: none * * Author: Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ void SetReviewNum(int reviewnum) { reviews=reviewnum; } /********************************************************************** * * Function: GetReviewNum * * Input: void * * Returns: int - the current review number * * Description: * Gets the current review number * * Variables: none * * Called by: MainHandler * * Calls: none * * Author: Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ int GetReviewNum(void) { return reviews; } /********************************************************************** * * Function: NYA * * Input: none * * Returns: void * * Description: * Outputs a "Not Yet Available" message. * * Variables: none * * Called by: menu_options[configuration][selection] * * Calls: none * * Author: Tim McGaughey * Revisions: none * * Version: 1.0 * * **********************************************************************/ void NYA(void) { SetMsgNum(21); DisplayMessage(); int temp = Response(JUST_ENTER, 1, "Please press 'ENTER' to continue."); }