OSDN Git Service

use the autoconf/automake
[lha/lha.git] / src / append.c
1 /* ------------------------------------------------------------------------ */
2 /* LHa for UNIX                                                                                                                         */
3 /*                              append.c -- append to archive                                                           */
4 /*                                                                                                                                                      */
5 /*              Modified                        Nobutaka Watazaki                                                       */
6 /*                                                                                                                                                      */
7 /*      Ver. 1.14       Source All chagned                              1995.01.14      N.Watazaki              */
8 /* ------------------------------------------------------------------------ */
9 #include "lha.h"
10
11 /* ------------------------------------------------------------------------ */
12 int
13 encode_lzhuf(infp, outfp, size, original_size_var, packed_size_var,
14              name, hdr_method)
15         FILE           *infp;
16         FILE           *outfp;
17         long            size;
18         long           *original_size_var;
19         long           *packed_size_var;
20         char           *name;
21         char           *hdr_method;
22 {
23         static int      method = -1;
24
25         if (method < 0) {
26                 method = compress_method;
27                 if (method > 0)
28                         method = encode_alloc(method);
29         }
30
31         interface.method = method;
32
33         if (interface.method > 0) {
34                 interface.infile = infp;
35                 interface.outfile = outfp;
36                 interface.original = size;
37                 start_indicator(name, size, "Freezing", 1 << dicbit);
38                 encode(&interface);
39                 *packed_size_var = interface.packed;
40                 *original_size_var = interface.original;
41         } else {
42                 copyfile(infp, outfp, size, 1);
43                 *packed_size_var = *original_size_var = size;
44         }
45         bcopy("-lh -", hdr_method, 5);
46         hdr_method[3] = interface.method + '0';
47
48         finish_indicator2(name, "Frozen",
49                     (int) ((*packed_size_var * 100L) / *original_size_var));
50         return crc;
51 }
52 /* ------------------------------------------------------------------------ */
53 void
54 start_indicator(name, size, msg, def_indicator_threshold)
55         char           *name;
56         long            size;
57         char           *msg;
58         long            def_indicator_threshold;
59 {
60 #ifdef NEED_INCREMENTAL_INDICATOR
61         long            i;
62         int             m;
63 #endif
64
65         if (quiet)
66                 return;
67
68 #ifdef NEED_INCREMENTAL_INDICATOR
69         switch (quiet_mode) {
70         case 0:
71                 m = MAX_INDICATOR_COUNT - strlen(name);
72                 if (m < 1)              /* Bug Fixed by N.Watazaki */
73                         m = 3;          /* (^_^) */
74                 printf("\r%s\t- %s :  ", name, msg);
75                 indicator_threshold =
76                         ((size + (m * def_indicator_threshold - 1)) /
77                          (m * def_indicator_threshold) *
78                          def_indicator_threshold);
79                 if (indicator_threshold)
80                         i = ((size + (indicator_threshold - 1)) / indicator_threshold);
81                 else
82                         i = 0;
83                 while (i--)
84                         putchar('.');
85                 indicator_count = 0;
86                 printf("\r%s\t- %s :  ", name, msg);
87                 break;
88         case 1:
89                 printf("\r%s :", name);
90                 break;
91         }
92 #else
93         printf("%s\t- ", name);
94 #endif
95         fflush(stdout);
96         reading_size = 0L;
97 }
98 /* ------------------------------------------------------------------------ */
99 void
100 finish_indicator2(name, msg, pcnt)
101         char           *name;
102         char           *msg;
103         int             pcnt;
104 {
105         if (quiet)
106                 return;
107
108         if (pcnt > 100)
109                 pcnt = 100;     /* (^_^) */
110 #ifdef NEED_INCREMENTAL_INDICATOR
111         printf("\r%s\t- %s(%d%%)\n", name,  msg, pcnt);
112 #else
113         printf("%s\n", msg);
114 #endif
115         fflush(stdout);
116 }
117 /* ------------------------------------------------------------------------ */
118 void
119 finish_indicator(name, msg)
120         char           *name;
121         char           *msg;
122 {
123         if (quiet)
124                 return;
125
126 #ifdef NEED_INCREMENTAL_INDICATOR
127         printf("\r%s\t- %s\n", name, msg);
128 #else
129         printf("%s\n", msg);
130 #endif
131         fflush(stdout);
132 }
133 /* Local Variables: */
134 /* tab-width : 4 */
135 /* End: */