|
|
1.1 ! root 1: /* display_rec.c: Display a sys, port or dial entry. This will open ! 2: * the appropriate file and read an entire port, sys, or dial entry, ! 3: * diaplaying it on the screen. If there are too many lines to be ! 4: * displayed, the user will be told that he may select the modify ! 5: * option from the action menu to be pulled into an editor so that ! 6: * he may view the entire entry in that manner. ! 7: */ ! 8: ! 9: #include "uuinstall.h" ! 10: ! 11: /* these are the possible operations we will perform. This is stored ! 12: * in opflag. ! 13: */ ! 14: ! 15: #define VIEW 0166 ! 16: #define DELETE 0144 ! 17: #define EDIT 0155 ! 18: ! 19: display_rec(position, opflag) ! 20: int position; /* the record # we are looking for */ ! 21: int opflag; /* this will tell us if we are viewing, ! 22: * deleting, or going to edit an entry. ! 23: */ ! 24: { ! 25: int counter = -1; ! 26: int lines_before = 0; ! 27: int entry_lines = 0; ! 28: char fname[30] = {"/usr/lib/uucp/"}; ! 29: char workstring[80]; ! 30: char b; ! 31: FILE * filefd; /* point to file we will work with */ ! 32: char compare[7] = {""}; /* hold the string (sys, port or dial) ! 33: * that we will compare against when ! 34: * trying to determine the boundaries of ! 35: * an entry within one of these files. ! 36: */ ! 37: ! 38: /* determine which file we're working with, build our filename ! 39: * string and compare string based upon this. ! 40: */ ! 41: ! 42: if (dialflag){ ! 43: strcat(fname,"dial"); ! 44: strcpy(compare,"dialer"); ! 45: } ! 46: if (sysflag){ ! 47: strcat(fname,"sys"); ! 48: strcpy(compare,"system"); ! 49: } ! 50: if (portflag){ ! 51: strcat(fname,"port"); ! 52: strcpy(compare,"port"); ! 53: } ! 54: ! 55: /* open the file */ ! 56: if ((filefd = fopen(fname,"r")) == NULL){ ! 57: mvwaddstr(portwin,12,24,"Error opening file for reading!"); ! 58: wrefresh(portwin); ! 59: sleep(1); ! 60: wclear(portwin); ! 61: wrefresh(portwin); ! 62: return; ! 63: } ! 64: ! 65: /* read the file, looking for "port", "system" or "dialer", depending ! 66: * upon which file we're reading. When a line like this is found, ! 67: * increment our counter, then test to see if the counter matches the ! 68: * position (or entry #) within the file we're searching. If it matches, ! 69: * terminate the loop. This is how we find the entry we want to display. ! 70: * We will also keep track of the number of lines we read before finding ! 71: * the desired entry and the number of lines in the entry. This ! 72: * information will be used to delete or edit an entry, if we are indeed ! 73: * going to perform a delete or edit operation. ! 74: */ ! 75: ! 76: while (fgets(workstring, sizeof(workstring) -1, filefd) != NULL){ ! 77: if (strstr(workstring,compare)) ! 78: counter ++; ! 79: if(position == counter) ! 80: break; ! 81: if((opflag == DELETE) || (opflag == EDIT)) ! 82: lines_before ++; ! 83: } ! 84: ! 85: /* clear other windows */ ! 86: wclear(selwin); ! 87: wclear(promptwin); ! 88: wrefresh(promptwin); ! 89: wrefresh(selwin); ! 90: ! 91: /* display the entry for view and delete operations*/ ! 92: ! 93: if(opflag != EDIT){ ! 94: wclear(portwin); ! 95: wmove(portwin,0,22); ! 96: wstandout(portwin); ! 97: wprintw(portwin,"Entry from file %s .",fname); ! 98: wstandend(portwin); ! 99: ! 100: /* print the line that is already in our buffer */ ! 101: mvwaddstr(portwin,2,1,workstring); ! 102: } ! 103: entry_lines++; ! 104: ! 105: /* now print the rest of the entry. We read and print until ! 106: * we hit a line consisting only of a newline char. ! 107: */ ! 108: ! 109: while (fgets(workstring, sizeof(workstring) -1, filefd) != NULL){ ! 110: if(workstring[0] != '\n'){ ! 111: ! 112: /* test for entry too long for screen. */ ! 113: if ( (2 + entry_lines) <= 22){ ! 114: if(opflag != EDIT) ! 115: mvwaddstr(portwin,2+entry_lines,1,workstring); ! 116: }else{ ! 117: if (opflag != EDIT){ ! 118: wstandout(portwin); ! 119: mvwaddstr(portwin,23,3,"Entry too long! To view entire entry, select MODIFY mode from action menu."); ! 120: wstandend(portwin); ! 121: wrefresh(portwin); ! 122: } ! 123: } ! 124: entry_lines++; ! 125: }else{ ! 126: break; ! 127: } ! 128: } ! 129: ! 130: fclose(filefd); ! 131: wrefresh(portwin); ! 132: ! 133: /* if we're deleting, get a confirmation before continuing. IF not, ! 134: * we're just viewing, so any old keypress will send us back to the ! 135: * main menu. ! 136: */ ! 137: ! 138: if(opflag == DELETE){ ! 139: mvwaddstr(portwin,1,19,"Do you wish to delete this entry? (y/n)"); ! 140: wrefresh(portwin); ! 141: b = ' '; ! 142: do{ ! 143: b = wgetch(portwin); ! 144: } ! 145: while ( (b != 'n') && (b != 'y') ); ! 146: ! 147: if (b == 'y') ! 148: delete_entry(fname, lines_before, entry_lines, 0); ! 149: }else{ ! 150: if(opflag == EDIT){ ! 151: delete_entry(fname, lines_before, entry_lines, 1); ! 152: }else{ ! 153: mvwaddstr(portwin,1,21,"Press any key to return to main menu."); ! 154: wrefresh(portwin); ! 155: b = wgetch(portwin); ! 156: } ! 157: } ! 158: wclear(portwin); ! 159: wrefresh(portwin); ! 160: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.