// if this is used as a path use stdin or stdout instead
#define ULAS_STDFILEPATH "-"
+#define ULAS_PATHSEP "/"
#define ULAS_SYMNAMEMAX 256
#define ULAS_PATHMAX 4096
struct ulas_config ulas_cfg_from_env(void);
void ulas_init(struct ulas_config cfg);
void ulas_free(void);
-FILE* ulas_incpathfopen(const char *path, const char *mode);
+FILE *ulas_incpathfopen(const char *path, const char *mode);
int ulas_main(struct ulas_config cfg);
ulas_preprocfree(&ulas.pp);
}
+FILE *ulas_incpathfopen(const char *path, const char *mode) {
+ char pathbuf[ULAS_PATHMAX];
+ memset(pathbuf, 0, ULAS_PATHMAX);
+
+ for (int i = 0; i < ulas.include_paths_len; i++) {
+ pathbuf[0] = '\0';
+ char *ip = ulas.include_paths[i];
+ int len = strlen(ip);
+
+ strcat(pathbuf, ip);
+ if (ip[len-1] != ULAS_PATHSEP[0]) {
+ strcat(pathbuf, ULAS_PATHSEP);
+ }
+ strcat(pathbuf, path);
-FILE* ulas_incpathfopen(const char *path, const char *mode) {
- // TODO: loop inc-paths
+ FILE *f = fopen(pathbuf, mode);
+ if (f != NULL) {
+ return f;
+ }
+ }
+
+ // TODO: loop inc-paths
// lastly check .
- return NULL;
+ FILE *f = fopen(path, mode);
+ if (f == NULL) {
+ ULASERR("%s: %s\n", path, strerror(errno));
+ }
+
+ return f;
}
int ulas_icntr(void) { return ulas.icntr++; }