query.c 19 KB

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