64
65
else if (!isatty(1))
67
70
if ((fd=open("/dev/tty",O_RDONLY))!=-1) {
68
if (ioctl(fd, TIOCGWINSZ, &ws)==-1)
71
if (ioctl(fd, TIOCGWINSZ, &ws) == 0)
77
list1package(struct pkginfo *pkg, bool *head, struct pkg_array *array)
87
list_format_init(struct list_format *fmt, struct pkg_array *array)
82
static char format[80] = "";
84
if (format[0] == '\0') {
88
for (i = 0; i < array->n_pkgs; i++) {
91
plen = strlen(array->pkgs[i]->name);
92
vlen = strlen(versiondescribe(&array->pkgs[i]->installed.version,
94
pkg_summary(array->pkgs[i], &dlen);
96
if (plen > nw) nw = plen;
97
if (vlen > vw) vw = vlen;
98
if (dlen > dw) dw = dlen;
102
if (w<0) w=0; /* lets not try to deal with terminals that are too small */
103
w>>=2; /* halve that so we can add that to the both the name and description */
104
nw=(14+w); /* name width */
105
vw=(14+w); /* version width */
106
dw=(44+(2*w)); /* description width */
91
if (fmt->format[0] != '\0')
102
for (i = 0; i < array->n_pkgs; i++) {
103
int plen, vlen, dlen;
105
plen = strlen(array->pkgs[i]->name);
106
vlen = strlen(versiondescribe(&array->pkgs[i]->installed.version,
108
pkg_summary(array->pkgs[i], &dlen);
108
sprintf(format,"%%c%%c%%c %%-%d.%ds %%-%d.%ds %%.*s\n", nw, nw, vw, vw);
119
/* Let's not try to deal with terminals that are too small. */
122
/* Halve that so we can add it to both the name and description. */
128
/* Description width. */
129
fmt->dw = (44 + (2 * w));
131
sprintf(fmt->format, "%%c%%c%%c %%-%d.%ds %%-%d.%ds %%.*s\n",
132
fmt->nw, fmt->nw, fmt->vw, fmt->vw);
136
list_format_print_header(struct list_format *fmt)
143
/* TRANSLATORS: This is the header that appears on 'dpkg-query -l'. The
144
* string should remain under 80 characters. The uppercase letters in
145
* the state values denote the abbreviated letter that will appear on
146
* the first three columns, which should ideally match the English one
147
* (e.g. Remove → supRimeix), see dpkg-query(1) for further details. The
148
* translated message can use additional lines if needed. */
113
150
Desired=Unknown/Install/Remove/Purge/Hold\n\
114
151
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend\n\
115
152
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)\n"), stdout);
116
printf(format,'|','|','/', _("Name"), _("Version"), 40, _("Description"));
117
printf("+++-"); /* status */
118
for (l=0;l<nw;l++) printf("="); printf("-"); /* packagename */
119
for (l=0;l<vw;l++) printf("="); printf("-"); /* version */
120
for (l=0;l<dw;l++) printf("="); /* description */
153
printf(fmt->format, '|', '|', '/', _("Name"), _("Version"), 40,
160
for (l = 0; l < fmt->nw; l++)
165
for (l = 0; l < fmt->vw; l++)
170
for (l = 0; l < fmt->dw; l++)
178
list1package(struct pkginfo *pkg, struct list_format *fmt, struct pkg_array *array)
183
list_format_init(fmt, array);
184
list_format_print_header(fmt);
125
186
pdesc = pkg_summary(pkg, &l);
129
190
"uihrp"[pkg->want],
130
191
"ncHUFWti"[pkg->status],
131
192
" R"[pkg->eflag],
141
202
struct pkginfo *pkg;
143
204
int failures = 0;
205
struct list_format fmt;
146
modstatdb_init(admindir,msdbrw_readonly);
208
modstatdb_open(msdbrw_readonly);
210
modstatdb_open(msdbrw_readonly | msdbrw_available_readonly);
148
212
pkg_array_init_from_db(&array);
149
213
pkg_array_sort(&array, pkg_sorter_by_name);
216
fmt.format[0] = '\0';
154
219
for (i = 0; i < array.n_pkgs; i++) {
155
220
pkg = array.pkgs[i];
156
221
if (pkg->status == stat_notinstalled) continue;
157
list1package(pkg, &head, &array);
222
list1package(pkg, &fmt, &array);
160
225
int argc, ip, *found;
239
304
int failures = 0;
240
305
struct varbuf path = VARBUF_INIT;
241
306
static struct varbuf vb;
244
309
badusage(_("--search needs at least one file name pattern argument"));
246
modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
311
modstatdb_open(msdbrw_readonly);
247
312
ensure_allinstfiles_available_quiet();
248
313
ensure_diversions();
250
315
while ((thisarg = *argv++) != NULL) {
253
/* Trim trailing slash and slash dot from the argument if it's
254
* not a pattern, just a path.
318
/* Trim trailing ‘/’ and ‘/.’ from the argument if it's
319
* not a pattern, just a path. */
256
320
if (!strpbrk(thisarg, "*[?\\")) {
258
varbufaddstr(&path, thisarg);
259
varbufaddc(&path, '\0');
322
varbuf_add_str(&path, thisarg);
323
varbuf_end_str(&path);
261
varbuf_trunc(&path, path_rtrim_slash_slashdot(path.buf));
325
varbuf_trunc(&path, path_trim_slash_slashdot(path.buf));
263
327
thisarg = path.buf;
266
330
if (!strchr("*[?/",*thisarg)) {
269
varbufaddstr(&vb,thisarg);
332
varbuf_add_char(&vb, '*');
333
varbuf_add_str(&vb, thisarg);
334
varbuf_add_char(&vb, '*');
274
338
if (!strpbrk(thisarg, "*[?\\")) {
305
370
struct pkginfo *pkg;
306
371
struct filenamenode *namenode;
307
372
int failures = 0;
310
375
badusage(_("--%s needs at least one package name argument"), cipaction->olong);
312
if (cipaction->arg==act_listfiles)
313
modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
315
modstatdb_init(admindir,msdbrw_readonly);
377
if (cipaction->arg_int == act_printavail)
378
modstatdb_open(msdbrw_readonly | msdbrw_available_readonly);
380
modstatdb_open(msdbrw_readonly);
317
382
while ((thisarg = *argv++) != NULL) {
318
pkg= findpackage(thisarg);
383
pkg = pkg_db_find(thisarg);
320
switch (cipaction->arg) {
385
switch (cipaction->arg_int) {
323
387
if (pkg->status == stat_notinstalled &&
324
388
pkg->priority == pri_unknown &&
325
389
!(pkg->section && *pkg->section) &&
327
391
pkg->want == want_unknown &&
328
!informative(pkg,&pkg->installed)) {
392
!pkg_is_informative(pkg, &pkg->installed)) {
329
393
fprintf(stderr,_("Package `%s' is not installed and no info is available.\n"),pkg->name);
332
396
writerecord(stdout, _("<standard output>"), pkg, &pkg->installed);
336
399
case act_printavail:
337
if (!informative(pkg,&pkg->available)) {
400
if (!pkg_is_informative(pkg, &pkg->available)) {
338
401
fprintf(stderr,_("Package `%s' is not available.\n"),pkg->name);
341
404
writerecord(stdout, _("<standard output>"), pkg, &pkg->available);
345
407
case act_listfiles:
346
408
switch (pkg->status) {
347
case stat_notinstalled:
409
case stat_notinstalled:
348
410
fprintf(stderr,_("Package `%s' is not installed.\n"),pkg->name);
353
414
ensure_packagefiles_available(pkg);
354
415
ensure_diversions();
528
pkg_infodb_print_filename(const char *filename, const char *filetype)
530
/* Do not expose internal database files. */
531
if (strcmp(filetype, LISTFILE) == 0 ||
532
strcmp(filetype, CONFFILESFILE) == 0)
535
if (strlen(filetype) > MAXCONTROLFILENAME)
538
printf("%s\n", filename);
465
542
control_path_file(struct pkginfo *pkg, const char *control_file)
467
544
const char *control_path;
470
/* Do not expose internal database files. */
471
if (strcmp(control_file, LISTFILE) == 0 ||
472
strcmp(control_file, CONFFILESFILE) == 0)
475
547
control_path = pkgadminfile(pkg, control_file);
477
548
if (stat(control_path, &st) < 0)
480
550
if (!S_ISREG(st.st_mode))
483
printf("%s\n", control_path);
487
control_path_pkg(struct pkginfo *pkg)
490
struct dirent *db_de;
491
struct varbuf db_path;
494
varbufinit(&db_path, 0);
495
varbufaddstr(&db_path, pkgadmindir());
496
db_path_len = db_path.used;
497
varbufaddc(&db_path, '\0');
499
db_dir = opendir(db_path.buf);
501
ohshite(_("cannot read info directory"));
503
push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)db_dir);
504
while ((db_de = readdir(db_dir)) != NULL) {
507
/* Ignore dotfiles, including ‘.’ and ‘..’. */
508
if (db_de->d_name[0] == '.')
511
/* Ignore anything odd. */
512
p = strrchr(db_de->d_name, '.');
516
/* Ignore files from other packages. */
517
if (strlen(pkg->name) != (size_t)(p - db_de->d_name) ||
518
strncmp(db_de->d_name, pkg->name, p - db_de->d_name))
521
/* Skip past the full stop. */
524
/* Do not expose internal database files. */
525
if (strcmp(p, LISTFILE) == 0 ||
526
strcmp(p, CONFFILESFILE) == 0)
529
if (strlen(p) > MAXCONTROLFILENAME)
532
varbuf_trunc(&db_path, db_path_len);
533
varbufaddstr(&db_path, db_de->d_name);
534
varbufaddc(&db_path, '\0');
536
printf("%s\n", db_path.buf);
538
pop_cleanup(ehflag_normaltidy); /* closedir */
540
varbuf_destroy(&db_path);
553
pkg_infodb_print_filename(control_path, control_file);
565
578
badusage(_("control file contains %c"), *c);
568
modstatdb_init(admindir, msdbrw_readonly | msdbrw_noavail);
581
modstatdb_open(msdbrw_readonly);
570
pkg = findpackage(pkg_name);
583
pkg = pkg_db_find(pkg_name);
571
584
if (pkg->status == stat_notinstalled)
572
badusage(_("Package `%s' is not installed.\n"), pkg->name);
585
ohshit(_("Package `%s' is not installed.\n"), pkg->name);
574
587
if (control_file)
575
588
control_path_file(pkg, control_file);
577
control_path_pkg(pkg);
590
pkg_infodb_foreach(pkg, pkg_infodb_print_filename);
579
592
modstatdb_shutdown();
642
655
const char thisname[]= "dpkg-query";
643
656
const char printforhelp[]= N_("Use --help for help about querying packages.");
645
const struct cmdinfo *cipaction = NULL;
647
const char *admindir= ADMINDIR;
649
static void setaction(const struct cmdinfo *cip, const char *value) {
651
badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"),
652
cip->oshort, cip->olong, cipaction->oshort, cipaction->olong);
658
static const char *admindir;
660
/* This table has both the action entries in it and the normal options.
661
* The action entries are made with the ACTION macro, as they all
662
* have a very similar structure. */
656
663
static const struct cmdinfo cmdinfos[]= {
657
/* This table has both the action entries in it and the normal options.
658
* The action entries are made with the ACTION macro, as they all
659
* have a very similar structure.
661
#define ACTION(longopt,shortopt,code,function) \
662
{ longopt, shortopt, 0, NULL, NULL, setaction, code, NULL, (voidfnp)function }
663
#define OBSOLETE(longopt,shortopt) \
664
{ longopt, shortopt, 0, NULL, NULL, setobsolete, 0, NULL, NULL }
666
664
ACTION( "listfiles", 'L', act_listfiles, enqperpackage ),
667
665
ACTION( "status", 's', act_status, enqperpackage ),
668
666
ACTION( "print-avail", 'p', act_printavail, enqperpackage ),
681
679
int main(int argc, const char *const *argv) {
683
int (*actionfunction)(const char *const *argv);
686
682
setlocale(LC_ALL, "");
687
683
bindtextdomain(PACKAGE, LOCALEDIR);
688
684
textdomain(PACKAGE);
690
standard_startup(&ejbuf);
691
687
myopt(&argv, cmdinfos);
689
admindir = dpkg_db_set_dir(admindir);
693
691
if (!cipaction) badusage(_("need an action option"));
695
693
setvbuf(stdout, NULL, _IONBF, 0);
698
actionfunction = (int (*)(const char *const *))cipaction->farg;
700
ret = actionfunction(argv);
696
ret = cipaction->action(argv);
702
698
standard_shutdown();