OSDN Git Service

*** empty log message ***
[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 static long reading_size;
12
13 /* ------------------------------------------------------------------------ */
14 int
15 encode_lzhuf(infp, outfp, size, original_size_var, packed_size_var,
16              name, hdr_method)
17         FILE           *infp;
18         FILE           *outfp;
19         long            size;
20         long           *original_size_var;
21         long           *packed_size_var;
22         char           *name;
23         char           *hdr_method;
24 {
25         static int      method = -1;
26     unsigned int crc;
27
28         if (method < 0) {
29                 method = compress_method;
30                 if (method > 0)
31                         method = encode_alloc(method);
32         }
33
34         interface.method = method;
35
36         if (interface.method > 0) {
37                 interface.infile = infp;
38                 interface.outfile = outfp;
39                 interface.original = size;
40                 start_indicator(name, size, "Freezing", 1 << dicbit);
41                 crc = encode(&interface);
42                 *packed_size_var = interface.packed;
43                 *original_size_var = interface.original;
44         } else {
45                 copyfile(infp, outfp, size, 0, &crc);
46                 *packed_size_var = *original_size_var = size;
47         }
48         memcpy(hdr_method, "-lh -", 5);
49         hdr_method[3] = interface.method + '0';
50
51         finish_indicator2(name, "Frozen",
52                     (int) ((*packed_size_var * 100L) / *original_size_var));
53         return crc;
54 }
55 /* ------------------------------------------------------------------------ */
56 void
57 start_indicator(name, size, msg, def_indicator_threshold)
58         char           *name;
59         long            size;
60         char           *msg;
61         long            def_indicator_threshold;
62 {
63 #ifdef NEED_INCREMENTAL_INDICATOR
64         long            i;
65         int             m;
66 #endif
67
68         if (quiet)
69                 return;
70
71 #ifdef NEED_INCREMENTAL_INDICATOR
72         switch (quiet_mode) {
73         case 0:
74                 m = MAX_INDICATOR_COUNT - strlen(name);
75                 if (m < 1)              /* Bug Fixed by N.Watazaki */
76                         m = 3;          /* (^_^) */
77                 printf("\r%s\t- %s :  ", name, msg);
78                 indicator_threshold =
79                         ((size + (m * def_indicator_threshold - 1)) /
80                          (m * def_indicator_threshold) *
81                          def_indicator_threshold);
82                 if (indicator_threshold)
83                         i = ((size + (indicator_threshold - 1)) / indicator_threshold);
84                 else
85                         i = 0;
86                 while (i--)
87                         putchar('.');
88                 indicator_count = 0;
89                 printf("\r%s\t- %s :  ", name, msg);
90                 break;
91         case 1:
92                 printf("\r%s :", name);
93                 break;
94         }
95 #else
96         printf("%s\t- ", name);
97 #endif
98         fflush(stdout);
99         reading_size = 0L;
100 }
101 /* ------------------------------------------------------------------------ */
102 #ifdef NEED_INCREMENTAL_INDICATOR
103 void
104 put_indicator(count)
105         long int        count;
106 {
107     reading_size += count;
108         if (!quiet && indicator_threshold) {
109                 while (reading_size > indicator_count) {
110                         putchar('o');
111                         fflush(stdout);
112                         indicator_count += indicator_threshold;
113                 }
114         }
115 }
116 #endif
117
118 /* ------------------------------------------------------------------------ */
119 void
120 finish_indicator2(name, msg, pcnt)
121         char           *name;
122         char           *msg;
123         int             pcnt;
124 {
125         if (quiet)
126                 return;
127
128         if (pcnt > 100)
129                 pcnt = 100;     /* (^_^) */
130 #ifdef NEED_INCREMENTAL_INDICATOR
131         printf("\r%s\t- %s(%d%%)\n", name,  msg, pcnt);
132 #else
133         printf("%s\n", msg);
134 #endif
135         fflush(stdout);
136 }
137
138 /* ------------------------------------------------------------------------ */
139 void
140 finish_indicator(name, msg)
141         char           *name;
142         char           *msg;
143 {
144         if (quiet)
145                 return;
146
147 #ifdef NEED_INCREMENTAL_INDICATOR
148         printf("\r%s\t- %s\n", name, msg);
149 #else
150         printf("%s\n", msg);
151 #endif
152         fflush(stdout);
153 }
154 /* Local Variables: */
155 /* tab-width : 4 */
156 /* End: */
157 /* vi: set tabstop=4: */