// Source: seelist.cpp // Author: Michele Estebon // Date: 12/2/96 // For: CS1704: Introduction to Data Structures and Software Design // Last revision: 12/2/96 /************************************************************************ See Also List operations for DR. DOC Provided functions: (public functions) *************************************************************************/ /*-- INCLUDES ----------------------------------------------------------*/ #include #include #include "seelist.h" #include "globals.h" #include "curses.h" #include "listglob.h" #include "dblist.h" #include "menus.h" #include "docops.h" #include "display.h" #include "dblmanip.h" /*-- CONSTANTS ---------------------------------------------------------*/ const int SALN = 11; // See Also line number in doc file const char SADELIM = ','; // See Also item delimiter in doc file const int MAXSA = 40; // maximum number of see also items typedef string seeray[MAXSA]; /*-- PUBLIC DECLARATIONS -----------------------------------------------*/ void GetCatSAL(seeray &seenames, int &count, string file); void GetDocSAL(seeray &seenames, int &count, string file); void ParseSA (seeray &seenames, string line, int &count); void GetSeeMenu (winptr &seemenu, seeptr SeeList, int count); seeptr SeeUp(seeptr SeeList, seeptr &curitem, winptr &seemenu, int &i); seeptr SeeDown(seeptr SeeList, seeptr &curitem, winptr &seemenu, int &i); void InsertSeeList (seeptr &SeeList, nodeptr curptr); /************************************************************************/ //--------------------------------------------------------------------------\\ // FN: UpdateSeeList // IN: SeeList, seemenu, curptr, RFSet // OUT: SeeList, seemenu // CALLS: GetItem, DestroySAL, GetCode, Fexists, GetCatSAL, GetDocSAL, SearchList // GetSeeMenu, InsertSeeList // PRE: // POST: SeeList is ready to be traversed and seemenu is ready for a refresh // ****** Creates a new See Also list, and menu window for it. //--------------------------------------------------------------------------\\ void UpdateSeeList (seeptr& SeeList, winptr& seemenu, nodeptr curptr, nodeptr RFSet) { string file; codetype fcode; seeray seenames; int count, i; nodeptr current; if (curptr != null) GetItem(curptr, file); DestroySAL(SeeList); if (seemenu!=null) delwin(seemenu); if (Fexists(file)) { GetCode(curptr, fcode); if (fcode == CATCODE) GetCatSAL(seenames, count, file); else GetDocSAL(seenames, count, file); for (i=0; inext; delete oldptr; oldptr = SeeList; } } //--------------------------------------------------------------------------\\ // FN: GetCatSAL // IN: file // OUT: seenames, count // CALLS: CatHeadRead, strupr, strcpy // PRE: // POST: // ****** Stores a list of See Also references for a category file based on // the files referenced in the file //--------------------------------------------------------------------------\\ void GetCatSAL(seeray &seenames, int &count, string file) { ifstream infile; int i = 0; string name; char* nameptr; infile.open(file); if (CatHeadRead(infile)) { while ( (infile.ignore(19,'\n')) && (infile >> name) ) { infile.ignore(200,'\n'); nameptr = strupr(name); strcpy(seenames[i++],nameptr); } // while } // if infile.close(); count = i; } //--------------------------------------------------------------------------\\ // FN: GetDocSAL // IN: file // OUT: seenames, count // CALLS: ParseSA, strupr // PRE: // POST: // ****** Stores a lsit of See Also references for a documentaion file // based on the entries in that file on the See Also line (SALN) //--------------------------------------------------------------------------\\ void GetDocSAL(seeray &seenames, int &count, string file) { ifstream infile; int i = 0; string line = " "; char* lineptr; infile.open(file); for (i=0; iseeitem, label); mvwaddstr(seemenu, i, 1, label); current = current->next; ResetColors(seemenu, MENUCOLORS); } for (i=1; (i < count) && (current != null) ; i++) { GetLabel(current->seeitem, label); mvwaddstr(seemenu, i, 1, label); current = current->next; } } //--------------------------------------------------------------------------\\ // FN: TraverseSAL // IN: mainwin, seemenu, Seelist, curptr // OUT: Function returns ptr to RFSet element, curptr // CALLS: Nobuff, keypad, wgetch, SeeUp, SeeDown, Buffin, Resetwin // PRE: // POST: // ****** Activates the See Also menu window for the user to scroll through. // If user selects an element, function returns that ptr // else returns curptr unchanged. //--------------------------------------------------------------------------\\ nodeptr TraverseSAL (winptr &mainwin, winptr &seemenu, seeptr SeeList, nodeptr &curptr) { int opt = 0; seeptr current = SeeList; int linecount = 0; Nobuff(); keypad(seemenu, TRUE); while (opt!=FORCEQUIT) { wrefresh(seemenu); opt = wgetch(seemenu); switch (opt) { case KEY_UP: current = SeeUp(SeeList, current, seemenu, linecount); break; case KEY_DOWN: current = SeeDown(SeeList, current, seemenu, linecount); break; case KEY_DC: Buffin(); ResetWin(mainwin); return (curptr); case KEYRETURN: Buffin(); ResetWin(mainwin); return (current->seeitem); default: beep(); } // switch } // while //Buffin(); return (curptr); } //--------------------------------------------------------------------------\\ // FN: SeeUP // IN: SeeList, curitem, seemenu, count // OUT: curitem, count // CALLS: GetLabel, mvwaddstr, Reversetxt, GetLabel, resetColors // PRE: // POST: // ****** Scrolls See Also menu up one element, if at top, goes to bottom //--------------------------------------------------------------------------\\ seeptr SeeUp(seeptr SeeList, seeptr &curitem, winptr &seemenu, int &count) { keytype item; GetLabel(curitem->seeitem, item); mvwaddstr(seemenu, count, 1, item); if (curitem->prev == null) { // go to bottom of list since can't go up anymore curitem = SeeList; while (curitem->next != null) { curitem = curitem->next; count++; } // while } // if else { // move up one curitem = curitem->prev; count--; } // else Reversetxt(seemenu); GetLabel(curitem->seeitem, item); mvwaddstr(seemenu, count, 1, item); ResetColors(seemenu, MENUCOLORS); return (curitem); } //--------------------------------------------------------------------------\\ // FN: SeeDown // IN: Seelist, curitem, seemenu, i // OUT: curitem, i // CALLS: GetLabel, mvwaddstr, Reversetxt, GetLabel, ResetColors // PRE: // POST: // ****** Scrolls See Also menu down one element, if at bottom, goes to top //--------------------------------------------------------------------------\\ seeptr SeeDown(seeptr SeeList, seeptr &curitem, winptr &seemenu, int &i) { keytype item; GetLabel(curitem->seeitem, item); mvwaddstr(seemenu, i, 1, item); if (curitem->next == null) { // go to top curitem = SeeList; i = 0; } else { // move down one curitem = curitem->next; i++; } Reversetxt(seemenu); GetLabel(curitem->seeitem, item); mvwaddstr(seemenu, i, 1, item); ResetColors(seemenu, MENUCOLORS); return (curitem); } //--------------------------------------------------------------------------\\ // FN: InsertSeeList // IN: SeeList, curptr // OUT: SeeList // CALLS: --- // PRE: --- // POST: SeeList contains ptr to curptr // ****** inserts a new element into the See Also list //--------------------------------------------------------------------------\\ void InsertSeeList (seeptr &SeeList, nodeptr curptr) { seeptr newitem; seeptr current = SeeList; newitem = new seenode; if (current != null) { while (current->next != null) current = current->next; newitem->prev = current; current->next = newitem; } else { newitem->prev = null; SeeList = newitem; } newitem->next = null; newitem->seeitem = curptr; } void GetItemSAL(seeptr List, keytype &item) { if (List!=null) GetItem(List->seeitem, item); else item[0] = NULLCHR; } seeptr GetNextLinkSAL(seeptr List) { if (List!=null) return (List->next); else return (null); } int CountSAL( seeptr SeeList) { int count = 0; seeptr sal = SeeList; while (sal!=null) { count++; sal = sal->next; } return (count); }