OSDN Git Service

* src/prototypes.h: updated.
[lha/lha.git] / src / indicator.c
1 /* ------------------------------------------------------------------------ */
2 /* LHa for UNIX                                                             */
3 /*              indicator.c -- put indicator                                */
4 /*                                                                          */
5 /*      Modified                Nobutaka Watazaki                           */
6 /*                                                                          */
7 /*  Ver. 1.14   Source All chagned              1995.01.14  N.Watazaki      */
8 /*              Separated from append.c         2003.07.21  Koji Arai       */
9 /* ------------------------------------------------------------------------ */
10 #include "lha.h"
11
12 #define MAX_INDICATOR_COUNT     64
13
14 static size_t reading_size;
15
16 #ifdef NEED_INCREMENTAL_INDICATOR
17 static size_t indicator_count;
18 static long indicator_threshold;
19 #endif
20
21 void
22 start_indicator(name, size, msg, def_indicator_threshold)
23     char           *name;
24     size_t          size;
25     char           *msg;
26     long            def_indicator_threshold;
27 {
28 #ifdef NEED_INCREMENTAL_INDICATOR
29     long i;
30     int m;
31 #endif
32
33     if (quiet)
34         return;
35
36 #ifdef NEED_INCREMENTAL_INDICATOR
37     switch (quiet_mode) {
38     case 0:
39         m = MAX_INDICATOR_COUNT - strlen(name);
40         if (m < 1)      /* Bug Fixed by N.Watazaki */
41             m = 3;      /* (^_^) */
42         printf("\r%s\t- %s :  ", name, msg);
43         indicator_threshold =
44             ((size + (m * def_indicator_threshold - 1)) /
45              (m * def_indicator_threshold) *
46              def_indicator_threshold);
47         if (indicator_threshold)
48             i = ((size + (indicator_threshold - 1)) / indicator_threshold);
49         else
50             i = 0;
51         while (i--)
52             putchar('.');
53         indicator_count = 0;
54         printf("\r%s\t- %s :  ", name, msg);
55         break;
56     case 1:
57         printf("\r%s :", name);
58         break;
59     }
60 #else
61     printf("%s\t- ", name);
62 #endif
63     fflush(stdout);
64     reading_size = 0L;
65 }
66
67 #ifdef NEED_INCREMENTAL_INDICATOR
68 void
69 put_indicator(count)
70     long int        count;
71 {
72     reading_size += count;
73     if (!quiet && indicator_threshold) {
74         while (reading_size > indicator_count) {
75             putchar('o');
76             fflush(stdout);
77             indicator_count += indicator_threshold;
78         }
79     }
80 }
81 #endif
82
83 void
84 finish_indicator2(name, msg, pcnt)
85     char           *name;
86     char           *msg;
87     int             pcnt;
88 {
89     if (quiet)
90         return;
91
92     if (pcnt > 100)
93         pcnt = 100; /* (^_^) */
94 #ifdef NEED_INCREMENTAL_INDICATOR
95     printf("\r%s\t- %s(%d%%)\n", name,  msg, pcnt);
96 #else
97     printf("%s\n", msg);
98 #endif
99     fflush(stdout);
100 }
101
102 void
103 finish_indicator(name, msg)
104     char           *name;
105     char           *msg;
106 {
107     if (quiet)
108         return;
109
110 #ifdef NEED_INCREMENTAL_INDICATOR
111     printf("\r%s\t- %s\n", name, msg);
112 #else
113     printf("%s\n", msg);
114 #endif
115     fflush(stdout);
116 }