MCPcopy Create free account
hub / github.com/creatale/node-dv / strcodeFinalize

Function strcodeFinalize

deps/leptonica/src/stringcode.c:335–506  ·  view source on GitHub ↗

! * \brief strcodeFinalize() * * \param[in,out] pstrcode destroys after .c and .h files have been generated * \param[in] outdir [optional] if NULL, files are made in /tmp/lept/auto * \return void */

Source from the content-addressed store, hash-verified

333 * \return void
334 */
335l_int32
336strcodeFinalize(L_STRCODE **pstrcode,
337 const char *outdir)
338{
339char buf[256];
340char *filestr, *casestr, *descr, *datastr, *realoutdir;
341l_int32 actstart, end, newstart, fileno, nbytes;
342size_t size;
343L_STRCODE *strcode;
344SARRAY *sa1, *sa2, *sa3;
345
346 PROCNAME("strcodeFinalize");
347
348 lept_mkdir("lept/auto");
349
350 if (!pstrcode || *pstrcode == NULL)
351 return ERROR_INT("No input data", procName, 1);
352 strcode = *pstrcode;
353 if (!outdir) {
354 L_INFO("no outdir specified; writing to /tmp/lept/auto\n", procName);
355 realoutdir = stringNew("/tmp/lept/auto");
356 } else {
357 realoutdir = stringNew(outdir);
358 }
359
360 /* ------------------------------------------------------- */
361 /* Make the output autogen.*.c file */
362 /* ------------------------------------------------------- */
363
364 /* Make array of textlines from TEMPLATE1 */
365 filestr = (char *)l_binaryRead(TEMPLATE1, &size);
366 sa1 = sarrayCreateLinesFromString(filestr, 1);
367 LEPT_FREE(filestr);
368 sa3 = sarrayCreate(0);
369
370 /* Copyright notice */
371 sarrayParseRange(sa1, 0, &actstart, &end, &newstart, "--", 0);
372 sarrayAppendRange(sa3, sa1, actstart, end);
373
374 /* File name comment */
375 fileno = strcode->fileno;
376 snprintf(buf, sizeof(buf), " * autogen.%d.c", fileno);
377 sarrayAddString(sa3, buf, L_COPY);
378
379 /* More text */
380 sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
381 sarrayAppendRange(sa3, sa1, actstart, end);
382
383 /* Description of function types by index */
384 descr = sarrayToString(strcode->descr, 1);
385 descr[strlen(descr) - 1] = '\0';
386 sarrayAddString(sa3, descr, L_INSERT);
387
388 /* Includes */
389 sarrayParseRange(sa1, newstart, &actstart, &end, &newstart, "--", 0);
390 sarrayAppendRange(sa3, sa1, actstart, end);
391 snprintf(buf, sizeof(buf), "#include \"autogen.%d.h\"", fileno);
392 sarrayAddString(sa3, buf, L_COPY);

Callers 1

strcodeCreateFromFileFunction · 0.85

Calls 12

lept_mkdirFunction · 0.85
stringNewFunction · 0.85
l_binaryReadFunction · 0.85
sarrayCreateFunction · 0.85
sarrayParseRangeFunction · 0.85
sarrayAppendRangeFunction · 0.85
sarrayAddStringFunction · 0.85
sarrayToStringFunction · 0.85
l_binaryWriteFunction · 0.85
sarrayDestroyFunction · 0.85
strcodeDestroyFunction · 0.85

Tested by

no test coverage detected