88 #include <config_auto.h>
92 #include "allheaders.h"
95 #define TEMPLATE1 "stringtemplate1.txt"
96 #define TEMPLATE2 "stringtemplate2.txt"
112 {0,
"INVALID",
"invalid",
"invalid",
"invalid" },
113 {1,
"BOXA",
"Boxa",
"boxaRead",
"boxaReadMem" },
114 {2,
"BOXAA",
"Boxaa",
"boxaaRead",
"boxaaReadMem" },
115 {3,
"L_DEWARP",
"Dewarp",
"dewarpRead",
"dewarpReadMem" },
116 {4,
"L_DEWARPA",
"Dewarpa",
"dewarpaRead",
"dewarpaReadMem" },
117 {5,
"L_DNA",
"L_Dna",
"l_dnaRead",
"l_dnaReadMem" },
118 {6,
"L_DNAA",
"L_Dnaa",
"l_dnaaRead",
"l_dnaaReadMem" },
119 {7,
"DPIX",
"DPix",
"dpixRead",
"dpixReadMem" },
120 {8,
"FPIX",
"FPix",
"fpixRead",
"fpixReadMem" },
121 {9,
"NUMA",
"Numa",
"numaRead",
"numaReadMem" },
122 {10,
"NUMAA",
"Numaa",
"numaaRead",
"numaaReadMem" },
123 {11,
"PIX",
"Pix",
"pixRead",
"pixReadMem" },
124 {12,
"PIXA",
"Pixa",
"pixaRead",
"pixaReadMem" },
125 {13,
"PIXAA",
"Pixaa",
"pixaaRead",
"pixaaReadMem" },
126 {14,
"PIXACOMP",
"Pixacomp",
"pixacompRead",
"pixacompReadMem" },
127 {15,
"PIXCMAP",
"Pixcmap",
"pixcmapRead",
"pixcmapReadMem" },
128 {16,
"PTA",
"Pta",
"ptaRead",
"ptaReadMem" },
129 {17,
"PTAA",
"Ptaa",
"ptaaRead",
"ptaaReadMem" },
130 {18,
"RECOG",
"Recog",
"recogRead",
"recogReadMem" },
131 {19,
"SARRAY",
"Sarray",
"sarrayRead",
"sarrayReadMem" }
139 static char *
l_genDescrString(
const char *filein, l_int32 ifunc, l_int32 itype);
166 return (
L_STRCODE *)ERROR_PTR(
"strcode not made", __func__, NULL);
187 if (pstrcode == NULL) {
188 L_WARNING(
"ptr address is null!\n", __func__);
192 if ((strcode = *pstrcode) == NULL)
234 return ERROR_INT(
"filein not defined", __func__, 1);
237 return ERROR_INT(
"data not read from file", __func__, 1);
241 return ERROR_INT(
"sa not made", __func__, 1);
244 return ERROR_INT(
"no filenames in the file", __func__, 1);
249 for (i = 0; i < n; i++) {
251 if (fname[0] ==
'#')
continue;
253 L_ERROR(
"File %s has no recognizable type\n", __func__, fname);
256 L_INFO(
"File %s is type %s\n", __func__, fname, type);
289 char *strdata, *strfunc, *strdescr;
293 return ERROR_INT(
"strcode not defined", __func__, 1);
295 return ERROR_INT(
"filein not defined", __func__, 1);
297 return ERROR_INT(
"type not defined", __func__, 1);
301 return ERROR_INT(
"data type unknown", __func__, 1);
305 return ERROR_INT(
"strdata not made", __func__, 1);
335 char *filestr, *casestr, *descr, *datastr, *realoutdir;
336 l_int32 actstart, end, newstart, fileno, nbytes;
343 if (!pstrcode || *pstrcode == NULL)
344 return ERROR_INT(
"No input data", __func__, 1);
347 L_INFO(
"no outdir specified; writing to /tmp/lept/auto\n", __func__);
348 realoutdir =
stringNew(
"/tmp/lept/auto");
369 snprintf(buf,
sizeof(buf),
" * autogen.%d.c", fileno);
378 descr[strlen(descr) - 1] =
'\0';
384 snprintf(buf,
sizeof(buf),
"#include \"autogen.%d.h\"", fileno);
392 snprintf(buf,
sizeof(buf),
" * \\brief l_autodecode_%d()", fileno);
400 snprintf(buf,
sizeof(buf),
"l_autodecode_%d(l_int32 index)", fileno);
408 snprintf(buf,
sizeof(buf),
"l_int32 nfunc = %d;\n", strcode->
n);
412 snprintf(buf,
sizeof(buf),
" PROCNAME(\"l_autodecode_%d\");", fileno);
421 casestr[strlen(casestr) - 1] =
'\0';
430 nbytes = strlen(filestr);
431 snprintf(buf,
sizeof(buf),
"%s/autogen.%d.c", realoutdir, fileno);
452 snprintf(buf,
sizeof(buf),
" * autogen.%d.h", fileno);
460 snprintf(buf,
sizeof(buf),
"#ifndef LEPTONICA_AUTOGEN_%d_H\n"
461 "#define LEPTONICA_AUTOGEN_%d_H",
470 snprintf(buf,
sizeof(buf),
"void *l_autodecode_%d(l_int32 index);", fileno);
479 datastr[strlen(datastr) - 1] =
'\0';
483 snprintf(buf,
sizeof(buf),
"#endif /* LEPTONICA_AUTOGEN_%d_H */", fileno);
488 nbytes = strlen(filestr);
489 snprintf(buf,
sizeof(buf),
"%s/autogen.%d.h", realoutdir, fileno);
492 LEPT_FREE(realoutdir);
525 return ERROR_INT(
"&str not defined", __func__, 1);
528 return ERROR_INT(
"filename not defined", __func__, 1);
531 return ERROR_INT(
"invalid field", __func__, 1);
534 return ERROR_INT(
"index not retrieved", __func__, 1);
569 return ERROR_INT(
"&index not defined", __func__, 1);
572 return ERROR_INT(
"type string not defined", __func__, 1);
576 if (strcmp(type,
l_assoc[i].type) == 0) {
607 return ERROR_INT(
"&index not defined", __func__, 1);
610 return ERROR_INT(
"sn string not defined", __func__, 1);
614 if (strcmp(sn,
l_assoc[i].structname) == 0) {
638 l_int32 notfound, format;
642 return ERROR_INT(
"&index not defined", __func__, 1);
645 return ERROR_INT(
"filename not defined", __func__, 1);
650 return ERROR_INT(
"stream not opened", __func__, 1);
652 if ((fgets(buf,
sizeof(buf), fp)) == NULL) {
654 return ERROR_INT(
"fgets read fail", __func__, 1);
656 }
while (buf[0] ==
'\n');
669 return ERROR_INT(
"no file type identified", __func__, 1);
689 char *cdata1, *cdata2, *cdata3;
690 l_uint8 *data1, *data2;
691 l_int32 csize1, csize2;
696 return (
char *)ERROR_PTR(
"filein not defined", __func__, NULL);
701 return (
char *)ERROR_PTR(
"bindata not returned", __func__, NULL);
703 cdata1 = encodeBase64(data2, size2, &csize1);
704 cdata2 = reformatPacked64(cdata1, csize1, 4, 72, 1, &csize2);
711 snprintf(buf,
sizeof(buf),
"static const char *l_strdata_%d =\n", ifunc);
740 snprintf(buf,
sizeof(buf),
" case %d:\n", ifunc);
742 snprintf(buf,
sizeof(buf),
743 " data1 = decodeBase64(l_strdata_%d, strlen(l_strdata_%d), "
744 "&size1);\n", ifunc, ifunc);
747 " data2 = zlibUncompress(data1, size1, &size2);\n");
748 snprintf(buf,
sizeof(buf),
749 " result = (void *)%s(data2, size2);\n",
776 return (
char *)ERROR_PTR(
"filein not defined", __func__, NULL);
779 snprintf(buf,
sizeof(buf),
" * %-2d %-10s %-14s %s",
l_ok findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
SARRAY * sarrayCreateWordsFromString(const char *string)
sarrayCreateWordsFromString()
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
l_int32 sarrayParseRange(SARRAY *sa, l_int32 start, l_int32 *pactualstart, l_int32 *pend, l_int32 *pnewstart, const char *substr, l_int32 loc)
sarrayParseRange()
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
l_ok sarrayAppendRange(SARRAY *sa1, SARRAY *sa2, l_int32 start, l_int32 end)
sarrayAppendRange()
static l_int32 l_getIndexFromType(const char *type, l_int32 *pindex)
l_getIndexFromType()
static l_int32 l_getIndexFromFile(const char *file, l_int32 *pindex)
l_getIndexFromFile()
static char * l_genCaseString(l_int32 ifunc, l_int32 itype)
l_genCaseString()
l_ok strcodeGenerate(L_STRCODE *strcode, const char *filein, const char *type)
strcodeGenerate()
static void strcodeDestroy(L_STRCODE **pstrcode)
strcodeDestroy()
static char * l_genDataString(const char *filein, l_int32 ifunc)
l_genDataString()
static const struct L_GenAssoc l_assoc[]
static l_int32 l_getIndexFromStructname(const char *sn, l_int32 *pindex)
l_getIndexFromStructname()
L_STRCODE * strcodeCreate(l_int32 fileno)
strcodeCreate()
l_int32 strcodeFinalize(L_STRCODE **pstrcode, const char *outdir)
strcodeFinalize()
l_ok strcodeCreateFromFile(const char *filein, l_int32 fileno, const char *outdir)
strcodeCreateFromFile()
l_int32 l_getStructStrFromFile(const char *filename, l_int32 field, char **pstr)
l_getStructStrFromFile()
static const l_int32 l_ntypes
static char * l_genDescrString(const char *filein, l_int32 ifunc, l_int32 itype)
l_genDescrString()
char * stringNew(const char *src)
stringNew()
l_ok stringJoinIP(char **psrc1, const char *src2)
stringJoinIP()
l_ok splitPathAtDirectory(const char *pathname, char **pdir, char **ptail)
splitPathAtDirectory()
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
l_ok l_binaryWrite(const char *filename, const char *operation, const void *data, size_t nbytes)
l_binaryWrite()
FILE * fopenReadStream(const char *filename)
fopenReadStream()
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
l_uint8 * zlibCompress(const l_uint8 *datain, size_t nin, size_t *pnout)
zlibCompress()