2 * Copyright (c) 2022 Omar Polo <op@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
25 #include "dictionary.h"
35 xstrdup(const char *s)
42 if ((t = strdup(s)) == NULL)
50 fprintf(stderr, "usage: %s [-o dbpath] [-m p|w] [path]\n",
56 main(int argc, char **argv)
58 struct dictionary dict;
59 struct db_entry *entries = NULL;
60 const char *dbpath = NULL;
63 int ch, r = 0, mode = MODE_SQLPORTS;
66 /* sqlite needs flock */
67 if (pledge("stdio rpath wpath cpath flock", NULL) == -1)
71 while ((ch = getopt(argc, argv, "m:o:")) != -1) {
98 if (!dictionary_init(&dict))
99 err(1, "dictionary_init");
101 if (mode == MODE_SQLPORTS)
102 r = idx_ports(&dict, &entries, &len, argc, argv);
104 r = idx_wiki(&dict, &entries, &len, argc, argv);
107 if ((fp = fopen(dbpath, "w+")) == NULL)
108 err(1, "can't open %s", dbpath);
109 if (db_create(fp, &dict, entries, len) == -1) {
117 for (i = 0; i < len; ++i) {
118 free(entries[i].name);
119 free(entries[i].descr);
122 dictionary_free(&dict);