• R/O
  • HTTP
  • SSH
  • HTTPS

olha: Commit


Commit MetaInfo

Révision1fda245771a2952d1333311c1d1db84e2c434651 (tree)
l'heure2008-08-25 22:16:49
AuteurKoji Arai <jca02266@gmai...>
CommiterKoji Arai

Message de Log

struct huf_t was discarded.
use function instead of PUTBUF() macro.

Change Summary

Modification

--- a/ar.h
+++ b/ar.h
@@ -37,8 +37,11 @@ struct lzh_istream {
3737
3838 uint8_t c_len[NC];
3939 uint16_t c_table[4096];
40+ uint16_t c_left[2 * NC - 1], c_right[2 * NC - 1];
41+
4042 uint8_t p_len[NP];
4143 uint16_t p_table[256];
44+ uint16_t p_left[2 * NP - 1], p_right[2 * NP - 1];
4245
4346 int np;
4447 int pbit;
@@ -132,13 +135,6 @@ extern struct lha_opts opts;
132135
133136 #define BITBUFSIZ (CHAR_BIT * sizeof(unsigned short)) /* size of bitbuf */
134137
135-/* huf.c */
136-
137-/* decoding */
138-struct huf_t {
139- ushort left[2 * NC - 1], right[2 * NC - 1];
140-};
141-
142138 /* utilities */
143139 #define MIN(a, b) (((a) > (b)) ? (b) : (a))
144140
--- a/decode.c
+++ b/decode.c
@@ -5,50 +5,61 @@
55
66 extern struct lha_opts opts;
77
8-#define PUTBUF(c) do { \
9- buf[pos++] = (c); \
10- if (pos == n) { \
11- fwrite_crc(buf, n, outfile, crc); \
12- if (outfile != stdout && opts.quiet < 1) { \
13- putc('.', stdout); \
14- } \
15- \
16- remainder -= n; \
17- if (remainder == 0) return; \
18- \
19- pos = 0; \
20- n = (size_t)MIN(remainder, MAXDICSIZ); \
21- } \
22-} while (0)
8+static off_t
9+put_decode_buf(char *buf, size_t size,
10+ uint32_t *pos, uint32_t c, size_t *limit,
11+ FILE *outfile, off_t remainder, uint16_t *crc)
12+{
13+ buf[(*pos)++] = c;
14+
15+ if (*pos == *limit) {
16+ fwrite_crc(buf, *limit, outfile, crc);
17+ if (outfile != stdout && opts.quiet < 1) {
18+ putc('.', stdout);
19+ }
20+
21+ remainder -= *limit;
22+ if (remainder == 0) return 0;
2323
24+ *pos = 0;
25+ *limit = (uint)MIN(remainder, size);
26+ return remainder;
27+ }
28+
29+ return remainder;
30+}
2431
2532 void
2633 decode(struct lzh_istream *rp, FILE *outfile, off_t remainder, uint16_t *crc)
2734 {
2835 char buf[MAXDICSIZ];
29- struct huf_t huf;
3036 uint32_t pos;
31- size_t n;
37+ size_t limit;
3238
3339 huf_decode_start(rp, opts.method);
3440
3541 pos = 0;
36- n = (size_t)MIN(remainder, MAXDICSIZ);
42+ limit = (size_t)MIN(remainder, MAXDICSIZ);
3743
3844 for (;;) {
39- uint16_t c = decode_c(&huf, rp);
45+ uint16_t c = decode_c(rp);
4046 if (c <= UCHAR_MAX) {
41- PUTBUF(c);
47+ remainder = put_decode_buf(buf, sizeof(buf), &pos, c, &limit,
48+ outfile, remainder, crc);
49+ if (remainder == 0) return;
4250 }
4351 else {
4452 uint32_t off;
4553 uint16_t len, i;
4654
4755 len = c - (UCHAR_MAX + 1 - THRESHOLD);
48- off = (pos - decode_p(&huf, rp) - 1) & (MAXDICSIZ - 1);
56+ off = (pos - decode_p(rp) - 1) & (MAXDICSIZ - 1);
4957
5058 for (i = 0; i < len; i++) {
51- PUTBUF(buf[off]);
59+ remainder = put_decode_buf(buf, sizeof(buf), &pos, buf[off],
60+ &limit,
61+ outfile, remainder, crc);
62+ if (remainder == 0) return;
5263 off = (off+1) & (MAXDICSIZ - 1);
5364 }
5465 }
--- a/huf.c
+++ b/huf.c
@@ -384,8 +384,9 @@ huf_encode_end(struct lzh_ostream *wp)
384384 /***** decoding *****/
385385
386386 static void
387-read_pt_len(struct huf_t *huf, struct lzh_istream *rp, int nn, int nbit,
388- int i_special, uint8_t *pt_len, uint16_t *pt_table)
387+read_pt_len(struct lzh_istream *rp, int nn, int nbit,
388+ int i_special, uint8_t *pt_len, uint16_t *pt_table,
389+ uint16_t *left, uint16_t *right)
389390 {
390391 int i, c, n;
391392 unsigned int mask;
@@ -419,12 +420,13 @@ read_pt_len(struct huf_t *huf, struct lzh_istream *rp, int nn, int nbit,
419420 }
420421 while (i < nn)
421422 pt_len[i++] = 0;
422- make_table(huf, nn, pt_len, 8, pt_table);
423+ make_table(nn, pt_len, 8, pt_table, left, right);
423424 }
424425 }
425426
426427 static void
427-read_c_len(struct huf_t *huf, struct lzh_istream *rp, uint8_t *t_len, uint16_t *t_table)
428+read_c_len(struct lzh_istream *rp, uint8_t *t_len, uint16_t *t_table,
429+ uint16_t *t_left, uint16_t *t_right)
428430 {
429431 int i, c, n;
430432 unsigned int mask;
@@ -445,9 +447,9 @@ read_c_len(struct huf_t *huf, struct lzh_istream *rp, uint8_t *t_len, uint16_t *
445447 mask = 1U << (BITBUFSIZ - 1 - 8);
446448 do {
447449 if (rp->bitbuf & mask)
448- c = huf->right[c];
450+ c = t_right[c];
449451 else
450- c = huf->left[c];
452+ c = t_left[c];
451453 mask >>= 1;
452454 } while (c >= NT);
453455 }
@@ -467,23 +469,25 @@ read_c_len(struct huf_t *huf, struct lzh_istream *rp, uint8_t *t_len, uint16_t *
467469 }
468470 while (i < NC)
469471 rp->c_len[i++] = 0;
470- make_table(huf, NC, rp->c_len, 12, rp->c_table);
472+ make_table(NC, rp->c_len, 12, rp->c_table, rp->c_left, rp->c_right);
471473 }
472474 }
473475
474476 uint16_t
475-decode_c(struct huf_t *huf, struct lzh_istream *rp)
477+decode_c(struct lzh_istream *rp)
476478 {
477479 uint16_t j, mask;
478480
479481 if (rp->blocksize == 0) {
480482 uint8_t t_len[NT];
481483 uint16_t t_table[256];
484+ uint16_t t_left[2*NT-1], t_right[2*NT-1];
482485
483486 rp->blocksize = getbits(rp, 16);
484- read_pt_len(huf, rp, NT, TBIT, 3, t_len, t_table);
485- read_c_len(huf, rp, t_len, t_table);
486- read_pt_len(huf, rp, rp->np, rp->pbit, -1, rp->p_len, rp->p_table);
487+ read_pt_len(rp, NT, TBIT, 3, t_len, t_table, t_left, t_right);
488+ read_c_len(rp, t_len, t_table, t_left, t_right);
489+ read_pt_len(rp, rp->np, rp->pbit, -1, rp->p_len, rp->p_table,
490+ rp->p_left, rp->p_right);
487491 }
488492 rp->blocksize--;
489493 j = rp->c_table[rp->bitbuf >> (BITBUFSIZ - 12)];
@@ -491,9 +495,9 @@ decode_c(struct huf_t *huf, struct lzh_istream *rp)
491495 mask = 1U << (BITBUFSIZ - 1 - 12);
492496 do {
493497 if (rp->bitbuf & mask)
494- j = huf->right[j];
498+ j = rp->c_right[j];
495499 else
496- j = huf->left[j];
500+ j = rp->c_left[j];
497501 mask >>= 1;
498502 } while (j >= NC);
499503 }
@@ -502,7 +506,7 @@ decode_c(struct huf_t *huf, struct lzh_istream *rp)
502506 }
503507
504508 uint16_t
505-decode_p(struct huf_t *huf, struct lzh_istream *rp)
509+decode_p(struct lzh_istream *rp)
506510 {
507511 uint16_t j, mask;
508512
@@ -511,9 +515,9 @@ decode_p(struct huf_t *huf, struct lzh_istream *rp)
511515 mask = 1U << (BITBUFSIZ - 1 - 8);
512516 do {
513517 if (rp->bitbuf & mask)
514- j = huf->right[j];
518+ j = rp->p_right[j];
515519 else
516- j = huf->left[j];
520+ j = rp->p_left[j];
517521 mask >>= 1;
518522 } while (j >= rp->np);
519523 }
--- a/list.c
+++ b/list.c
@@ -54,12 +54,18 @@ void
5454 list(struct lzh_header *h)
5555 {
5656 unsigned int r;
57+ char *fmt;
5758
5859 printf("%-14.*s", h->namelen, h->filename);
5960 if (h->namelen > 14)
6061 printf("\n ");
6162 r = ratio(h->compsize, h->origsize);
62- printf(" %-7s %10lu %10lu %u.%03u %04x %-6.5s [%d]\n",
63+ if (sizeof(off_t) == 8)
64+ fmt = " %-7s %10llu %10llu %u.%03u %04x %-6.5s [%d]\n";
65+ else
66+ fmt = " %-7s %10lu %10lu %u.%03u %04x %-6.5s [%d]\n";
67+
68+ printf(fmt,
6369 os_string(h->os_id),
6470 h->origsize,
6571 h->compsize,
--- a/maketbl.c
+++ b/maketbl.c
@@ -4,7 +4,8 @@
44 #include "ar.h"
55
66 void
7-make_table(struct huf_t *huf, int nchar, uint8_t *bitlen, int tablebits, uint16_t *table)
7+make_table(int nchar, uint8_t *bitlen, int tablebits, uint16_t *table,
8+ uint16_t *left, uint16_t *right)
89 {
910 uint16_t count[17], weight[17], start[18], *p;
1011 unsigned int i, k, len, ch, jutbits, avail, nextcode, mask; /* XXX variable type is vague */
@@ -53,13 +54,13 @@ make_table(struct huf_t *huf, int nchar, uint8_t *bitlen, int tablebits, uint16_
5354 i = len - tablebits;
5455 while (i != 0) {
5556 if (*p == 0) {
56- huf->right[avail] = huf->left[avail] = 0;
57+ right[avail] = left[avail] = 0;
5758 *p = avail++;
5859 }
5960 if (k & mask)
60- p = &huf->right[*p];
61+ p = &right[*p];
6162 else
62- p = &huf->left[*p];
63+ p = &left[*p];
6364 k <<= 1;
6465 i--;
6566 }
--- a/prototypes.h
+++ b/prototypes.h
@@ -28,13 +28,13 @@ void decode P_((struct lzh_istream *rp, FILE *outfile, off_t remainder, uint16_t
2828 /* maketree.c */
2929 int make_tree P_((uint16_t nparm, uint16_t *freqparm, uint8_t *lenparm, uint16_t *codeparm));
3030 /* maketbl.c */
31-void make_table P_((struct huf_t *huf, int nchar, uint8_t *bitlen, int tablebits, uint16_t *table));
31+void make_table P_((int nchar, uint8_t *bitlen, int tablebits, uint16_t *table, uint16_t *left, uint16_t *right));
3232 /* huf.c */
3333 void output P_((struct lzh_ostream *wp, uint16_t c, uint32_t p));
3434 void huf_encode_start P_((struct lzh_ostream *wp, struct lha_method *m));
3535 void huf_encode_end P_((struct lzh_ostream *wp));
36-uint16_t decode_c P_((struct huf_t *huf, struct lzh_istream *rp));
37-uint16_t decode_p P_((struct huf_t *huf, struct lzh_istream *rp));
36+uint16_t decode_c P_((struct lzh_istream *rp));
37+uint16_t decode_p P_((struct lzh_istream *rp));
3838 void huf_decode_start P_((struct lzh_istream *rp, struct lha_method *m));
3939 /* strlib.c */
4040 int string_equal P_((char *str1, char *str2));
Afficher sur ancien navigateur de dépôt.