Deleted Added
full compact
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>
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
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)
68 usage();
69
70 if (piece_dir == NULL && (base_dir == NULL || argc>1))
71 usage();
72
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;
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;
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;
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;
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
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;
250 }
251
252 cksum = 0xffff;
253 decoding++;
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 ---