|
|
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 "uuinstall.h"
7:
8: char names[MAXENTRIES][15]; /* array of port names read */
9:
10: /* open_config_file(): does just that, opens a configuration file */
11:
12: open_config_file()
13: {
14:
15: FILE * configfile;
16:
17: if(portflag){
18: if ( (configfile = fopen(PORTFILE,"r")) == NULL){
19: printf("Error opening %s.\n",PORTFILE);
20: exit_program(-1);
21: }
22: }
23:
24: if(sysflag){
25: if ( (configfile = fopen(SYSFILE,"r")) == NULL){
26: printf("Error opening %s.\n",SYSFILE);
27: exit_program(-1);
28: }
29: }
30:
31: if(dialflag){
32: if ( (configfile = fopen(DIALFILE,"r")) == NULL){
33: printf("Error opening %s.\n",DIALFILE);
34: exit_program(-1);
35: }
36: }
37:
38: /* file exists, but is empty */
39: if( -1 == read_entries(configfile)){
40: fclose(configfile);
41: return;
42: }
43:
44: fclose(configfile);
45: print_selections();
46:
47: lite(selwin,0,1,1); /* highlight our first record */
48: prompt();
49: wrefresh(selwin);
50:
51: }
52:
53:
54: /* read the information from the specified file. We want to keep track of the
55: * port, system or dialer name we have read, the line we began reading it
56: * on and the total number of entries read;
57: */
58:
59:
60: read_entries(configfile)
61: FILE * configfile; /* pointer to our configuration file */
62: {
63:
64: int y;
65: int x = 0; /* counter of lines read */
66:
67: char buffer[256];
68: char lookfor[8];
69:
70: if(dialflag){
71: strcpy(lookfor,"dialer");
72: }
73: if(sysflag){
74: strcpy(lookfor,"system");
75: }
76: if(portflag){
77: strcpy(lookfor,"port");
78: }
79:
80: total_entries_found = 0; /* total number of port entries found */
81:
82: while(fgets(buffer,sizeof(buffer) -1, configfile) != NULL){
83: x++;
84:
85: /* found first line of a configuration entry, copy name and
86: * the line number we found it on.
87: */
88:
89: if(strstr(buffer,lookfor)){
90: /* there's a newline here, get rid of it */
91: buffer[strlen(buffer) -1] = '\0';
92:
93: /* if someone has editted the file to comment out an entry, we still
94: * want to display it, but must accomodate the new offset within the
95: * string of the actual name we want caused by the addition of a
96: * '#' character. To do this, we will begin at the end of the line
97: * and walk backward until we hit a space. This will account for
98: * a '#' followed by any number of spaces.
99: */
100: y = strlen(buffer) -1;
101:
102: while(!isspace( *( buffer + y ) ) ){
103: y--;
104: }
105:
106: /* while(isspace( *(buffer + size) ) ){
107: * size++;
108: * }
109: */
110: strcpy(names[total_entries_found],buffer + (y+1));
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.