diff options
Diffstat (limited to 'bp.c')
| -rw-r--r-- | bp.c | 16 |
1 files changed, 12 insertions, 4 deletions
@@ -97,6 +97,14 @@ static inline void fprint_filename(FILE *out, const char *filename) { else fprintf(out, "%s:\n", filename); } +static void *portable_memrchr(const void *s, int c, size_t n) { + const unsigned char *p = (const unsigned char *)s + n; + while (n--) { + if (*--p == (unsigned char)c) return (void *)p; + } + return NULL; +} + // // If there was a parse error while building a pattern, print an error message and exit. // @@ -106,7 +114,7 @@ static inline bp_pat_t *assert_pat(const char *start, const char *end, maybe_pat const char *err_start = maybe_pat.value.error.start, *err_end = maybe_pat.value.error.end, *err_msg = maybe_pat.value.error.msg; - const char *nl = memrchr(start, '\n', (size_t)(err_start - start)); + const char *nl = portable_memrchr(start, '\n', (size_t)(err_start - start)); const char *sol = nl ? nl + 1 : start; nl = memchr(err_start, '\n', (size_t)(end - err_start)); const char *eol = nl ? nl : end; @@ -517,9 +525,9 @@ int main(int argc, char *argv[]) { bp_pat_t *pattern = NULL; // Load builtins: - file_t *builtins_file = load_file(&loaded_files, "/etc/" BP_NAME "/builtins.bp"); + file_t *builtins_file = load_file(&loaded_files, BP_PREFIX "/" BP_NAME "/builtins.bp"); if (builtins_file) defs = load_grammar(defs, builtins_file); - file_t *local_file = load_filef(&loaded_files, "%s/.config/" BP_NAME "/builtins.bp", getenv("HOME")); + file_t *local_file = load_file(&loaded_files, BP_PREFIX "/share/" BP_NAME "/grammars/builtins.bp"); if (local_file) defs = load_grammar(defs, local_file); bool explicit_case_sensitivity = false; @@ -561,7 +569,7 @@ int main(int argc, char *argv[]) { file_t *f = NULL; if (strlen(flag) > 3 && strncmp(&flag[strlen(flag) - 3], ".bp", 3) == 0) f = load_file(&loaded_files, flag); if (f == NULL) f = load_filef(&loaded_files, "%s/.config/" BP_NAME "/%s.bp", getenv("HOME"), flag); - if (f == NULL) f = load_filef(&loaded_files, "/etc/" BP_NAME "/%s.bp", flag); + if (f == NULL) f = load_filef(&loaded_files, BP_PREFIX "/share/" BP_NAME "/grammars/%s.bp", flag); if (f == NULL) errx(EXIT_FAILURE, "Couldn't find grammar: %s", flag); defs = load_grammar(defs, f); // Keep in memory for debug output } else if (FLAG("-w") || FLAG("--word")) { |
