diff options
Diffstat (limited to 'Build/source/texk/chktex/chktex-src/OpSys.c')
-rw-r--r-- | Build/source/texk/chktex/chktex-src/OpSys.c | 88 |
1 files changed, 85 insertions, 3 deletions
diff --git a/Build/source/texk/chktex/chktex-src/OpSys.c b/Build/source/texk/chktex/chktex-src/OpSys.c index 7d055b72284..67e2bea4a47 100644 --- a/Build/source/texk/chktex/chktex-src/OpSys.c +++ b/Build/source/texk/chktex/chktex-src/OpSys.c @@ -115,7 +115,9 @@ static char term_buffer[2048]; # define LOCALRCFILE "." RCBASENAME #endif -char ConfigFile[BUFSIZ] = LOCALRCFILE; +char ConfigFile[BUFFER_SIZE] = LOCALRCFILE; +struct WordList ConfigFiles; + const char *ReverseOn; const char *ReverseOff; @@ -150,6 +152,7 @@ enum LookIn liMin, liSysDir, liUsrDir, + liXdgDir, liEnvir, liCurDir, liNFound, @@ -177,12 +180,10 @@ int SetupVars(void) break; case liEnvir: /* Environment defined */ #ifdef __MSDOS__ - if ((Env = getenv("CHKTEXRC")) || (Env = getenv("CHKTEX_HOME"))) #elif defined(TEX_LIVE) if ((Env = kpse_var_value("CHKTEXRC"))) #else - if ((Env = getenv("CHKTEXRC"))) #endif @@ -206,6 +207,27 @@ int SetupVars(void) *ConfigFile = 0; break; + + case liXdgDir: /* Cross-desktop group dir for resource files */ + + /* XDG is really unix specific, but it shouldn't hurt to + * support it on Windows, should someone set the variables. */ + if ((Env = getenv("XDG_CONFIG_HOME")) && *Env) + { + strcpy(ConfigFile, Env); + tackon(ConfigFile, RCBASENAME); + } + else if ((Env = getenv("HOME")) && *Env) + { + strcpy(ConfigFile, Env); + tackon(ConfigFile, ".config"); + tackon(ConfigFile, RCBASENAME); + } + else + *ConfigFile = 0; + + break; + case liUsrDir: /* User dir for resource files */ #if defined(__unix__) @@ -446,6 +468,45 @@ static int HasFile(char *Dir, const char *Filename, const char *App) } +/* + * If Filename is contains a directory component, then add a fully qualified + * directory to the TeXInputs WordList. + * + * I'm not sure how it will work with some Windows paths, + * e.g. C:path\to\file.tex since it doesn't really understand the leading C: + * But I'm not sure it would even work with a path like that, and I have no + * way to test it. + * + * Behaviour somewhat controlled by the macros SLASH and DIRCHARS in the + * OpSys.h file. + * + */ + +void AddDirectoryFromRelativeFile(const char * Filename, struct WordList *TeXInputs) +{ + if ( ! Filename ) + return; + + /* There are no path delimiters, so it's just a file, return null */ + if ( ! strstr( Filename, DIRCHARS ) ) + return; + + + char buf[BUFFER_SIZE]; + if ( strchr(DIRCHARS,Filename[0]) ) { + strcpy(buf,Filename); + } else { + getcwd(buf, BUFFER_SIZE); + tackon(buf,Filename); + } + + /* Keep up to the final SLASH -- that will be the directory. */ + char * end = strrchr(buf,SLASH); + *end = '\0'; + InsertWord(buf,TeXInputs); +} + + #if USE_RECURSE static int SearchFile(char *Dir, const char *Filename, const char *App) { @@ -490,3 +551,24 @@ static int SearchFile(char *Dir, const char *Filename, const char *App) return (Found); } #endif /* USE_RECURSE */ + +#if defined(HAVE_STAT) +int IsRegFile(const char *Filename) +{ + int Retval = FALSE; + struct stat *statbuf; + if ((statbuf = malloc(sizeof(struct stat)))) + { + if (!stat(Filename, statbuf)) + { + if ((statbuf->st_mode & S_IFMT) == S_IFREG) + Retval = TRUE; + } + free(statbuf); + } + + return Retval; +} +#else +int IsRegFile(const char *Filename) { printf("WTF\n");return TRUE; } +#endif |