Temporarily set system-dependant default defines
This commit is contained in:
parent
dcb6613290
commit
241af9326b
34
src/main.c
34
src/main.c
@ -16,6 +16,7 @@
|
||||
|
||||
|
||||
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
@ -60,6 +61,7 @@ static int _usage(void)
|
||||
|
||||
/* public */
|
||||
/* main */
|
||||
static int _main_default_defines(C99Prefs * prefs);
|
||||
static int _main_default_paths(C99Prefs * prefs);
|
||||
static int _main_add_define(C99Prefs * prefs, char * define);
|
||||
static int _main_add_path(C99Prefs * prefs, char const * path);
|
||||
@ -73,7 +75,8 @@ int main(int argc, char * argv[])
|
||||
int o;
|
||||
|
||||
memset(&prefs, 0, sizeof(prefs));
|
||||
if(_main_default_paths(&prefs) != 0)
|
||||
if(_main_default_defines(&prefs) != 0
|
||||
|| _main_default_paths(&prefs) != 0)
|
||||
return 2;
|
||||
while((o = getopt(argc, argv, "cD:EgI:L:m:M:o:O123sU:W")) != -1)
|
||||
switch(o)
|
||||
@ -139,6 +142,23 @@ int main(int argc, char * argv[])
|
||||
return (ret == 0) ? 0 : 2;
|
||||
}
|
||||
|
||||
static int _main_default_defines(C99Prefs * prefs)
|
||||
/* FIXME define these in the as plug-in instead */
|
||||
{
|
||||
struct utsname uts;
|
||||
static char sysname[sizeof(uts.sysname) + 7];
|
||||
static char machine[sizeof(uts.machine) + 7];
|
||||
|
||||
if(uname(&uts) != 0)
|
||||
return error_set_print(PACKAGE, 1, "%s", strerror(errno));
|
||||
snprintf(sysname, sizeof(sysname), "__%s__=1", uts.sysname);
|
||||
snprintf(machine, sizeof(machine), "__%s__=1", uts.machine);
|
||||
if(_main_add_define(prefs, sysname) != 0
|
||||
|| _main_add_define(prefs, machine) != 0)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _main_default_paths(C99Prefs * prefs)
|
||||
{
|
||||
char * paths[] = { "/usr/include" };
|
||||
@ -163,6 +183,9 @@ static int _main_add_define(C99Prefs * prefs, char * define)
|
||||
char ** p;
|
||||
char * value;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, define);
|
||||
#endif
|
||||
if(strlen(define) == 0)
|
||||
return 1;
|
||||
value = strtok(define, "=");
|
||||
@ -178,6 +201,9 @@ static int _main_add_path(C99Prefs * prefs, char const * path)
|
||||
{
|
||||
const char ** p;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, path);
|
||||
#endif
|
||||
if((p = realloc(prefs->paths, sizeof(*p) * (prefs->paths_cnt + 1)))
|
||||
== NULL)
|
||||
return error_set_print(PACKAGE, 1, "%s", strerror(errno));
|
||||
@ -190,6 +216,9 @@ static int _main_add_undefine(C99Prefs * prefs, char const * undefine)
|
||||
{
|
||||
const char ** p;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, undefine);
|
||||
#endif
|
||||
if(strlen(undefine) == 0)
|
||||
return 1;
|
||||
if((p = realloc(prefs->undefines, sizeof(*p)
|
||||
@ -205,6 +234,9 @@ static int _main_add_option(C99Prefs * prefs, char const * option)
|
||||
C99Option * p;
|
||||
char * q;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, option);
|
||||
#endif
|
||||
if(strlen(option) == 0)
|
||||
return 1;
|
||||
if((p = realloc(prefs->options, sizeof(*p)
|
||||
|
Loading…
Reference in New Issue
Block a user