generalize find_calibration_by_model with a loop

This commit is contained in:
Egor Shestakov
2025-03-12 12:08:42 +00:00
parent ae48e07f84
commit 9b1ee0161d

View File

@@ -7,34 +7,27 @@
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#ifndef SYSCONFDIR
#include "config.h"
#endif
bool
find_calibration_by_model(char *conffile, char *model, const char *sensor)
{
// Check config/%model,%sensor.dcp in the current working directory
sprintf(conffile, "config/%s,%s.dcp", model, sensor);
if (access(conffile, F_OK) != -1) {
printf("Found calibration file at %s\n", conffile);
return true;
static const char *paths[] = {
"config/%s,%s.dcp",
SYSCONFDIR "/megapixels/config/%s,%s.dcp",
DATADIR "/megapixels/config/%s,%s.dcp",
NULL
};
for (const char *fmt = paths[0]; fmt; fmt++) {
sprintf(conffile, fmt, model, sensor);
if (access(conffile, F_OK) != -1) {
printf("Found calibration file at %s\n", conffile);
return true;
}
}
// Check user overridden /etc/megapixels/config/%model,%sensor.dcp
sprintf(conffile, "%s/megapixels/config/%s,%s.dcp", "/etc", model, sensor);
if (access(conffile, F_OK) != -1) {
printf("Found calibration file at %s\n", conffile);
return true;
}
// Check packaged /usr/share/megapixels/config/%model,%sensor.ini
sprintf(conffile,
"%s/megapixels/config/%s,%s.dcp",
"/usr/share",
model,
sensor);
if (access(conffile, F_OK) != -1) {
printf("Found calibration file at %s\n", conffile);
return true;
}
printf("No calibration found for %s,%s\n", model, sensor);
return false;
}