query.c 19 KB

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