/* Read Property File */ Bool /* True == Error, False == Success */ SPropRecValList_read_prop_file(SDynPropRecValList *pThisList, char const * const strFileName) { Bool result = False; FILE *is; #if 1 if (!strcmp(strFileName, "-")) is = stdin; else #endif is = fopen(strFileName, "r"); if (NULL == is) { fprintf(stderr, "truetype font property : cannot open file %s.\n", strFileName); result = True; goto abort; } { for (;;) { if (False != (result = parse_one_line(pThisList, is))) goto quit; if (feof(is)) break; } } quit: #if 1 if (strcmp(strFileName, "-")) #endif fclose(is); abort: return result; }
/* * We keep on re-using the membuffer that we use for * strings, but the callback function can "steal" it by * saving its value and just clear the original. */ static void for_each_line(git_blob *blob, line_fn_t *fn, void *fndata) { const char *content = git_blob_rawcontent(blob); unsigned int size = git_blob_rawsize(blob); struct membuffer str = { 0 }; while (size) { unsigned int n = parse_one_line(content, size, fn, fndata, &str); content += n; size -= n; /* Re-use the allocation, but forget the data */ str.len = 0; } free_buffer(&str); }
/* * Parse config file. */ int parse_conf_file(char *path) { char key[MAX_LINE_LEN], val[MAX_LINE_LEN], buf[MAX_LINE_LEN]; char line[MAX_LINE_LEN]; char *p; int len, i; FILE *fp; if ((fp = fopen(path, "r")) == NULL) { return -1; } line[0] = '\0'; while (fgets(buf, sizeof(buf), fp) != NULL) { if (strlen(buf) >= MAX_LINE_LEN - 1) { log_msg(LOG_ERR, "parse error: line too long"); goto error_exit; } p = strtrim(buf); if (p[0] == '#') /* comments, continue */ continue; len = strlen(p) - 1; if (p[len] == '\\') { /* line continue */ p[len] = '\0'; len = MAX_LINE_LEN - strlen(line); strncat(line, p, len); if (strlen(line) >= MAX_LINE_LEN - 1) { log_msg(LOG_ERR, "parse error: %s line too long", path); goto error_exit; } continue; } len = MAX_LINE_LEN - strlen(line); strncat(line, p, len); if (strlen(line) >= MAX_LINE_LEN - 1) { log_msg(LOG_ERR, "parse error: %s line too long", path); goto error_exit; } if (parse_one_line(line, key, val) == -1) { log_msg(LOG_ERR, "syntax error: %s: %s", path, buf); goto error_exit; } i = 0; while (options[i].name != NULL) { if (options[i].value != NULL) { ++i; continue; } if (!strcasecmp(options[i].name, key)) { if (val[0] != '\0') options[i].value = stralloc(val); break; } else { ++i; } } line[0] = '\0'; } /* end while(fgets()) */ fclose(fp); return 0; error_exit: fclose(fp); return -2; }