Deleted Added
full compact
ctm_rmail.c (6081) ctm_rmail.c (6290)
1/*
2 * Accept one (or more) ASCII encoded chunks that together make a compressed
3 * CTM delta. Decode them and reconstruct the deltas. Any completed
4 * deltas may be passed to ctm for unpacking.
5 *
6 * Author: Stephen McKay
7 *
8 * NOTICE: This is free software. I hope you get some use from this program.
9 * In return you should think about all the nice people who give away software.
10 * Maybe you should write some free software too.
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
1/*
2 * Accept one (or more) ASCII encoded chunks that together make a compressed
3 * CTM delta. Decode them and reconstruct the deltas. Any completed
4 * deltas may be passed to ctm for unpacking.
5 *
6 * Author: Stephen McKay
7 *
8 * NOTICE: This is free software. I hope you get some use from this program.
9 * In return you should think about all the nice people who give away software.
10 * Maybe you should write some free software too.
11 */
12
13#include <stdio.h>
14#include <stdlib.h>
15#include <unistd.h>
15#include <string.h>
16#include <errno.h>
17#include <unistd.h>
18#include <sys/types.h>
19#include <sys/stat.h>
20#include "error.h"
21#include "options.h"
22

--- 18 unchanged lines hidden (view full) ---

41 * be timestamped and written to the given file.
42 *
43 * Exit status is 0 for success or 1 for indigestible input. That is,
44 * 0 means the encode input pieces were decoded and stored, and 1 means
45 * some input was discarded. If a delta fails to apply, this won't be
46 * reflected in the exit status. In this case, the delta is left in
47 * 'deltadir'.
48 */
16#include <string.h>
17#include <errno.h>
18#include <unistd.h>
19#include <sys/types.h>
20#include <sys/stat.h>
21#include "error.h"
22#include "options.h"
23

--- 18 unchanged lines hidden (view full) ---

42 * be timestamped and written to the given file.
43 *
44 * Exit status is 0 for success or 1 for indigestible input. That is,
45 * 0 means the encode input pieces were decoded and stored, and 1 means
46 * some input was discarded. If a delta fails to apply, this won't be
47 * reflected in the exit status. In this case, the delta is left in
48 * 'deltadir'.
49 */
50
51int
49main(int argc, char **argv)
50 {
51 char *log_file = NULL;
52 int status = 0;
53
54 err_prog_name(argv[0]);
55
56 OPTIONS("[-D] [-p piecedir] [-d deltadir] [-b basedir] [-l log] [file ...]")
57 FLAG('D', delete_after)
58 STRING('p', piece_dir)
59 STRING('d', delta_dir)
60 STRING('b', base_dir)
61 STRING('l', log_file)
62 ENDOPTS
63
52main(int argc, char **argv)
53 {
54 char *log_file = NULL;
55 int status = 0;
56
57 err_prog_name(argv[0]);
58
59 OPTIONS("[-D] [-p piecedir] [-d deltadir] [-b basedir] [-l log] [file ...]")
60 FLAG('D', delete_after)
61 STRING('p', piece_dir)
62 STRING('d', delta_dir)
63 STRING('b', base_dir)
64 STRING('l', log_file)
65 ENDOPTS
66
64 if (delta_dir == NULL || piece_dir == NULL && (base_dir == NULL || argc>1))
67 if (delta_dir == NULL)
65 usage();
66
68 usage();
69
70 if (piece_dir == NULL && (base_dir == NULL || argc>1))
71 usage();
72
67 if (log_file != NULL)
68 err_set_log(log_file);
69
70 if (argc <= 1)
71 {
72 if (piece_dir != NULL)
73 status = read_piece(NULL);
74 }

--- 117 unchanged lines hidden (view full) ---

192 * Multiple pieces can be present in a single file, bracketed by BEGIN/END.
193 * If we have all pieces of a delta, combine them. Returns 0 on success,
194 * and 1 for any sort of failure.
195 */
196int
197read_piece(char *input_file)
198 {
199 int status = 0;
73 if (log_file != NULL)
74 err_set_log(log_file);
75
76 if (argc <= 1)
77 {
78 if (piece_dir != NULL)
79 status = read_piece(NULL);
80 }

--- 117 unchanged lines hidden (view full) ---

198 * Multiple pieces can be present in a single file, bracketed by BEGIN/END.
199 * If we have all pieces of a delta, combine them. Returns 0 on success,
200 * and 1 for any sort of failure.
201 */
202int
203read_piece(char *input_file)
204 {
205 int status = 0;
200 FILE *ifp, *ofp;
206 FILE *ifp, *ofp = 0;
201 int decoding = 0;
202 int line_no = 0;
203 int i, n;
204 int pce, npieces;
205 unsigned claimed_cksum;
207 int decoding = 0;
208 int line_no = 0;
209 int i, n;
210 int pce, npieces;
211 unsigned claimed_cksum;
206 unsigned short cksum;
212 unsigned short cksum = 0;
207 char out_buf[200];
208 char line[200];
209 char delta[30];
210 char pname[1000];
211 char junk[2];
212
213 ifp = stdin;
214 if (input_file != NULL && (ifp = fopen(input_file, "r")) == NULL)

--- 6 unchanged lines hidden (view full) ---

221 {
222 line_no++;
223
224 /*
225 * Look for the beginning of an encoded piece.
226 */
227 if (!decoding)
228 {
213 char out_buf[200];
214 char line[200];
215 char delta[30];
216 char pname[1000];
217 char junk[2];
218
219 ifp = stdin;
220 if (input_file != NULL && (ifp = fopen(input_file, "r")) == NULL)

--- 6 unchanged lines hidden (view full) ---

227 {
228 line_no++;
229
230 /*
231 * Look for the beginning of an encoded piece.
232 */
233 if (!decoding)
234 {
229 if (sscanf(line, "CTM_MAIL BEGIN %s %d %d %c", delta, &pce, &npieces, junk) == 3)
230 {
231 char *s;
235 char *s;
232
236
233 while ((s = strchr(delta, '/')) != NULL)
234 *s = '_';
237 if (sscanf(line, "CTM_MAIL BEGIN %s %d %d %c",
238 delta, &pce, &npieces, junk) != 3)
239 continue;
235
240
236 mk_piece_name(pname, delta, pce, npieces);
237 if ((ofp = fopen(pname, "w")) == NULL)
238 {
239 err("cannot open '%s' for writing", pname);
240 status++;
241 continue;
242 }
241 while ((s = strchr(delta, '/')) != NULL)
242 *s = '_';
243
243
244 cksum = 0xffff;
245 decoding++;
244 mk_piece_name(pname, delta, pce, npieces);
245 if ((ofp = fopen(pname, "w")) == NULL)
246 {
247 err("cannot open '%s' for writing", pname);
248 status++;
249 continue;
246 }
250 }
251
252 cksum = 0xffff;
253 decoding++;
247 continue;
248 }
249
250 /*
251 * We are decoding. Stop if we see the end flag.
252 */
253 if (sscanf(line, "CTM_MAIL END %d %c", &claimed_cksum, junk) == 1)
254 {

--- 232 unchanged lines hidden ---
254 continue;
255 }
256
257 /*
258 * We are decoding. Stop if we see the end flag.
259 */
260 if (sscanf(line, "CTM_MAIL END %d %c", &claimed_cksum, junk) == 1)
261 {

--- 232 unchanged lines hidden ---