* We've got two lists of fields, the old list from the original * format string and the new one from the parsed gettext reply. The * new list has the localized words, where the old list has the * formatting information. We need to combine them into a single list * (the new list). * * If the list needs to be reordered, then we've got more serious work * to do. */
| 6048 | * to do. |
| 6049 | */ |
| 6050 | static int |
| 6051 | xo_gettext_combine_formats (xo_handle_t *xop, const char *fmt UNUSED, |
| 6052 | const char *gtfmt, xo_field_info_t *old_fields, |
| 6053 | xo_field_info_t *new_fields, unsigned new_max_fields, |
| 6054 | int *reorderedp) |
| 6055 | { |
| 6056 | int reordered = 0; |
| 6057 | xo_field_info_t *newp, *oldp, *startp = old_fields; |
| 6058 | |
| 6059 | xo_gettext_finish_numbering_fields(xop, fmt, old_fields); |
| 6060 | |
| 6061 | for (newp = new_fields; newp->xfi_ftype; newp++) { |
| 6062 | switch (newp->xfi_ftype) { |
| 6063 | case XO_ROLE_NEWLINE: |
| 6064 | case XO_ROLE_TEXT: |
| 6065 | case XO_ROLE_EBRACE: |
| 6066 | continue; |
| 6067 | |
| 6068 | case 'V': |
| 6069 | for (oldp = startp; oldp->xfi_ftype; oldp++) { |
| 6070 | if (oldp->xfi_ftype != 'V') |
| 6071 | continue; |
| 6072 | if (newp->xfi_clen != oldp->xfi_clen |
| 6073 | || strncmp(newp->xfi_content, oldp->xfi_content, |
| 6074 | oldp->xfi_clen) != 0) { |
| 6075 | reordered = 1; |
| 6076 | continue; |
| 6077 | } |
| 6078 | startp = oldp + 1; |
| 6079 | break; |
| 6080 | } |
| 6081 | |
| 6082 | /* Didn't find it on the first pass (starting from start) */ |
| 6083 | if (oldp->xfi_ftype == 0) { |
| 6084 | for (oldp = old_fields; oldp < startp; oldp++) { |
| 6085 | if (oldp->xfi_ftype != 'V') |
| 6086 | continue; |
| 6087 | if (newp->xfi_clen != oldp->xfi_clen) |
| 6088 | continue; |
| 6089 | if (strncmp(newp->xfi_content, oldp->xfi_content, |
| 6090 | oldp->xfi_clen) != 0) |
| 6091 | continue; |
| 6092 | reordered = 1; |
| 6093 | break; |
| 6094 | } |
| 6095 | if (oldp == startp) { |
| 6096 | /* Field not found */ |
| 6097 | xo_failure(xop, "post-gettext format can't find field " |
| 6098 | "'%.*s' in format '%s'", |
| 6099 | newp->xfi_clen, newp->xfi_content, |
| 6100 | xo_printable(gtfmt)); |
| 6101 | return -1; |
| 6102 | } |
| 6103 | } |
| 6104 | break; |
| 6105 | |
| 6106 | default: |
| 6107 | /* |
no test coverage detected