* fmorphautogen2() * * Input: sela * fileindex * filename ( ; can be null) * Return: 0 if OK; 1 on error * * Notes: * (1) This function uses morphtemplate2.txt to create a * low-level file that contains the low-level functions for * implementing dilation and erosion for every sel * in the input sela. *
| 487 | * (4) If filename != NULL, the output file is <filename>low.<n>.c. |
| 488 | */ |
| 489 | l_int32 |
| 490 | fmorphautogen2(SELA *sela, |
| 491 | l_int32 fileindex, |
| 492 | const char *filename) |
| 493 | { |
| 494 | char *filestr, *linestr, *fname; |
| 495 | char *str_doc1, *str_doc2, *str_doc3, *str_doc4, *str_def1; |
| 496 | char bigbuf[L_BUF_SIZE]; |
| 497 | char breakstring[] = " break;"; |
| 498 | char staticstring[] = "static void"; |
| 499 | l_int32 i, nsels, nbytes, actstart, end, newstart; |
| 500 | l_int32 argstart, argend, loopstart, loopend, finalstart, finalend; |
| 501 | size_t size; |
| 502 | SARRAY *sa1, *sa2, *sa3, *sa4, *sa5, *sa6; |
| 503 | SEL *sel; |
| 504 | |
| 505 | PROCNAME("fmorphautogen2"); |
| 506 | |
| 507 | if (!sela) |
| 508 | return ERROR_INT("sela not defined", procName, 1); |
| 509 | if (fileindex < 0) |
| 510 | fileindex = 0; |
| 511 | if ((nsels = selaGetCount(sela)) == 0) |
| 512 | return ERROR_INT("no sels in sela", procName, 1); |
| 513 | |
| 514 | /* Make the array of textlines from morphtemplate2.txt */ |
| 515 | if ((filestr = (char *)l_binaryRead(TEMPLATE2, &size)) == NULL) |
| 516 | return ERROR_INT("filestr not made", procName, 1); |
| 517 | sa1 = sarrayCreateLinesFromString(filestr, 1); |
| 518 | LEPT_FREE(filestr); |
| 519 | if (!sa1) |
| 520 | return ERROR_INT("sa1 not made", procName, 1); |
| 521 | |
| 522 | /* Make the array of static function names */ |
| 523 | if ((sa2 = sarrayCreate(2 * nsels)) == NULL) { |
| 524 | sarrayDestroy(&sa1); |
| 525 | return ERROR_INT("sa2 not made", procName, 1); |
| 526 | } |
| 527 | for (i = 0; i < nsels; i++) { |
| 528 | sprintf(bigbuf, "fdilate_%d_%d", fileindex, i); |
| 529 | sarrayAddString(sa2, bigbuf, L_COPY); |
| 530 | sprintf(bigbuf, "ferode_%d_%d", fileindex, i); |
| 531 | sarrayAddString(sa2, bigbuf, L_COPY); |
| 532 | } |
| 533 | |
| 534 | /* Make the static prototype strings */ |
| 535 | sa3 = sarrayCreate(2 * nsels); /* should be ok */ |
| 536 | for (i = 0; i < 2 * nsels; i++) { |
| 537 | fname = sarrayGetString(sa2, i, L_NOCOPY); |
| 538 | sprintf(bigbuf, "static void %s%s", fname, PROTOARGS); |
| 539 | sarrayAddString(sa3, bigbuf, L_COPY); |
| 540 | } |
| 541 | |
| 542 | /* Make strings containing function names */ |
| 543 | sprintf(bigbuf, " * l_int32 fmorphopgen_low_%d()", |
| 544 | fileindex); |
| 545 | str_doc1 = stringNew(bigbuf); |
| 546 | sprintf(bigbuf, " * void fdilate_%d_*()", fileindex); |
no test coverage detected