generalize find_calibration_by_model with a loop
This commit is contained in:
37
src/dcp.c
37
src/dcp.c
@@ -7,34 +7,27 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#ifndef SYSCONFDIR
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
bool
|
bool
|
||||||
find_calibration_by_model(char *conffile, char *model, const char *sensor)
|
find_calibration_by_model(char *conffile, char *model, const char *sensor)
|
||||||
{
|
{
|
||||||
// Check config/%model,%sensor.dcp in the current working directory
|
static const char *paths[] = {
|
||||||
sprintf(conffile, "config/%s,%s.dcp", model, sensor);
|
"config/%s,%s.dcp",
|
||||||
if (access(conffile, F_OK) != -1) {
|
SYSCONFDIR "/megapixels/config/%s,%s.dcp",
|
||||||
printf("Found calibration file at %s\n", conffile);
|
DATADIR "/megapixels/config/%s,%s.dcp",
|
||||||
return true;
|
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);
|
printf("No calibration found for %s,%s\n", model, sensor);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user