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 /* ------------------------------------------------------------------------ */
18 static long packed_size_total;
19 static long original_size_total;
20 static int list_files;
22 /* ------------------------------------------------------------------------ */
24 /* ------------------------------------------------------------------------ */
25 /* need 14 or 22 (when verbose_listing is TRUE) column spaces */
27 print_size(packed_size, original_size)
28 long packed_size, original_size;
31 printf("%7d ", packed_size);
33 printf("%7d ", 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 boolean got_now = FALSE;
49 static unsigned int threshold;
50 static char t_month[12 * 3 + 1] = "JanFebMarAprMayJunJulAugSepOctNovDec";
54 printf(" "); /* 12 spaces */
59 now = time((time_t *) 0);
61 threshold = p->tm_year * 12 + p->tm_mon - 6;
67 if (p->tm_year * 12 + p->tm_mon > threshold)
68 printf("%.3s %2d %02d:%02d",
69 &t_month[p->tm_mon * 3], p->tm_mday, p->tm_hour, p->tm_min);
71 printf("%.3s %2d %04d",
72 &t_month[p->tm_mon * 3], p->tm_mday, p->tm_year + 1900);
75 /* ------------------------------------------------------------------------ */
80 /* 17+1+(0 or 7+1)+7+1+6+1+(0 or 1+4)+(12 or 17)+1+20 */
81 /* 12345678901234567_ 1234567_123456 _123456789012 1234 */
83 if (verbose_listing) {
84 p = "- ------ ---------- ";
89 q = " --------------------";
95 printf("---------- ----------- ------- ------%s------------%s\n", p, q);
98 /* ------------------------------------------------------------------------ */
100 /* ------------------------------------------------------------------------ */
106 if (verbose_listing) {
107 p = "PACKED SIZE RATIO METHOD CRC";
118 printf(" PERMSSN UID GID %s STAMP%s\n", p, q);
120 printf(" PERMSSN UID GID %s SIZE RATIO%s %s STAMP%s%s\n",
121 verbose_listing ? " PACKED " : "", /* 8,0 */
122 verbose_listing ? " CRC" : "", /* 5,0 */
123 verbose_listing ? " " : "", /* 2,0 */
124 verbose_listing ? " " : " ", /* 6,3 */
125 verbose ? "" : " NAME");
130 /* ------------------------------------------------------------------------ */
133 register LzHeader *hdr;
141 printf("%s\n", hdr->name);
143 strncpy(method, hdr->method, 5);
146 switch (mode = hdr->extend_type) {
148 mode = hdr->unix_mode;
150 if (mode & UNIX_FILE_DIRECTORY)
152 else if ((mode & UNIX_FILE_SYMLINK) == UNIX_FILE_SYMLINK)
156 modebits[1] = ((mode & UNIX_OWNER_READ_PERM) ? 'r' : '-');
157 modebits[2] = ((mode & UNIX_OWNER_WRITE_PERM) ? 'w' : '-');
158 modebits[3] = (mode & UNIX_SETUID) ? 's' :
159 ((mode & UNIX_OWNER_EXEC_PERM) ? 'x' : '-');
160 modebits[4] = ((mode & UNIX_GROUP_READ_PERM) ? 'r' : '-');
161 modebits[5] = ((mode & UNIX_GROUP_WRITE_PERM) ? 'w' : '-');
162 modebits[6] = (mode & UNIX_SETGID) ? 's' :
163 ((mode & UNIX_GROUP_EXEC_PERM) ? 'x' : '-');
164 modebits[7] = ((mode & UNIX_OTHER_READ_PERM) ? 'r' : '-');
165 modebits[8] = ((mode & UNIX_OTHER_WRITE_PERM) ? 'w' : '-');
166 modebits[9] = (mode & UNIX_STYCKYBIT) ? 't' :
167 ((mode & UNIX_OTHER_EXEC_PERM) ? 'x' : '-');
170 printf("%s %5d/%-5d ", modebits,
171 hdr->unix_uid, hdr->unix_gid);
174 /**/ case EXTEND_XOSK:/**/
175 mode = hdr->unix_mode;
176 printf("%c%c%c%c%c%c%c%c %5d/%-5d",
177 ((mode & OSK_DIRECTORY_PERM) ? 'd' : '-'),
178 ((mode & OSK_SHARED_PERM) ? 's' : '-'),
179 ((mode & OSK_OTHER_EXEC_PERM) ? 'e' : '-'),
180 ((mode & OSK_OTHER_WRITE_PERM) ? 'w' : '-'),
181 ((mode & OSK_OTHER_READ_PERM) ? 'r' : '-'),
182 ((mode & OSK_OWNER_EXEC_PERM) ? 'e' : '-'),
183 ((mode & OSK_OWNER_WRITE_PERM) ? 'w' : '-'),
184 ((mode & OSK_OWNER_READ_PERM) ? 'r' : '-'),
185 hdr->unix_uid, hdr->unix_gid);
188 switch (hdr->extend_type) { /* max 18 characters */
222 #ifdef EXTEND_TOWNSOS
223 /* This ID isn't fixed */
228 /* Ouch! Please customize it's ID. */
233 printf("%-23.23s", p);
237 print_size(hdr->packed_size, hdr->original_size);
241 printf(" %s %04x", method, hdr->crc);
243 printf(" %s ****", method);
246 print_stamp(hdr->unix_last_modified_stamp);
249 if ((mode & UNIX_FILE_SYMLINK) != UNIX_FILE_SYMLINK)
250 printf(" %s", hdr->name);
252 char buf[256], *b1, *b2;
253 strcpy(buf, hdr->name);
254 b1 = strtok(buf, "|");
255 b2 = strtok(NULL, "|");
256 printf(" %s -> %s", b1, b2);
260 printf(" [%d]", hdr->header_level);
265 /* ------------------------------------------------------------------------ */
273 printf(" Total %9d file%c ",
274 list_files, (list_files == 1) ? ' ' : 's');
275 print_size(packed_size_total, original_size_total);
281 if (stat(archive_name, &stbuf) < 0)
282 print_stamp((time_t) 0);
284 print_stamp(stbuf.st_mtime);
289 /* ------------------------------------------------------------------------ */
290 /* LIST COMMAND MAIN */
291 /* ------------------------------------------------------------------------ */
299 /* initialize total count */
300 packed_size_total = 0L;
301 original_size_total = 0L;
304 /* open archive file */
305 if ((afp = open_old_archive()) == NULL) {
306 error(archive_name, "");
309 if (archive_is_msdos_sfx1(archive_name))
310 skip_msdos_sfx1_code(afp);
312 /* print header message */
316 /* print each file information */
317 while (get_header(afp, &hdr)) {
318 if (need_file(hdr.name)) {
321 packed_size_total += hdr.packed_size;
322 original_size_total += hdr.original_size;
326 fseek(afp, hdr.packed_size, SEEK_CUR);
334 /* close archive file */
337 /* print tailer message */
344 /* Local Variables: */
347 /* compile-command:"gcc -c lhlist.c" */
349 /* vi: set tabstop=4: */