pspp-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 4/5] file_handle: Store the character encoding of the file name


From: John Darrington
Subject: [PATCH 4/5] file_handle: Store the character encoding of the file name
Date: Thu, 8 Oct 2015 18:30:26 +0200

---
 src/data/file-handle-def.c |   13 +++++++++++--
 src/data/file-handle-def.h |    3 ++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/data/file-handle-def.c b/src/data/file-handle-def.c
index a7e2788..5a78a79 100644
--- a/src/data/file-handle-def.c
+++ b/src/data/file-handle-def.c
@@ -50,6 +50,7 @@ struct file_handle
 
     /* FH_REF_FILE only. */
     char *file_name;           /* File name as provided by user. */
+    char *file_name_encoding;  /* The character encoding of the file name (or 
NULL if unknown). */
     enum fh_mode mode;         /* File mode. */
     enum fh_line_ends line_ends; /* Line ends for text files. */
 
@@ -114,6 +115,7 @@ free_handle (struct file_handle *handle)
   free (handle->id);
   free (handle->name);
   free (handle->file_name);
+  free (handle->file_name_encoding);
   free (handle->encoding);
   free (handle);
 }
@@ -233,11 +235,10 @@ fh_create_file (const char *id, const char *file_name, 
const char *file_name_enc
   char *handle_name;
   struct file_handle *handle;
 
-  //  printf ("%s:%d Creating file handle for file %s with encoding %s\n", 
__FILE__, __LINE__, file_name, file_name_encoding);
-
   handle_name = id != NULL ? xstrdup (id) : xasprintf ("`%s'", file_name);
   handle = create_handle (id, handle_name, FH_REF_FILE, properties->encoding);
   handle->file_name = xstrdup (file_name);
+  handle->file_name_encoding = file_name_encoding ? xstrdup 
(file_name_encoding) : NULL;
   handle->mode = properties->mode;
   handle->line_ends = properties->line_ends;
   handle->record_width = properties->record_width;
@@ -316,6 +317,14 @@ fh_get_file_name (const struct file_handle *handle)
   return handle->file_name;
 }
 
+const char *
+fh_get_file_name_encoding (const struct file_handle *handle)
+{
+  assert (handle->referent == FH_REF_FILE);
+  return handle->file_name_encoding;
+}
+
+
 /* Returns the mode of HANDLE. */
 enum fh_mode
 fh_get_mode (const struct file_handle *handle)
diff --git a/src/data/file-handle-def.h b/src/data/file-handle-def.h
index a57d3d7..2fa73e5 100644
--- a/src/data/file-handle-def.h
+++ b/src/data/file-handle-def.h
@@ -98,7 +98,8 @@ const char *fh_get_encoding (const struct file_handle *);
 
 /* Properties of FH_REF_FILE file handles. */
 const char *fh_get_file_name (const struct file_handle *);
-enum fh_mode fh_get_mode (const struct file_handle *) ;
+const char *fh_get_file_name_encoding (const struct file_handle *handle);
+enum fh_mode fh_get_mode (const struct file_handle *) ; /*  */
 enum fh_line_ends fh_get_line_ends (const struct file_handle *);
 
 /* Properties of FH_REF_FILE and FH_REF_INLINE file handles. */
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]