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(off_t packed_size, off_t original_size)
26 printf("%7llu ", packed_size);
28 printf("%7llu ", original_size);
31 printf("%7lu ", packed_size);
33 printf("%7lu ", original_size);
35 if (original_size == 0L)
37 else /* Changed N.Watazaki */
38 printf("%5.1f%%", packed_size * 100.0 / original_size);
41 /* ------------------------------------------------------------------------ */
42 /* need 12 or 17 (when verbose_listing is TRUE) column spaces */
47 static unsigned int threshold;
48 static char t_month[12 * 3 + 1] = "JanFebMarAprMayJunJulAugSepOctNovDec";
52 if (verbose_listing && verbose)
53 printf(" "); /* 19 spaces */
55 printf(" "); /* 12 spaces */
62 threshold = p->tm_year * 12 + p->tm_mon - 6;
67 if (verbose_listing && verbose)
68 printf("%04d-%02d-%02d %02d:%02d:%02d",
69 p->tm_year+1900, p->tm_mon+1, p->tm_mday,
70 p->tm_hour, p->tm_min, p->tm_sec);
71 else if (p->tm_year * 12 + p->tm_mon > threshold)
72 printf("%.3s %2d %02d:%02d",
73 &t_month[p->tm_mon * 3], p->tm_mday, p->tm_hour, p->tm_min);
75 printf("%.3s %2d %04d",
76 &t_month[p->tm_mon * 3], p->tm_mday, p->tm_year + 1900);
79 /* ------------------------------------------------------------------------ */
83 if (verbose_listing) {
85 /* PERMISSION UID GID PACKED SIZE RATIO METHOD CRC STAMP LV */
86 printf("---------- ----------- ------- ------- ------ ---------- ------------------- ---\n");
88 /* PERMISSION UID GID PACKED SIZE RATIO METHOD CRC STAMP NAME */
89 printf("---------- ----------- ------- ------- ------ ---------- ------------ ----------\n");
93 /* PERMISSION UID GID SIZE RATIO STAMP LV */
94 printf("---------- ----------- ------- ------ ------------ ---\n");
96 /* PERMISSION UID GID SIZE RATIO STAMP NAME */
97 printf("---------- ----------- ------- ------ ------------ --------------------\n");
101 /* ------------------------------------------------------------------------ */
103 /* ------------------------------------------------------------------------ */
107 if (verbose_listing) {
109 printf("PERMISSION UID GID PACKED SIZE RATIO METHOD CRC STAMP LV\n");
111 printf("PERMISSION UID GID PACKED SIZE RATIO METHOD CRC STAMP NAME\n");
115 printf("PERMISSION UID GID SIZE RATIO STAMP LV\n");
117 printf("PERMISSION UID GID SIZE RATIO STAMP NAME\n");
122 /* ------------------------------------------------------------------------ */
125 register LzHeader *hdr;
127 register int mode = 0;
133 if ((hdr->unix_mode & UNIX_FILE_SYMLINK) != UNIX_FILE_SYMLINK)
134 printf("%s\n", hdr->name);
136 printf("%s -> %s\n", hdr->name, hdr->realname);
139 strncpy(method, hdr->method, 5);
142 switch (hdr->extend_type) {
144 mode = hdr->unix_mode;
146 if (mode & UNIX_FILE_DIRECTORY)
148 else if ((mode & UNIX_FILE_SYMLINK) == UNIX_FILE_SYMLINK)
152 modebits[1] = ((mode & UNIX_OWNER_READ_PERM) ? 'r' : '-');
153 modebits[2] = ((mode & UNIX_OWNER_WRITE_PERM) ? 'w' : '-');
154 modebits[3] = (mode & UNIX_SETUID) ? 's' :
155 ((mode & UNIX_OWNER_EXEC_PERM) ? 'x' : '-');
156 modebits[4] = ((mode & UNIX_GROUP_READ_PERM) ? 'r' : '-');
157 modebits[5] = ((mode & UNIX_GROUP_WRITE_PERM) ? 'w' : '-');
158 modebits[6] = (mode & UNIX_SETGID) ? 's' :
159 ((mode & UNIX_GROUP_EXEC_PERM) ? 'x' : '-');
160 modebits[7] = ((mode & UNIX_OTHER_READ_PERM) ? 'r' : '-');
161 modebits[8] = ((mode & UNIX_OTHER_WRITE_PERM) ? 'w' : '-');
162 modebits[9] = (mode & UNIX_STICKYBIT) ? 't' :
163 ((mode & UNIX_OTHER_EXEC_PERM) ? 'x' : '-');
166 printf("%s ", modebits);
169 /**/ case EXTEND_XOSK:/**/
170 mode = hdr->unix_mode;
171 printf("%c%c%c%c%c%c%c%c ",
172 ((mode & OSK_DIRECTORY_PERM) ? 'd' : '-'),
173 ((mode & OSK_SHARED_PERM) ? 's' : '-'),
174 ((mode & OSK_OTHER_EXEC_PERM) ? 'e' : '-'),
175 ((mode & OSK_OTHER_WRITE_PERM) ? 'w' : '-'),
176 ((mode & OSK_OTHER_READ_PERM) ? 'r' : '-'),
177 ((mode & OSK_OWNER_EXEC_PERM) ? 'e' : '-'),
178 ((mode & OSK_OWNER_WRITE_PERM) ? 'w' : '-'),
179 ((mode & OSK_OWNER_READ_PERM) ? 'r' : '-'));
183 switch (hdr->extend_type) { /* max 18 characters */
217 #ifdef EXTEND_TOWNSOS
218 /* This ID isn't fixed */
226 /* Ouch! Please customize it's ID. */
231 printf("%-11.11s", p);
235 switch (hdr->extend_type) {
240 printf("%5.5s/", hdr->user);
242 printf("%5d/", hdr->unix_uid);
245 printf("%-5.5s ", hdr->group);
247 printf("%-5d ", hdr->unix_gid);
254 print_size(hdr->packed_size, hdr->original_size);
256 if (verbose_listing) {
258 printf(" %s %04x", method, hdr->crc);
260 printf(" %s ****", method);
264 print_stamp(hdr->unix_last_modified_stamp);
267 if ((hdr->unix_mode & UNIX_FILE_SYMLINK) != UNIX_FILE_SYMLINK)
268 printf(" %s", hdr->name);
270 printf(" %s -> %s", hdr->name, hdr->realname);
274 printf(" [%d]", hdr->header_level);
279 /* ------------------------------------------------------------------------ */
281 list_tailer(list_files, packed_size_total, original_size_total)
283 off_t packed_size_total, original_size_total;
289 printf(" Total %9d file%c ",
290 list_files, (list_files == 1) ? ' ' : 's');
291 print_size(packed_size_total, original_size_total);
297 if (stat(archive_name, &stbuf) < 0)
298 print_stamp((time_t) 0);
300 print_stamp(stbuf.st_mtime);
305 /* ------------------------------------------------------------------------ */
306 /* LIST COMMAND MAIN */
307 /* ------------------------------------------------------------------------ */
315 off_t packed_size_total;
316 off_t original_size_total;
319 /* initialize total count */
320 packed_size_total = 0L;
321 original_size_total = 0L;
324 /* open archive file */
325 if ((afp = open_old_archive()) == NULL) {
326 error("Cannot open archive \"%s\"", archive_name);
329 if (archive_is_msdos_sfx1(archive_name))
330 seek_lha_header(afp);
332 /* print header message */
336 /* print each file information */
337 while (get_header(afp, &hdr)) {
338 if (need_file(hdr.name)) {
341 packed_size_total += hdr.packed_size;
342 original_size_total += hdr.original_size;
346 fseeko(afp, hdr.packed_size, SEEK_CUR);
354 /* close archive file */
357 /* print tailer message */
359 list_tailer(list_files, packed_size_total, original_size_total);