querycmd.c 19 KB

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