|
|
1.1 ! root 1: /* config.c: this is the code for opening the config files; ! 2: * printing a screen of existing ports, systems or ! 3: * dialers; viewing or deleting an existing entry. ! 4: */ ! 5: ! 6: #include <stdio.h> ! 7: #include <curses.h> ! 8: #include <fcntl.h> ! 9: #include "uuinstall.h" ! 10: ! 11: char names[MAXENTRIES][15]; /* array of port names read */ ! 12: ! 13: /* open_config_file(): does just that, opens a configuration file */ ! 14: ! 15: open_config_file() ! 16: { ! 17: ! 18: FILE * configfile; ! 19: ! 20: if(portflag){ ! 21: if ( (configfile = fopen(PORTFILE,"r")) == NULL){ ! 22: printf("Error opening %s.\n",PORTFILE); ! 23: exit_program(-1); ! 24: } ! 25: } ! 26: ! 27: if(sysflag){ ! 28: if ( (configfile = fopen(SYSFILE,"r")) == NULL){ ! 29: printf("Error opening %s.\n",SYSFILE); ! 30: exit_program(-1); ! 31: } ! 32: } ! 33: ! 34: if(dialflag){ ! 35: if ( (configfile = fopen(DIALFILE,"r")) == NULL){ ! 36: printf("Error opening %s.\n",DIALFILE); ! 37: exit_program(-1); ! 38: } ! 39: } ! 40: ! 41: /* file exists, but is empty */ ! 42: if( -1 == read_entries(configfile)){ ! 43: fclose(configfile); ! 44: return; ! 45: } ! 46: ! 47: fclose(configfile); ! 48: print_selections(); ! 49: ! 50: lite(selwin,0,1,1); /* highlight our first record */ ! 51: prompt(); ! 52: wrefresh(selwin); ! 53: ! 54: } ! 55: ! 56: ! 57: /* read the information from the specified file. We want to keep track of the ! 58: * port, system or dialer name we have read, the line we began reading it ! 59: * on and the total number of entries read; ! 60: */ ! 61: ! 62: ! 63: read_entries(configfile) ! 64: FILE * configfile; /* pointer to our configuration file */ ! 65: { ! 66: ! 67: int x = 0; /* counter of lines read */ ! 68: int size = 0; /* offset where we will find the ! 69: * port name, system name or dialer ! 70: * name on the first line of a port, ! 71: * dial or sys entry in a config file. ! 72: */ ! 73: char buffer[256]; ! 74: char lookfor[8]; ! 75: ! 76: if(dialflag){ ! 77: strcpy(lookfor,"dialer"); ! 78: size = 7; ! 79: } ! 80: if(sysflag){ ! 81: strcpy(lookfor,"system"); ! 82: size = 7; ! 83: } ! 84: if(portflag){ ! 85: strcpy(lookfor,"port"); ! 86: size = 5; ! 87: } ! 88: ! 89: total_entries_found = 0; /* total number of port entries found */ ! 90: ! 91: while(fgets(buffer,sizeof(buffer) -1, configfile) != NULL){ ! 92: x++; ! 93: ! 94: /* found first line of a configuration entry, copy name and ! 95: * the line number we found it on. ! 96: */ ! 97: ! 98: if(strstr(buffer,lookfor)){ ! 99: /* there's a newline here, get rid of it */ ! 100: buffer[strlen(buffer) -1] = '\0'; ! 101: /* if someone has editted the file to comment out an entry, we still ! 102: * want to display it, but must accomodate the new offset within the ! 103: * string of the actual name we want caused by the addition of a ! 104: * '#' character. ! 105: */ ! 106: while(isspace( *(buffer + size) ) ){ ! 107: size++; ! 108: } ! 109: ! 110: strcpy(names[total_entries_found],buffer + size); ! 111: startpos[total_entries_found] = x; ! 112: total_entries_found++; ! 113: ! 114: if (total_entries_found == MAXENTRIES){ ! 115: return; ! 116: } ! 117: /* printf("Found port %s on line %d\n",names[total_entries_found -1],x); */ ! 118: } ! 119: } ! 120: ! 121: /* if the file exists but is empty, return -1 to the calling process */ ! 122: if(x == 0){ ! 123: return(-1); ! 124: } ! 125: } ! 126: ! 127: ! 128: /* print the entries we found to the selection window */ ! 129: ! 130: print_selections() ! 131: { ! 132: int r,c,z; /* counters */ ! 133: ! 134: z = 0; ! 135: ! 136: for(r = 0; r < 20 ; r++){ /* 20 is the max # lines we have */ ! 137: if (z == total_entries_found) /* if we have no more ports, then abort */ ! 138: break; ! 139: ! 140: /* increment our column by 15 positions. This will cause ! 141: * the port names to be printed to line up properly. ! 142: */ ! 143: ! 144: for(c = 1; c < 75 ; c+=15){ ! 145: mvwaddstr(selwin,r,c, names[z]); ! 146: z++; ! 147: if (z == total_entries_found) /* break if out of ports */ ! 148: break; ! 149: } ! 150: } ! 151: wmove(selwin, 0,1); /* put our cursor at the first entry on the win */ ! 152: ! 153: return; ! 154: ! 155: } ! 156: ! 157: ! 158: /* prompt(): print a message telling the user what to do */ ! 159: ! 160: prompt() ! 161: { ! 162: wclear(promptwin); ! 163: wmove(promptwin,0,0); ! 164: wprintw(promptwin,"Highlite the entry you wish to work"); ! 165: wmove(promptwin,1,0); ! 166: wprintw(promptwin,"with by using arrow keys or the vi"); ! 167: wmove(promptwin,2,0); ! 168: wprintw(promptwin,"keys h,j,k &l. <RETURN> selects entry."); ! 169: wmove(promptwin,3,0); ! 170: wprintw(promptwin,"To exit, press 'q'."); ! 171: wrefresh(promptwin); ! 172: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.