~dannf/ubuntu/trusty/base-installer/lp1247601

« back to all changes in this revision

Viewing changes to pkgdetails.c

  • Committer: Package Import Robot
  • Author(s): Colin Watson
  • Date: 2011-11-21 13:45:55 UTC
  • Revision ID: package-import@ubuntu.com-20111121134555-iur0mby9lyo66w8d
Tags: 1.122ubuntu1
* Resynchronise with Debian.  Remaining changes:
  - Use and depend on the Ubuntu keyring.
  - Enable the restricted component by default, unless
    apt-setup/restricted is preseeded to false.
  - Set up the default sources.list to look in -updates and -security (the
    latter from apt-setup/security_host and apt-setup/security_path) as
    well as the unadorned suite; also -proposed if apt-setup/proposed is
    true.
  - Use Ubuntu kernel image names.
  - Allow preseeding base-installer/kernel/override-image to force a given
    kernel to be used.
  - Install busybox-initramfs rather than busybox.
  - Revert Joey's patch to call base-installer.d hooks after running
    debootstrap, which broke console-setup's expectation of being able to
    insert its configuration file into /target before console-setup is
    installed by debootstrap.
  - Add armel/imx51, armel/dove, armel/omap, and armel/omap4
    subarchitectures.
  - Install kernel headers to match the kernel. This may be overridden by
    setting base-installer/kernel/headers to false.
  - Add base-installer/kernel/backports-modules template, which may be
    preseeded to install selected linux-backports-modules-* packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
#include <stdlib.h>
3
3
#include <string.h>
4
4
#include <ctype.h>
 
5
#include <stdarg.h>
 
6
#include <errno.h>
5
7
 
6
8
#define MAX_LINE 1000
7
9
#define MAX_PKGS 100
8
10
 
9
11
char *checksum_field=NULL;
10
12
 
 
13
static void oom_die(void)
 
14
{
 
15
    fprintf(stderr, "Out of memory!\n");
 
16
    exit(1);
 
17
}
 
18
 
 
19
static char *xvasprintf(const char *fmt, va_list ap) {
 
20
    char *ret;
 
21
 
 
22
    if (vasprintf (&ret, fmt, ap) < 0) {
 
23
        if (errno == ENOMEM)
 
24
            oom_die();
 
25
        return NULL;
 
26
    }
 
27
    return ret;
 
28
}
 
29
 
 
30
static char *xasprintf(const char *fmt, ...) {
 
31
    va_list ap;
 
32
    char *ret;
 
33
 
 
34
    va_start(ap, fmt);
 
35
    ret = xvasprintf(fmt, ap);
 
36
    va_end(ap);
 
37
    return ret;
 
38
}
 
39
 
11
40
static char *fieldcpy(char *dst, char *fld) {
12
41
    while (*fld && *fld != ':') 
13
42
        fld++;
17
46
    return strcpy(dst, fld);
18
47
}
19
48
 
 
49
static void outputdeps(char *deps) {
 
50
    char *pch = deps;
 
51
 
 
52
    while (1) {
 
53
        while (isspace(*pch)) pch++;
 
54
        if (!*pch) break;
 
55
 
 
56
        while (*pch && *pch != '(' && *pch != '|' && *pch != ','
 
57
               && !isspace(*pch))
 
58
        {
 
59
            fputc(*pch++, stdout);
 
60
        }
 
61
        fputc('\n', stdout);
 
62
        while (*pch && *pch++ != ',') (void)NULL;
 
63
    }
 
64
}
 
65
 
20
66
static void dogetdeps(char *pkgsfile, char **in_pkgs, int pkgc) {
21
67
    char buf[MAX_LINE];
22
68
    char cur_pkg[MAX_LINE];
23
69
    char cur_deps[MAX_LINE];
 
70
    char cur_predeps[MAX_LINE];
 
71
    char prev_pkg[MAX_LINE];
24
72
    char *pkgs[MAX_PKGS];
25
73
    int i;
26
74
    int skip;
27
75
    FILE *f;
 
76
    int output_pkg = -1;
28
77
 
29
 
    cur_pkg[0] = cur_deps[0] = '\0';
 
78
    cur_pkg[0] = cur_deps[0] = cur_predeps[0] = prev_pkg[0] = '\0';
30
79
 
31
80
    for (i = 0; i < pkgc; i++) pkgs[i] = in_pkgs[i];
32
81
 
43
92
            int any = 0;
44
93
            skip = 1;
45
94
            fieldcpy(cur_pkg, buf);
 
95
            if (strcmp(cur_pkg, prev_pkg) != 0) {
 
96
                if (output_pkg != -1)
 
97
                    pkgs[output_pkg] = NULL;
 
98
                if (cur_deps[0])
 
99
                    outputdeps(cur_deps);
 
100
                if (cur_predeps[0])
 
101
                    outputdeps(cur_predeps);
 
102
                strcpy(prev_pkg, cur_pkg);
 
103
            }
 
104
            cur_deps[0] = cur_predeps[0] = '\0';
 
105
            output_pkg = -1;
46
106
            for (i = 0; i < pkgc; i++) {
47
107
                if (!pkgs[i]) continue;
48
108
                any = 1;
49
109
                if (strcmp(cur_pkg, pkgs[i]) == 0) {
50
110
                    skip = 0;
51
 
                    pkgs[i] = NULL;
 
111
                    output_pkg = i;
52
112
                    break;
53
113
                }
54
114
            }
55
115
            if (!any) break;
56
 
        } else if (!skip && 
57
 
            (strncasecmp(buf, "Depends:", 8) == 0 || 
58
 
             strncasecmp(buf, "Pre-Depends:", 12) == 0)) 
59
 
        {
60
 
            char *pch;
 
116
        } else if (!skip && strncasecmp(buf, "Depends:", 8) == 0)
61
117
            fieldcpy(cur_deps, buf);
62
 
            pch = cur_deps;
63
 
            while (1) {
64
 
                while (isspace(*pch)) pch++;
65
 
                if (!*pch) break;
66
 
 
67
 
                while (*pch && *pch != '(' && *pch != '|' && *pch != ','
68
 
                       && !isspace(*pch))
69
 
                {
70
 
                    fputc(*pch++, stdout);
71
 
                }
72
 
                fputc('\n', stdout);
73
 
                while (*pch && *pch++ != ',') (void)NULL;
74
 
            }
75
 
        }
 
118
        else if (!skip && strncasecmp(buf, "Pre-Depends:", 12) == 0)
 
119
            fieldcpy(cur_predeps, buf);
76
120
    }
 
121
    if (cur_deps[0])
 
122
        outputdeps(cur_deps);
 
123
    if (cur_predeps[0])
 
124
        outputdeps(cur_predeps);
77
125
    fclose(f);
78
126
}
79
127
 
88
136
    char cur_size[MAX_LINE];
89
137
    char cur_checksum[MAX_LINE];
90
138
    char cur_filename[MAX_LINE];
 
139
    char prev_pkg[MAX_LINE];
91
140
    char *pkgs[MAX_PKGS];
92
141
    int i;
93
142
    FILE *f;
 
143
    char *output = NULL;
 
144
    int output_pkg = -1;
94
145
 
95
 
    cur_pkg[0] = cur_ver[0] = cur_arch[0] = cur_filename[0] = '\0';
 
146
    cur_field[0] = cur_pkg[0] = cur_ver[0] = cur_arch[0] = cur_filename[0] = prev_pkg[0] = '\0';
96
147
 
97
148
    for (i = 0; i < pkgc; i++) pkgs[i] = in_pkgs[i];
98
149
 
108
159
        }
109
160
        if (strncasecmp(buf, "Package:", 8) == 0) {
110
161
            fieldcpy(cur_pkg, buf);
 
162
            if (strcmp(cur_pkg, prev_pkg) != 0) {
 
163
                if (output)
 
164
                    fputs(output, stdout);
 
165
                if (uniq && output_pkg != -1)
 
166
                    pkgs[output_pkg] = NULL;
 
167
                strcpy(prev_pkg, cur_pkg);
 
168
            }
 
169
            free(output);
 
170
            output = NULL;
 
171
            output_pkg = -1;
111
172
        } else if (strncasecmp(buf, "Version:", 8) == 0) {
112
173
            fieldcpy(cur_ver, buf);
113
174
        } else if (strncasecmp(buf, "Architecture:", 13) == 0) {
125
186
                if (!pkgs[i]) continue;
126
187
                any = 1;
127
188
                if (strcmp(cur_field, pkgs[i]) == 0) {
128
 
                    printf("%s %s %s %s %s %s %s\n", cur_pkg, cur_ver, cur_arch, mirror, cur_filename, cur_checksum, cur_size);
129
 
                    if (uniq) pkgs[i] = NULL;
 
189
                    free(output);
 
190
                    output = xasprintf("%s %s %s %s %s %s %s\n", cur_pkg, cur_ver, cur_arch, mirror, cur_filename, cur_checksum, cur_size);
 
191
                    output_pkg = i;
130
192
                    break;
131
193
                }
132
194
            }
133
195
            if (!any) break;
 
196
            cur_field[0] = '\0';
134
197
        }
135
198
    }
 
199
    if (output)
 
200
        fputs(output, stdout);
 
201
    if (uniq && output_pkg != -1)
 
202
        pkgs[output_pkg] = NULL;
136
203
    fclose(f);
137
204
 
138
205
    /* any that weren't found are returned as "pkg -" */
145
212
    }
146
213
}
147
214
 
148
 
static void oom_die(void)
149
 
{
150
 
    fprintf(stderr, "Out of memory!\n");
151
 
    exit(1);
152
 
}
153
 
 
154
215
static void dopkgstanzas(char *pkgsfile, char **pkgs, int pkgc)
155
216
{
156
217
    char buf[MAX_LINE];