DLLSYM BOOL8 read_variables_file(const char *file // name to read ) { BOOL8 anyerr; // true if any error char flag; // file flag BOOL8 foundit; // found variable inT16 length; // length of line inT16 nameoffset; // offset for real name char *valptr; // value field char *stringend; // end of string value FILE *fp; // file pointer // iterators char line[MAX_PATH]; // input line anyerr = FALSE; if (*file == PLUS) { flag = PLUS; // file has flag nameoffset = 1; } else if (*file == MINUS) { flag = MINUS; nameoffset = 1; } else { flag = EQUAL; nameoffset = 0; } fp = fopen(file + nameoffset, "r"); if (fp == NULL) { printf("read_variables_file:Can't open %s", file + nameoffset); return TRUE; // can't open it } while (fgets (line, MAX_PATH, fp)) { if (line[0] != '\n' && line[0] != '#') { length = strlen (line); if (line[length - 1] == '\n') line[length - 1] = '\0'; // cut newline for (valptr = line; *valptr && *valptr != ' ' && *valptr != '\t'; valptr++); if (*valptr) { //found blank *valptr = '\0'; //make name a string do valptr++; //find end of blanks while (*valptr == ' ' || *valptr == '\t'); if (*valptr && *valptr != '#') { //last char in string stringend = valptr + strlen (valptr) - 1; while (stringend != valptr) { while (stringend != valptr && (*stringend == ' ' || *stringend == '\t')) // cut trailing blanks stringend--; stringend[1] = '\0'; // terminate string while (stringend != valptr && ((*stringend != ' ' && *stringend != '\t') || stringend[1] != '#')) stringend--; // find word start } } } foundit = set_new_style_variable(line, valptr); if (!foundit) { anyerr = TRUE; // had an error printf("read_variables_file:variable not found: %s\n", line); } } } fclose(fp); // close file return anyerr; }
// Set the value of an internal "variable" (of either old or new types). // Supply the name of the variable and the value as a string, just as // you would in a config file. // Returns false if the name lookup failed. bool TessBaseAPI::SetVariable(const char* variable, const char* value) { if (set_new_style_variable(variable, value)) return true; return set_old_style_variable(variable, value); }