-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathprogress.c
162 lines (133 loc) · 2.83 KB
/
progress.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#include "config.h"
#include <sys/types.h>
#include <sys/param.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include "argcargv.h"
#include "code.h"
#include "largefile.h"
#include "progress.h"
int progress = -1;
int showprogress = 0;
off_t lsize = 0, total = 0;
void
linecheck( char *line, int ac, int linenum )
{
if ( ac < 8 ) {
if ( line[ strlen( line ) - 1 ] == '\n' ) {
line[ strlen( line ) - 1 ] = '\0';
}
fprintf( stderr, "%s: line %d: invalid transcript line\n",
line, linenum );
exit( 2 );
}
}
off_t
loadsetsize( FILE *tran )
{
char tline[ LINE_MAX ], line[ LINE_MAX ];
char **targv;
int tac, linenum = 0;
off_t size = 0;
while ( fgets( tline, LINE_MAX, tran ) != NULL ) {
linenum++;
strcpy( line, tline );
if (( tac = argcargv( tline, &targv )) == 0 ) {
continue;
}
switch ( *targv[ 0 ] ) {
case 'a':
case 'f':
break;
default:
continue;
}
linecheck( line, tac, linenum );
size += strtoofft( targv[ 6 ], NULL, 10 );
}
rewind( tran );
return( size );
}
off_t
applyloadsetsize( FILE *tran )
{
char tline[ LINE_MAX ], line[ LINE_MAX ];
char **targv;
int tac, linenum = 0;
off_t size = 0;
while ( fgets( tline, LINE_MAX, tran ) != NULL ) {
linenum++;
strcpy( line, tline );
/* skip empty lines and transcript marker lines */
if (( tac = argcargv( tline, &targv )) <= 1 ) {
continue;
}
switch ( *targv[ 0 ] ) {
case '+':
switch ( *targv[ 1 ] ) {
case 'a':
case 'f':
linecheck( line, tac, linenum );
size += strtoofft( targv[ 7 ], NULL, 10 );
default:
break;
}
default:
break;
}
size += PROGRESSUNIT;
}
rewind( tran );
return( size );
}
off_t
lcksum_loadsetsize( FILE *tran, char *prefix )
{
char tline[ LINE_MAX ], line[ LINE_MAX ];
char *d_path = NULL;
char **targv;
int tac, linenum = 0;
off_t size = 0;
while ( fgets( tline, LINE_MAX, tran ) != NULL ) {
linenum++;
strcpy( line, tline );
if (( tac = argcargv( tline, &targv )) <= 1 ) {
continue;
}
if ( prefix != NULL ) {
if (( d_path = decode( targv[ 1 ] )) == NULL ) {
fprintf( stderr, "%d: path too long\n", linenum );
exit( 2 );
}
if ( strncmp( d_path, prefix, strlen( prefix )) != 0 ) {
continue;
}
}
switch ( *targv[ 0 ] ) {
case 'a':
case 'f':
linecheck( line, tac, linenum );
size += strtoofft( targv[ 6 ], NULL, 10 );
default:
size += PROGRESSUNIT;
break;
}
}
rewind( tran );
return( size );
}
void
progressupdate( ssize_t bytes, char *path )
{
int last = progress;
if ( bytes < 0 ) {
return;
}
total += bytes;
progress = ( int )((( float )total / ( float )lsize ) * 100 );
if ( progress > last ) {
printf( "%%%.2d %s\n", progress, path );
}
}