|
|
1.1 root 1: /* print.c
2: * With any luck, this program will read the Content file format
3: * and print information to a text file which can later be spooled
4: * for printing by the user.
5: */
6:
7: #include <stdio.h>
8: #include <curses.h>
9: #include "contents.h"
10:
11: #define PRINTFILE "mwcbbs.print"
12:
13: void print(win2)
14: WINDOW *win2;
15:
16: {
17: FILE *infp, *outfp;
18: char new_date[3];
19: int month, day, year;
20: int cmp_month, cmp_day, cmp_year;
21: char choice, dummy;
22:
23:
24: /* we will first as if the user wants to specify a date. If
25: * the user responds 'yes', we will get a month and year
26: * only. Later in the read/fprintf loop, we will perform
27: * the comparison before printing a record to the file.
28: */
29:
30: wclear(win2);
31: wmove(win2,0,10);
32: wprintw(win2,"Do you wish to specify a start date for printing only");
33: wmove(win2,1,10);
34: wprintw(win2,"those file entries NEWER than the date you specify?");
35: wmove(win2,3,10);
36: wprintw(win2,"[y]es or any other key for no date specification.");
37: wrefresh(win2);
38:
39: choice = 0;
40: while( choice == 0)
41: choice = wgetch(win2);
42:
43: if(choice == 'y')
44: {
45:
46: noraw();
47:
48: /* print our screen to get the user's info */
49:
50: wclear(win2);
51:
52: wmove(win2,0,15);
53: wprintw(win2,"Please specify the month and year from which to");
54: wmove(win2,1,15);
55: wprintw(win2,"begin searching new entries. Only those files");
56: wmove(win2,2,15);
57: wprintw(win2,"with a month and year greater than the specified");
58: wmove(win2,3,15);
59: wprintw(win2,"date will be printed to the file %s.",PRINTFILE);
60: wmove(win2,5,35);
61: wprintw(win2,"Month: ");
62: wmove(win2,7,35);
63: wprintw(win2,"Year: ");
64: wstandout(win2);
65: wmove(win2,5,42);
66: wprintw(win2," ");
67: wmove(win2,7,42);
68: wprintw(win2," ");
69: wstandend(win2);
70: wrefresh(win2);
71:
72: wmove(win2,5,42);
73: wrefresh(win2);
74: cmp_month = 99;
75: while((cmp_month > 12) || (cmp_month < 1))
76: {
77: wscanw(win2,"%d",&cmp_month);
78: wmove(win2,5,42);
79: wrefresh(win2);
80: wstandout(win2);
81: wprintw(win2," ");
82: wstandend(win2);
83: wmove(win2,5,44);
84: wprintw(win2," ");
85: wmove(win2,5,42);
86: wrefresh(win2);
87: }
88: wmove(win2,5,42);
89: clrtoeol();
90: wstandout(win2);
91: wprintw(win2,"%2d",cmp_month);
92: wstandend(win2);
93: wmove(win2,5,44);
94: wprintw(win2," ");
95: wrefresh(win2);
96:
97: wmove(win2,7,42);
98: wrefresh(win2);
99: cmp_year = -1;
100: while((cmp_year > 99) || (cmp_year<0))
101: {
102: wscanw(win2,"%d",&cmp_year);
103: wmove(win2,7,42);
104: wrefresh(win2);
105: wstandout(win2);
106: wprintw(win2," ");
107: wstandend(win2);
108: wmove(win2,7,44);
109: wprintw(win2," ");
110: wmove(win2,7,42);
111: wrefresh(win2);
112: }
113: wmove(win2,7,42);
114: clrtoeol();
115: wstandout(win2);
116: wprintw(win2,"%2d",cmp_year);
117: wstandend(win2);
118: wmove(win2,7,44);
119: wprintw(win2," ");
120: wrefresh(win2);
121:
122: raw();
123: }
124:
125: if ((infp=(fopen(workfile,"r")))==NULL)
126: {
127: noraw();
128: endwin();
129: printf("Could not open file %s for input!\n",workfile);
130: exit(1);
131: }
132: if ((outfp=(fopen(PRINTFILE,"w")))==NULL)
133: {
134: noraw();
135: endwin();
136: printf("Could not open file %s for writing!\n",PRINTFILE);
137: exit(1);
138: }
139:
140:
141: if(choice != 'y')
142: wclear(win2);
143: wmove(win2,12,15);
144: wprintw(win2,"Writing file %s... please wait.",PRINTFILE);
145: wrefresh(win2);
146:
147: fprintf(outfp,"Contents file for: %s ",workfile);
148:
149: /* if we're doing a date search, then print the date */
150: if(choice == 'y')
151: fprintf(outfp,"Search after: %d/%d\n",cmp_month, cmp_year);
152: else
153: fprintf(outfp,"\n");
154:
155: while ((fread(&record,sizeof(struct entry),1,infp))!=0)
156: {
157: strcpy(new_date,"");
158: strncpy(new_date,record.date,2);
159: month = atoi(new_date);
160: strcpy(new_date,"");
161:
162: new_date[0] = record.date[2];
163: new_date[1] = record.date[3];
164: new_date[2] = '/';
165: day = atoi(new_date);
166: strcpy(new_date,"");
167:
168: new_date[0] = record.date[4];
169: new_date[1] = record.date[5];
170: new_date[2] = '\0';
171: year = atoi(new_date);
172:
173:
174: if ((choice != 'y') || ((choice == 'y') && ((month > cmp_month) && (year >= cmp_year) || (year > cmp_year) )))
175: {
176: fprintf(outfp,"\nFILE: %15s\t\tDATE: %d/%d/%d\t\tSIZE: %s\n\n",
177: record.filename, month, day, year ,record.filesize);
178: fprintf(outfp,"Description:\n");
179: fprintf(outfp," %s\n",record.description);
180: fprintf(outfp,"Other notes:\n");
181: fprintf(outfp," %s\n",record.notes);
182: fprintf(outfp,"Required files:\n");
183: fprintf(outfp," %s\n\n",record.requires);
184: }
185: }
186: fclose(infp);
187: fclose(outfp);
188: wclear(win2);
189: wmove(win2,0,10);
190: wprintw(win2,"Because we have just written the file %s,",PRINTFILE);
191: wmove(win2,1,10);
192: wprintw(win2,"the program will now end so that you may view the");
193: wmove(win2,2,10);
194: wprintw(win2,"file and/or print it. This is to prevent you from the");
195: wmove(win2,3,10);
196: wprintw(win2,"possibility of immediate accidental erasure of the file.");
197: wmove(win2,6,10);
198: wprintw(win2,"File written. Press <RETURN> to exit program.");
199: clrtoeol();
200: wrefresh(win2);
201: while(13 != wgetch(win2)) ;
202: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.