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.

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

208 int i, n;
209 int pce, npieces;
210 unsigned claimed_cksum;
211 unsigned short cksum = 0;
212 char out_buf[200];
213 char line[200];
214 char delta[30];
215 char pname[1000];
216 char tname[1000];
217 char junk[2];
218
219 ifp = stdin;
220 if (input_file != NULL && (ifp = fopen(input_file, "r")) == NULL)
221 {
222 err("cannot open '%s' for reading", input_file);
223 return 1;
224 }

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

237 if (sscanf(line, "CTM_MAIL BEGIN %s %d %d %c",
238 delta, &pce, &npieces, junk) != 3)
239 continue;
240
241 while ((s = strchr(delta, '/')) != NULL)
242 *s = '_';
243
244 mk_piece_name(pname, delta, pce, npieces);
244 if ((ofp = fopen(pname, "w")) == NULL)
245 sprintf(tname,"tmp.%s",pname);
246 if ((ofp = fopen(tname, "w")) == NULL)
247 {
246 err("cannot open '%s' for writing", pname);
248 err("cannot open '%s' for writing", tname);
249 status++;
250 continue;
251 }
252
253 cksum = 0xffff;
254 decoding++;
255 continue;
256 }

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

264
265 decoding = 0;
266
267 fflush(ofp);
268 e = ferror(ofp);
269 fclose(ofp);
270
271 if (e)
270 err("error writing %s", pname);
272 err("error writing %s", tname);
273
274 if (cksum != claimed_cksum)
275 err("checksum: read %d, calculated %d", claimed_cksum, cksum);
276
277 if (e || cksum != claimed_cksum)
278 {
279 err("%s %d/%d discarded", delta, pce, npieces);
278 unlink(pname);
280 unlink(tname);
281 status++;
282 continue;
283 }
284
285 if (rename(tname, pname) < 0)
286 {
287 err("error renaming %s to %s",tname,pname);
288 unlink(tname);
289 status++;
290 continue;
291 }
292
293 err("%s %d/%d stored", delta, pce, npieces);
294
295 if (!combine_if_complete(delta, pce, npieces))
296 status++;
297 continue;
298 }
299
300 /*

--- 202 unchanged lines hidden ---