6
static char *fieldcpy(char *dst, char *fld) {
7
while (*fld && *fld != ':')
11
while (isspace(*fld)) fld++;
12
return strcpy(dst, fld);
15
static void dopkgmirrorpkgs(int argc, char *argv[]) {
22
char cur_filename[1000];
25
if (argc != 4) return;
27
cur_pkg[0] = cur_ver[0] = cur_arch[0] = cur_filename[0] = '\0';
29
f = fopen(argv[3], "r");
34
while (fgets(buf, sizeof(buf), f)) {
35
if (*buf && buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
36
if (strncasecmp(buf, "Package:", 8) == 0) {
37
fieldcpy(cur_pkg, buf);
38
} else if (strncasecmp(buf, "Version:", 8) == 0) {
39
fieldcpy(cur_ver, buf);
40
} else if (strncasecmp(buf, "Architecture:", 13) == 0) {
41
fieldcpy(cur_arch, buf);
42
} else if (strncasecmp(buf, "Size:", 5) == 0) {
43
fieldcpy(cur_size, buf);
44
} else if (strncasecmp(buf, "MD5sum:", 7) == 0) {
45
fieldcpy(cur_md5, buf);
46
} else if (strncasecmp(buf, "Filename:", 9) == 0) {
47
fieldcpy(cur_filename, buf);
49
if (strcmp(cur_pkg, argv[1]) == 0) {
50
printf("%s %s %s %s %s %s %s\n", cur_pkg, cur_ver, cur_arch, argv[2], cur_filename, cur_md5, cur_size);
55
/* no output indicates not found */
59
static int dotranslatewgetpercent(int low, int high, int end, char *str) {
63
/* print out anything that looks like a % on its own line, appropriately
67
while ( (ch = getchar()) != EOF ) {
69
val *= 10; val += ch - '0';
70
} else if (ch == '%') {
71
float f = (float) val / 100.0 * (high - low) + low;
73
printf("P: %d %d %s\n", (int) f, end, str);
75
printf("P: %d %d\n", (int) f, end);
82
return lastval == 100;
85
int main(int argc, char *argv[]) {
87
dopkgmirrorpkgs(argc, argv);
89
} else if ((argc == 6 || argc == 5) && strcmp(argv[1], "WGET%") == 0) {
90
if (dotranslatewgetpercent(atoi(argv[2]), atoi(argv[3]),
91
atoi(argv[4]), argc == 6 ? argv[5] : NULL))
98
fprintf(stderr, "usage: %s pkg mirror packages_file\n", argv[0]);
99
fprintf(stderr, " or: %s WGET%% low high end reason\n", argv[0]);