1 | /********************************************************************** |
---|
2 | * File Exchange pickup client |
---|
3 | * |
---|
4 | * $Id: pickup.c,v 1.1 1999-09-28 22:10:59 danw Exp $ |
---|
5 | * |
---|
6 | * Copyright 1989, 1990 by the Massachusetts Institute of Technology. |
---|
7 | * |
---|
8 | * For copying and distribution information, please see the file |
---|
9 | * <mit-copyright.h>. |
---|
10 | **********************************************************************/ |
---|
11 | |
---|
12 | #include <mit-copyright.h> |
---|
13 | |
---|
14 | #ifndef lint |
---|
15 | static char rcsid_collect_c[] = "$Id: pickup.c,v 1.1 1999-09-28 22:10:59 danw Exp $"; |
---|
16 | #endif /* lint */ |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <string.h> |
---|
20 | #include <ctype.h> |
---|
21 | #include <sys/errno.h> |
---|
22 | #include <sys/types.h> |
---|
23 | #include <sys/stat.h> |
---|
24 | #include "fxmain.h" |
---|
25 | |
---|
26 | /*** Global variables ***/ |
---|
27 | long do_dump(); |
---|
28 | extern int verbose, errno; |
---|
29 | int kbytes = 0; |
---|
30 | |
---|
31 | /* |
---|
32 | * pickup_arg checks to see if the current argument indicates |
---|
33 | * a type for which PRESERVE should be set or a type for which |
---|
34 | * we pickup papers authored by others, e.g. handouts. |
---|
35 | */ |
---|
36 | |
---|
37 | /*ARGSUSED*/ |
---|
38 | int |
---|
39 | pickup_arg(argc, argv, ip, p, flagp) |
---|
40 | int argc; |
---|
41 | char *argv[]; |
---|
42 | int *ip; |
---|
43 | Paper *p; |
---|
44 | int *flagp; |
---|
45 | { |
---|
46 | static int initialized = 0; |
---|
47 | |
---|
48 | if (!initialized) { |
---|
49 | *flagp |= ONE_AUTHOR; |
---|
50 | initialized = 1; |
---|
51 | } |
---|
52 | if (argv[*ip][0] == '-' && strchr("*TtPheAH", argv[*ip][1])) { |
---|
53 | *flagp |= PRESERVE; |
---|
54 | *flagp &= ~ONE_AUTHOR; |
---|
55 | } |
---|
56 | return(0); |
---|
57 | } |
---|
58 | |
---|
59 | /* |
---|
60 | * adjust_criterion -- put filename in criterion |
---|
61 | */ |
---|
62 | |
---|
63 | void |
---|
64 | adjust_criterion(p, s) |
---|
65 | Paper *p; |
---|
66 | char *s; |
---|
67 | { |
---|
68 | p->filename = s; |
---|
69 | return; |
---|
70 | } |
---|
71 | |
---|
72 | /* |
---|
73 | * compar -- compares two papers, used by qsort |
---|
74 | */ |
---|
75 | |
---|
76 | compar(p1, p2) |
---|
77 | Paper **p1, **p2; |
---|
78 | { |
---|
79 | register int ret; |
---|
80 | |
---|
81 | ret = strcmp((*p1)->filename, (*p2)->filename); |
---|
82 | if (ret) return(ret); |
---|
83 | ret = (int) (*p1)->modified.tv_sec - (*p2)->modified.tv_sec; |
---|
84 | if (ret) return(ret); |
---|
85 | return((int) ((*p1)->modified.tv_usec - (*p2)->modified.tv_usec)); |
---|
86 | } |
---|
87 | |
---|
88 | /* |
---|
89 | * prep_paper -- gets filename, disk usage for paper |
---|
90 | */ |
---|
91 | |
---|
92 | /*ARGSUSED*/ |
---|
93 | long |
---|
94 | prep_paper(p, f, flags) |
---|
95 | Paper *p; /* paper to retrieve */ |
---|
96 | char *f; /* filename (modified) */ |
---|
97 | int flags; /* flags (unused) */ |
---|
98 | { |
---|
99 | (void) strcpy(f, p->filename); |
---|
100 | kbytes += ((p->size + 1023) >> 10); |
---|
101 | return(0L); |
---|
102 | } |
---|
103 | |
---|
104 | void |
---|
105 | empty_list(criterion) |
---|
106 | Paper *criterion; |
---|
107 | { |
---|
108 | printf("No papers to pick up\n"); |
---|
109 | } |
---|
110 | |
---|
111 | void |
---|
112 | mark_retrieved(fxp, p) |
---|
113 | FX *fxp; |
---|
114 | Paper *p; |
---|
115 | { |
---|
116 | Paper pickedup; |
---|
117 | static int warned = 0; |
---|
118 | long code; |
---|
119 | |
---|
120 | if (!warned) { |
---|
121 | /******** mark file on server as PICKEDUP ********/ |
---|
122 | paper_copy(p, &pickedup); |
---|
123 | pickedup.type = PICKEDUP; |
---|
124 | if (!warned && (code = fx_move(fxp, p, &pickedup))) { |
---|
125 | com_err("Warning", code, "-- files not marked PICKEDUP on server.", ""); |
---|
126 | warned = 1; |
---|
127 | } |
---|
128 | } |
---|
129 | return; |
---|
130 | } |
---|
131 | |
---|
132 | /* |
---|
133 | * main pickup procedure |
---|
134 | */ |
---|
135 | |
---|
136 | main(argc, argv) |
---|
137 | int argc; |
---|
138 | char *argv[]; |
---|
139 | { |
---|
140 | Paper p; |
---|
141 | |
---|
142 | paper_clear(&p); |
---|
143 | p.type = GRADED; |
---|
144 | |
---|
145 | if (fxmain(argc, argv, |
---|
146 | "Usage: %s [options] [assignment] [filename ...]\n", |
---|
147 | &p, pickup_arg, do_dump)) exit(1); |
---|
148 | if (verbose && kbytes) printf("%d kbytes total\n", kbytes); |
---|
149 | exit(0); |
---|
150 | } |
---|