|
|
1.1 root 1: /* wfile.c
2: * This routine will write a contents entry to a specified file
3: */
4:
5: #define MASTERFILE "Contents"
6: #define TRACE printf
7: #define PATHNAME "/usr/spool/uucppublic/"
8: #define LENPATH 22
9: #define NAMELOCATE 2,1
10: #define DESCLOCATE 4,1
11: #define DATELOCATE 6,1
12: #define SIZELOCATE 6,30
13: #define PARTLOCATE 6,49
14: #define REQLOCATE 9,1
15: #define NOTELOCATE 12,1
16: #define PATHLOCATE 15,1
17: #define PATHLOCATE2 16,1
18: #define PATHLOCATE3 17,1
19: #define NAMEHI 2,12
20: #define DESCHI 5,1
21: #define DATEHI 7,5
22: #define SIZEHI 7,30
23: #define PARTHI 7,60
24: #define REQHI 10,2
25: #define NOTEHI 13,2
26: #define PATHHI 18,2
27: #define PATHHI2 18,34
28:
29: #include <stdio.h>
30: #include <curses.h>
31:
32: char filename[14];
33:
34: void entry_screen();
35: int get_data();
36: void getstring();
37:
38: struct entry{
39: char filename [15];
40: char filesize [10];
41: char date[7];
42: char description [78];
43: char requires [60];
44: char notes [78];
45: char pathname [60];
46: int noparts;
47: }
48:
49:
50: main()
51: {
52: WINDOW *win2;
53: int x;
54:
55: initscr();
56: raw();
57:
58: if((win2=newwin(20, 79, 0,0)) == NULL)
59: {
60: printf("\007Window Memroy allocation for win2 failed!\n");
61: exit(1);
62: }
63:
64:
65: /* the following loop will draw the data entry screen and then go into
66: * the function to get the data. This will continue until a '1' is
67: * returned from get_data.
68: */
69:
70: do
71: {
72: entry_screen(win2);
73: x = get_data(win2);
74: }
75: while (x == 0);
76:
77: noraw();
78: endwin();
79: }
80:
81:
82: /* this function will draw the file entry screen */
83:
84: void entry_screen(win2)
85: WINDOW *win2;
86:
87: {
88: int x;
89:
90: wclear(win2);
91:
92: /* print field labels */
93:
94: wmove (win2,0,31);
95: waddstr (win2,"Add record to file");
96:
97: wmove (win2, NAMELOCATE );
98: waddstr (win2,"Filename:");
99:
100: wmove (win2, DESCLOCATE);
101: waddstr(win2,"Description:");
102:
103: wmove(win2, DATELOCATE );
104: waddstr(win2,"Date added/modified:");
105:
106: wmove(win2, SIZELOCATE);
107: waddstr(win2,"File size:");
108:
109: wmove(win2, PARTLOCATE);;
110: waddstr(win2,"Number of parts to download:");
111:
112: wmove(win2, REQLOCATE );
113: waddstr(win2,"Requires these other files:");
114:
115: wmove(win2, NOTELOCATE);
116: waddstr(win2,"Other notes:");
117:
118: wmove(win2, PATHLOCATE);
119: waddstr(win2, "Path to download file... Must give complete path including filename.");
120: wmove (win2, PATHLOCATE2);
121: waddstr(win2,"If a file is split into several parts, enter the first filename part");
122: wmove (win2, PATHLOCATE3);
123: waddstr(win2,"leaving the LAST character off of the filename:");
124:
125:
126: /* highlite available fields */
127:
128: wstandout(win2);
129:
130: wmove (win2, NAMEHI);
131: waddstr(win2," ");
132:
133: wmove (win2,DESCHI);
134: for (x=1;x<79;x++)
135: waddstr(win2," ");
136:
137: wmove(win2, DATEHI);
138: waddstr(win2," ");
139:
140: wmove(win2, SIZEHI);
141: waddstr(win2," ");
142:
143: wmove(win2,PARTHI);
144: waddstr(win2," ");
145:
146: wmove (win2,REQHI);
147: for (x=1;x<61;x++)
148: waddstr(win2," ");
149:
150: wmove (win2,NOTEHI);
151: for (x=1;x<69;x++)
152: waddstr(win2," ");
153:
154: wmove (win2, PATHHI);
155: waddstr(win2,PATHNAME);
156: for (x=23;x<61;x++)
157: waddstr(win2," ");
158:
159: wstandend(win2);
160:
161: refresh();
162: wrefresh(win2);
163:
164: }
165:
166:
167: /* this function will get the input and write it to a file */
168:
169: int get_data(win2)
170: WINDOW *win2;
171:
172: {
173: struct entry record;
174: /* char pathname[38]; */
175: FILE *outfp;
176: WINDOW *win3;
177: int x;
178:
179: if( (win3=newwin(4,79,20,0)) == NULL )
180: {
181: wclear(win2);
182: wmove(win2,0,0);
183: wstandout(win2);
184: waddstr(win2,"\007Error allocating memory for win3. Press <RETURN>");
185: wrefresh(win2);
186: while('\n' != getch())
187: ;
188: exit(1);
189: }
190:
191: wclear(win3);
192: wmove(win3,1,1);
193: waddstr(win3,"Enter a filename, or press <RETURN> to end");
194: wrefresh(win3);
195: getstring(win2, win3, NAMEHI, 14, 0);
196: strcpy(record.filename, filename);
197:
198:
199: if(strlen(record.filename) == 0)
200: exit(1);
201:
202: for(x=strlen(filename);x < sizeof (record.filename) ; x++)
203: record.filename[x] = '\0';
204:
205: wclear(win3);
206: wmove(win3,1,1);
207: waddstr(win3,"Describe the uses of this package");
208: wrefresh(win3);
209:
210: getstring(win2, win3, DESCHI, 78, 1);
211: strcpy(record.description, filename);
212:
213: for(x=strlen(filename);x < sizeof (record.description) ; x++)
214: record.description[x] = '\0';
215:
216: wclear(win3);
217: wmove(win3,1,1);
218: waddstr(win3,"Enter the date that the file was added or last modified");
219: wmove(win3,2,1);
220: waddstr(win3,"Enter no more than 6 characters");
221: wrefresh(win3);
222:
223: getstring(win2, win3, DATEHI, 6, 1);
224: strcpy(record.date, filename);
225:
226: for(x=strlen(filename);x < sizeof (record.date) ; x++)
227: record.date[x] = '\0';
228:
229: wclear(win3);
230: wmove(win3,1,1);
231: waddstr(win3,"Enter the file size in number of bytes");
232: wrefresh(win3);
233:
234:
235: getstring(win2, win3, SIZEHI, 10, 1);
236: strcpy(record.filesize, filename);
237:
238: for(x=strlen(filename);x < sizeof (record.filesize) ; x++)
239: record.filesize[x] = '\0';
240:
241: wclear(win3);
242: wmove(win3,3,1);
243: waddstr(win3,"Enter the number of parts that this file is divided into");
244: wrefresh(win3);
245:
246: getstring(win2, win3, PARTHI, 2, 1);
247: record.noparts = atoi(filename);
248:
249:
250: /* if the number of parts is 0 (not a split file), then we can
251: * cat the filename on to the end of the pathname. We can later
252: * test the length of the pathname to determine whether or not
253: * to ask for a pathname, as would be required for a split file.
254: */
255:
256: if(record.noparts ==0)
257: {
258: strcpy(record.pathname, PATHNAME);
259: strcat(record.pathname, record.filename);
260: wmove(win2,PATHHI);
261: wstandout(win2);
262: waddstr(win2, record.pathname);
263: wstandend(win2);
264: wrefresh(win2);
265: }
266: else
267: strcpy(record.pathname, PATHNAME);
268:
269:
270: wclear(win3);
271: wmove(win3,3,1);
272: waddstr(win3,"Enter the names of any support files required");
273: wrefresh(win3);
274:
275: getstring(win2, win3, REQHI, 60, 0);
276: if(strlen(filename) == 0 )
277: {
278: wmove(win2, REQHI);
279: wstandout(win2);
280: waddstr(win2,"none");
281: wstandend(win2);
282: wrefresh(win2);
283: strcpy(record.requires, "none");
284: }
285: else
286: strcpy(record.requires, filename);
287:
288: for(x=strlen(record.requires);x < sizeof (record.requires) ; x++)
289: record.requires[x] = '\0';
290:
291: wclear(win3);
292: wmove(win3,3,1);
293: waddstr(win3,"Enter any relevant notes about this file");
294: wrefresh(win3);
295:
296: getstring(win2, win3, NOTEHI, 78, 0);
297: if(strlen(filename) == 0)
298: {
299: wmove(win2,NOTEHI);
300: wstandout(win2);
301: waddstr(win2,"none");
302: wstandend(win2);
303: wrefresh(win2);
304: strcpy(record.notes, "none");
305: }
306:
307: else
308: strcpy(record.notes, filename);
309:
310: for(x=strlen(record.notes);x < sizeof (record.notes) ; x++)
311: record.notes[x] = '\0';
312:
313: wclear(win3);
314: wmove(win3,3,1);
315: waddstr(win3,"Enter the pathlist to this file.");
316: wrefresh(win3);
317:
318: /* if the length of the pathname is the default, as determined
319: * by "PATHNAME and LENPATH" #defs, then we need to get a
320: * completed pathlist.
321: * Remember, the need for this is also determined when asked
322: * for the number of parts (above).
323: */
324:
325: if(strlen(record.pathname) == LENPATH)
326: {
327: wmove(win2,PATHHI);
328: wstandout(win2);
329: waddstr(win2, PATHNAME);
330: wstandend(win2);
331: wrefresh(win2);
332: getstring(win2, win3, PATHHI2, 37, 1);
333: strcpy(record.pathname, PATHNAME);
334: strcat(record.pathname, filename);
335: }
336:
337: for(x=strlen(record.pathname);x < sizeof (record.pathname) ; x++)
338: record.pathname[x] = '\0';
339:
340: /* time to write the record */
341:
342: if ((outfp = fopen(MASTERFILE,"a")) == NULL)
343: {
344: wclear(win3);
345: wmove(win3,2,22);
346: waddstr("\007ERROR opening file for writing!");
347: wmove(win3,3,25);
348: waddstr(win3,"press <RETURN> to continue");
349: wrefresh(win3);
350: noraw();
351: while('\n' != wgetch(win3))
352: ;
353: raw();
354: exit(1);
355: }
356:
357: else
358: {
359: fwrite(&record, sizeof(struct entry),1, outfp);
360: fclose(outfp);
361: wclear(win3);
362: wmove(win3, 2, 25);
363: waddstr(win3,"Record added... press <RETURN>");
364: wrefresh(win3);
365: noraw();
366: while('\n' != wgetch(win3))
367: ;
368: raw();
369: wclear(win3);
370: wrefresh(win3);
371: }
372:
373: return(0);
374:
375: }
376:
377:
378: /* this function will get a string char by char and print to the approp.
379: * field on win2. This is to prevent people from entering too many characters.
380: */
381:
382: void getstring (win2, win3, row, col, maxchars, musthave)
383:
384: WINDOW *win2, *win3;
385: int row, col, maxchars, musthave;
386:
387: {
388:
389:
390: noraw();
391: wmove(win2,row,col);
392: wrefresh(win2);
393: wgetstr(win2,filename);
394: wmove(win2,row,col);
395: wstandout(win2);
396: waddstr(win2,filename);
397: wstandend(win2);
398: wrefresh(win2);
399: raw();
400:
401:
402:
403: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.