#include <stdio.h>
#include "clst.h"
#include "strngs.h"
Go to the source code of this file.
#define BOOL_EVAR | ( | name, | |||
val, | |||||
comment | ) |
Value:
/*make BOOL_VARIABLE*/\ BOOL_VARIABLE name(val,#name,comment)
#define BOOL_EVAR_H | ( | name, | |||
val, | |||||
comment | ) |
#define BOOL_VAR | ( | name, | |||
val, | |||||
comment | ) |
Value:
/*make BOOL_VARIABLE*/\ BOOL_VARIABLE name(val,#name,comment)
#define BOOL_VAR_H | ( | name, | |||
val, | |||||
comment | ) |
#define double_EVAR | ( | name, | |||
val, | |||||
comment | ) |
Value:
/*make double_VARIABLE*/\ double_VARIABLE name(val,#name,comment)
#define double_EVAR_H | ( | name, | |||
val, | |||||
comment | ) |
#define double_VAR | ( | name, | |||
val, | |||||
comment | ) |
Value:
/*make double_VARIABLE*/\ double_VARIABLE name(val,#name,comment)
#define double_VAR_H | ( | name, | |||
val, | |||||
comment | ) |
#define INT_EVAR | ( | name, | |||
val, | |||||
comment | ) |
Value:
/*make INT_VARIABLE*/\ INT_VARIABLE name(val,#name,comment)
#define INT_EVAR_H | ( | name, | |||
val, | |||||
comment | ) |
#define INT_VAR | ( | name, | |||
val, | |||||
comment | ) |
Value:
/*make INT_VARIABLE*/\ INT_VARIABLE name(val,#name,comment)
#define INT_VAR_H | ( | name, | |||
val, | |||||
comment | ) |
#define STRING_EVAR | ( | name, | |||
val, | |||||
comment | ) |
Value:
/*make STRING_VARIABLE*/\ STRING_VARIABLE name(val,#name,comment)
#define STRING_EVAR_H | ( | name, | |||
val, | |||||
comment | ) |
#define STRING_VAR | ( | name, | |||
val, | |||||
comment | ) |
Value:
/*make STRING_VARIABLE*/\ STRING_VARIABLE name(val,#name,comment)
#define STRING_VAR_H | ( | name, | |||
val, | |||||
comment | ) |
DLLSYM void print_variables | ( | FILE * | fp | ) |
Print all variable types to the given file.
Definition at line 627 of file varable.cpp.
References double_VARIABLE::print(), STRING_VARIABLE::print(), BOOL_VARIABLE::print(), and INT_VARIABLE::print().
Referenced by init_tesseract(), and main_setup().
00629 { 00630 INT_VARIABLE::print(fp); //print INTs 00631 BOOL_VARIABLE::print(fp); //print BOOLs 00632 STRING_VARIABLE::print(fp); //print STRINGs 00633 double_VARIABLE::print(fp); //print doubles 00634 }
DLLSYM BOOL8 read_variables_file | ( | const char * | file | ) |
Read a file of variables definitions and set/modify the values therein.
If the filename begins with a + or -, the BOOL_VARIABLEs will be ORed or ANDed with any current values. Blank lines and lines beginning # are ignored. Values may have any whitespace after the name and are the rest of line.
Definition at line 471 of file varable.cpp.
References EQUAL, FALSE, double_VARIABLE::head, STRING_VARIABLE::head, BOOL_VARIABLE::head, INT_VARIABLE::head, INT32FORMAT, MAX_PATH, MINUS, NULL, PLUS, strtofloat(), tprintf(), and TRUE.
Referenced by init_tesseract(), and main_setup().
00473 { 00474 BOOL8 anyerr; //true if any error 00475 char flag; //file flag 00476 BOOL8 foundit; //found variable 00477 INT16 length; //length of line 00478 INT16 nameoffset; //offset for real name 00479 char *valptr; //value field 00480 char *stringend; //end of string value 00481 FILE *fp; //file pointer 00482 INT32 intval; //value from file 00483 double doubleval; //value form file 00484 //iterators 00485 INT_VARIABLE_C_IT int_it = &INT_VARIABLE::head; 00486 BOOL_VARIABLE_C_IT BOOL_it = &BOOL_VARIABLE::head; 00487 STRING_VARIABLE_C_IT STRING_it = &STRING_VARIABLE::head; 00488 double_VARIABLE_C_IT double_it = &double_VARIABLE::head; 00489 char line[MAX_PATH]; //input line 00490 00491 anyerr = FALSE; 00492 if (*file == PLUS) { 00493 flag = PLUS; //file has flag 00494 nameoffset = 1; 00495 } 00496 else if (*file == MINUS) { 00497 flag = MINUS; 00498 nameoffset = 1; 00499 } 00500 else { 00501 flag = EQUAL; 00502 nameoffset = 0; 00503 } 00504 00505 fp = fopen (file + nameoffset, "r"); 00506 if (fp == NULL) { 00507 tprintf ("read_variables_file:Can't open %s", file + nameoffset); 00508 return TRUE; //can't open it 00509 } 00510 while (fgets (line, MAX_PATH, fp)) { 00511 if (line[0] != '\n' && line[0] != '#') { 00512 length = strlen (line); 00513 if (line[length - 1] == '\n') 00514 line[length - 1] = '\0'; //cut newline 00515 for (valptr = line; *valptr && *valptr != ' ' && *valptr != '\t'; 00516 valptr++); 00517 if (*valptr) { //found blank 00518 *valptr = '\0'; //make name a string 00519 do 00520 00521 valptr++; //find end of blanks 00522 while (*valptr == ' ' || *valptr == '\t'); 00523 00524 if (*valptr && *valptr != '#') { 00525 //last char in string 00526 stringend = valptr + strlen (valptr) - 1; 00527 while (stringend != valptr) { 00528 while (stringend != valptr 00529 && (*stringend == ' ' || *stringend == '\t')) 00530 //cut trailing blanks 00531 stringend--; 00532 stringend[1] = '\0'; //terminate string 00533 00534 while (stringend != valptr 00535 && (*stringend != ' ' && *stringend != '\t' 00536 || stringend[1] != '#')) 00537 stringend--; //find word start 00538 } 00539 } 00540 } 00541 foundit = FALSE; 00542 00543 //find name 00544 for (STRING_it.mark_cycle_pt (); !STRING_it.cycled_list () && strcmp (line, STRING_it.data ()->name); STRING_it.forward ()); 00545 //found it 00546 if (!STRING_it.cycled_list ()) { 00547 foundit = TRUE; //found the varaible 00548 if (*valptr == '\0' || *valptr == '#') 00549 STRING_it.data ()->set_value ((char *) NULL); 00550 //no value 00551 else 00552 //set its value 00553 STRING_it.data ()->set_value (valptr); 00554 } 00555 00556 if (*valptr) { 00557 //find name 00558 for (int_it.mark_cycle_pt (); !int_it.cycled_list () && strcmp (line, int_it.data ()->name); int_it.forward ()); 00559 //found it 00560 if (!int_it.cycled_list () 00561 && sscanf (valptr, INT32FORMAT, &intval) == 1) { 00562 foundit = TRUE; //found the varaible 00563 //set its value 00564 int_it.data ()->set_value (intval); 00565 } 00566 00567 //find name 00568 for (BOOL_it.mark_cycle_pt (); !BOOL_it.cycled_list () && strcmp (line, BOOL_it.data ()->name); BOOL_it.forward ()); 00569 //found it 00570 if (!BOOL_it.cycled_list ()) { 00571 if (*valptr == 'T' || *valptr == 't' 00572 || *valptr == 'Y' || *valptr == 'y' || *valptr == '1') { 00573 foundit = TRUE; 00574 if (flag == MINUS) 00575 BOOL_it.data ()->set_value (FALSE); 00576 //set to false 00577 else 00578 BOOL_it.data ()->set_value (TRUE); 00579 //set to true 00580 } 00581 else if (*valptr == 'F' || *valptr == 'f' 00582 || *valptr == 'N' || *valptr == 'n' 00583 || *valptr == '0') { 00584 foundit = TRUE; 00585 if (flag == EQUAL) 00586 BOOL_it.data ()->set_value (FALSE); 00587 //set to false 00588 } 00589 } 00590 00591 //find name 00592 for (double_it.mark_cycle_pt (); !double_it.cycled_list () && strcmp (line, double_it.data ()->name); double_it.forward ()); 00593 //found it 00594 00595 #ifdef EMBEDDED 00596 if (!double_it.cycled_list ()) { 00597 doubleval = strtofloat(valptr); 00598 #else 00599 if (!double_it.cycled_list () 00600 && sscanf (valptr, "%lf", &doubleval) == 1) { 00601 #endif 00602 foundit = TRUE; //found the varaible 00603 double_it.data ()->set_value (doubleval); 00604 //set its value 00605 } 00606 00607 if (!foundit) { 00608 anyerr = TRUE; //had an error 00609 tprintf ("read_variables_file:variable not found: %s", 00610 line); 00611 } 00612 } 00613 else if (!foundit) { 00614 anyerr = TRUE; //had an error 00615 tprintf ("read_variables_file:No value for variable %s", line); 00616 } 00617 } 00618 } 00619 fclose(fp); //close file 00620 return anyerr; 00621 }
class DLLSYM BOOL_VARIABLE |
class DLLSYM double_VARIABLE |
class DLLSYM INT_VARIABLE |
* (C) Copyright 1991, Hewlett-Packard Ltd. ** 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.
class DLLSYM STRING_VARIABLE |