query.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. /*
  2. * dpkg-query - program for query the dpkg database
  3. * query.c - status enquiry and listing options
  4. *
  5. * Copyright © 1995,1996 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2000,2001 Wichert Akkerman <wakkerma@debian.org>
  7. * Copyright © 2006-2009 Guillem Jover <guillem@debian.org>
  8. *
  9. * This is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #include <config.h>
  23. #include <compat.h>
  24. #include <sys/types.h>
  25. #include <sys/stat.h>
  26. #include <sys/ioctl.h>
  27. #include <sys/termios.h>
  28. #if HAVE_LOCALE_H
  29. #include <locale.h>
  30. #endif
  31. #include <string.h>
  32. #include <fcntl.h>
  33. #include <dirent.h>
  34. #include <fnmatch.h>
  35. #include <unistd.h>
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <dpkg/i18n.h>
  39. #include <dpkg/dpkg.h>
  40. #include <dpkg/dpkg-db.h>
  41. #include <dpkg/pkg-array.h>
  42. #include <dpkg/pkg-format.h>
  43. #include <dpkg/pkg-show.h>
  44. #include <dpkg/path.h>
  45. #include <dpkg/myopt.h>
  46. #include "filesdb.h"
  47. #include "main.h"
  48. static const char* showformat = "${Package}\t${Version}\n";
  49. static int getwidth(void) {
  50. int fd;
  51. int res;
  52. struct winsize ws;
  53. const char* columns;
  54. if ((columns=getenv("COLUMNS")) && ((res=atoi(columns))>0))
  55. return res;
  56. else if (!isatty(1))
  57. return -1;
  58. else {
  59. if ((fd=open("/dev/tty",O_RDONLY))!=-1) {
  60. if (ioctl(fd, TIOCGWINSZ, &ws)==-1)
  61. ws.ws_col=80;
  62. close(fd);
  63. }
  64. return ws.ws_col;
  65. }
  66. }
  67. static void
  68. list1package(struct pkginfo *pkg, bool *head, struct pkg_array *array)
  69. {
  70. int i,l,w;
  71. static int nw,vw,dw;
  72. const char *pdesc;
  73. static char format[80] = "";
  74. if (format[0] == '\0') {
  75. w=getwidth();
  76. if (w == -1) {
  77. nw=14, vw=14, dw=44;
  78. for (i = 0; i < array->n_pkgs; i++) {
  79. const char *pdesc;
  80. int plen, vlen, dlen;
  81. pdesc = pkg->installed.description;
  82. if (!pdesc) pdesc= _("(no description available)");
  83. plen = strlen(array->pkgs[i]->name);
  84. vlen = strlen(versiondescribe(&array->pkgs[i]->installed.version,
  85. vdew_nonambig));
  86. dlen= strcspn(pdesc, "\n");
  87. if (plen > nw) nw = plen;
  88. if (vlen > vw) vw = vlen;
  89. if (dlen > dw) dw = dlen;
  90. }
  91. } else {
  92. w-=80;
  93. if (w<0) w=0; /* lets not try to deal with terminals that are too small */
  94. w>>=2; /* halve that so we can add that to the both the name and description */
  95. nw=(14+w); /* name width */
  96. vw=(14+w); /* version width */
  97. dw=(44+(2*w)); /* description width */
  98. }
  99. sprintf(format,"%%c%%c%%c %%-%d.%ds %%-%d.%ds %%.*s\n", nw, nw, vw, vw);
  100. }
  101. if (!*head) {
  102. fputs(_("\
  103. Desired=Unknown/Install/Remove/Purge/Hold\n\
  104. | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend\n\
  105. |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)\n"), stdout);
  106. printf(format,'|','|','/', _("Name"), _("Version"), 40, _("Description"));
  107. printf("+++-"); /* status */
  108. for (l=0;l<nw;l++) printf("="); printf("-"); /* packagename */
  109. for (l=0;l<vw;l++) printf("="); printf("-"); /* version */
  110. for (l=0;l<dw;l++) printf("="); /* description */
  111. printf("\n");
  112. *head = true;
  113. }
  114. pkg_summary(pkg, &pdesc, &l);
  115. l = min(l, dw);
  116. printf(format,
  117. "uihrp"[pkg->want],
  118. "ncHUFWti"[pkg->status],
  119. " R"[pkg->eflag],
  120. pkg->name,
  121. versiondescribe(&pkg->installed.version, vdew_nonambig),
  122. l, pdesc);
  123. }
  124. static int
  125. listpackages(const char *const *argv)
  126. {
  127. struct pkg_array array;
  128. struct pkginfo *pkg;
  129. int i;
  130. int failures = 0;
  131. bool head;
  132. modstatdb_init(admindir,msdbrw_readonly);
  133. pkg_array_init_from_db(&array);
  134. pkg_array_sort(&array, pkg_sorter_by_name);
  135. head = false;
  136. if (!*argv) {
  137. for (i = 0; i < array.n_pkgs; i++) {
  138. pkg = array.pkgs[i];
  139. if (pkg->status == stat_notinstalled) continue;
  140. list1package(pkg, &head, &array);
  141. }
  142. } else {
  143. int argc, ip, *found;
  144. for (argc = 0; argv[argc]; argc++);
  145. found = m_malloc(sizeof(int) * argc);
  146. memset(found, 0, sizeof(int) * argc);
  147. for (i = 0; i < array.n_pkgs; i++) {
  148. pkg = array.pkgs[i];
  149. for (ip = 0; ip < argc; ip++) {
  150. if (!fnmatch(argv[ip], pkg->name, 0)) {
  151. list1package(pkg, &head, &array);
  152. found[ip]++;
  153. break;
  154. }
  155. }
  156. }
  157. /* FIXME: we might get non-matching messages for sub-patterns specified
  158. * after their super-patterns, due to us skipping on first match. */
  159. for (ip = 0; ip < argc; ip++) {
  160. if (!found[ip]) {
  161. fprintf(stderr, _("No packages found matching %s.\n"), argv[ip]);
  162. failures++;
  163. }
  164. }
  165. }
  166. m_output(stdout, _("<standard output>"));
  167. m_output(stderr, _("<standard error>"));
  168. pkg_array_destroy(&array);
  169. modstatdb_shutdown();
  170. return failures;
  171. }
  172. static int searchoutput(struct filenamenode *namenode) {
  173. struct filepackages_iterator *iter;
  174. struct pkginfo *pkg_owner;
  175. int found;
  176. if (namenode->divert) {
  177. const char *name_from = namenode->divert->camefrom ?
  178. namenode->divert->camefrom->name : namenode->name;
  179. const char *name_to = namenode->divert->useinstead ?
  180. namenode->divert->useinstead->name : namenode->name;
  181. if (namenode->divert->pkg) {
  182. printf(_("diversion by %s from: %s\n"),
  183. namenode->divert->pkg->name, name_from);
  184. printf(_("diversion by %s to: %s\n"),
  185. namenode->divert->pkg->name, name_to);
  186. } else {
  187. printf(_("local diversion from: %s\n"), name_from);
  188. printf(_("local diversion to: %s\n"), name_to);
  189. }
  190. }
  191. found= 0;
  192. iter = filepackages_iter_new(namenode);
  193. while ((pkg_owner = filepackages_iter_next(iter))) {
  194. if (found)
  195. fputs(", ", stdout);
  196. fputs(pkg_owner->name, stdout);
  197. found++;
  198. }
  199. filepackages_iter_free(iter);
  200. if (found) printf(": %s\n",namenode->name);
  201. return found + (namenode->divert ? 1 : 0);
  202. }
  203. static int
  204. searchfiles(const char *const *argv)
  205. {
  206. struct filenamenode *namenode;
  207. struct fileiterator *it;
  208. const char *thisarg;
  209. int found;
  210. int failures = 0;
  211. struct varbuf path = VARBUF_INIT;
  212. static struct varbuf vb;
  213. if (!*argv)
  214. badusage(_("--search needs at least one file name pattern argument"));
  215. modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
  216. ensure_allinstfiles_available_quiet();
  217. ensure_diversions();
  218. while ((thisarg = *argv++) != NULL) {
  219. found= 0;
  220. /* Trim trailing slash and slash dot from the argument if it's
  221. * not a pattern, just a path.
  222. */
  223. if (!strpbrk(thisarg, "*[?\\")) {
  224. varbufreset(&path);
  225. varbufaddstr(&path, thisarg);
  226. varbufaddc(&path, '\0');
  227. path.used = path_rtrim_slash_slashdot(path.buf);
  228. thisarg = path.buf;
  229. }
  230. if (!strchr("*[?/",*thisarg)) {
  231. varbufreset(&vb);
  232. varbufaddc(&vb,'*');
  233. varbufaddstr(&vb,thisarg);
  234. varbufaddc(&vb,'*');
  235. varbufaddc(&vb,0);
  236. thisarg= vb.buf;
  237. }
  238. if (!strpbrk(thisarg, "*[?\\")) {
  239. namenode= findnamenode(thisarg, 0);
  240. found += searchoutput(namenode);
  241. } else {
  242. it= iterfilestart();
  243. while ((namenode = iterfilenext(it)) != NULL) {
  244. if (fnmatch(thisarg,namenode->name,0)) continue;
  245. found+= searchoutput(namenode);
  246. }
  247. iterfileend(it);
  248. }
  249. if (!found) {
  250. fprintf(stderr,_("dpkg: %s not found.\n"),thisarg);
  251. failures++;
  252. m_output(stderr, _("<standard error>"));
  253. } else {
  254. m_output(stdout, _("<standard output>"));
  255. }
  256. }
  257. modstatdb_shutdown();
  258. varbuf_destroy(&path);
  259. return failures;
  260. }
  261. static int
  262. enqperpackage(const char *const *argv)
  263. {
  264. const char *thisarg;
  265. struct fileinlist *file;
  266. struct pkginfo *pkg;
  267. struct filenamenode *namenode;
  268. int failures = 0;
  269. if (!*argv)
  270. badusage(_("--%s needs at least one package name argument"), cipaction->olong);
  271. if (cipaction->arg==act_listfiles)
  272. modstatdb_init(admindir,msdbrw_readonly|msdbrw_noavail);
  273. else
  274. modstatdb_init(admindir,msdbrw_readonly);
  275. while ((thisarg = *argv++) != NULL) {
  276. pkg= findpackage(thisarg);
  277. switch (cipaction->arg) {
  278. case act_status:
  279. if (pkg->status == stat_notinstalled &&
  280. pkg->priority == pri_unknown &&
  281. !(pkg->section && *pkg->section) &&
  282. !pkg->files &&
  283. pkg->want == want_unknown &&
  284. !informative(pkg,&pkg->installed)) {
  285. fprintf(stderr,_("Package `%s' is not installed and no info is available.\n"),pkg->name);
  286. failures++;
  287. } else {
  288. writerecord(stdout, _("<standard output>"), pkg, &pkg->installed);
  289. }
  290. break;
  291. case act_printavail:
  292. if (!informative(pkg,&pkg->available)) {
  293. fprintf(stderr,_("Package `%s' is not available.\n"),pkg->name);
  294. failures++;
  295. } else {
  296. writerecord(stdout, _("<standard output>"), pkg, &pkg->available);
  297. }
  298. break;
  299. case act_listfiles:
  300. switch (pkg->status) {
  301. case stat_notinstalled:
  302. fprintf(stderr,_("Package `%s' is not installed.\n"),pkg->name);
  303. failures++;
  304. break;
  305. default:
  306. ensure_packagefiles_available(pkg);
  307. ensure_diversions();
  308. file= pkg->clientdata->files;
  309. if (!file) {
  310. printf(_("Package `%s' does not contain any files (!)\n"),pkg->name);
  311. } else {
  312. while (file) {
  313. namenode= file->namenode;
  314. puts(namenode->name);
  315. if (namenode->divert && !namenode->divert->camefrom) {
  316. if (!namenode->divert->pkg)
  317. printf(_("locally diverted to: %s\n"),
  318. namenode->divert->useinstead->name);
  319. else if (pkg == namenode->divert->pkg)
  320. printf(_("package diverts others to: %s\n"),
  321. namenode->divert->useinstead->name);
  322. else
  323. printf(_("diverted by %s to: %s\n"),
  324. namenode->divert->pkg->name,
  325. namenode->divert->useinstead->name);
  326. }
  327. file= file->next;
  328. }
  329. }
  330. break;
  331. }
  332. break;
  333. default:
  334. internerr("unknown action '%d'", cipaction->arg);
  335. }
  336. if (*(argv + 1) == NULL)
  337. putchar('\n');
  338. m_output(stdout, _("<standard output>"));
  339. }
  340. if (failures) {
  341. fputs(_("Use dpkg --info (= dpkg-deb --info) to examine archive files,\n"
  342. "and dpkg --contents (= dpkg-deb --contents) to list their contents.\n"),stderr);
  343. m_output(stderr, _("<standard error>"));
  344. }
  345. modstatdb_shutdown();
  346. return failures;
  347. }
  348. static int
  349. showpackages(const char *const *argv)
  350. {
  351. struct pkg_array array;
  352. struct pkginfo *pkg;
  353. struct pkg_format_node *fmt = pkg_format_parse(showformat);
  354. int i;
  355. int failures = 0;
  356. if (!fmt) {
  357. failures++;
  358. return failures;
  359. }
  360. modstatdb_init(admindir,msdbrw_readonly);
  361. pkg_array_init_from_db(&array);
  362. pkg_array_sort(&array, pkg_sorter_by_name);
  363. if (!*argv) {
  364. for (i = 0; i < array.n_pkgs; i++) {
  365. pkg = array.pkgs[i];
  366. if (pkg->status == stat_notinstalled) continue;
  367. pkg_format_show(fmt, pkg, &pkg->installed);
  368. }
  369. } else {
  370. int argc, ip, *found;
  371. for (argc = 0; argv[argc]; argc++);
  372. found = m_malloc(sizeof(int) * argc);
  373. memset(found, 0, sizeof(int) * argc);
  374. for (i = 0; i < array.n_pkgs; i++) {
  375. pkg = array.pkgs[i];
  376. for (ip = 0; ip < argc; ip++) {
  377. if (!fnmatch(argv[ip], pkg->name, 0)) {
  378. pkg_format_show(fmt, pkg, &pkg->installed);
  379. found[ip]++;
  380. break;
  381. }
  382. }
  383. }
  384. /* FIXME: we might get non-matching messages for sub-patterns specified
  385. * after their super-patterns, due to us skipping on first match. */
  386. for (ip = 0; ip < argc; ip++) {
  387. if (!found[ip]) {
  388. fprintf(stderr, _("No packages found matching %s.\n"), argv[ip]);
  389. failures++;
  390. }
  391. }
  392. }
  393. m_output(stdout, _("<standard output>"));
  394. m_output(stderr, _("<standard error>"));
  395. pkg_array_destroy(&array);
  396. pkg_format_free(fmt);
  397. modstatdb_shutdown();
  398. return failures;
  399. }
  400. static void
  401. control_path_file(struct pkginfo *pkg, const char *control_file)
  402. {
  403. const char *control_path;
  404. struct stat st;
  405. /* Do not expose internal database files. */
  406. if (strcmp(control_file, LISTFILE) == 0 ||
  407. strcmp(control_file, CONFFILESFILE) == 0)
  408. return;
  409. control_path = pkgadminfile(pkg, control_file);
  410. if (stat(control_path, &st) < 0)
  411. return;
  412. if (!S_ISREG(st.st_mode))
  413. return;
  414. printf("%s\n", control_path);
  415. }
  416. static void
  417. control_path_pkg(struct pkginfo *pkg)
  418. {
  419. DIR *db_dir;
  420. struct dirent *db_de;
  421. struct varbuf db_path;
  422. size_t db_path_len;
  423. varbufinit(&db_path, 0);
  424. varbufaddstr(&db_path, pkgadmindir());
  425. db_path_len = db_path.used;
  426. varbufaddc(&db_path, '\0');
  427. db_dir = opendir(db_path.buf);
  428. if (!db_dir)
  429. ohshite(_("cannot read info directory"));
  430. push_cleanup(cu_closedir, ~0, NULL, 0, 1, (void *)db_dir);
  431. while ((db_de = readdir(db_dir)) != NULL) {
  432. const char *p;
  433. /* Ignore dotfiles, including ‘.’ and ‘..’. */
  434. if (db_de->d_name[0] == '.')
  435. continue;
  436. /* Ignore anything odd. */
  437. p = strrchr(db_de->d_name, '.');
  438. if (!p)
  439. continue;
  440. /* Ignore files from other packages. */
  441. if (strlen(pkg->name) != (size_t)(p - db_de->d_name) ||
  442. strncmp(db_de->d_name, pkg->name, p - db_de->d_name))
  443. continue;
  444. /* Skip past the full stop. */
  445. p++;
  446. /* Do not expose internal database files. */
  447. if (strcmp(p, LISTFILE) == 0 ||
  448. strcmp(p, CONFFILESFILE) == 0)
  449. continue;
  450. if (strlen(p) > MAXCONTROLFILENAME)
  451. continue;
  452. db_path.used = db_path_len;
  453. varbufaddstr(&db_path, db_de->d_name);
  454. varbufaddc(&db_path, '\0');
  455. printf("%s\n", db_path.buf);
  456. }
  457. pop_cleanup(ehflag_normaltidy); /* closedir */
  458. varbuf_destroy(&db_path);
  459. }
  460. static int
  461. control_path(const char *const *argv)
  462. {
  463. struct pkginfo *pkg;
  464. const char *pkg_name;
  465. const char *control_file;
  466. pkg_name = *argv++;
  467. if (!pkg_name)
  468. badusage(_("--%s needs at least one package name argument"),
  469. cipaction->olong);
  470. control_file = *argv++;
  471. if (control_file && *argv)
  472. badusage(_("--%s takes at most two arguments"), cipaction->olong);
  473. /* Validate control file name for sanity. */
  474. if (control_file) {
  475. const char *c;
  476. for (c = "/."; *c; c++)
  477. if (strchr(control_file, *c))
  478. badusage(_("control file contains %c"), *c);
  479. }
  480. modstatdb_init(admindir, msdbrw_readonly | msdbrw_noavail);
  481. pkg = findpackage(pkg_name);
  482. if (pkg->status == stat_notinstalled)
  483. badusage(_("Package `%s' is not installed.\n"), pkg->name);
  484. if (control_file)
  485. control_path_file(pkg, control_file);
  486. else
  487. control_path_pkg(pkg);
  488. modstatdb_shutdown();
  489. return 0;
  490. }
  491. static void DPKG_ATTR_NORET
  492. printversion(const struct cmdinfo *ci, const char *value)
  493. {
  494. printf(_("Debian %s package management program query tool version %s.\n"),
  495. DPKGQUERY, DPKG_VERSION_ARCH);
  496. printf(_(
  497. "This is free software; see the GNU General Public License version 2 or\n"
  498. "later for copying conditions. There is NO warranty.\n"));
  499. m_output(stdout, _("<standard output>"));
  500. exit(0);
  501. }
  502. static void DPKG_ATTR_NORET
  503. usage(const struct cmdinfo *ci, const char *value)
  504. {
  505. printf(_(
  506. "Usage: %s [<option> ...] <command>\n"
  507. "\n"), DPKGQUERY);
  508. printf(_(
  509. "Commands:\n"
  510. " -s|--status <package> ... Display package status details.\n"
  511. " -p|--print-avail <package> ... Display available version details.\n"
  512. " -L|--listfiles <package> ... List files `owned' by package(s).\n"
  513. " -l|--list [<pattern> ...] List packages concisely.\n"
  514. " -W|--show <pattern> ... Show information on package(s).\n"
  515. " -S|--search <pattern> ... Find package(s) owning file(s).\n"
  516. " -c|--control-path <package> [<file>]\n"
  517. " Print path for package control file.\n"
  518. "\n"));
  519. printf(_(
  520. " -h|--help Show this help message.\n"
  521. " --version Show the version.\n"
  522. "\n"));
  523. printf(_(
  524. "Options:\n"
  525. " --admindir=<directory> Use <directory> instead of %s.\n"
  526. " -f|--showformat=<format> Use alternative format for --show.\n"
  527. "\n"), ADMINDIR);
  528. printf(_(
  529. "Format syntax:\n"
  530. " A format is a string that will be output for each package. The format\n"
  531. " can include the standard escape sequences \\n (newline), \\r (carriage\n"
  532. " return) or \\\\ (plain backslash). Package information can be included\n"
  533. " by inserting variable references to package fields using the ${var[;width]}\n"
  534. " syntax. Fields will be right-aligned unless the width is negative in which\n"
  535. " case left alignment will be used.\n"));
  536. m_output(stdout, _("<standard output>"));
  537. exit(0);
  538. }
  539. const char thisname[]= "dpkg-query";
  540. const char printforhelp[]= N_("Use --help for help about querying packages.");
  541. const struct cmdinfo *cipaction = NULL;
  542. const char *admindir= ADMINDIR;
  543. static void setaction(const struct cmdinfo *cip, const char *value) {
  544. if (cipaction)
  545. badusage(_("conflicting actions -%c (--%s) and -%c (--%s)"),
  546. cip->oshort, cip->olong, cipaction->oshort, cipaction->olong);
  547. cipaction= cip;
  548. }
  549. static const struct cmdinfo cmdinfos[]= {
  550. /* This table has both the action entries in it and the normal options.
  551. * The action entries are made with the ACTION macro, as they all
  552. * have a very similar structure.
  553. */
  554. #define ACTION(longopt,shortopt,code,function) \
  555. { longopt, shortopt, 0, NULL, NULL, setaction, code, NULL, (voidfnp)function }
  556. #define OBSOLETE(longopt,shortopt) \
  557. { longopt, shortopt, 0, NULL, NULL, setobsolete, 0, NULL, NULL }
  558. ACTION( "listfiles", 'L', act_listfiles, enqperpackage ),
  559. ACTION( "status", 's', act_status, enqperpackage ),
  560. ACTION( "print-avail", 'p', act_printavail, enqperpackage ),
  561. ACTION( "list", 'l', act_listpackages, listpackages ),
  562. ACTION( "search", 'S', act_searchfiles, searchfiles ),
  563. ACTION( "show", 'W', act_listpackages, showpackages ),
  564. ACTION( "control-path", 'c', act_controlpath, control_path ),
  565. { "admindir", 0, 1, NULL, &admindir, NULL },
  566. { "showformat", 'f', 1, NULL, &showformat, NULL },
  567. { "help", 'h', 0, NULL, NULL, usage },
  568. { "version", 0, 0, NULL, NULL, printversion },
  569. { NULL, 0, 0, NULL, NULL, NULL }
  570. };
  571. int main(int argc, const char *const *argv) {
  572. jmp_buf ejbuf;
  573. int (*actionfunction)(const char *const *argv);
  574. int ret;
  575. setlocale(LC_ALL, "");
  576. bindtextdomain(PACKAGE, LOCALEDIR);
  577. textdomain(PACKAGE);
  578. standard_startup(&ejbuf);
  579. myopt(&argv, cmdinfos);
  580. if (!cipaction) badusage(_("need an action option"));
  581. setvbuf(stdout, NULL, _IONBF, 0);
  582. filesdbinit();
  583. actionfunction = (int (*)(const char *const *))cipaction->farg;
  584. ret = actionfunction(argv);
  585. standard_shutdown();
  586. return !!ret;
  587. }