OSDN Git Service

added add.c extract.c list.c
[lha/olha.git] / list.c
1 #include "ar.h"
2
3 void
4 list_start(void)
5 {
6     if (opts.quiet < 2)
7         printf("%-14.14s %-7.7s %10.10s %10.10s %-5.5s %-4.4s %-5.5s %-4.4s\n",
8                "Filename",
9                "OS",
10                "Original",
11                "Compressed",
12                "Ratio",
13                "CRC",
14                "Method",
15                "Lv");
16 }
17
18 static char*
19 os_string(char id)
20 {
21     int i;
22     static struct os {
23         char id;
24         char *name;
25     } os_types[] = {
26         {'M',  "MS-DOS"},       /* Microsoft */
27         {'U',  "Unix"},         /* Unix or POSIX compliant OS */
28         {'J',  "Java"},         /* Sun Microsystems */
29         {'\0', "generic"},
30         {'w',  "Win9x"},        /* reserved by UNLHA32.DLL */
31         {'W',  "WinNT"},        /* reserved by UNLHA32.DLL */
32         {'2',  "OS/2"},         /* IBM OS/2 */
33         {'9',  "OS9"},          /* unknown */
34         {'K',  "OS/68K"},       /* unknown */
35         {'3',  "OS/386"},       /* unknown */
36         {'H',  "Human"},        /* SHARP Human68K */
37         {'C',  "CP/M"},         /* Digital Research */
38         {'F',  "FLEX"},         /* unknown */
39         {'m',  "Mac"},          /* Apple */
40         {'R',  "Runser"},       /* unknown */
41         {'T',  "TownsOS"},      /* Fujitsu FM-TOWNS */
42         {'X',  "XOSK"},         /* unknown */
43     };
44
45     for (i = 0; i < sizeof(os_types)/sizeof(os_types[0]); i++) {
46         if (id == os_types[i].id)
47             return os_types[i].name;
48     }
49
50     return "Unknown";
51 }
52
53 void
54 list(struct lzh_header *h)
55 {
56     uint r;
57
58     printf("%-14.*s", h->namelen, h->filename);
59     if (h->namelen > 14)
60         printf("\n              ");
61     r = ratio(h->compsize, h->origsize);
62     printf(" %-7s %10lu %10lu %u.%03u %04x %-6.6s [%d]\n",
63            os_string(h->os_id),
64            h->origsize,
65            h->compsize,
66            r / 1000,
67            r % 1000,
68            h->file_crc,
69            h->method,
70            h->level);
71 }