Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/extract/src/text.c @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 #include "text.h" | |
| 2 | |
| 3 #include "astring.h" | |
| 4 #include "outf.h" | |
| 5 | |
| 6 #include <assert.h> | |
| 7 #include <errno.h> | |
| 8 #include <string.h> | |
| 9 | |
| 10 | |
| 11 int | |
| 12 extract_content_insert( | |
| 13 extract_alloc_t *alloc, | |
| 14 const char *original, | |
| 15 const char *single_name, | |
| 16 const char *mid_begin_name, | |
| 17 const char *mid_end_name, | |
| 18 extract_astring_t *contentss, | |
| 19 int contentss_num, | |
| 20 char **o_out) | |
| 21 { | |
| 22 int e = -1; | |
| 23 const char *mid_begin = NULL; | |
| 24 const char *mid_end = NULL; | |
| 25 const char *single = NULL; | |
| 26 extract_astring_t out; | |
| 27 extract_astring_init(&out); | |
| 28 | |
| 29 assert(single_name || mid_begin_name || mid_end_name); | |
| 30 | |
| 31 if (single_name) single = strstr(original, single_name); | |
| 32 | |
| 33 if (single) | |
| 34 { | |
| 35 outf("Have found single_name='%s', using in preference to mid_begin_name=%s mid_end_name=%s", | |
| 36 single_name, | |
| 37 mid_begin_name, | |
| 38 mid_end_name); | |
| 39 mid_begin = single; | |
| 40 mid_end = single + strlen(single_name); | |
| 41 } | |
| 42 else | |
| 43 { | |
| 44 if (mid_begin_name) { | |
| 45 mid_begin = strstr(original, mid_begin_name); | |
| 46 if (!mid_begin) { | |
| 47 outf("error: could not find '%s' in odt content", mid_begin_name); | |
| 48 errno = ESRCH; | |
| 49 goto end; | |
| 50 } | |
| 51 mid_begin += strlen(mid_begin_name); | |
| 52 } | |
| 53 if (mid_end_name) { | |
| 54 mid_end = strstr(mid_begin ? mid_begin : original, mid_end_name); | |
| 55 if (!mid_end) { | |
| 56 outf("error: could not find '%s' in odt content", mid_end_name); | |
| 57 e = -1; | |
| 58 errno = ESRCH; | |
| 59 goto end; | |
| 60 } | |
| 61 } | |
| 62 if (!mid_begin) { | |
| 63 mid_begin = mid_end; | |
| 64 } | |
| 65 if (!mid_end) { | |
| 66 mid_end = mid_begin; | |
| 67 } | |
| 68 } | |
| 69 | |
| 70 if (extract_astring_catl(alloc, &out, original, mid_begin - original)) goto end; | |
| 71 { | |
| 72 int i; | |
| 73 for (i=0; i<contentss_num; ++i) { | |
| 74 if (extract_astring_catl(alloc, &out, contentss[i].chars, contentss[i].chars_num)) goto end; | |
| 75 } | |
| 76 } | |
| 77 assert( mid_end); | |
| 78 /* As per docs, at least one of <single_name>, <mid_begin_name> and | |
| 79 <mid_end_name> is non-null, and this ensures that mid_end must not be null. | |
| 80 */ | |
| 81 /* coverity[var_deref_model] */ | |
| 82 if (extract_astring_cat(alloc, &out, mid_end)) goto end; | |
| 83 | |
| 84 *o_out = out.chars; | |
| 85 out.chars = NULL; | |
| 86 | |
| 87 e = 0; | |
| 88 end: | |
| 89 | |
| 90 if (e) { | |
| 91 extract_astring_free(alloc, &out); | |
| 92 *o_out = NULL; | |
| 93 } | |
| 94 | |
| 95 return e; | |
| 96 } |
