1 /* ------------------------------------------------------------------------ */
3 /* lhlist.c -- LHarc list */
5 /* Copyright (C) MCMLXXXIX Yooichi.Tagawa */
6 /* Modified Nobutaka Watazaki */
8 /* Ver. 0.00 Original 1988.05.23 Y.Tagawa */
9 /* Ver. 1.00 Fixed 1989.09.22 Y.Tagawa */
10 /* Ver. 1.01 Bug Fix for month name 1989.12.25 Y.Tagawa */
11 /* Ver. 1.10 Changed list format 1993.10.01 N.Watazaki */
12 /* Ver. 1.14 Source All chagned 1995.01.14 N.Watazaki */
13 /* Ver. 1.14e Bug Fix for many problems 1999.05.25 T.Okamoto */
14 /* ------------------------------------------------------------------------ */
17 /* ------------------------------------------------------------------------ */
19 /* ------------------------------------------------------------------------ */
20 /* need 14 or 22 (when verbose_listing is TRUE) column spaces */
22 print_size(packed_size, original_size)
23 long packed_size, original_size;
26 printf("%7lu ", packed_size);
28 printf("%7lu ", original_size);
30 if (original_size == 0L)
32 else /* Changed N.Watazaki */
33 printf("%5.1f%%", packed_size * 100.0 / original_size);
36 /* ------------------------------------------------------------------------ */
37 /* need 12 or 17 (when verbose_listing is TRUE) column spaces */
42 static unsigned int threshold;
43 static char t_month[12 * 3 + 1] = "JanFebMarAprMayJunJulAugSepOctNovDec";
47 if (verbose_listing && verbose)
48 printf(" "); /* 19 spaces */
50 printf(" "); /* 12 spaces */
57 threshold = p->tm_year * 12 + p->tm_mon - 6;
62 if (verbose_listing && verbose)
63 printf("%04d-%02d-%02d %02d:%02d:%02d",
64 p->tm_year+1900, p->tm_mon+1, p->tm_mday,
65 p->tm_hour, p->tm_min, p->tm_sec);
66 else if (p->tm_year * 12 + p->tm_mon > threshold)
67 printf("%.3s %2d %02d:%02d",
68 &t_month[p->tm_mon * 3], p->tm_mday, p->tm_hour, p->tm_min);
70 printf("%.3s %2d %04d",
71 &t_month[p->tm_mon * 3], p->tm_mday, p->tm_year + 1900);
74 /* ------------------------------------------------------------------------ */
78 if (verbose_listing) {
80 /* PERMISSION UID GID PACKED SIZE RATIO METHOD CRC STAMP LV */
81 printf("---------- ----------- ------- ------- ------ ---------- ------------------- ---\n");
83 /* PERMISSION UID GID PACKED SIZE RATIO METHOD CRC STAMP NAME */
84 printf("---------- ----------- ------- ------- ------ ---------- ------------ ----------\n");
88 /* PERMISSION UID GID SIZE RATIO STAMP LV */
89 printf("---------- ----------- ------- ------ ------------ ---\n");
91 /* PERMISSION UID GID SIZE RATIO STAMP NAME */
92 printf("---------- ----------- ------- ------ ------------ --------------------\n");
96 /* ------------------------------------------------------------------------ */
98 /* ------------------------------------------------------------------------ */
102 if (verbose_listing) {
104 printf("PERMISSION UID GID PACKED SIZE RATIO METHOD CRC STAMP LV\n");
106 printf("PERMISSION UID GID PACKED SIZE RATIO METHOD CRC STAMP NAME\n");
110 printf("PERMISSION UID GID SIZE RATIO STAMP LV\n");
112 printf("PERMISSION UID GID SIZE RATIO STAMP NAME\n");
117 /* ------------------------------------------------------------------------ */
120 register LzHeader *hdr;
122 register int mode = 0;
128 if ((hdr->unix_mode & UNIX_FILE_SYMLINK) != UNIX_FILE_SYMLINK)
129 printf("%s\n", hdr->name);
131 printf("%s -> %s\n", hdr->realname, hdr->name);
134 strncpy(method, hdr->method, 5);
137 switch (hdr->extend_type) {
139 mode = hdr->unix_mode;
141 if (mode & UNIX_FILE_DIRECTORY)
143 else if ((mode & UNIX_FILE_SYMLINK) == UNIX_FILE_SYMLINK)
147 modebits[1] = ((mode & UNIX_OWNER_READ_PERM) ? 'r' : '-');
148 modebits[2] = ((mode & UNIX_OWNER_WRITE_PERM) ? 'w' : '-');
149 modebits[3] = (mode & UNIX_SETUID) ? 's' :
150 ((mode & UNIX_OWNER_EXEC_PERM) ? 'x' : '-');
151 modebits[4] = ((mode & UNIX_GROUP_READ_PERM) ? 'r' : '-');
152 modebits[5] = ((mode & UNIX_GROUP_WRITE_PERM) ? 'w' : '-');
153 modebits[6] = (mode & UNIX_SETGID) ? 's' :
154 ((mode & UNIX_GROUP_EXEC_PERM) ? 'x' : '-');
155 modebits[7] = ((mode & UNIX_OTHER_READ_PERM) ? 'r' : '-');
156 modebits[8] = ((mode & UNIX_OTHER_WRITE_PERM) ? 'w' : '-');
157 modebits[9] = (mode & UNIX_STICKYBIT) ? 't' :
158 ((mode & UNIX_OTHER_EXEC_PERM) ? 'x' : '-');
161 printf("%s ", modebits);
164 /**/ case EXTEND_XOSK:/**/
165 mode = hdr->unix_mode;
166 printf("%c%c%c%c%c%c%c%c ",
167 ((mode & OSK_DIRECTORY_PERM) ? 'd' : '-'),
168 ((mode & OSK_SHARED_PERM) ? 's' : '-'),
169 ((mode & OSK_OTHER_EXEC_PERM) ? 'e' : '-'),
170 ((mode & OSK_OTHER_WRITE_PERM) ? 'w' : '-'),
171 ((mode & OSK_OTHER_READ_PERM) ? 'r' : '-'),
172 ((mode & OSK_OWNER_EXEC_PERM) ? 'e' : '-'),
173 ((mode & OSK_OWNER_WRITE_PERM) ? 'w' : '-'),
174 ((mode & OSK_OWNER_READ_PERM) ? 'r' : '-'));
178 switch (hdr->extend_type) { /* max 18 characters */
212 #ifdef EXTEND_TOWNSOS
213 /* This ID isn't fixed */
221 /* Ouch! Please customize it's ID. */
226 printf("%-11.11s", p);
230 switch (hdr->extend_type) {
235 printf("%5.5s/", hdr->user);
237 printf("%5d/", hdr->unix_uid);
240 printf("%-5.5s ", hdr->group);
242 printf("%-5d ", hdr->unix_gid);
249 print_size(hdr->packed_size, hdr->original_size);
251 if (verbose_listing) {
253 printf(" %s %04x", method, hdr->crc);
255 printf(" %s ****", method);
259 print_stamp(hdr->unix_last_modified_stamp);
262 if ((hdr->unix_mode & UNIX_FILE_SYMLINK) != UNIX_FILE_SYMLINK)
263 printf(" %s", hdr->name);
265 printf(" %s -> %s", hdr->realname, hdr->name);
269 printf(" [%d]", hdr->header_level);
274 /* ------------------------------------------------------------------------ */
276 list_tailer(list_files, packed_size_total, original_size_total)
278 unsigned long packed_size_total, original_size_total;
284 printf(" Total %9d file%c ",
285 list_files, (list_files == 1) ? ' ' : 's');
286 print_size(packed_size_total, original_size_total);
292 if (stat(archive_name, &stbuf) < 0)
293 print_stamp((time_t) 0);
295 print_stamp(stbuf.st_mtime);
300 /* ------------------------------------------------------------------------ */
301 /* LIST COMMAND MAIN */
302 /* ------------------------------------------------------------------------ */
310 unsigned long packed_size_total;
311 unsigned long original_size_total;
314 /* initialize total count */
315 packed_size_total = 0L;
316 original_size_total = 0L;
319 /* open archive file */
320 if ((afp = open_old_archive()) == NULL) {
321 error("Cannot open archive \"%s\"", archive_name);
324 if (archive_is_msdos_sfx1(archive_name))
325 seek_lha_header(afp);
327 /* print header message */
331 /* print each file information */
332 while (get_header(afp, &hdr)) {
333 if (need_file(hdr.name)) {
336 packed_size_total += hdr.packed_size;
337 original_size_total += hdr.original_size;
341 fseeko(afp, hdr.packed_size, SEEK_CUR);
349 /* close archive file */
352 /* print tailer message */
354 list_tailer(list_files, packed_size_total, original_size_total);