2010-12-29 16:42:26 +01:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
|
2011-06-29 22:45:40 +02:00
|
|
|
static char *trimcopy(char *src, char *dest, int size)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
while (*src == ' ') src++;
|
2010-12-29 16:42:26 +01:00
|
|
|
|
2011-06-29 22:45:40 +02:00
|
|
|
while (*src != 0 && *src != '\n' && *src != '\r' && i < size-1)
|
|
|
|
{
|
|
|
|
dest[i] = *src;
|
|
|
|
i++;
|
|
|
|
src++;
|
|
|
|
}
|
|
|
|
dest[i] = 0;
|
|
|
|
i--;
|
2010-12-29 16:42:26 +01:00
|
|
|
|
2011-06-29 22:45:40 +02:00
|
|
|
while(i > 0 && dest[i] == ' ')
|
|
|
|
{
|
|
|
|
dest[i] = 0;
|
|
|
|
i--;
|
|
|
|
}
|
2010-12-29 16:42:26 +01:00
|
|
|
|
|
|
|
return dest;
|
|
|
|
}
|
|
|
|
|
2011-06-29 22:45:40 +02:00
|
|
|
static char *cfg_parseline(char *line)
|
2010-12-29 16:42:26 +01:00
|
|
|
{
|
2011-06-29 22:45:40 +02:00
|
|
|
char tmp[300], name[200];
|
|
|
|
snprintf(tmp, sizeof(tmp), line);
|
2010-12-29 16:42:26 +01:00
|
|
|
char *eq = strchr(tmp, '=');
|
2011-06-29 22:45:40 +02:00
|
|
|
if (!eq)
|
|
|
|
return NULL;
|
|
|
|
|
2010-12-29 16:42:26 +01:00
|
|
|
*eq = 0;
|
|
|
|
|
2011-06-29 22:45:40 +02:00
|
|
|
trimcopy(tmp, name, sizeof(name));
|
2010-12-29 16:42:26 +01:00
|
|
|
|
2011-06-29 22:45:40 +02:00
|
|
|
if(strcmp(name, "update_path") == 0)
|
|
|
|
return eq+1;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-12-29 16:42:26 +01:00
|
|
|
|
2011-06-29 22:45:40 +02:00
|
|
|
bool cfg_parsefile(char *fname, int size)
|
|
|
|
{
|
|
|
|
FILE *f = fopen(fname, "r");
|
|
|
|
if (!f)
|
2010-12-29 16:42:26 +01:00
|
|
|
return false;
|
2011-06-29 22:45:40 +02:00
|
|
|
|
|
|
|
char line[300];
|
|
|
|
|
|
|
|
while (fgets(line, sizeof(line), f))
|
|
|
|
{
|
2010-12-29 16:42:26 +01:00
|
|
|
if (line[0] == '#') continue;
|
2011-06-29 22:45:40 +02:00
|
|
|
|
|
|
|
char * value = cfg_parseline(line);
|
|
|
|
if(value)
|
|
|
|
{
|
|
|
|
trimcopy(value, fname, size);
|
|
|
|
break;
|
|
|
|
}
|
2010-12-29 16:42:26 +01:00
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|