Generate the correct cast error message.
[gedcom-parse.git] / gedcom / write.c
index 1e44ff46476b5a12c92bde65786b765c8cb56323..f880bbbe90ef0279d4ab3b1cbfcccab7c608b38b 100644 (file)
@@ -24,6 +24,7 @@
 #include "gedcom_internal.h"
 #include "gedcom.h"
 #include "encoding.h"
+#include "encoding_state.h"
 #include "tag_data.h"
 #include "buffer.h"
 #include "utf8tools.h"
 
 #define MAXWRITELEN MAXGEDCLINELEN
 
-/* SYS_NEWLINE is defined in config.h */
-struct encoding_state write_encoding =
-{ "ASCII", "ASCII", ONE_BYTE, WITHOUT_BOM, SYS_NEWLINE };
-
 struct Gedcom_write_struct {
   int       filedesc;
   convert_t conv;
@@ -47,19 +44,6 @@ struct Gedcom_write_struct {
   int       ctxt_level;
 };
 
-const char* default_encoding[] = {
-  /* ONE_BYTE */      "ASCII",
-  /* TWO_BYTE_HILO */ "UCS-2BE",
-  /* TWO_BYTE_LOHI */ "UCS-2LE"
-};
-
-const char* terminator[] = {
-  /* END_CR */     "\x0D",
-  /* END_LF */     "\x0A",
-  /* END_CR_LF */  "\x0D\x0A",
-  /* END_LF_CR */  "\x0A\x0D"
-};
-
 void cleanup_write_buffer();
 struct safe_buffer write_buffer = { NULL, 0, NULL, 0, cleanup_write_buffer };
 
@@ -199,47 +183,6 @@ int write_long(Gedcom_write_hndl hndl, int elt_or_rec,
   return 0;
 }
 
-int gedcom_write_set_encoding(const char* new_charset,
-                             Encoding width, Enc_bom bom)
-{
-  char* new_encoding = NULL;
-  if (!strcmp(new_charset, "UNICODE")) {
-    if (width == ONE_BYTE) {
-      gedcom_error(_("Unicode cannot be encoded into one byte"));
-      return 1;
-    }
-    else {
-      new_encoding = get_encoding(new_charset, width);
-      if (new_encoding) {
-       write_encoding.encoding = new_encoding;
-       write_encoding.width = width;
-       write_encoding.bom   = bom;
-       strncpy(write_encoding.charset, new_charset, MAX_CHARSET_LEN);
-      }
-      else
-       return 1;
-    }
-  }
-  else {
-    new_encoding = get_encoding(new_charset, ONE_BYTE);
-    if (new_encoding) {
-      write_encoding.encoding = new_encoding;
-      write_encoding.width = ONE_BYTE;
-      write_encoding.bom   = bom;
-      strncpy(write_encoding.charset, new_charset, MAX_CHARSET_LEN);
-    }
-    else
-      return 1;
-  }
-  return 0;
-}
-
-int gedcom_write_set_line_terminator(Enc_line_end end)
-{
-  strncpy(write_encoding.terminator, terminator[end], MAX_TERMINATOR_LEN);
-  return 0;
-}
-
 Gedcom_write_hndl gedcom_write_open(const char *filename)
 {
   Gedcom_write_hndl hndl;
@@ -249,6 +192,8 @@ Gedcom_write_hndl gedcom_write_open(const char *filename)
   if (!hndl)
     MEMORY_ERROR;
   else {
+    init_write_encoding();
+    init_write_terminator();
     hndl->total_conv_fails = 0;
     hndl->conv = initialize_utf8_conversion(write_encoding.encoding, 0);
     if (!hndl->conv) {