int
add_dir(struct lzh_ostream *wp, int replace_flag, struct lzh_header *h)
{
- long headerpos, arcpos;
- uint r;
-
h->origsize = h->compsize = 0;
h->file_crc = INIT_CRC;
- headerpos = ftell(wp->fp);
write_header(wp->fp, h);
- arcpos = ftell(wp->fp);
- if (opts.quiet < 2)
- printf(" %d.%d%%\n", r / 10, r % 10);
+ if (opts.quiet < 2) {
+ if (replace_flag)
+ printf("Replacing %s/ ", h->filename);
+ else
+ printf("Adding %s/ ", h->filename);
+
+ printf("(directory)\n");
+ }
return 1; /* success */
}
static int
add_1(struct lzh_ostream *wp, int replace_flag, struct lzh_header *h)
{
- long headerpos, arcpos;
+ long headerpos, arcpos, arcendpos;
uint r;
FILE *rfp;
fprintf(stderr, "Can't open %s\n", h->filename);
return 0; /* failure */
}
- if (replace_flag) {
- if (opts.quiet < 2)
+ if (opts.quiet < 2) {
+ if (replace_flag)
printf("Replacing %s ", h->filename);
- }
- else {
- if (opts.quiet < 2)
+ else
printf("Adding %s ", h->filename);
}
h->file_crc = wp->crc ^ INIT_CRC;
fclose(rfp);
+ /* rewrite compsize and origsize to the header */
+ arcendpos = ftell(wp->fp);
fseek(wp->fp, headerpos, SEEK_SET);
write_header(wp->fp, h);
- fseek(wp->fp, 0L, SEEK_END);
+ fseek(wp->fp, arcendpos, SEEK_SET);
+
r = ratio(wp->compsize, wp->origsize);
if (opts.quiet < 2)
printf(" %d.%d%%\n", r / 10, r % 10);
h.mtime = st.st_mtime;
if (S_ISDIR(st.st_mode)) {
+ /* directory */
DIR *dir;
struct dirent *ent;
memcpy(h.method, "-lhd-", sizeof(h.method)); /* directory */
add_dir(wp, replace_flag, &h);
+ /* recursive call */
dir = opendir(h.filename);
if (dir == NULL)
error("cannot open directory: \"%s\"", h.filename);
closedir(dir);
}
else {
- memcpy(h.method, opts.method->id, sizeof(h.method)); /* compress */
+ /* regular file */
+ memcpy(h.method, opts.method->id, sizeof(h.method));
add_1(wp, replace_flag, &h);
}
+
+ return 0;
}