! * \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 "#". *
| 220 | * </pre> |
| 221 | */ |
| 222 | l_int32 |
| 223 | strcodeCreateFromFile(const char *filein, |
| 224 | l_int32 fileno, |
| 225 | const char *outdir) |
| 226 | { |
| 227 | char *fname; |
| 228 | const char *type; |
| 229 | l_uint8 *data; |
| 230 | size_t nbytes; |
| 231 | l_int32 i, n, index; |
| 232 | SARRAY *sa; |
| 233 | L_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 | /*! |
nothing calls this directly
no test coverage detected