~ubuntu-branches/ubuntu/oneiric/debootstrap/oneiric

« back to all changes in this revision

Viewing changes to pkgdetails.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2005-02-25 22:23:30 UTC
  • Revision ID: james.westby@ubuntu.com-20050225222330-dunyf2rhdn7nouyr
Tags: 0.2.45-0.2
* Non-maintainer upload.
* [sarge, sid] Replace libparted1.6-0 with libparted1.6-12 for ia64,
  to keep up with the ABI changes for that package. (Closes: #295571)
* [sarge, sid] include pciutils on hppa as well, per request of the
  hppa folks. (Closes: #283752)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <stdlib.h>
 
3
#include <string.h>
 
4
#include <ctype.h>
 
5
 
 
6
static char *fieldcpy(char *dst, char *fld) {
 
7
    while (*fld && *fld != ':') 
 
8
        fld++;
 
9
    if (!*(fld++)) 
 
10
        return NULL;
 
11
    while (isspace(*fld)) fld++;
 
12
    return strcpy(dst, fld);
 
13
}
 
14
 
 
15
static void dopkgmirrorpkgs(int argc, char *argv[]) {
 
16
    char buf[1000];
 
17
    char cur_pkg[1000];
 
18
    char cur_ver[1000];
 
19
    char cur_arch[1000];
 
20
    char cur_size[1000];
 
21
    char cur_md5[1000];
 
22
    char cur_filename[1000];
 
23
    FILE *f;
 
24
 
 
25
    if (argc != 4) return;
 
26
 
 
27
    cur_pkg[0] = cur_ver[0] = cur_arch[0] = cur_filename[0] = '\0';
 
28
 
 
29
    f = fopen(argv[3], "r");
 
30
    if (f == NULL) {
 
31
        perror(argv[3]);
 
32
        exit(1);
 
33
    }
 
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);
 
48
        } else if (!*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);
 
51
                exit(0);
 
52
            }
 
53
        }
 
54
    }
 
55
    /* no output indicates not found */
 
56
    exit(0);
 
57
}
 
58
 
 
59
static int dotranslatewgetpercent(int low, int high, int end, char *str) {
 
60
    int ch;
 
61
    int val, lastval;
 
62
 
 
63
    /* print out anything that looks like a % on its own line, appropriately
 
64
     * scaled */
 
65
 
 
66
    lastval = val = 0;
 
67
    while ( (ch = getchar()) != EOF ) {
 
68
        if (isdigit(ch)) {
 
69
            val *= 10; val += ch - '0';
 
70
        } else if (ch == '%') {
 
71
            float f = (float) val / 100.0 * (high - low) + low;
 
72
            if (str) {
 
73
                printf("P: %d %d %s\n", (int) f, end, str);
 
74
            } else {
 
75
                printf("P: %d %d\n", (int) f, end);
 
76
            }
 
77
            lastval = val;
 
78
        } else {
 
79
            val = 0;
 
80
        }
 
81
    }
 
82
    return lastval == 100;
 
83
}
 
84
 
 
85
int main(int argc, char *argv[]) {
 
86
    if (argc == 4) {
 
87
        dopkgmirrorpkgs(argc, argv);
 
88
        exit(0);
 
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))
 
92
        {
 
93
            exit(0);
 
94
        } else {
 
95
            exit(1);
 
96
        }
 
97
    } else {
 
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]);
 
100
        exit(1);
 
101
    }
 
102
}