#include "dataops.h" int retval=0; Boolean saveflag=FALSE; Boolean exitflag=FALSE; winMsgLine tempString[1] = {NULL}; char response = NULL; char tempMsg[MAXMSGSTRNG] = {NULL}; /********************************************************************** * * Function: ReadVRS * Input: void * * Returns: int 0 in all cases * * Description: * A function to start the reading from a VRS category file and to call * the correct functions to build the data set and to maintain the data. * This function serves as a wrapper for those functions, providing * information, and managing specific details. * * Variables: char tempnameVRSFile - the name of the file to process * char outputname - the name of the report file * char mrsoutput - the name of the MRS file to build. * ifstream NameVRSFile - the input file stream * ofstream outputfile - the file in which to create the report * int temp - used to find the length of the filename * * Called by: DoWork * * Calls: Verify * Fexists * SetFile * GetFile * strcpy * tolower * CheckExtension * DoMaintenance * strlen * toupper * abs * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ void ReadVRS(void) { char tempnameVRSFile[255]; char* sometempnameVRSFile; char outputname[255]; char mrsoutput[255]; char response = NULL; Boolean condition = FALSE; window iowindow; if (GetMode()) { response = Response((char *)YES_NO, 2, "This will close the current file, continue? "); if (response == 'y') Close(); else return; } SetMsgNum(-4); DisplayMessage(); CommandLineInterface(tempnameVRSFile, 50, "Please Enter a file name"); for (int count=0; count < abs(strlen(tempnameVRSFile));count++) tempnameVRSFile[count]=toupper(tempnameVRSFile[count]); do { if (!CheckExtension(tempnameVRSFile, CAT_FILE_EXTENSION)) { SetMsgNum(11); DisplayMessage(); if(Response(YES_NO, 2, "Please press 'y' to continue, 'n' to return to the previous menu.") == 'n') return; strcat(tempnameVRSFile, CAT_FILE_EXTENSION); } if (!Fexists(tempnameVRSFile)) { SetFile(tempnameVRSFile); if(FileFault()) return; sometempnameVRSFile=GetFile(); if(!strcmp(tempnameVRSFile, sometempnameVRSFile)) condition = TRUE; strcpy(tempnameVRSFile, sometempnameVRSFile); } }while(condition); ifstream nameVRSFile(tempnameVRSFile); strcpy(outputname, tempnameVRSFile); strcpy(mrsoutput, tempnameVRSFile); int temp = strlen(outputname); outputname[temp-3] ='R'; //a quick way to change the extension outputname[temp-2] ='P'; outputname[temp-1] ='T'; mrsoutput[temp-3]='C'; mrsoutput[temp-2]='C'; mrsoutput[temp-1]='C'; SetOutFile(mrsoutput); if(Fexists(outputname)) { strcpy(tempString[0], "The filename "); strcat(tempString[0], outputname); strcat(tempString[0], " already exists. Do you wish to continue?"); SetMsgNum(MakeMessage((char *)tempString, 38)); DisplayMessage(); if(Response(YES_NO, 2, "Please press 'y' to continue, 'n' to cancel.") == 'n') return; } ofstream outputfile(outputname); outputfile << tempnameVRSFile << endl; //be to send to a class for outputfile << "===============" << endl; //outputs by overloading the << operator WaitMessage(true); Verify (nameVRSFile, 0, 'v', outputfile, tempnameVRSFile); nameVRSFile.close(); outputfile.close(); if(GetErrorFlag()) { WaitMessage(false); strcpy(tempString[0], "One or more errors were found during verification. Please check the file '"); strcat(tempString[0], outputname); strcat(tempString[0], "' for more details."); SetMsgNum(MakeMessage((char *)tempString, 38)); DisplayMessage(); Response(JUST_ENTER, 1, "Please press 'ENTER' to continue."); WaitMessage(true); } SetErrorFlag(FALSE); tempnameVRSFile[strlen(tempnameVRSFile)-4]='\0'; iowindow=GetWindow(STATUS1WIN); werase(iowindow); Add2Win(STATUS1WIN,0,0,tempnameVRSFile); SUDS(0,0,0,0,1,0,0,0,0,0); SetSaveFlag(FALSE); List(0); WaitMessage(false); return; } /********************************************************************** * * Function: ReadMRS * Input: void * * Returns: int 0 in all cases * * Description: * A function to start the reading from a MRS review set file and to call * the correct functions to build the data set and to maintain the data. * This function serves as a wrapper for those functions, providing * information, and managing specific details. * * Variables: char tempnameMRSFile - the name of the file to process * char outputname - the name of the report file * char mrsoutput - the name of the MRS file to build. * ifstream NameVRSFile - the input file stream * ofstream outputfile - the file in which to create the report * int temp - used to find the length of the filename * * Called by: DoWork * * Calls: Verify * Fexists * SetFile * GetFile * strcpy * tolower * CheckExtension * DoMaintenance * strlen * abs * toupper * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ void ReadMRS(void) { char tempnameMRSFile[255]; char* sometempnameMRSFile; char outputname[255]; char mrsoutput[255]; char response = NULL; bool condition = false; char * argument = GetArgument(); if(argument) { strcpy(tempnameMRSFile, argument); } if (GetMode()) { response = Response(YES_NO, 2, "This will close the current file, continue? "); if (response == 'y') Close(); else return; } if(argument == NULL) { SetMsgNum(-1); DisplayMessage(); CommandLineInterface(tempnameMRSFile, 50, "Please Enter a file name"); } for (int count=0; count < abs(strlen(tempnameMRSFile));count++) tempnameMRSFile[count]=toupper(tempnameMRSFile[count]); do { if(!CheckExtension(tempnameMRSFile, CCC_FILE_EXTENSION)) { SetMsgNum(11); DisplayMessage(); if(Response(YES_NO, 2, "Please press 'y' to continue, 'n' to return to the previous menu.") == 'n') return; condition = false; strcat(tempnameMRSFile, CCC_FILE_EXTENSION); } if (!Fexists(tempnameMRSFile)) { SetFile(tempnameMRSFile); if(FileFault()) return; sometempnameMRSFile=GetFile(); if(!strcmp(tempnameMRSFile, sometempnameMRSFile)) condition = true; strcpy(tempnameMRSFile, sometempnameMRSFile); } }while(condition); ifstream nameMRSFile(tempnameMRSFile); strcpy(outputname, tempnameMRSFile); strcpy(mrsoutput, tempnameMRSFile); int temp = strlen(outputname); outputname[temp-3] ='R'; //a quick way to change the extension outputname[temp-2] ='P'; outputname[temp-1] ='T'; mrsoutput[temp-3]='C'; mrsoutput[temp-2]='C'; mrsoutput[temp-1]='C'; SetOutFile(mrsoutput); if(Fexists(outputname)) { strcpy(tempString[0], "The filename "); strcat(tempString[0], outputname); strcat(tempString[0], " already exists. Do you wish to continue?"); SetMsgNum(MakeMessage((char *)tempString, 38)); DisplayMessage(); if(Response(YES_NO, 2, "Please press 'y' to continue, 'n' to cancel.") == 'n') return; } ofstream outputfile(outputname); outputfile << tempnameMRSFile << endl; //be to send to a class for outputfile << "===============" << endl; //outputs by overloading the << operator WaitMessage(true); Verify (nameMRSFile, 0, 's', outputfile, tempnameMRSFile); nameMRSFile.close(); outputfile.close(); if(GetErrorFlag()) { WaitMessage(false); strcpy(tempString[0], "One or more errors were found during verification. Please check the file '"); strcat(tempString[0], outputname); strcat(tempString[0], "' for more details."); SetMsgNum(MakeMessage((char *)tempString, 38)); DisplayMessage(); Response(JUST_ENTER, 1, "Please press 'ENTER' to continue."); WaitMessage(true); } SetErrorFlag(FALSE); tempnameMRSFile[strlen(tempnameMRSFile)-4]='\0'; window iowindow=GetWindow(STATUS1WIN); werase(iowindow); Add2Win(STATUS1WIN,0,0,tempnameMRSFile); SUDS(0,0,0,0,1,0,0,0,0,0); DLnkNodePtr Gonzo=GetList(); int largestsofar=-1; while (GetPrevLink(Gonzo)) { Gonzo=GetPrevLink(Gonzo); } while (Gonzo) { if (Gonzo->Item.movieindex > largestsofar) largestsofar=Gonzo->Item.movieindex; Gonzo=GetNextLink(Gonzo); SetMovieCounter(largestsofar); } SetSaveFlag(FALSE); List(0); WaitMessage(false); return; } /********************************************************************** * * Function: FileFault * Input: void * * Returns: int 0 in completion int 1 when user does not continue * * Description: * This function provides the requirement that the user corrects the * incorrect filename that was supplied, or to choose to terminate the * current line of execution. * * Variables: char filename - the name of the file to process * char response - the user's reply * int index - a counter for the length of the string * * Called by: Modify * * Calls: Fexists * abs * strlen * SetFile * tolower * * Author: Glenn Rioux * Revisions: none * Version: 1.0 * * **********************************************************************/ int FileFault(void) { char filename[55] = {NULL}; char tempFileExt[5] = {NULL}; SetMsgNum(6); DisplayMessage(); do{ CommandLineInterface(filename, 54, "Please enter a valid filename to process."); for (int index=0;index<(abs(strlen(filename)));index++) filename[index]=toupper(filename[index]); if(GetMsgNum() == -1) strcpy(tempFileExt, CCC_FILE_EXTENSION); else strcpy(tempFileExt, CAT_FILE_EXTENSION); if(!CheckExtension(filename, tempFileExt)) { SetMsgNum(11); DisplayMessage(); if(Response(YES_NO, 2, "Please press 'y' to continue, 'n' to cancel.") == 'n') return 1; strcat(filename, tempFileExt); } if(Fexists(filename)) { SetFile(filename); return 0; } else { SetMsgNum(7); DisplayMessage(); strcpy(tempMsg, "Please press 'y' to reenter, 'n' to cancel."); if(Response(YES_NO, 2, tempMsg) == 'n') return 1; } }while(true); } /********************************************************************** * * Function: FileWarn * Input: char * checkname * * Returns: int 0 if exists, int 1 when no continue, int 2 if continue * * Description: * This function provides the notification to the user, but not the * requirement that the user corrects the incorrect filename that * was supplied, or to choose to terminate the current line of execution. * * Variables: char response * * Called by: Add * * Calls: Fexists * tolower * * Author: Glenn Rioux * Revisions: none * Version: 1.1 * * **********************************************************************/ int FileWarn(char * checkname) { if(Fexists(checkname)) { return 0; } else { SetMsgNum(8); DisplayMessage(); strcpy(tempMsg, "Please press 'y' to continue, 'n' to cancel."); if(Response(YES_NO, 2, tempMsg) == 'y') return 0; else { SetMsgNum(9); DisplayMessage(); if(Response(YES_NO, 2, tempMsg) == 'y') return 2; else return 1; } } } /********************************************************************** * * Function: Add * Input: void * * Returns: void * * Description: * Goes through the steps necessary to add an entry into the movie * review set. * * Variables: char response - the user's selection from the menu * char possFileName - the name of the file to add * DLnkNodePtr CurrPtr - Keeps the pointer for the list * char fileTitle - The title to add * char tempRating - holds star rating * char fileType - the type of file to add * int reviewOrRating - the number of reviews or the rating * char fileName - another variable with the name * Boolean errorFlag - controls loop * * Called by: DoMaintenance * * Calls: Fexists * strcpy * CheckExtension * FileWarn * tolower * Insert * GetList * * Author: Glenn Rioux * Revisions: none * Version: 1.0 * * **********************************************************************/ void Add(void) { char response = NULL; Boolean flag = FALSE; char possFileName[35] = {NULL}; DLnkNodePtr CurrPtr=NULL; char fileTitle[30] = {NULL}; char tempRating[5] = {NULL}; char fileType; int reviewOrRating; char fileName[35]; mode currMode=GetMode(); //Get file type switch(currMode) { case CAT_VIEW: { fileType = 'm'; break; } case MOV_VIEW: { fileType = 'r'; break; } } //Get filename do{ response = NULL; flag = FALSE; CommandLineInterface(possFileName, 34, "Please Enter a file name"); strcpy(fileName, possFileName); if(((fileType == 'r') && (!CheckExtension(possFileName, reviewFileExt))) || ((fileType == 'm') && (!CheckExtension(possFileName, movieFileExt)))) { SetMsgNum(11); DisplayMessage(); strcpy(tempMsg, "Please press 'y' to continue, 'n' to reenter the name, or 'Q' to quit."); switch(Response("ynq", 3, tempMsg)) { case 'y': { if(fileType == 'r') strcat(fileName, ".REV"); else strcat(fileName, ".MOV"); response = NULL; break; } case 'n': { flag = TRUE; break; } case 'q': return; } } if(flag == FALSE) { switch(FileWarn(possFileName)) { case 0 : { possFileName[0] = NULL; break; } case 1 : return; case 2 : break; } } }while(possFileName[0]!=NULL); //Get Title SetMsgNum(12); DisplayMessage(); CommandLineInterface(fileTitle, 28, "Please Enter a title for this file"); //Get Size/Rating if(fileType == 'm') { reviewOrRating=0; CurrPtr=GetList(); Insert(CurrPtr, fileName, FALSE, 0); } else { float starRating; char tempROR[4] = {NULL}; bool errorFlag = false; do { SetMsgNum(15); strcpy(tempMsg, "Please enter the movie 'star' rating, or 'ESCAPE' to cancel."); CommandLineInterface(tempROR, 4, tempMsg); if(tempROR[0] == NULL) return; starRating = (float)atof(tempROR); if (!CheckStarRating(starRating)) { reviewOrRating = int(starRating*10); errorFlag = false; } else { errorFlag = true; SetMsgNum(-2); DisplayMessage(); } }while (errorFlag == true); CurrPtr=GetList(); Insert(CurrPtr, fileName, TRUE, GetSelNode()->Item.movieindex); DLnkNodePtr Cleanup=CurrPtr; while (GetPrevLink(Cleanup)) { Cleanup=GetPrevLink(Cleanup); } while (Cleanup) { if ((Cleanup->Item.filetype=='M')&&(Cleanup->Item.movieindex==GetSelNode()->Item.movieindex)) { Cleanup->Item.revieworrating++; Cleanup=NULL; } else { Cleanup=GetNextLink(Cleanup); } } } CurrPtr->Item.filetype=toupper(fileType); CurrPtr->Item.revieworrating=reviewOrRating; strcpy(CurrPtr->Item.title,fileTitle); while (GetPrevLink(CurrPtr)) { CurrPtr=GetPrevLink(CurrPtr); } SetSaveFlag(FALSE); SetList(CurrPtr); if(toupper(fileType)=='M') Category(); else Movie(); } /********************************************************************** * * Function: Delete * Input: void * * Returns: void * * Description: * Goes through the steps necessary to remove an entry from the movie * review set. * * Variables: char possFileName - the name of the file to remove * DLnkNodePtr CurrPtr - Keeps the pointer for the list * * Called by: DoMaintenance * * Calls: GetList * toupper * Remove * * Author: Glenn Rioux * Revisions: none * Version: 1.0 * * **********************************************************************/ void Delete(void) { char possFileName[35] = {NULL}; DLnkNodePtr CurrPtr=NULL; DLnkNodePtr Cleanup=NULL; int reviewclean=0; Boolean Review=FALSE; strcpy(possFileName,GetSelNode()->Item.filename); CurrPtr=GetList(); if (GetSelNode()->Item.filetype == 'R') { reviewclean=GetSelNode()->Item.movieindex; Cleanup=CurrPtr; Review=TRUE; } for (int index=0;index<(abs(strlen(possFileName)));index++) possFileName[index]=toupper(possFileName[index]); if(Remove(CurrPtr,possFileName)) { if((Review)&&(Cleanup)) { while (Cleanup) { if ((Cleanup->Item.filetype=='M')&&(Cleanup->Item.movieindex==reviewclean)) { Cleanup->Item.revieworrating--; Cleanup=NULL; Review=FALSE; } else { Cleanup=GetNextLink(Cleanup); } } Movie(); } else { Category(); } return; SetSaveFlag(FALSE); } else { SetMsgNum(16); DisplayMessage(); Response(JUST_ENTER, 1, "Please press 'ENTER' to continue."); return; } } /********************************************************************** * * Function: ModFileType * Input: DLnkNodePtr CurrPtr - current pointer to the list * * Returns: void * * Description: * Presents menus and modifies the type of the entry. If necessary, * it also modifies the extension. * * 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 * * Called by: Modify * * Calls: tolower * strlen * * Author: Glenn Rioux * Revisions: none * Version: 1.0 * * **********************************************************************/ void ModFileType(DLnkNodePtr CurrPtr) { char filetype = NULL; bool change = false; strcpy(tempString[0], (const char *)"The present type of this file is '"); strcat(tempString[0], (const char *)CurrPtr->Item.filetype); strcat(tempString[0], "'."); SetMsgNum(MakeMessage((char *)tempString, 50)); DisplayMessage(); response = Response(ENTER_ESCAPE, 2, "Please press 'ENTER' to change the type or 'ESCAPE' to cancel"); if(response == ENTER) { if(CurrPtr->Item.filetype = 'M') response = 'r'; else response = 'm'; switch(response) { case 'm': { filetype = 'M'; int temp = strlen(CurrPtr->Item.filename); CurrPtr->Item.filetype=filetype; CurrPtr->Item.filename[temp-3] ='M'; //a quick way to change the extension CurrPtr->Item.filename[temp-2] ='O'; CurrPtr->Item.filename[temp-1] ='V'; response=NULL; break; } case 'r': { filetype = 'R'; int temp = strlen(CurrPtr->Item.filename); CurrPtr->Item.filetype=filetype; CurrPtr->Item.filename[temp-3] ='R'; //a quick way to change the extension CurrPtr->Item.filename[temp-2] ='E'; CurrPtr->Item.filename[temp-1] ='V'; response=NULL; break; } } // end case SetSaveFlag(FALSE); } // end if } /********************************************************************** * * Function: ModFileTitle * Input: DLnkNodePtr CurrPtr - current pointer to the list * * Returns: void * * Description: * Presents menus and modifies the title of the entry. * * Variables: char possTitle - the title to substitute * * Called by: Modify * * Calls: strcpy * * Author: Glenn Rioux * Revisions: none * Version: 1.0 * * **********************************************************************/ void ModFileTitle() { DLnkNodePtr CurrPtr; DLnkNodePtr NewPtr=NULL; CurrPtr=GetSelNode(); char possTitle[29] = {NULL}; strcpy(tempString[0], "The present title is '"); strcat(tempString[0], CurrPtr->Item.title); strcat(tempString[0], "'."); SetMsgNum(MakeMessage((char *)tempString, 50)); DisplayMessage(); CommandLineInterface(possTitle, 29, "Please enter the new title, or 'ESCAPE' to cancel."); if(possTitle[0] == NULL) return; else { strcpy(CurrPtr->Item.title, possTitle); SetSaveFlag(FALSE); } if(CurrPtr->Item.filetype=='M') Category(); else Movie(); } /********************************************************************** * * Function: ModFileName * Input: DLnkNodePtr CurrPtr - current pointer to the list * * Returns: void * * Description: * Presents menus and modifies the name of the entry. If necessary, * it also modifies the type of the file. * * Variables: char possFileName - the new name of the file * char filetype - the type of the file to change * char response - the reply from the user * int index - a counter for string length * * Called by: Modify * * Calls: tolower * strlen * abs * toupper * strcpy * BinarySearch * FileWarn * CheckExtension * * Author: Glenn Rioux * Revisions: none * Version: 1.0 * * **********************************************************************/ void ModFileName() { char possFileName[35] = {NULL}; char fileName[35] = {NULL}; char filetype = NULL; DLnkNodePtr CurrPtr=GetSelNode(); //the following holds the structure char oldfiletype; char title[29]; int revieworrating; int movieindex = NULL; char filename[35]; Boolean verified; char response = NULL; do{ strcpy(tempString[0], "The present name of this file is '"); strcat(tempString[0], CurrPtr->Item.filename); strcat(tempString[0], "'. Please enter the new name, or 'ESCAPE' to cancel this operation."); SetMsgNum(MakeMessage((char *)tempString, 38)); DisplayMessage(); SetMsgNum(17); CommandLineInterface(possFileName, 35); if(possFileName[0] == NULL) return; for (int index=0;index<(abs(strlen(possFileName)));index++) possFileName[index]=toupper(possFileName[index]); DLnkNodePtr dummyPtr; dummyPtr=CurrPtr; if(BinarySearch(dummyPtr,possFileName)) { SetMsgNum(-3); DisplayMessage(); response = Response(ENTER_ESCAPE, 2, "Please press 'ENTER' to reenter the file name or 'ESCAPE' to cancel"); if(response == ESCAPE) return; possFileName[0] = NULL; } switch(FileWarn(possFileName)) { case 0 : break; case 1 : return; case 2 : possFileName[0] = NULL; } oldfiletype=CurrPtr->Item.filetype; strcpy (title, CurrPtr->Item.title); revieworrating=CurrPtr->Item.revieworrating; movieindex=CurrPtr->Item.movieindex; strcpy(filename,CurrPtr->Item.filename); verified=CurrPtr->Item.verified; if(possFileName) { if(CheckExtension(possFileName, reviewFileExt)) { Remove(CurrPtr, filename); strcpy(filename, possFileName); Insert(CurrPtr, filename, TRUE, movieindex); oldfiletype = 'R'; DLnkNodePtr Temp=GetList(); BinarySearch(Temp,filename); CurrPtr=GetSrchPtr(); CurrPtr->Item.filetype=oldfiletype; strcpy (CurrPtr->Item.title, title); CurrPtr->Item.revieworrating=revieworrating; strcpy(CurrPtr->Item.filename, filename); CurrPtr->Item.verified=verified; possFileName[0] = NULL; while (GetPrevLink(CurrPtr)) { CurrPtr=GetPrevLink(CurrPtr); } SetList(CurrPtr); SetSaveFlag(FALSE); Movie(); return; } else { SetMsgNum(18); response = Response(ENTER_ESCAPE, 2, "Please press 'ENTER' to reenter the file name or 'ESCAPE' to cancel"); if(response == ESCAPE) return; } } //end if(filename) }while(possFileName); } /********************************************************************** * * Function: ModStarRating * Input: void * * Returns: void * * Description: * Lets the user modify the star rating for a review * * Variables: DLnkNodePtr CurrPtr - The item we are editing * float newnum - the new star rating to use * * Called by: menu_options * * Calls: GetSelNode * CheckStarRating * SetSaveFlag * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ void ModStarRating() { //print out current rating. //get new rating //check star rating //if bad, re-input rating. float starRating = NULL; char tempRating[4] = {NULL}; int newNumber = NULL; DLnkNodePtr CurrPtr=GetSelNode(); bool errorFlag = false; do { char tempRatng[6] = {NULL}; int len=0; itoa(CurrPtr->Item.revieworrating,tempRatng, 10); len=strlen(tempRatng); tempRatng[len]=tempRatng[1]; tempRatng[1]='.'; strcpy(tempString[0], "The current star rating is '"); strcat(tempString[0], tempRatng); strcat(tempString[0], "'. Please enter the new rating, or 'ESCAPE' to cancel this operation."); SetMsgNum(MakeMessage((char *)tempString, 38)); DisplayMessage(); SetMsgNum(15); strcpy(tempMsg, "Please enter the new movie 'star' rating, or 'ESCAPE' to cancel."); CommandLineInterface(tempRating, 4, tempMsg); if(tempRating[0] == NULL) return; starRating = (float)atof(tempRating); if (!CheckStarRating(starRating)) { newNumber = (int)(starRating*10); errorFlag = false; } else { errorFlag = true; SetMsgNum(-2); DisplayMessage(); response = Response(ENTER_ESCAPE, 2, "Please press 'ENTER' to reenter the rating or 'ESCAPE' to cancel"); if(response == ESCAPE) return; } }while (errorFlag == true); CurrPtr->Item.revieworrating=newNumber; SetSaveFlag(FALSE); Movie(); } /********************************************************************** * * Function: ViewFile * Input: DLnkNodePtr * * Returns: void * * Description: * Shows the files included in the review set. * * Variables: ifstream movInput - the movie file to open * char tempLine - the line pulled from the file * ifstream revInput - the review file to open * * Called by: View * * Calls: Fexists * * Author: Glenn Rioux * Revisions: Tim McGaughey - Overhaul for curses and MainHandler * Version: 2.0 * * **********************************************************************/ void ViewFile() { DLnkNodePtr CurrPtr=GetSelNode(); window tempwin=GetWindow(TITLEWIN); werase(tempwin); ifstream revInput; char tempLine[81] = {NULL}; char line[80]; int key=SPACE; if(Fexists(CurrPtr->Item.filename)) { WaitMessage(true); revInput.open(CurrPtr->Item.filename); tempwin=GetWindow(DISPLAYWIN); werase(tempwin); int tempnum; noraw(); strcpy(line, "Title: "); revInput.getline(tempLine,80,'\n'); strcat(line, tempLine); Add2Win(TITLEWIN,0,0,line); strcpy(line, "Director: "); revInput.getline(tempLine,80,'\n'); strcat(line, tempLine); Add2Win(DISPLAYWIN,1,0,line); strcpy(line, "Year: "); revInput>>tempnum; itoa(tempnum, tempLine, 10); strcat(line, tempLine); Add2Win(DISPLAYWIN,2,0,line); strcpy(line, "Stars: "); revInput.getline(tempLine,80,'\n'); revInput.getline(tempLine,80,'\n'); strcat(line, tempLine); Add2Win(DISPLAYWIN,3,0,line); strcpy(line, "Brief Review: "); revInput.getline(tempLine,80,'\n'); strcat(line, tempLine); Add2Win(DISPLAYWIN,4,0,line); raw(); window displaywindow=GetWindow(STATUS3WIN); werase(displaywindow); line[0]='\0'; for (int loop=1;loop<=25-abs(strlen(CurrPtr->Item.filename));loop++) strcat(line," "); strcat(line,CurrPtr->Item.filename); Add2Win(STATUS3WIN,0,0,line); SUDS(0,1,1,1,0,0,1,0,0,0); UpdateDisplay(); WaitMessage(false); response = Response(YES_NO, 2, "Do you wish to show the remainder of the file?"); if(response == 'n') { Movie(); return; } else { while((!revInput.eof())&&(key)) { WaitMessage(true); tempwin=GetWindow(DISPLAYWIN); werase(tempwin); for(int j = 0;(j<=21 && !revInput.eof());j++) { revInput.getline(tempLine, 80, '\n'); Add2Win(DISPLAYWIN,j,0,tempLine); } SUDS(0,0,1,1,0,0,0,0,0,0); UpdateDisplay(); WaitMessage(false); response = Response(ENTER_ESCAPE, 2, "Please press 'ENTER' to continue, or 'ESCAPE' to stop."); if(response == ESCAPE) break; } revInput.close(); Movie(); } } else { Response(JUST_ENTER, 1, "File does not exist. Please press 'ENTER' to continue."); } } /********************************************************************** * * Function: Close * Input: void * * Returns: void * * Description: * Writes the MRS file, and notifies the user of errors during verification. * * Variables: DLnkNodePtr TempLine - pointer to the current node * char* outputname - the name of the output file * ofstream outputfile - the output file * ifstream inputfile - the report file to read from * int temp - holds string length * * Called by: View * * Calls: GetList * GetFile * * Author: Tim McGaughey/Glenn Rioux * Revisions: Tim McGaughey - updated for curses and changed purpose * Version: 2.0 * * **********************************************************************/ void Close(void) { if(!GetSaveFlag()) { SetMsgNum(19); DisplayMessage(); strcpy(tempMsg, "Please press 'y' for yes, 'n' for no, or 'c' to cancel."); switch(Response("ync", 3, tempMsg)) { case 'y': Save(); break; case 'n': break; case 'c': retval=1; return; } } DeleteList(); SetMode(NO_FILE); window tempwin=GetWindow(DISPLAYWIN); werase(tempwin); tempwin=GetWindow(TITLEWIN); werase(tempwin); tempwin=GetWindow(STATUS1WIN); werase(tempwin); SUDS(0,0,1,1,1,0,0,0,0,0); UpdateDisplay(); } /********************************************************************** * * Function: Save * Input: void * * Returns: void * * Description: * Saves the file * * Variables: DLnkNodePtr TempLine - The current node being output * char* outputname - the name of the output file * * Called by: menu_options * * Calls: GetList * GetOutFile * GetNextLink * SetSaveFlag * * Author: Tim McGaughey * Revisions: Tim McGaughey - changed for curses and new purpose * Version: 2.0 * * **********************************************************************/ void Save() { DLnkNodePtr TempLine=NULL; char* outputname; TempLine=GetList(); if(TempLine==NULL) { return; } outputname=GetOutFile(); ofstream outputfile(outputname); outputfile.fill(' '); outputfile.setf(ios::left); while(TempLine)// != NULL) { outputfile << setw(4) << TempLine->Item.filetype << setw(29) << TempLine->Item.title << setw(5) << TempLine->Item.revieworrating << setw(5) << TempLine->Item.movieindex << setw(35) << TempLine->Item.filename << endl; TempLine=GetNextLink(TempLine);//->Link; } outputfile.close(); SetSaveFlag(TRUE); } /********************************************************************** * * Function: DeleteList * Input: void * * Returns: void * * Description: * Trashes the entire list * * Variables: DLnkNodePtr List - A pointer to the curent head of the list * * Called by: Close * * Calls: GetList * Remove * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ void DeleteList() { DLnkNodePtr List; List=GetList(); while (List) { Remove(List, List->Item.filename); List=GetList(); } } /********************************************************************** * * Function: SaveAs * Input: void * * Returns: void * * Description: * Lets the user change the name of the save file and then save to it. * * Variables: char* outputname - the output name retrieved * char possFileName[35] - the name from the user * window iowindow - used for window operations * * Called by: menu_options * * Calls: GetOutFile * SetOutFile * Add2Win * GetWindow * SUDS * UpdateDisplay * Save * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ void SaveAs(void) { char* outputname=NULL; char possFileName[35]; possFileName[0]=NULL; window iowindow; outputname=GetOutFile(); strcpy(tempString[0], "The present name of this file is '"); strcat(tempString[0], outputname); strcat(tempString[0], "'. Please enter the new name, or 'ESCAPE' to cancel this operation."); SetMsgNum(MakeMessage((char *)tempString, 38)); DisplayMessage(); SetMsgNum(20); CommandLineInterface(possFileName, 35); if(possFileName[0] == NULL) return; for (int index=0;index<(abs(strlen(possFileName)));index++) possFileName[index]=toupper(possFileName[index]); possFileName[strlen(possFileName)-4]='\0'; iowindow=GetWindow(STATUS1WIN); werase(iowindow); Add2Win(STATUS1WIN,0,0,possFileName); SUDS(0,0,0,0,1,0,0,0,0,0); UpdateDisplay(); SetOutFile(possFileName); Save(); } /********************************************************************** * * Function: Quit * Input: void * * Returns: void * * Description: * Cleans up and confirms that the user wants to quit * * Variables: none * * Called by: menu_options * * Calls: Close * GetMode * SetExit * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ void Quit() { if(GetMode()) { Close(); if (retval) return; } SetMsgNum(3); DisplayMessage(); if(Response(YES_NO, 2, "Please press 'y' or 'n' to continue.") == 'y') SetExit(TRUE); } /********************************************************************** * * Function: SetSaveFlag * Input: Boolean flag - the setting action to perform * * Returns: void * * Description: * Marks the file as saved or unsaved. * * Variables: none * * Called by: Add * Delete * ModFileTitle * ModFileName * ModStarRating * * Calls: none * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ void SetSaveFlag(Boolean flag) { saveflag=flag; } /********************************************************************** * * Function: GetSaveFlag * Input: void * * Returns: Boolean status of the save flag * * Description: * Returns the value if the file is saved or unsaved. * * Variables: none * * Called by: Close * * Calls: none * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ Boolean GetSaveFlag(void) { return saveflag; } /********************************************************************** * * Function: SetExit * Input: Boolean indicator - the setting action to perform * * Returns: void * * Description: * Marks if it is time to exit. * * Variables: none * * Called by: Quit * * Calls: none * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ void SetExit(Boolean indicator) { exitflag=indicator; } /********************************************************************** * * Function: GetExit * Input: none * * Returns: Boolean - the current state of the exit flag * * Description: * Returns if it is time to exit. * * Variables: none * * Called by: MainHandler * * Calls: none * * Author: Tim McGaughey * Revisions: none * Version: 1.0 * * **********************************************************************/ Boolean GetExit(void) { return exitflag; }