Leptonica  1.82.0
Image processing and image analysis suite
stringcode.c
Go to the documentation of this file.
1 /*====================================================================*
2  - Copyright (C) 2001 Leptonica. All rights reserved.
3  -
4  - Redistribution and use in source and binary forms, with or without
5  - modification, are permitted provided that the following conditions
6  - are met:
7  - 1. Redistributions of source code must retain the above copyright
8  - notice, this list of conditions and the following disclaimer.
9  - 2. Redistributions in binary form must reproduce the above
10  - copyright notice, this list of conditions and the following
11  - disclaimer in the documentation and/or other materials
12  - provided with the distribution.
13  -
14  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18  - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *====================================================================*/
26 
87 #ifdef HAVE_CONFIG_H
88 #include <config_auto.h>
89 #endif /* HAVE_CONFIG_H */
90 
91 #include <string.h>
92 #include "allheaders.h"
93 #include "stringcode.h"
94 
95 #define TEMPLATE1 "stringtemplate1.txt" /* for assembling autogen.*.c */
96 #define TEMPLATE2 "stringtemplate2.txt" /* for assembling autogen.*.h */
97 
99 struct L_GenAssoc
100 {
101  l_int32 index;
102  char type[16]; /* e.g., "PIXA" */
103  char structname[16]; /* e.g., "Pixa" */
104  char reader[16]; /* e.g., "pixaRead" */
105  char memreader[20]; /* e.g., "pixaReadMem" */
106 };
107 
109 static const l_int32 l_ntypes = 19;
111 static const struct L_GenAssoc l_assoc[] = {
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" }
132 };
133 
134 static l_int32 l_getIndexFromType(const char *type, l_int32 *pindex);
135 static l_int32 l_getIndexFromStructname(const char *sn, l_int32 *pindex);
136 static l_int32 l_getIndexFromFile(const char *file, l_int32 *pindex);
137 static char *l_genDataString(const char *filein, l_int32 ifunc);
138 static char *l_genCaseString(l_int32 ifunc, l_int32 itype);
139 static char *l_genDescrString(const char *filein, l_int32 ifunc, l_int32 itype);
140 
141 /*---------------------------------------------------------------------*/
142 /* Stringcode functions */
143 /*---------------------------------------------------------------------*/
158 L_STRCODE *
159 strcodeCreate(l_int32 fileno)
160 {
161 L_STRCODE *strcode;
162 
163  PROCNAME("strcodeCreate");
164 
165  lept_mkdir("lept/auto");
166 
167  if ((strcode = (L_STRCODE *)LEPT_CALLOC(1, sizeof(L_STRCODE))) == NULL)
168  return (L_STRCODE *)ERROR_PTR("strcode not made", procName, NULL);
169 
170  strcode->fileno = fileno;
171  strcode->function = sarrayCreate(0);
172  strcode->data = sarrayCreate(0);
173  strcode->descr = sarrayCreate(0);
174  return strcode;
175 }
176 
177 
184 static void
186 {
187 L_STRCODE *strcode;
188 
189  PROCNAME("strcodeDestroy");
190 
191  if (pstrcode == NULL) {
192  L_WARNING("ptr address is null!\n", procName);
193  return;
194  }
195 
196  if ((strcode = *pstrcode) == NULL)
197  return;
198 
199  sarrayDestroy(&strcode->function);
200  sarrayDestroy(&strcode->data);
201  sarrayDestroy(&strcode->descr);
202  LEPT_FREE(strcode);
203  *pstrcode = NULL;
204 }
205 
206 
224 l_ok
225 strcodeCreateFromFile(const char *filein,
226  l_int32 fileno,
227  const char *outdir)
228 {
229 char *fname;
230 const char *type;
231 l_uint8 *data;
232 size_t nbytes;
233 l_int32 i, n, index;
234 SARRAY *sa;
235 L_STRCODE *strcode;
236 
237  PROCNAME("strcodeCreateFromFile");
238 
239  if (!filein)
240  return ERROR_INT("filein not defined", procName, 1);
241 
242  if ((data = l_binaryRead(filein, &nbytes)) == NULL)
243  return ERROR_INT("data not read from file", procName, 1);
244  sa = sarrayCreateLinesFromString((char *)data, 0);
245  LEPT_FREE(data);
246  if (!sa)
247  return ERROR_INT("sa not made", procName, 1);
248  if ((n = sarrayGetCount(sa)) == 0) {
249  sarrayDestroy(&sa);
250  return ERROR_INT("no filenames in the file", procName, 1);
251  }
252 
253  strcode = strcodeCreate(fileno);
254 
255  for (i = 0; i < n; i++) {
256  fname = sarrayGetString(sa, i, L_NOCOPY);
257  if (fname[0] == '#') continue;
258  if (l_getIndexFromFile(fname, &index)) {
259  L_ERROR("File %s has no recognizable type\n", procName, fname);
260  } else {
261  type = l_assoc[index].type;
262  L_INFO("File %s is type %s\n", procName, fname, type);
263  strcodeGenerate(strcode, fname, type);
264  }
265  }
266  strcodeFinalize(&strcode, outdir);
267  sarrayDestroy(&sa);
268  return 0;
269 }
270 
271 
290 l_ok
292  const char *filein,
293  const char *type)
294 {
295 char *strdata, *strfunc, *strdescr;
296 l_int32 itype;
297 
298  PROCNAME("strcodeGenerate");
299 
300  if (!strcode)
301  return ERROR_INT("strcode not defined", procName, 1);
302  if (!filein)
303  return ERROR_INT("filein not defined", procName, 1);
304  if (!type)
305  return ERROR_INT("type not defined", procName, 1);
306 
307  /* Get the index corresponding to type and validate */
308  if (l_getIndexFromType(type, &itype) == 1)
309  return ERROR_INT("data type unknown", procName, 1);
310 
311  /* Generate the encoded data string */
312  if ((strdata = l_genDataString(filein, strcode->ifunc)) == NULL)
313  return ERROR_INT("strdata not made", procName, 1);
314  sarrayAddString(strcode->data, strdata, L_INSERT);
315 
316  /* Generate the case data for the decoding function */
317  strfunc = l_genCaseString(strcode->ifunc, itype);
318  sarrayAddString(strcode->function, strfunc, L_INSERT);
319 
320  /* Generate row of table for function type selection */
321  strdescr = l_genDescrString(filein, strcode->ifunc, itype);
322  sarrayAddString(strcode->descr, strdescr, L_INSERT);
323 
324  strcode->n++;
325  strcode->ifunc++;
326  return 0;
327 }
328 
329 
338 l_int32
340  const char *outdir)
341 {
342 char buf[256];
343 char *filestr, *casestr, *descr, *datastr, *realoutdir;
344 l_int32 actstart, end, newstart, fileno, nbytes;
345 size_t size;
346 L_STRCODE *strcode;
347 SARRAY *sa1, *sa2, *sa3;
348 
349  PROCNAME("strcodeFinalize");
350 
351  lept_mkdir("lept/auto");
352 
353  if (!pstrcode || *pstrcode == NULL)
354  return ERROR_INT("No input data", procName, 1);
355  strcode = *pstrcode;
356  if (!outdir) {
357  L_INFO("no outdir specified; writing to /tmp/lept/auto\n", procName);
358  realoutdir = stringNew("/tmp/lept/auto");
359  } else {
360  realoutdir = stringNew(outdir);
361  }
362 
363  /* ------------------------------------------------------- */
364  /* Make the output autogen.*.c file */
365  /* ------------------------------------------------------- */
366 
367  /* Make array of textlines from TEMPLATE1 */
368  filestr = (char *)l_binaryRead(TEMPLATE1, &size);
369  sa1 = sarrayCreateLinesFromString(filestr, 1);
370  LEPT_FREE(filestr);
371  sa3 = sarrayCreate(0);
372 
373  /* Copyright notice */
374  sarrayParseRange(sa1, 0, &actstart, &end, &newstart, "--", 0);
375  sarrayAppendRange(sa3, sa1, actstart, end);
376 
377  /* File name comment */
378  fileno = strcode->fileno;
379  snprintf(buf, sizeof(buf), " * autogen.%d.c", fileno);
380  sarrayAddString(sa3, buf, L_COPY);
381 
382  /* More text */
383  sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
384  sarrayAppendRange(sa3, sa1, actstart, end);
385 
386  /* Description of function types by index */
387  descr = sarrayToString(strcode->descr, 1);
388  descr[strlen(descr) - 1] = '\0';
389  sarrayAddString(sa3, descr, L_INSERT);
390 
391  /* Includes */
392  sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
393  sarrayAppendRange(sa3, sa1, actstart, end);
394  snprintf(buf, sizeof(buf), "#include \"autogen.%d.h\"", fileno);
395  sarrayAddString(sa3, buf, L_COPY);
396 
397  /* Header for auto-generated deserializers */
398  sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
399  sarrayAppendRange(sa3, sa1, actstart, end);
400 
401  /* Function name (as comment) */
402  snprintf(buf, sizeof(buf), " * \\brief l_autodecode_%d()", fileno);
403  sarrayAddString(sa3, buf, L_COPY);
404 
405  /* Input and return values */
406  sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
407  sarrayAppendRange(sa3, sa1, actstart, end);
408 
409  /* Function name */
410  snprintf(buf, sizeof(buf), "l_autodecode_%d(l_int32 index)", fileno);
411  sarrayAddString(sa3, buf, L_COPY);
412 
413  /* Stack vars */
414  sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
415  sarrayAppendRange(sa3, sa1, actstart, end);
416 
417  /* Declaration of nfunc on stack */
418  snprintf(buf, sizeof(buf), "l_int32 nfunc = %d;\n", strcode->n);
419  sarrayAddString(sa3, buf, L_COPY);
420 
421  /* Declaration of PROCNAME */
422  snprintf(buf, sizeof(buf), " PROCNAME(\"l_autodecode_%d\");", fileno);
423  sarrayAddString(sa3, buf, L_COPY);
424 
425  /* Test input variables */
426  sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
427  sarrayAppendRange(sa3, sa1, actstart, end);
428 
429  /* Insert case string */
430  casestr = sarrayToString(strcode->function, 0);
431  casestr[strlen(casestr) - 1] = '\0';
432  sarrayAddString(sa3, casestr, L_INSERT);
433 
434  /* End of function */
435  sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
436  sarrayAppendRange(sa3, sa1, actstart, end);
437 
438  /* Flatten to string and output to autogen*.c file */
439  filestr = sarrayToString(sa3, 1);
440  nbytes = strlen(filestr);
441  snprintf(buf, sizeof(buf), "%s/autogen.%d.c", realoutdir, fileno);
442  l_binaryWrite(buf, "w", filestr, nbytes);
443  LEPT_FREE(filestr);
444  sarrayDestroy(&sa1);
445  sarrayDestroy(&sa3);
446 
447  /* ------------------------------------------------------- */
448  /* Make the output autogen.*.h file */
449  /* ------------------------------------------------------- */
450 
451  /* Make array of textlines from TEMPLATE2 */
452  filestr = (char *)l_binaryRead(TEMPLATE2, &size);
453  sa2 = sarrayCreateLinesFromString(filestr, 1);
454  LEPT_FREE(filestr);
455  sa3 = sarrayCreate(0);
456 
457  /* Copyright notice */
458  sarrayParseRange(sa2, 0, &actstart, &end, &newstart, "--", 0);
459  sarrayAppendRange(sa3, sa2, actstart, end);
460 
461  /* File name comment */
462  snprintf(buf, sizeof(buf), " * autogen.%d.h", fileno);
463  sarrayAddString(sa3, buf, L_COPY);
464 
465  /* More text */
466  sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
467  sarrayAppendRange(sa3, sa2, actstart, end);
468 
469  /* Beginning header protection */
470  snprintf(buf, sizeof(buf), "#ifndef LEPTONICA_AUTOGEN_%d_H\n"
471  "#define LEPTONICA_AUTOGEN_%d_H",
472  fileno, fileno);
473  sarrayAddString(sa3, buf, L_COPY);
474 
475  /* Prototype header text */
476  sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
477  sarrayAppendRange(sa3, sa2, actstart, end);
478 
479  /* Prototype declaration */
480  snprintf(buf, sizeof(buf), "void *l_autodecode_%d(l_int32 index);", fileno);
481  sarrayAddString(sa3, buf, L_COPY);
482 
483  /* Prototype trailer text */
484  sarrayParseRange(sa2, newstart, &actstart, &end, &newstart, "--", 0);
485  sarrayAppendRange(sa3, sa2, actstart, end);
486 
487  /* Insert serialized data strings */
488  datastr = sarrayToString(strcode->data, 1);
489  datastr[strlen(datastr) - 1] = '\0';
490  sarrayAddString(sa3, datastr, L_INSERT);
491 
492  /* End header protection */
493  snprintf(buf, sizeof(buf), "#endif /* LEPTONICA_AUTOGEN_%d_H */", fileno);
494  sarrayAddString(sa3, buf, L_COPY);
495 
496  /* Flatten to string and output to autogen*.h file */
497  filestr = sarrayToString(sa3, 1);
498  nbytes = strlen(filestr);
499  snprintf(buf, sizeof(buf), "%s/autogen.%d.h", realoutdir, fileno);
500  l_binaryWrite(buf, "w", filestr, nbytes);
501  LEPT_FREE(filestr);
502  LEPT_FREE(realoutdir);
503  sarrayDestroy(&sa2);
504  sarrayDestroy(&sa3);
505 
506  /* Cleanup */
507  strcodeDestroy(pstrcode);
508  return 0;
509 }
510 
511 
527 l_int32
528 l_getStructStrFromFile(const char *filename,
529  l_int32 field,
530  char **pstr)
531 {
532 l_int32 index;
533 
534  PROCNAME("l_getStructStrFromFile");
535 
536  if (!pstr)
537  return ERROR_INT("&str not defined", procName, 1);
538  *pstr = NULL;
539  if (!filename)
540  return ERROR_INT("filename not defined", procName, 1);
541  if (field != L_STR_TYPE && field != L_STR_NAME &&
542  field != L_STR_READER && field != L_STR_MEMREADER)
543  return ERROR_INT("invalid field", procName, 1);
544 
545  if (l_getIndexFromFile(filename, &index))
546  return ERROR_INT("index not retrieved", procName, 1);
547  if (field == L_STR_TYPE)
548  *pstr = stringNew(l_assoc[index].type);
549  else if (field == L_STR_NAME)
550  *pstr = stringNew(l_assoc[index].structname);
551  else if (field == L_STR_READER)
552  *pstr = stringNew(l_assoc[index].reader);
553  else /* field == L_STR_MEMREADER */
554  *pstr = stringNew(l_assoc[index].memreader);
555  return 0;
556 }
557 
558 
559 /*---------------------------------------------------------------------*/
560 /* Static helpers */
561 /*---------------------------------------------------------------------*/
574 static l_int32
575 l_getIndexFromType(const char *type,
576  l_int32 *pindex)
577 {
578 l_int32 i, found;
579 
580  PROCNAME("l_getIndexFromType");
581 
582  if (!pindex)
583  return ERROR_INT("&index not defined", procName, 1);
584  *pindex = 0;
585  if (!type)
586  return ERROR_INT("type string not defined", procName, 1);
587 
588  found = 0;
589  for (i = 1; i <= l_ntypes; i++) {
590  if (strcmp(type, l_assoc[i].type) == 0) {
591  found = 1;
592  *pindex = i;
593  break;
594  }
595  }
596  return !found;
597 }
598 
599 
614 static l_int32
616  l_int32 *pindex)
617 {
618 l_int32 i, found;
619 
620  PROCNAME("l_getIndexFromStructname");
621 
622  if (!pindex)
623  return ERROR_INT("&index not defined", procName, 1);
624  *pindex = 0;
625  if (!sn)
626  return ERROR_INT("sn string not defined", procName, 1);
627 
628  found = 0;
629  for (i = 1; i <= l_ntypes; i++) {
630  if (strcmp(sn, l_assoc[i].structname) == 0) {
631  found = 1;
632  *pindex = i;
633  break;
634  }
635  }
636  return !found;
637 }
638 
639 
647 static l_int32
648 l_getIndexFromFile(const char *filename,
649  l_int32 *pindex)
650 {
651 char buf[256];
652 char *word;
653 FILE *fp;
654 l_int32 notfound, format;
655 SARRAY *sa;
656 
657  PROCNAME("l_getIndexFromFile");
658 
659  if (!pindex)
660  return ERROR_INT("&index not defined", procName, 1);
661  *pindex = 0;
662  if (!filename)
663  return ERROR_INT("filename not defined", procName, 1);
664 
665  /* Open the stream, read lines until you find one with more
666  * than a newline, and grab the first word. */
667  if ((fp = fopenReadStream(filename)) == NULL)
668  return ERROR_INT("stream not opened", procName, 1);
669  do {
670  if ((fgets(buf, sizeof(buf), fp)) == NULL) {
671  fclose(fp);
672  return ERROR_INT("fgets read fail", procName, 1);
673  }
674  } while (buf[0] == '\n');
675  fclose(fp);
676  sa = sarrayCreateWordsFromString(buf);
677  word = sarrayGetString(sa, 0, L_NOCOPY);
678 
679  /* Find the index associated with the word. If it is not
680  * found, test to see if the file is a compressed pix. */
681  notfound = l_getIndexFromStructname(word, pindex);
682  sarrayDestroy(&sa);
683  if (notfound) { /* maybe a Pix */
684  if (findFileFormat(filename, &format) == 0) {
685  l_getIndexFromStructname("Pix", pindex);
686  } else {
687  return ERROR_INT("no file type identified", procName, 1);
688  }
689  }
690 
691  return 0;
692 }
693 
694 
702 static char *
703 l_genDataString(const char *filein,
704  l_int32 ifunc)
705 {
706 char buf[80];
707 char *cdata1, *cdata2, *cdata3;
708 l_uint8 *data1, *data2;
709 l_int32 csize1, csize2;
710 size_t size1, size2;
711 SARRAY *sa;
712 
713  PROCNAME("l_genDataString");
714 
715  if (!filein)
716  return (char *)ERROR_PTR("filein not defined", procName, NULL);
717 
718  /* Read it in, gzip it, encode, and reformat. We gzip because some
719  * serialized data has a significant amount of ascii content. */
720  if ((data1 = l_binaryRead(filein, &size1)) == NULL)
721  return (char *)ERROR_PTR("bindata not returned", procName, NULL);
722  data2 = zlibCompress(data1, size1, &size2);
723  cdata1 = encodeBase64(data2, size2, &csize1);
724  cdata2 = reformatPacked64(cdata1, csize1, 4, 72, 1, &csize2);
725  LEPT_FREE(data1);
726  LEPT_FREE(data2);
727  LEPT_FREE(cdata1);
728 
729  /* Prepend the string declaration signature and put it together */
730  sa = sarrayCreate(3);
731  snprintf(buf, sizeof(buf), "static const char *l_strdata_%d =\n", ifunc);
732  sarrayAddString(sa, buf, L_COPY);
733  sarrayAddString(sa, cdata2, L_INSERT);
734  sarrayAddString(sa, ";\n", L_COPY);
735  cdata3 = sarrayToString(sa, 0);
736  sarrayDestroy(&sa);
737  return cdata3;
738 }
739 
740 
753 static char *
754 l_genCaseString(l_int32 ifunc,
755  l_int32 itype)
756 {
757 char buf[256];
758 char *code = NULL;
759 
760  snprintf(buf, sizeof(buf), " case %d:\n", ifunc);
761  stringJoinIP(&code, buf);
762  snprintf(buf, sizeof(buf),
763  " data1 = decodeBase64(l_strdata_%d, strlen(l_strdata_%d), "
764  "&size1);\n", ifunc, ifunc);
765  stringJoinIP(&code, buf);
766  stringJoinIP(&code,
767  " data2 = zlibUncompress(data1, size1, &size2);\n");
768  snprintf(buf, sizeof(buf),
769  " result = (void *)%s(data2, size2);\n",
770  l_assoc[itype].memreader);
771  stringJoinIP(&code, buf);
772  stringJoinIP(&code, " lept_free(data1);\n");
773  stringJoinIP(&code, " lept_free(data2);\n");
774  stringJoinIP(&code, " break;\n");
775  return code;
776 }
777 
778 
787 static char *
788 l_genDescrString(const char *filein,
789  l_int32 ifunc,
790  l_int32 itype)
791 {
792 char buf[256];
793 char *tail;
794 
795  PROCNAME("l_genDescrString");
796 
797  if (!filein)
798  return (char *)ERROR_PTR("filein not defined", procName, NULL);
799 
800  splitPathAtDirectory(filein, NULL, &tail);
801  snprintf(buf, sizeof(buf), " * %-2d %-10s %-14s %s",
802  ifunc, l_assoc[itype].type, l_assoc[itype].reader, tail);
803 
804  LEPT_FREE(tail);
805  return stringNew(buf);
806 }
@ L_COPY
Definition: pix.h:712
@ L_NOCOPY
Definition: pix.h:710
@ L_INSERT
Definition: pix.h:711
l_ok findFileFormat(const char *filename, l_int32 *pformat)
findFileFormat()
Definition: readfile.c:584
SARRAY * sarrayCreate(l_int32 n)
sarrayCreate()
Definition: sarray1.c:170
char * sarrayGetString(SARRAY *sa, l_int32 index, l_int32 copyflag)
sarrayGetString()
Definition: sarray1.c:703
l_int32 sarrayGetCount(SARRAY *sa)
sarrayGetCount()
Definition: sarray1.c:643
void sarrayDestroy(SARRAY **psa)
sarrayDestroy()
Definition: sarray1.c:362
SARRAY * sarrayCreateWordsFromString(const char *string)
sarrayCreateWordsFromString()
Definition: sarray1.c:233
SARRAY * sarrayCreateLinesFromString(const char *string, l_int32 blankflag)
sarrayCreateLinesFromString()
Definition: sarray1.c:283
l_ok sarrayAddString(SARRAY *sa, const char *string, l_int32 copyflag)
sarrayAddString()
Definition: sarray1.c:451
l_int32 sarrayParseRange(SARRAY *sa, l_int32 start, l_int32 *pactualstart, l_int32 *pend, l_int32 *pnewstart, const char *substr, l_int32 loc)
sarrayParseRange()
Definition: sarray1.c:1356
char * sarrayToString(SARRAY *sa, l_int32 addnlflag)
sarrayToString()
Definition: sarray1.c:785
l_ok sarrayAppendRange(SARRAY *sa1, SARRAY *sa2, l_int32 start, l_int32 end)
sarrayAppendRange()
Definition: sarray1.c:1012
static l_int32 l_getIndexFromType(const char *type, l_int32 *pindex)
l_getIndexFromType()
Definition: stringcode.c:575
static l_int32 l_getIndexFromFile(const char *file, l_int32 *pindex)
l_getIndexFromFile()
Definition: stringcode.c:648
static char * l_genCaseString(l_int32 ifunc, l_int32 itype)
l_genCaseString()
Definition: stringcode.c:754
l_ok strcodeGenerate(L_STRCODE *strcode, const char *filein, const char *type)
strcodeGenerate()
Definition: stringcode.c:291
static void strcodeDestroy(L_STRCODE **pstrcode)
strcodeDestroy()
Definition: stringcode.c:185
static char * l_genDataString(const char *filein, l_int32 ifunc)
l_genDataString()
Definition: stringcode.c:703
static const struct L_GenAssoc l_assoc[]
Definition: stringcode.c:111
static l_int32 l_getIndexFromStructname(const char *sn, l_int32 *pindex)
l_getIndexFromStructname()
Definition: stringcode.c:615
L_STRCODE * strcodeCreate(l_int32 fileno)
strcodeCreate()
Definition: stringcode.c:159
l_int32 strcodeFinalize(L_STRCODE **pstrcode, const char *outdir)
strcodeFinalize()
Definition: stringcode.c:339
l_ok strcodeCreateFromFile(const char *filein, l_int32 fileno, const char *outdir)
strcodeCreateFromFile()
Definition: stringcode.c:225
l_int32 l_getStructStrFromFile(const char *filename, l_int32 field, char **pstr)
l_getStructStrFromFile()
Definition: stringcode.c:528
static const l_int32 l_ntypes
Definition: stringcode.c:109
static char * l_genDescrString(const char *filein, l_int32 ifunc, l_int32 itype)
l_genDescrString()
Definition: stringcode.c:788
@ L_STR_TYPE
Definition: stringcode.h:55
@ L_STR_READER
Definition: stringcode.h:57
@ L_STR_MEMREADER
Definition: stringcode.h:58
@ L_STR_NAME
Definition: stringcode.h:56
SARRAY * data
Definition: stringcode.h:45
l_int32 ifunc
Definition: stringcode.h:43
l_int32 fileno
Definition: stringcode.h:42
l_int32 n
Definition: stringcode.h:47
SARRAY * function
Definition: stringcode.h:44
SARRAY * descr
Definition: stringcode.h:46
Definition: array.h:127
char * stringNew(const char *src)
stringNew()
Definition: utils2.c:223
l_ok stringJoinIP(char **psrc1, const char *src2)
stringJoinIP()
Definition: utils2.c:573
l_ok splitPathAtDirectory(const char *pathname, char **pdir, char **ptail)
splitPathAtDirectory()
Definition: utils2.c:2824
l_int32 lept_mkdir(const char *subdir)
lept_mkdir()
Definition: utils2.c:2218
l_ok l_binaryWrite(const char *filename, const char *operation, const void *data, size_t nbytes)
l_binaryWrite()
Definition: utils2.c:1569
FILE * fopenReadStream(const char *filename)
fopenReadStream()
Definition: utils2.c:1932
l_uint8 * l_binaryRead(const char *filename, size_t *pnbytes)
l_binaryRead()
Definition: utils2.c:1352
l_uint8 * zlibCompress(const l_uint8 *datain, size_t nin, size_t *pnout)
zlibCompress()
Definition: zlibmem.c:92