+ if (utf8_strlen(get_buf_string(&write_buffer)) > MAXGEDCLINELEN) {
+ gedcom_error(_("Line too long"));
+ }
+ else {
+ converted = convert_from_utf8(hndl->conv, get_buf_string(&write_buffer),
+ &conv_fails, &outlen);
+
+ if (converted && (conv_fails == 0)) {
+ line_no++;
+ write(hndl->filedesc, converted, outlen);
+ }
+ else {
+ hndl->total_conv_fails += conv_fails;
+ gedcom_error
+ (_("Error converting output string: %s (%d conversion failures)"),
+ strerror(errno), conv_fails);
+ }
+ }
+ }
+ return 0;
+}
+
+int write_encoding(Gedcom_write_hndl hndl,
+ int level, char* xref, char* tag, char* value)
+{
+ if (strcmp(value, charset))
+ gedcom_warning(_("Forcing HEAD.CHAR value to '%s'"), charset);
+ return write_simple(hndl, level, xref, tag, charset);
+}
+
+int supports_continuation(int elt_or_rec, int which_continuation)
+{
+ return tag_data[elt_or_rec].options & which_continuation;
+}
+
+int write_long(Gedcom_write_hndl hndl, int elt_or_rec,
+ int level, const char* xref, const char* tag, const char* value)
+{
+ int prefix_len, value_len = 0, term_len;
+ char* nl_pos = NULL;
+ if (value) nl_pos = strchr(value, '\n');
+
+ prefix_len = utf8_strlen(tag) + 3; /* for e.g. "0 INDI " */
+ if (level > 9) prefix_len++;
+ if (xref) prefix_len += utf8_strlen(xref) + 1;
+ if (value) value_len = utf8_strlen(value);
+ term_len = strlen(hndl->term);
+
+ if (!nl_pos && prefix_len + value_len + term_len <= MAXWRITELEN)
+ write_simple(hndl, level, xref, tag, value);
+ else {
+ const char* value_ptr = value;
+ int cont_supported = supports_continuation(elt_or_rec, OPT_CONT);
+ int cont_as_conc = supports_continuation(elt_or_rec, OPT_CONT_AS_CONC);
+ if (nl_pos && !cont_supported) {
+ gedcom_error (_("The tag %s doesn't support newlines"), tag);
+ return 1;
+ }