Index: xc/programs/xrdb/xrdb.c =================================================================== RCS file: /cvs/xorg/xc/programs/xrdb/xrdb.c,v retrieving revision 1.2 diff -u -r1.2 xrdb.c --- xc/programs/xrdb/xrdb.c 23 Apr 2004 19:55:03 -0000 1.2 +++ xc/programs/xrdb/xrdb.c 31 Aug 2005 23:10:42 -0000 @@ -67,6 +67,9 @@ #endif /* __UNIXOS2__ */ #endif /* CPP */ +/* A list of C preprocessor programs to try before falling back to CPP */ +char *preferred_cpps[] = { "mcpp" }; + #define INIT_BUFFER_SIZE 10000 #define INIT_ENTRY_SIZE 500 @@ -120,7 +123,7 @@ #endif int oper = OPLOAD; char *editFile = NULL; -char *cpp_program = CPP; +char *cpp_program; char *backup_suffix = BACKUP_SUFFIX; Bool dont_execute = False; String defines; @@ -767,6 +770,63 @@ arg->used += strlen(s); } +static char * +find_program(char *progname) +{ + static char *progpath = NULL; + char *path; + size_t len; + + if(progpath != NULL) + free(progpath); + + path = getenv("PATH"); + + progpath = malloc(strlen(path) + strlen(progname) + 2); + if(!progpath) + fatal("%s: Not enough memory\n", ProgramName); + + while(path && *path) + { + len = strcspn(path, ":"); + if(len > 0) + { + strncpy(progpath, path, len); + progpath[len] = '\0'; + strcat(progpath, "/"); + strcat(progpath, progname); + + if(access(progpath, X_OK) == 0) + return progpath; + } + + path += len; + if(*path) + path++; + } + + return NULL; +} + +static char* +find_cpp(void) +{ + char progname[sizeof(preferred_cpps[0])]; + int i; + size_t len; + + for(i = 0; i < sizeof(preferred_cpps) / sizeof(preferred_cpps[0]) ; i++) + { + len = strcspn(preferred_cpps[i], " "); + strncpy(progname, preferred_cpps[i], len); + progname[len] = '\0'; + + if(find_program(progname)) + return preferred_cpps[i]; + } + + return CPP; +} int main(int argc, char *argv[]) @@ -785,6 +845,8 @@ /* initialize the includes String struct */ addstring(&includes, ""); + cpp_program = find_cpp(); + /* needs to be replaced with XrmParseCommand */ for (i = 1; i < argc; i++) {