Leptonica  1.54
Файл stringcode.c
#include <string.h>
#include "allheaders.h"
#include "stringcode.h"

Классы

struct  L_GenAssoc
 

Макросы

#define TEMPLATE1   "stringtemplate1.txt" /* for assembling autogen.*.c */
 
#define TEMPLATE2   "stringtemplate2.txt" /* for assembling autogen.*.h */
 

Функции

static l_int32 l_getIndexFromType (const char *type, l_int32 *pindex)
 
static l_int32 l_getIndexFromStructname (const char *sn, l_int32 *pindex)
 
static l_int32 l_getIndexFromFile (const char *file, l_int32 *pindex)
 
static char * l_genDataString (const char *filein, l_int32 ifunc)
 
static char * l_genCaseString (l_int32 ifunc, l_int32 itype)
 
static char * l_genDescrString (const char *filein, l_int32 ifunc, l_int32 itype)
 
L_STRCODEstrcodeCreate (l_int32 fileno)
 
static void strcodeDestroy (L_STRCODE **pstrcode)
 
l_int32 strcodeCreateFromFile (const char *filein, l_int32 fileno, const char *outdir)
 
l_int32 strcodeGenerate (L_STRCODE *strcode, const char *filein, const char *type)
 
l_int32 strcodeFinalize (L_STRCODE **pstrcode, const char *outdir)
 
l_int32 l_getStructnameFromFile (const char *filename, char **psn)
 

Переменные

static const l_int32 l_ntypes = 20
 
static const struct L_GenAssoc l_assoc []
 

Макросы

◆ TEMPLATE1

#define TEMPLATE1   "stringtemplate1.txt" /* for assembling autogen.*.c */

◆ TEMPLATE2

#define TEMPLATE2   "stringtemplate2.txt" /* for assembling autogen.*.h */

Функции

◆ l_genCaseString()

static char * l_genCaseString ( l_int32  ifunc,
l_int32  itype 
)
static

l_genCaseString()

Input:  ifunc (index into set of functions in generated file)
        itype (index into type of function to be used)
Return: case string for this decoding function

Notes: (1) @ifunc and @itype have been validated, so no error can occur

◆ l_genDataString()

static char * l_genDataString ( const char *  filein,
l_int32  ifunc 
)
static

l_genDataString()

Input:  filein (input file of serialized data)
        ifunc (index into set of functions in output file)
Return: encoded ascii data string, or null on error reading from file

◆ l_genDescrString()

static char * l_genDescrString ( const char *  filein,
l_int32  ifunc,
l_int32  itype 
)
static

l_genDescrString()

Input:  filein (input file of serialized data)
        ifunc (index into set of functions in generated file)
        itype (index into type of function to be used)
Return: description string for this decoding function

◆ l_getIndexFromFile()

static l_int32 l_getIndexFromFile ( const char *  filename,
l_int32 pindex 
)
static

l_getIndexFromFile()

Input:  filename
        &index (<return>)
Return: 0 if found, 1 on error.

◆ l_getIndexFromStructname()

static l_int32 l_getIndexFromStructname ( const char *  sn,
l_int32 pindex 
)
static

l_getIndexFromStructname()

Input:  structname (e.g., "Pixa")
        &index (<return>)
Return: 0 if found, 1 if not.

Notes: (1) This is used to identify the type of serialized file; the first word in the file is the structname. (2) For valid structname, @found == true and @index > 0.

◆ l_getIndexFromType()

static l_int32 l_getIndexFromType ( const char *  type,
l_int32 pindex 
)
static

l_getIndexFromType()

Input:  type (e.g., "PIXA")
        &index (<return>)
Return: 0 if found, 1 if not.

Notes: (1) For valid type, @found == true and @index > 0.

◆ l_getStructnameFromFile()

l_int32 l_getStructnameFromFile ( const char *  filename,
char **  psn 
)

l_getStructnameFromFile()

Input:  filename
        &sn (<return> structname; e.g., "Pixa")
Return: 0 if found, 1 on error.

◆ strcodeCreate()

L_STRCODE* strcodeCreate ( l_int32  fileno)

strcodeCreate()

Input:  fileno (integer that labels the two output files)
Return: initialized L_StrCode, or null on error

Notes: (1) This struct exists to build two files containing code for any number of data objects. The two files are named autogen.<fileno>.c autogen.<fileno>.h

◆ strcodeCreateFromFile()

l_int32 strcodeCreateFromFile ( const char *  filein,
l_int32  fileno,
const char *  outdir 
)

strcodeCreateFromFile()

Input:  filein (containing filenames of serialized data)
        fileno (integer that labels the two output files)
        outdir (<optional> if null, files are made in /tmp/lept/auto)
Return: 0 if OK, 1 on error

Notes: (1) The @filein has one filename on each line. Comment lines begin with "#". (2) The output is 2 files: autogen.<fileno>.c autogen.<fileno>.h

◆ strcodeDestroy()

static void strcodeDestroy ( L_STRCODE **  pstrcode)
static

strcodeDestroy()

Input:  &strcode (strcode is set to null after destroying the sarrays)
Return: void

◆ strcodeFinalize()

l_int32 strcodeFinalize ( L_STRCODE **  pstrcode,
const char *  outdir 
)

strcodeFinalize()

Input: &strcode (destroys after .c and .h files have been generated)
        outdir (<optional> if null, files are made in /tmp/lept/auto)
Return: void

◆ strcodeGenerate()

l_int32 strcodeGenerate ( L_STRCODE strcode,
const char *  filein,
const char *  type 
)

strcodeGenerate()

Input:  strcode (for accumulating data)
        filein (input file with serialized data)
        type (of data; use the typedef string)
Return: 0 if OK, 1 on error.

Notes: (1) The generated function name is l_autodecode_<fileno>() where <fileno> is the index label for the pair of output files. (2) To deserialize this data, the function is called with the argument 'ifunc', which increments each time strcodeGenerate() is called.

Переменные

◆ l_assoc

const struct L_GenAssoc l_assoc[]
static
Инициализатор
= {
{0, "INVALID", "invalid", "invalid" },
{1, "BOXA", "Boxa", "boxaRead" },
{2, "BOXAA", "Boxaa", "boxaaRead" },
{3, "L_DEWARP", "Dewarp", "dewarpRead" },
{4, "L_DEWARPA", "Dewarpa", "dewarpaRead" },
{5, "L_DNA", "L_Dna", "l_dnaRead" },
{6, "L_DNAA", "L_Dnaa", "l_dnaaRead" },
{7, "DPIX", "DPix", "dpixRead" },
{8, "FPIX", "FPix", "fpixRead" },
{9, "NUMA", "Numa", "numaRead" },
{10, "NUMAA", "Numaa", "numaaRead" },
{11, "PIX", "Pix", "pixRead" },
{12, "PIXA", "Pixa", "pixaRead" },
{13, "PIXAA", "Pixaa", "pixaaRead" },
{14, "PIXACOMP", "Pixacomp", "pixacompRead" },
{15, "PIXCMAP", "Pixcmap", "pixcmapRead" },
{16, "PTA", "Pta", "ptaRead" },
{17, "PTAA", "Ptaa", "ptaaRead" },
{18, "RECOG", "Recog", "recogRead" },
{19, "RECOGA", "Recoga", "recogaRead" },
{20, "SARRAY", "Sarray", "sarrayRead" }
}

◆ l_ntypes

const l_int32 l_ntypes = 20
static