static int do_auto_prefs(buffer *b, const char *ext, int (prefs_func)(buffer *, const char *)) { if (!b) { return ERROR; } assert_buffer(b); if (!ext && (!b->filename || !(ext = extension(b->filename)))) { return HAS_NO_EXTENSION; } /* Try global autoprefs -- We always load these before ~/.ne autoprefs. That way the user can override whatever he wants, but anything he doesn't override still gets passed through. */ int error = OK; char *auto_name; char *prefs_dir; if (*prefs_func == load_prefs && (prefs_dir = exists_gprefs_dir())) { if ((auto_name = malloc(strlen(ext) + strlen(prefs_dir) + strlen(PREF_FILE_SUFFIX) + 2))) { strcat(strcat(strcpy(auto_name, prefs_dir), ext), PREF_FILE_SUFFIX); error = prefs_func(b, auto_name); free(auto_name); /* We don't "return error;" here because we still haven't loaded the user's autoprefs. */ } } /* Try ~/.ne autoprefs */ if ((prefs_dir = exists_prefs_dir())) { if ((auto_name = malloc(strlen(ext) + strlen(prefs_dir) + strlen(PREF_FILE_SUFFIX) + 2))) { strcat(strcat(strcpy(auto_name, prefs_dir), ext), PREF_FILE_SUFFIX); error = prefs_func(b, auto_name); free(auto_name); } else { return OUT_OF_MEMORY; } } else { error = CANT_FIND_PREFS_DIR; } if (do_syntax && !b->syn) { load_syntax_by_name(b, ext); } return error; }
void load_virtual_extensions() { assert(virt_ext == NULL); char *prefs_dir; /* Try global directory first. */ if (prefs_dir = exists_gprefs_dir()) { char virt_name[strlen(VIRTUAL_EXT_NAME_G) + strlen(prefs_dir) + 1]; strcat(strcpy(virt_name, prefs_dir), VIRTUAL_EXT_NAME_G); load_virt_ext(virt_name); } /* Then try the user's ~/.ne/.extensions, possibly overriding global settings. */ if (prefs_dir = exists_prefs_dir()) { char virt_name[strlen(VIRTUAL_EXT_NAME) + strlen(prefs_dir) + 1]; strcat(strcpy(virt_name, prefs_dir), VIRTUAL_EXT_NAME); load_virt_ext(virt_name); } for(int i = 0; i < num_virt_ext; i++) max_max_line = max(max_max_line, virt_ext[i].max_line); }
char *request_syntax() { char syn_dir_name[512]; char *p; req_list rl; DIR *d; if (req_list_init(&rl, filenamecmp, false, false, '*') != OK) return NULL; if ((p = exists_prefs_dir()) && strlen(p) + 2 + strlen(SYNTAX_DIR) < sizeof syn_dir_name) { strcat(strcpy(syn_dir_name, p), SYNTAX_DIR); if (d = opendir(syn_dir_name)) { load_syntax_names(&rl,d,true); closedir(d); } } if ((p = exists_gprefs_dir()) && strlen(p) + 2 + strlen(SYNTAX_DIR) < sizeof syn_dir_name) { strcat(strcpy(syn_dir_name, p), SYNTAX_DIR); if (d = opendir(syn_dir_name)) { load_syntax_names(&rl,d,false); closedir(d); } } req_list_finalize(&rl); p = NULL; int result; if (rl.cur_entries && (result = request_strings(&rl, 0)) != ERROR) { char * const q = rl.entries[result >= 0 ? result : -result - 2]; if (p = malloc(strlen(q)+3)) { strcpy(p,q); if (p[strlen(p)-1] == rl.suffix) p[strlen(p)-1] = '\0'; if (result < 0) { memmove(p + 1, p, strlen(p) + 1); p[0] = '\0'; } } } req_list_free(&rl); return p; }
struct high_state *load_dfa(struct high_syntax *syntax) { unsigned char name[1024]; unsigned char buf[1024]; unsigned char bf[256]; int clist[256]; unsigned char *p; int c; FILE *f = NULL; struct ifstack *stack = 0; struct high_state *state = 0; /* Current state */ struct high_state *first = 0; /* First state */ int line = 0; int this_one = 0; int inside_subr = 0; /* Load it */ if ((p = (unsigned char *)exists_prefs_dir()) && strlen((const char *)p) + 2 + strlen(SYNTAX_DIR) + strlen(SYNTAX_EXT) + strlen((const char *)syntax->name) < sizeof name) { strcat(strcat(strcat(strcat(strcpy((char *)name, (const char *)p), SYNTAX_DIR), "/"), (const char *)syntax->name), SYNTAX_EXT); f = fopen((char *)name, "r"); } if (!f && (p = (unsigned char *)exists_gprefs_dir()) && strlen((const char *)p) + 2 + strlen(SYNTAX_DIR) + strlen(SYNTAX_EXT) + strlen((const char *)syntax->name) < sizeof name) { strcat(strcat(strcat(strcat(strcpy((char *)name, (const char *)p), SYNTAX_DIR), "/"), (const char *)syntax->name), SYNTAX_EXT); f = fopen((char *)name, "r"); } if (!f) { return 0; } /* Parse file */ while (fgets((char *)buf, 1023, f)) { ++line; p = buf; c = parse_ws(&p, '#'); if (!parse_char(&p, '.')) { if (!parse_ident(&p, bf, sizeof(bf))) { if (!zcmp(bf, USTR "ifdef")) { struct ifstack *st = joe_malloc(sizeof(struct ifstack)); st->next = stack; st->else_part = 0; st->ignore = 1; st->skip = 1; st->line = line; if (!stack || !stack->ignore) { parse_ws(&p, '#'); if (!parse_ident(&p, bf, sizeof(bf))) { struct high_param *param; for (param = syntax->params; param; param = param->next) if (!zcmp(param->name, bf)) { st->ignore = 0; break; } st->skip = 0; } else { i_printf_2((char *)joe_gettext(_("%s %d: missing parameter for ifdef\n")), name, line); } } stack = st; } else if (!zcmp(bf, USTR "else")) { if (stack && !stack->else_part) { stack->else_part = 1; if (!stack->skip) { stack->ignore = !stack->ignore; } } else { i_printf_2((char *)joe_gettext(_("%s %d: else with no matching if\n")), name, line); } } else if (!zcmp(bf, USTR "endif")) { if (stack) { struct ifstack *st = stack; stack = st->next; joe_free(st); } else { i_printf_2((char *)joe_gettext(_("%s %d: endif with no matching if\n")), name, line); } } else if (!zcmp(bf, USTR "subr")) { parse_ws(&p, '#'); if (parse_ident(&p, bf, sizeof(bf))) { i_printf_2((char *)joe_gettext(_("%s %d: Missing subroutine name\n")), name, line); } else { if (!stack || !stack->ignore) { inside_subr = 1; this_one = 0; if (syntax->subr && !zcmp(bf, syntax->subr)) { this_one = 1; } } } } else if (!zcmp(bf, USTR "end")) { if (!stack || !stack->ignore) { this_one = 0; inside_subr = 0; } } else { i_printf_2((char *)joe_gettext(_("%s %d: Unknown control statement\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing control statement name\n")), name, line); } } else if (stack && stack->ignore) { /* Ignore this line because of ifdef */ } else if (!parse_char(&p, '=')) { /* Parse color */ parse_color_def(&syntax->color, p, name, line); } else if ((syntax->subr && !this_one) || (!syntax->subr && inside_subr)) { /* Ignore this line because it's not the code we want */ } else if (!parse_char(&p, ':')) { if (!parse_ident(&p, bf, sizeof(bf))) { state = find_state(syntax, bf); if (!first) { first = state; } parse_ws(&p, '#'); if (!parse_tows(&p, bf)) { struct high_color *color; for (color = syntax->color; color; color = color->next) if (!zcmp(color->name, bf)) { break; } if (color) { state->color = color->color; } else { state->color = 0; i_printf_2((char *)joe_gettext(_("%s %d: Unknown class\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing color for state definition\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing state name\n")), name, line); } } else if (!parse_char(&p, '-')) { /* No. sync lines ignored */ } else { c = parse_ws(&p, '#'); if (!c) { } else if (c == '"' || c == '*' || c == '&') { if (state) { struct high_cmd *cmd; int delim = 0; if (!parse_field(&p, USTR "*")) { int z; for (z = 0; z != 256; ++z) { clist[z] = 1; } } else if (!parse_field(&p, USTR "&")) { delim = 1; } else { c = parse_string(&p, bf, sizeof(bf)); if (c < 0) { i_printf_2((char *)joe_gettext(_("%s %d: Bad string\n")), name, line); } else { int z; int first, second; unsigned char *t = bf; for (z = 0; z != 256; ++z) { clist[z] = 0; } while (!parse_range(&t, &first, &second)) { if (first > second) { second = first; } while (first <= second) { clist[first++] = 1; } } } } /* Create command */ cmd = mkcmd(); parse_ws(&p, '#'); if (!parse_ident(&p, bf, sizeof(bf))) { int z; cmd->new_state = find_state(syntax, bf); parse_options(syntax, cmd, f, p, 0, name, line); /* Install command */ if (delim) { state->delim = cmd; } else for (z = 0; z != 256; ++z) if (clist[z]) { state->cmd[z] = cmd; } } else { i_printf_2((char *)joe_gettext(_("%s %d: Missing jump\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: No state\n")), name, line); } } else { i_printf_2((char *)joe_gettext(_("%s %d: Unknown character\n")), name, line); } } } while (stack) { struct ifstack *st = stack; stack = st->next; i_printf_2((char *)joe_gettext(_("%s %d: ifdef with no matching endif\n")), name, st->line); joe_free(st); } fclose(f); return first; }