#include <stdio.h>
#include <stdlib.h>
#include "variables.h"
#include "callcpp.h"
#include "listio.h"
#include "globals.h"
#include "scanutils.h"
Go to the source code of this file.
#define scan_int | ( | stripped, | |||
integer | ) |
Value:
if (stripped [2] == 'x') \ sscanf (&stripped[3], "%x", &integer); \ else \ sscanf (&stripped[1], "%d", &integer)
It might be in decimal or hex. Read it into "integer".
Definition at line 48 of file variables.cpp.
Referenced by int_read(), and vfscanf().
void add_32bit_variable | ( | void * | address, | |
const char * | string, | |||
VALUE | default_value, | |||
variables_io | reader, | |||
variables_io | writer | |||
) |
Add a new 32bit variable to the global variable list.
Initalize its value.
Definition at line 100 of file variables.cpp.
References VARIABLE::address, VARIABLE::default_value, VALUE::int_part, push(), VARIABLE::string, VARIABLE::type_reader, VARIABLE::type_writer, and variable_list.
00104 { 00105 VARIABLE *this_var; 00106 this_var = (VARIABLE *) malloc (sizeof (VARIABLE)); 00107 00108 this_var->address = address; 00109 this_var->string = string; 00110 this_var->default_value = default_value; 00111 this_var->type_reader = reader; 00112 this_var->type_writer = writer; 00113 00114 *((int *) this_var->address) = default_value.int_part; 00115 variable_list = push (variable_list, this_var); 00116 }
void add_ptr_variable | ( | void * | address, | |
const char * | string, | |||
VALUE | default_value, | |||
variables_io | reader, | |||
variables_io | writer | |||
) |
Add a new variable to the global variable list & initalize its value.
address | Location of Name | |
string | Name of variable | |
default_value | Default value | |
reader | Function to read this variable (type) | |
writer | Function to write this variable (type) |
Definition at line 76 of file variables.cpp.
References VARIABLE::address, VARIABLE::default_value, VALUE::ptr_part, push(), VARIABLE::string, VARIABLE::type_reader, VARIABLE::type_writer, and variable_list.
00080 { 00081 VARIABLE *this_var; 00082 this_var = (VARIABLE *) malloc (sizeof (VARIABLE)); 00083 00084 this_var->address = address; 00085 this_var->string = string; 00086 this_var->default_value = default_value; 00087 this_var->type_reader = reader; 00088 this_var->type_writer = writer; 00089 00090 *((void **) this_var->address) = default_value.ptr_part; 00091 variable_list = push (variable_list, this_var); 00092 }
void float_read | ( | VARIABLE * | variable, | |
char * | string | |||
) |
Read a float value and save it in a variable structure.
Definition at line 122 of file variables.cpp.
References VARIABLE::address, f, strip_line(), and strtofloat().
00122 { 00123 float f; 00124 00125 #ifdef EMBEDDED 00126 // We have no sscanf with float functionality here 00127 *((float *) variable->address) = strtofloat(strip_line (string)); 00128 #else 00129 sscanf (strip_line (string), "%f", &f); 00130 *((float *) variable->address) = f; 00131 #endif 00132 }
void float_write | ( | VARIABLE * | variable, | |
char * | string | |||
) |
Write a float value to string.
Definition at line 138 of file variables.cpp.
References VARIABLE::address, f, and VARIABLE::string.
00138 { 00139 float *f; 00140 f = (float *) variable->address; 00141 sprintf (string, "%s\t%4.2f", variable->string, *f); 00142 }
void free_variables | ( | ) |
Free up memory used by tesseract variables.
Definition at line 61 of file variables.cpp.
References destroy_nodes(), NIL, and variable_list.
Referenced by program_editdown().
00061 { 00062 destroy_nodes(variable_list, free); 00063 variable_list = NIL; 00064 }
void int_read | ( | VARIABLE * | variable, | |
char * | string | |||
) |
Read an integer value and save it in a variable structure.
Definition at line 148 of file variables.cpp.
References VARIABLE::address, scan_int, and strip_line().
00148 { 00149 char *stripped; 00150 int integer; 00151 00152 stripped = strip_line (string); 00153 /* Add the value */ 00154 if (stripped[0] == '+') { 00155 scan_int(stripped, integer); 00156 *((int *) variable->address) += integer; 00157 } 00158 else if (stripped[0] == '|') { 00159 scan_int(stripped, integer); 00160 *((int *) variable->address) = integer | *((int *) variable->address); 00161 } /* Subtract the value */ 00162 else if (stripped[0] == '_') { 00163 scan_int(stripped, integer); 00164 *((int *) variable->address) = (~integer) & 00165 *((int *) variable->address); 00166 } 00167 else { 00168 /* Set the value */ 00169 if (stripped[1] == 'x') { 00170 sscanf (&stripped[2], "%x", &integer); 00171 } 00172 else { 00173 sscanf (stripped, "%d", &integer); 00174 } 00175 *((int *) variable->address) = integer; 00176 } 00177 }
void int_write | ( | VARIABLE * | variable, | |
char * | string | |||
) |
Write an integer value to string.
Definition at line 183 of file variables.cpp.
References VARIABLE::address, and VARIABLE::string.
void read_variables | ( | const char * | filename | ) |
Read a file that contains assignments for all the desired variables.
filename | Name of file to read |
Definition at line 197 of file variables.cpp.
References cprintf(), demodir, first, iterate, NULL, read_list(), same_var_name(), search(), VARIABLE::type_reader, and variable_list.
Referenced by program_editup().
00197 { 00198 int x = 0; 00199 char *this_string; 00200 LIST var_strings; 00201 char name[1024]; 00202 FILE *fp; 00203 VARIABLE *this_var; 00204 /* Read the strings */ 00205 if (filename == NULL || filename[0] == '\0') 00206 return; 00207 00208 strcpy(name, demodir); 00209 strcat (name, "tessdata/tessconfigs/"); 00210 strcat(name, filename); 00211 if ((fp = fopen (name, "r")) == NULL) 00212 strcpy(name, filename); 00213 else 00214 fclose(fp); 00215 var_strings = read_list (name); 00216 iterate(var_strings) { 00217 /* Get the name string */ 00218 this_string = (char *) first (var_strings); 00219 if (this_string[0] != '#') { 00220 for (x = 0; 00221 x < strlen (this_string) && this_string[x] != ' ' 00222 && this_string[x] != '\t'; x++); 00223 this_string[x] = '\0'; 00224 /* Find variable record */ 00225 this_var = (VARIABLE *) first (search (variable_list, this_string, 00226 same_var_name)); 00227 if (this_var == 0) { 00228 #ifndef TEXT_VERBOSE 00229 cprintf ("error: Could not find variable '%s'\n", this_string); 00230 exit (1); //?err_exit (); 00231 #else 00232 cprintf ("error: Could not find variable '%s', skipping\n", this_string); 00233 continue; 00234 #endif 00235 } 00236 /* Read the value */ 00237 this_string[x] = '\t'; 00238 (*(this_var->type_reader)) (this_var, this_string); 00239 } 00240 } 00241 }
int same_var_name | ( | void * | item1, | |
void * | item2 | |||
) |
Return TRUE if the VARIABLE has the name string in it.
Definition at line 247 of file variables.cpp.
References FALSE, VARIABLE::string, and TRUE.
Referenced by read_variables().
00248 { //char *string) 00249 VARIABLE *variable; 00250 char *string; 00251 00252 variable = (VARIABLE *) item1; 00253 string = (char *) item2; 00254 00255 if (strcmp (variable->string, string)) 00256 return (FALSE); 00257 else 00258 return (TRUE); 00259 }
void string_read | ( | VARIABLE * | variable, | |
char * | string | |||
) |
Read a string and save it in a variable structure.
Definition at line 265 of file variables.cpp.
References VARIABLE::address, strip_line(), and strsave.
00265 { 00266 char *value; 00267 00268 value = strsave (strip_line (string)); 00269 *((char **) variable->address) = value; 00270 }
void string_write | ( | VARIABLE * | variable, | |
char * | string | |||
) |
Write a string to ??
Definition at line 276 of file variables.cpp.
References VARIABLE::address, and VARIABLE::string.
00276 { 00277 sprintf (string, "%s\t%s", variable->string, 00278 *((char **) variable->address)); 00279 }
char* strip_line | ( | char * | string | ) |
Remove the name off the front of the line and strip the white space before and after the value.
Definition at line 286 of file variables.cpp.
Referenced by float_read(), int_read(), and string_read().
00286 { 00287 int x; 00288 int y; 00289 00290 /* Skip over name */ 00291 for (x = 0; 00292 x < strlen (string) && string[x] != '\t' && string[x] != ' '; x++); 00293 /* Skip over whitespace */ 00294 while (x < strlen (string) && (string[x] == '\t' || string[x] == ' ')) 00295 x++; 00296 /* Strip trailing whitespace */ 00297 for (y = strlen (string); 00298 y >= 0 && (string[y - 1] == '\t' || string[y - 1] == ' '); y--) 00299 string[y] = '\0'; 00300 /* Return result */ 00301 return (&string[x]); 00302 }
Needed for macros
Definition at line 38 of file variables.cpp.
Referenced by classify_word_pass2(), InitAdaptiveClassifierVars(), InitBlobClassifierVars(), InitMicroFxVars(), InitNormProtoVars(), InitPicoFXVars(), InitStopperVars(), program_variables(), re_segment_word(), read_pd_file(), resegment_box(), and scale_image().
LIST variable_list = NIL [static] |
* (c) Copyright 1989, Hewlett-Packard Company. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License.
Definition at line 35 of file variables.cpp.
Referenced by add_32bit_variable(), add_ptr_variable(), free_variables(), and read_variables().