|
|
1.1 root 1:
2: /* print_(mail_)recs.c
3: *
4: * This will take the 'statename' passed form the calling function,
5: * open the maillist file and print the records that match the statename
6: * to a window in formatted columns, If there are more records that lines
7: * permitted on the window, the user will be prompted to press <return> to
8: * continue on with any following screens of info.
9: /*
10:
11: void print_mail_recs(win2,statename)
12: WINDOW *win2;
13: char statename[20];
14:
15: {
16: struct mail record;
17: FILE *infp;
18: int x=2;
19:
20:
21: if ((infp=fopen(MAILFILE,"r")) == NULL)
22: {
23: noraw();
24: endwin();
25: printf("Error opening file for input!\n");
26: exit(1);
27: }
28:
29:
30: /* print column titles */
31:
32: wclear(win2);
33: wmove(win2,0,0);
34: wstandout(win2);
35: waddstr(win2,"Sitename");
36: wmove(win2,0,15);
37: waddstr(win2,"Login:");
38: wmove(win2,0,24);
39: waddstr(win2,"State/Country:");
40:
41: /* if we are looking for a US mailsite, then show a column for
42: * cities
43: */
44:
45: if(strcmp(statename,"NON-US") != 0)
46: {
47: wmove(win2,0,49);
48: waddstr(win2,"City/Other:");
49: }
50: wstandend(win2);
51: wmove(win2,2,0);
52:
53: wrefresh(win2);
54:
55: /* read each record, comparing statename for matches. When a
56: match is found, print the record */
57:
58: while ( fread(&record,sizeof(struct mail),1,infp) == 1)
59: {
60: if( (strcmp(statename,record.state)== 0) || ((strcmp(statename,"NON-US")==0) && (strcmp(record.city,"COUNTRY")==0)))
61:
62: {
63: wmove(win2,x,0);
64: waddstr(win2,record.site);
65: wmove(win2,x,16);
66: waddstr(win2,record.login);
67: wmove(win2,x,26);
68: waddstr(win2,record.state);
69: if(strcmp(statename,"NON-US")!=0)
70: {
71: wmove(win2,x,50);
72: waddstr(win2,record.city);
73: }
74:
75: /* increment our line counter, if we've filled our screen,
76: * prompt the user to press <return> to continue on reading
77: * any followinf mail entries from the file.
78: */
79: x++;
80: if(x==18)
81: {
82: wmove(win2,x,0);
83: waddstr(win2,"Press <RETURN> for more");
84: wrefresh(win2);
85: while (13 != wgetch(win2));
86: x = 2;
87: wclear(win2);
88:
89: /* reprint the column titles */
90:
91: wmove(win2,0,0);
92: wstandout(win2);
93: waddstr(win2,"Sitename");
94: wmove(win2,0,15);
95: waddstr(win2,"Login:");
96: wmove(win2,0,24);
97: waddstr(win2,"State/Country:");
98:
99: if(strcmp(statename,"NON-US") != 0)
100: {
101: wmove(win2,0,49);
102: waddstr(win2,"City/Other:");
103: }
104: wstandend(win2);
105:
106: wrefresh(win2);
107: }
108: }
109: }
110: fclose(infp);
111:
112: wmove(win2,18,0);
113: wstandout(win2);
114: waddstr(win2,"That's all folks!");
115: wstandend(win2);
116:
117: wmove(win2,19,0);
118: waddstr(win2,"Press <RETURN> to continue..");
119: wrefresh(win2);
120:
121: while(13 != wgetch(win2));
122: wclear(win2);
123:
124: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.