Change enum legacy_encoding to const char *.
[pspp-builds.git] / src / data / file-handle-def.c
index 872559154469cceebbbf3272aab1702a319b80e8..6ed3f8f9f95205158cbf2a33227e5dbec6a81529 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -49,6 +49,7 @@ struct file_handle
     /* FH_REF_FILE only. */
     char *file_name;           /* File name as provided by user. */
     enum fh_mode mode;         /* File mode. */
     /* FH_REF_FILE only. */
     char *file_name;           /* File name as provided by user. */
     enum fh_mode mode;         /* File mode. */
+    const char *encoding;       /* File encoding. */
 
     /* FH_REF_FILE and FH_REF_INLINE only. */
     size_t record_width;        /* Length of fixed-format records. */
 
     /* FH_REF_FILE and FH_REF_INLINE only. */
     size_t record_width;        /* Length of fixed-format records. */
@@ -234,6 +235,7 @@ fh_create_file (const char *id, const char *file_name,
   handle->mode = properties->mode;
   handle->record_width = properties->record_width;
   handle->tab_width = properties->tab_width;
   handle->mode = properties->mode;
   handle->record_width = properties->record_width;
   handle->tab_width = properties->tab_width;
+  handle->encoding = properties->encoding;
   return handle;
 }
 
   return handle;
 }
 
@@ -254,7 +256,7 @@ const struct fh_properties *
 fh_default_properties (void)
 {
   static const struct fh_properties default_properties
 fh_default_properties (void)
 {
   static const struct fh_properties default_properties
-    = {FH_MODE_TEXT, 1024, 4};
+    = {FH_MODE_TEXT, 1024, 4, LEGACY_NATIVE};
   return &default_properties;
 }
 
   return &default_properties;
 }
 
@@ -322,6 +324,14 @@ fh_get_tab_width (const struct file_handle *handle)
   return handle->tab_width;
 }
 
   return handle->tab_width;
 }
 
+/* Returns the encoding of characters read from HANDLE. */
+const char *
+fh_get_legacy_encoding (const struct file_handle *handle)
+{
+  assert (handle->referent & (FH_REF_FILE | FH_REF_INLINE));
+  return (handle->referent == FH_REF_FILE ? handle->encoding : LEGACY_NATIVE);
+}
+
 /* Returns the scratch file handle associated with HANDLE.
    Applicable to only FH_REF_SCRATCH files. */
 struct scratch_handle *
 /* Returns the scratch file handle associated with HANDLE.
    Applicable to only FH_REF_SCRATCH files. */
 struct scratch_handle *
@@ -403,6 +413,10 @@ static unsigned int hash_fh_lock (const void *, const void *);
    and similarly for writing.  If successful, a reference to TYPE
    is retained, so it should probably be a string literal.
 
    and similarly for writing.  If successful, a reference to TYPE
    is retained, so it should probably be a string literal.
 
+   TYPE should be marked with N_() in the caller: that is, the
+   caller should not translate it with gettext, but fh_lock will
+   do so.
+
    ACCESS specifies whether the lock is for reading or writing.
    EXCLUSIVE is true to require exclusive access, false to allow
    sharing with other accessors.  Exclusive read access precludes
    ACCESS specifies whether the lock is for reading or writing.
    EXCLUSIVE is true to require exclusive access, false to allow
    sharing with other accessors.  Exclusive read access precludes
@@ -578,10 +592,12 @@ static unsigned int
 hash_fh_lock (const void *lock_, const void *aux UNUSED)
 {
   const struct fh_lock *lock = lock_;
 hash_fh_lock (const void *lock_, const void *aux UNUSED)
 {
   const struct fh_lock *lock = lock_;
-  unsigned int hash = hsh_hash_int ((lock->referent << 3) | lock->access);
+  unsigned int basis;
   if (lock->referent == FH_REF_FILE)
   if (lock->referent == FH_REF_FILE)
-    hash ^= fn_hash_identity (lock->u.file);
+    basis = fn_hash_identity (lock->u.file);
   else if (lock->referent == FH_REF_SCRATCH)
   else if (lock->referent == FH_REF_SCRATCH)
-    hash ^= hsh_hash_int (lock->u.unique_id);
-  return hash;
+    basis = lock->u.unique_id;
+  else
+    basis = 0;
+  return hash_int ((lock->referent << 3) | lock->access, basis);
 }
 }