static struct attr_stack *read_attr_from_index(const struct index_state *istate, const char *path, int macro_ok) { struct attr_stack *res; char *buf, *sp; int lineno = 0; if (!istate) return NULL; buf = read_blob_data_from_index(istate, path, NULL); if (!buf) return NULL; res = xcalloc(1, sizeof(*res)); for (sp = buf; *sp; ) { char *ep; int more; ep = strchrnul(sp, '\n'); more = (*ep == '\n'); *ep = '\0'; handle_attr_line(res, sp, path, ++lineno, macro_ok); sp = ep + more; } free(buf); return res; }
static struct attr_stack *read_attr_from_array(const char **list) { struct attr_stack *res; const char *line; int lineno = 0; res = xcalloc(1, sizeof(*res)); while ((line = *(list++)) != NULL) handle_attr_line(res, line, "[builtin]", ++lineno, 1); return res; }
static struct attr_stack *read_attr_from_file(const char *path, int macro_ok) { FILE *fp = fopen_or_warn(path, "r"); struct attr_stack *res; char buf[2048]; int lineno = 0; if (!fp) return NULL; res = xcalloc(1, sizeof(*res)); while (fgets(buf, sizeof(buf), fp)) { char *bufp = buf; if (!lineno) skip_utf8_bom(&bufp, strlen(bufp)); handle_attr_line(res, bufp, path, ++lineno, macro_ok); } fclose(fp); return res; }