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

Function strcodeCreateFromFile

deps/leptonica/src/stringcode.c:222–267  ·  view source on GitHub ↗

! * \brief strcodeCreateFromFile() * * \param[in] filein containing filenames of serialized data * \param[in] fileno integer that labels the two output files * \param[in] outdir [optional] if null, files are made in /tmp/lept/auto * \return 0 if OK, 1 on error * * * Notes: * (1) The %filein has one filename on each line. * Comment lines begin with "#". *

Source from the content-addressed store, hash-verified

220 * </pre>
221 */
222l_int32
223strcodeCreateFromFile(const char *filein,
224 l_int32 fileno,
225 const char *outdir)
226{
227char *fname;
228const char *type;
229l_uint8 *data;
230size_t nbytes;
231l_int32 i, n, index;
232SARRAY *sa;
233L_STRCODE *strcode;
234
235 PROCNAME("strcodeCreateFromFile");
236
237 if (!filein)
238 return ERROR_INT("filein not defined", procName, 1);
239
240 if ((data = l_binaryRead(filein, &nbytes)) == NULL)
241 return ERROR_INT("data not read from file", procName, 1);
242 sa = sarrayCreateLinesFromString((char *)data, 0);
243 LEPT_FREE(data);
244 if (!sa)
245 return ERROR_INT("sa not made", procName, 1);
246 if ((n = sarrayGetCount(sa)) == 0) {
247 sarrayDestroy(&sa);
248 return ERROR_INT("no filenames in the file", procName, 1);
249 }
250
251 strcode = strcodeCreate(fileno);
252
253 for (i = 0; i < n; i++) {
254 fname = sarrayGetString(sa, i, L_NOCOPY);
255 if (fname[0] == '#') continue;
256 if (l_getIndexFromFile(fname, &index)) {
257 L_ERROR("File %s has no recognizable type\n", procName, fname);
258 } else {
259 type = l_assoc[index].type;
260 L_INFO("File %s is type %s\n", procName, fname, type);
261 strcodeGenerate(strcode, fname, type);
262 }
263 }
264 strcodeFinalize(&strcode, outdir);
265 sarrayDestroy(&sa);
266 return 0;
267}
268
269
270/*!

Callers

nothing calls this directly

Calls 9

l_binaryReadFunction · 0.85
sarrayGetCountFunction · 0.85
sarrayDestroyFunction · 0.85
strcodeCreateFunction · 0.85
sarrayGetStringFunction · 0.85
l_getIndexFromFileFunction · 0.85
strcodeGenerateFunction · 0.85
strcodeFinalizeFunction · 0.85

Tested by

no test coverage detected