! * \brief l_genDataString() * * \param[in] filein input file of serialized data * \param[in] ifunc index into set of functions in output file * \return encoded ascii data string, or NULL on error reading from file */
| 696 | * \return encoded ascii data string, or NULL on error reading from file |
| 697 | */ |
| 698 | static char * |
| 699 | l_genDataString(const char *filein, |
| 700 | l_int32 ifunc) |
| 701 | { |
| 702 | char buf[80]; |
| 703 | char *cdata1, *cdata2, *cdata3; |
| 704 | l_uint8 *data1, *data2; |
| 705 | l_int32 csize1, csize2; |
| 706 | size_t size1, size2; |
| 707 | SARRAY *sa; |
| 708 | |
| 709 | PROCNAME("l_genDataString"); |
| 710 | |
| 711 | if (!filein) |
| 712 | return (char *)ERROR_PTR("filein not defined", procName, NULL); |
| 713 | |
| 714 | /* Read it in, gzip it, encode, and reformat. We gzip because some |
| 715 | * serialized data has a significant amount of ascii content. */ |
| 716 | if ((data1 = l_binaryRead(filein, &size1)) == NULL) |
| 717 | return (char *)ERROR_PTR("bindata not returned", procName, NULL); |
| 718 | data2 = zlibCompress(data1, size1, &size2); |
| 719 | cdata1 = encodeBase64(data2, size2, &csize1); |
| 720 | cdata2 = reformatPacked64(cdata1, csize1, 4, 72, 1, &csize2); |
| 721 | LEPT_FREE(data1); |
| 722 | LEPT_FREE(data2); |
| 723 | LEPT_FREE(cdata1); |
| 724 | |
| 725 | /* Prepend the string declaration signature and put it together */ |
| 726 | sa = sarrayCreate(3); |
| 727 | snprintf(buf, sizeof(buf), "static const char *l_strdata_%d =\n", ifunc); |
| 728 | sarrayAddString(sa, buf, L_COPY); |
| 729 | sarrayAddString(sa, cdata2, L_INSERT); |
| 730 | sarrayAddString(sa, (char *)";\n", L_COPY); |
| 731 | cdata3 = sarrayToString(sa, 0); |
| 732 | sarrayDestroy(&sa); |
| 733 | return cdata3; |
| 734 | } |
| 735 | |
| 736 | |
| 737 | /*! |
no test coverage detected