-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindicator.c
141 lines (124 loc) · 3.27 KB
/
indicator.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* ------------------------------------------------------------------------ */
/* LHa for UNIX */
/* indicator.c -- put indicator */
/* */
/* Modified Nobutaka Watazaki */
/* */
/* Ver. 1.14 Source All chagned 1995.01.14 N.Watazaki */
/* Separated from append.c 2003.07.21 Koji Arai */
/* ------------------------------------------------------------------------ */
#include "lha.h"
#define MAX_INDICATOR_COUNT 58
static off_t reading_size;
#ifdef NEED_INCREMENTAL_INDICATOR
static off_t indicator_count;
static long indicator_threshold;
#endif
#define ALIGN(size, threshold) (((size) + ((threshold)-1))/(threshold))
static void
carriage_return()
{
static int tty = -1;
if (tty == -1) {
if (isatty(1)) /* stdout */
tty = 1;
else
tty = 0;
}
if (tty)
fputs("\r", stdout);
else
fputs("\n", stdout);
}
void
start_indicator(name, size, msg, def_indicator_threshold)
char *name;
off_t size;
char *msg;
long def_indicator_threshold;
{
#ifdef NEED_INCREMENTAL_INDICATOR
long i;
int m;
#endif
if (quiet)
return;
#ifdef NEED_INCREMENTAL_INDICATOR
switch (quiet_mode) {
case 0:
m = MAX_INDICATOR_COUNT - strlen(name);
if (m < 1) /* Bug Fixed by N.Watazaki */
m = 3; /* (^_^) */
carriage_return();
printf("%s\t- %s : ", name, msg);
indicator_threshold =
ALIGN(size, m*def_indicator_threshold) * def_indicator_threshold;
if (indicator_threshold)
i = ALIGN(size, indicator_threshold);
else
i = 0;
while (i--)
putchar('.');
indicator_count = 0;
carriage_return();
printf("%s\t- %s : ", name, msg);
break;
case 1:
carriage_return();
printf("%s :", name);
break;
}
#else
printf("%s\t- ", name);
#endif
fflush(stdout);
reading_size = 0L;
}
#ifdef NEED_INCREMENTAL_INDICATOR
void
put_indicator(count)
long int count;
{
reading_size += count;
if (!quiet && indicator_threshold) {
while (reading_size > indicator_count) {
putchar('o');
fflush(stdout);
indicator_count += indicator_threshold;
}
}
}
#endif
void
finish_indicator2(name, msg, pcnt)
char *name;
char *msg;
int pcnt;
{
if (quiet)
return;
if (pcnt > 100)
pcnt = 100; /* (^_^) */
#ifdef NEED_INCREMENTAL_INDICATOR
carriage_return();
printf("%s\t- %s(%d%%)\n", name, msg, pcnt);
#else
printf("%s\n", msg);
#endif
fflush(stdout);
}
void
finish_indicator(name, msg)
char *name;
char *msg;
{
if (quiet)
return;
#ifdef NEED_INCREMENTAL_INDICATOR
carriage_return();
printf("%s\t- %s\n", name, msg);
#else
printf("%s\n", msg);
#endif
fflush(stdout);
}