/*! * parseStringForNumbers() * * Input: string (containing numbers; not changed) * seps (string of characters that can be used between ints) * Return: numa (of numbers found), or null on error * * Note: * (1) The numbers can be ints or floats. */ NUMA * parseStringForNumbers(const char *str, const char *seps) { char *newstr, *head, *tail; l_float32 val; NUMA *na; PROCNAME("parseStringForNumbers"); if (!str) return (NUMA *)ERROR_PTR("str not defined", procName, NULL); newstr = stringNew(str); /* to enforce const-ness of str */ na = numaCreate(0); head = strtokSafe(newstr, seps, &tail); val = atof(head); numaAddNumber(na, val); FREE(head); while ((head = strtokSafe(NULL, seps, &tail)) != NULL) { val = atof(head); numaAddNumber(na, val); FREE(head); } FREE(newstr); return na; }
/* * sarraySplitString() * * Input: sa (to append to; typically empty initially) * str (string to split; not changed) * separators (characters that split input string) * Return: 0 if OK, 1 on error. * * Notes: * (1) This uses strtokSafe(). See the notes there in utils.c. */ l_int32 sarraySplitString(SARRAY *sa, const char *str, const char *separators) { char *cstr, *substr, *saveptr; PROCNAME("sarraySplitString"); if (!sa) return ERROR_INT("sa not defined", procName, 1); if (!str) return ERROR_INT("str not defined", procName, 1); if (!separators) return ERROR_INT("separators not defined", procName, 1); cstr = stringNew(str); /* preserves const-ness of input str */ substr = strtokSafe(cstr, separators, &saveptr); if (substr) sarrayAddString(sa, substr, L_INSERT); while ((substr = strtokSafe(NULL, separators, &saveptr))) sarrayAddString(sa, substr, L_INSERT); FREE(cstr); return 0; }
/*! * getImagelibVersions() * * Return: string of version numbers; e.g., * libgif 5.0.3 * libjpeg 8b * libpng 1.4.3 * libtiff 3.9.5 * zlib 1.2.5 * libwebp 0.3.0 * libopenjp2 2.1.0 * * Notes: * (1) The caller has responsibility to free the memory. */ char * getImagelibVersions() { char buf[128]; l_int32 first = TRUE; #if HAVE_LIBJPEG struct jpeg_compress_struct cinfo; struct jpeg_error_mgr err; char buffer[JMSG_LENGTH_MAX]; #endif char *tempStrP; char *versionNumP; char *nextTokenP; char *versionStrP = stringNew(""); #if HAVE_LIBGIF first = FALSE; stringJoinInPlace(versionStrP, "libgif "); #ifdef GIFLIB_MAJOR snprintf(buf, sizeof(buf), "%d.%d.%d", GIFLIB_MAJOR, GIFLIB_MINOR, GIFLIB_RELEASE); #else stringCopy(buf, "4.1.6(?)", sizeof(buf)); #endif stringJoinInPlace(versionStrP, buf); #endif #if HAVE_LIBJPEG cinfo.err = jpeg_std_error(&err); err.msg_code = JMSG_VERSION; (*err.format_message) ((j_common_ptr ) &cinfo, buffer); if (!first) stringJoinInPlace(versionStrP, " : "); first = FALSE; stringJoinInPlace(versionStrP, "libjpeg "); versionNumP = strtokSafe(buffer, " ", &nextTokenP); stringJoinInPlace(versionStrP, versionNumP); FREE(versionNumP); #endif #if HAVE_LIBPNG if (!first) stringJoinInPlace(versionStrP, " : "); first = FALSE; stringJoinInPlace(versionStrP, "libpng "); stringJoinInPlace(versionStrP, png_get_libpng_ver(NULL)); #endif #if HAVE_LIBTIFF if (!first) stringJoinInPlace(versionStrP, " : "); first = FALSE; stringJoinInPlace(versionStrP, "libtiff "); versionNumP = strtokSafe((char *)TIFFGetVersion(), " \n", &nextTokenP); FREE(versionNumP); versionNumP = strtokSafe(NULL, " \n", &nextTokenP); FREE(versionNumP); versionNumP = strtokSafe(NULL, " \n", &nextTokenP); stringJoinInPlace(versionStrP, versionNumP); FREE(versionNumP); #endif #if HAVE_LIBZ if (!first) stringJoinInPlace(versionStrP, " : "); first = FALSE; stringJoinInPlace(versionStrP, "zlib "); stringJoinInPlace(versionStrP, zlibVersion()); #endif #if HAVE_LIBWEBP { l_int32 val; char buf[32]; if (!first) stringJoinInPlace(versionStrP, " : "); first = FALSE; stringJoinInPlace(versionStrP, "libwebp "); val = WebPGetEncoderVersion(); snprintf(buf, sizeof(buf), "%d.%d.%d", val >> 16, (val >> 8) & 0xff, val & 0xff); stringJoinInPlace(versionStrP, buf); } #endif #if HAVE_LIBJP2K { const char *version; if (!first) stringJoinInPlace(versionStrP, " : "); first = FALSE; stringJoinInPlace(versionStrP, "libopenjp2 "); version = opj_version(); stringJoinInPlace(versionStrP, version); } #endif stringJoinInPlace(versionStrP, "\n"); return versionStrP; }
/*! * getImagelibVersions() * * Return: string of version numbers; e.g., * libgif 5.0.3 * libjpeg 8b (libjpeg-turbo 1.3.0) * libpng 1.4.3 * libtiff 3.9.5 * zlib 1.2.5 * libwebp 0.3.0 * libopenjp2 2.1.0 * * Notes: * (1) The caller must free the memory. */ char * getImagelibVersions() { char buf[128]; l_int32 first = TRUE; char *versionNumP; char *nextTokenP; char *versionStrP = NULL; #if HAVE_LIBGIF first = FALSE; stringJoinIP(&versionStrP, "libgif "); #ifdef GIFLIB_MAJOR snprintf(buf, sizeof(buf), "%d.%d.%d", GIFLIB_MAJOR, GIFLIB_MINOR, GIFLIB_RELEASE); #else stringCopy(buf, "4.1.6(?)", sizeof(buf)); #endif stringJoinIP(&versionStrP, buf); #endif /* HAVE_LIBGIF */ #if HAVE_LIBJPEG { struct jpeg_compress_struct cinfo; struct jpeg_error_mgr err; char buffer[JMSG_LENGTH_MAX]; cinfo.err = jpeg_std_error(&err); err.msg_code = JMSG_VERSION; (*err.format_message) ((j_common_ptr ) &cinfo, buffer); if (!first) stringJoinIP(&versionStrP, " : "); first = FALSE; stringJoinIP(&versionStrP, "libjpeg "); versionNumP = strtokSafe(buffer, " ", &nextTokenP); stringJoinIP(&versionStrP, versionNumP); FREE(versionNumP); #if defined(LIBJPEG_TURBO_VERSION) /* To stringify the result of expansion of a macro argument, * you must use two levels of macros. See: * https://gcc.gnu.org/onlinedocs/cpp/Stringification.html */ #define l_xstr(s) l_str(s) #define l_str(s) #s snprintf(buf, sizeof(buf), " (libjpeg-turbo %s)", l_xstr(LIBJPEG_TURBO_VERSION)); stringJoinIP(&versionStrP, buf); #endif /* LIBJPEG_TURBO_VERSION */ } #endif /* HAVE_LIBJPEG */ #if HAVE_LIBPNG if (!first) stringJoinIP(&versionStrP, " : "); first = FALSE; stringJoinIP(&versionStrP, "libpng "); stringJoinIP(&versionStrP, png_get_libpng_ver(NULL)); #endif /* HAVE_LIBPNG */ #if HAVE_LIBTIFF if (!first) stringJoinIP(&versionStrP, " : "); first = FALSE; stringJoinIP(&versionStrP, "libtiff "); versionNumP = strtokSafe((char *)TIFFGetVersion(), " \n", &nextTokenP); FREE(versionNumP); versionNumP = strtokSafe(NULL, " \n", &nextTokenP); FREE(versionNumP); versionNumP = strtokSafe(NULL, " \n", &nextTokenP); stringJoinIP(&versionStrP, versionNumP); FREE(versionNumP); #endif /* HAVE_LIBTIFF */ #if HAVE_LIBZ if (!first) stringJoinIP(&versionStrP, " : "); first = FALSE; stringJoinIP(&versionStrP, "zlib "); stringJoinIP(&versionStrP, zlibVersion()); #endif /* HAVE_LIBZ */ #if HAVE_LIBWEBP { l_int32 val; char buf[32]; if (!first) stringJoinIP(&versionStrP, " : "); first = FALSE; stringJoinIP(&versionStrP, "libwebp "); val = WebPGetEncoderVersion(); snprintf(buf, sizeof(buf), "%d.%d.%d", val >> 16, (val >> 8) & 0xff, val & 0xff); stringJoinIP(&versionStrP, buf); } #endif /* HAVE_LIBWEBP */ #if HAVE_LIBJP2K { const char *version; if (!first) stringJoinIP(&versionStrP, " : "); first = FALSE; stringJoinIP(&versionStrP, "libopenjp2 "); version = opj_version(); stringJoinIP(&versionStrP, version); } #endif /* HAVE_LIBJP2K */ stringJoinIP(&versionStrP, "\n"); return versionStrP; }