105int main(
int argc,
char *argv[])
111 const char *xml_dir = NULL;
112 const char *out_override = NULL;
113 const char *schema_override = NULL;
114 const char *configdir = NULL;
115 const char *datadir = NULL;
118 for(
int k = 1;
k < argc;
k++)
120 if(!strcmp(argv[
k],
"-h") || !strcmp(argv[
k],
"--help"))
126 if(!strcmp(argv[
k],
"--no-baseline"))
135 const char *
const opts[] = {
"--xml-dir",
"--output",
"--schema",
"--configdir",
"--datadir" };
136 const char **
const dests[] = { &xml_dir, &out_override, &schema_override, &configdir, &datadir };
138 for(
size_t o = 0; o <
sizeof(opts) /
sizeof(*opts); o++)
140 if(strcmp(argv[
k], opts[o]))
continue;
143 fprintf(stderr,
"%s: %s needs a value\n", argv[0], opts[o]);
146 *dests[o] = argv[++
k];
150 if(matched)
continue;
152 fprintf(stderr,
"%s: unknown argument `%s'\n", argv[0], argv[
k]);
167 char *application_directory = NULL;
168 int dirname_length = 0;
169 const int length = wai_getExecutablePath(NULL, 0, &dirname_length);
172 application_directory = (
char *)malloc(length + 1);
173 if(application_directory)
175 wai_getExecutablePath(application_directory, length, &dirname_length);
176 application_directory[dirname_length] =
'\0';
181 free(application_directory);
185 g_strlcpy(schema_path, schema_override,
sizeof(schema_path));
187 snprintf(schema_path,
sizeof(schema_path),
"%s/lenses-schema.sql",
dt_loc_datadir());
189 if(!g_file_test(schema_path, G_FILE_TEST_IS_REGULAR))
192 "%s: no schema at `%s'.\n"
193 "This file is installed with Ansel; if it is missing, the installation is\n"
194 "incomplete. Pass --schema to point at one explicitly.\n",
195 argv[0], schema_path);
201 g_strlcpy(out_path, out_override,
sizeof(out_path));
209 const char *base = NULL;
212 snprintf(base_dir,
sizeof(base_dir),
"%s/lensfun-xml",
dt_loc_datadir());
213 if(g_file_test(base_dir, G_FILE_TEST_IS_DIR))
217 "warning: no shipped calibrations at `%s'.\n"
218 "The result will hold ONLY what lensfun finds on this machine, which may be\n"
219 "far less than Ansel came with.\n",
224 printf(
"Reading lensfun XML from `%s'.\n", xml_dir);
226 printf(
"Reading every lensfun profile this machine has: the system database, the\n"
227 "system and user update directories, and your own profiles in\n"
228 "~/.local/share/lensfun (which override the rest).\n");
244 g_strlcpy(staged_path, out_path,
sizeof(staged_path));
245 g_strlcat(staged_path,
".incoming",
sizeof(staged_path));
247 const int rc = ls_import_run(schema_path, staged_path, base, xml_dir);
250 g_unlink(staged_path);
251 fprintf(stderr,
"%s: the database was NOT updated; the previous one is untouched.\n",
256 if(g_rename(staged_path, out_path) != 0)
258 fprintf(stderr,
"%s: cannot move `%s' to `%s'; nothing was changed.\n",
259 argv[0], staged_path, out_path);
260 g_unlink(staged_path);
264 printf(
"\nWrote `%s'.\n"
265 "Ansel reads this in preference to the database it shipped with, so the new\n"
266 "profiles are available next time you start it. Delete this file to go back to\n"
267 "the shipped one.\n",
static void usage(const char *progname)