LIST: Improve wording of error messages.
[pspp] / src / language / data-io / file-handle.q
index 80fdacab78fed60a7610417648201d9ddae9109f..7ac20a080c8ae063f2d9d797bd1f0d8f35ae9d27 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2010, 2011 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2010, 2011, 2012, 2013 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
 
 #include <config.h>
 
+#include "data/file-handle-def.h"
+
 #include <limits.h>
 #include <errno.h>
 #include <stdlib.h>
 
 #include "data/file-name.h"
 #include "data/session.h"
+#include "data/variable.h"
 #include "language/command.h"
 #include "language/data-io/file-handle.h"
 #include "language/lexer/lexer.h"
 #include "libpspp/assertion.h"
+#include "libpspp/cast.h"
 #include "libpspp/message.h"
 #include "libpspp/str.h"
-#include "data/variable.h"
-#include "data/file-handle-def.h"
 
 #include "gl/xalloc.h"
 
    "FILE HANDLE" (fh_):
      name=string;
      lrecl=integer;
-     tabwidth=integer "x>=0" "%s must be nonnegative";
+     tabwidth=integer;
      mode=mode:!character/binary/image/360;
-     recform=recform:fixed/f/variable/v/spanned/vs.
+     ends=ends:lf/crlf;
+     recform=recform:fixed/f/variable/v/spanned/vs;
+     encoding=string.
 */
 /* (declarations) */
 /* (functions) */
@@ -68,8 +72,8 @@ cmd_file_handle (struct lexer *lexer, struct dataset *ds)
   if (handle != NULL)
     {
       msg (SE, _("File handle %s is already defined.  "
-                 "Use CLOSE FILE HANDLE before redefining a file handle."),
-          handle_name);
+                 "Use %s before redefining a file handle."),
+          handle_name, "CLOSE FILE HANDLE");
       goto exit_free_handle_name;
     }
 
@@ -95,7 +99,16 @@ cmd_file_handle (struct lexer *lexer, struct dataset *ds)
     case FH_CHARACTER:
       properties.mode = FH_MODE_TEXT;
       if (cmd.sbc_tabwidth)
-        properties.tab_width = cmd.n_tabwidth[0];
+        {
+          if (cmd.n_tabwidth[0] >= 0)
+            properties.tab_width = cmd.n_tabwidth[0];
+          else
+            msg (SE, _("%s must not be negative."), "TABWIDTH");
+        }
+      if (cmd.ends == FH_LF)
+        properties.line_ends = FH_END_LF;
+      else if (cmd.ends == FH_CRLF)
+        properties.line_ends = FH_END_CRLF;
       break;
     case FH_IMAGE:
       properties.mode = FH_MODE_FIXED;
@@ -104,7 +117,7 @@ cmd_file_handle (struct lexer *lexer, struct dataset *ds)
       properties.mode = FH_MODE_VARIABLE;
       break;
     case FH_360:
-      properties.encoding = "EBCDIC-US";
+      properties.encoding = CONST_CAST (char *, "EBCDIC-US");
       if (cmd.recform == FH_FIXED || cmd.recform == FH_F)
         properties.mode = FH_MODE_FIXED;
       else if (cmd.recform == FH_VARIABLE || cmd.recform == FH_V)
@@ -119,7 +132,7 @@ cmd_file_handle (struct lexer *lexer, struct dataset *ds)
         }
       else
         {
-          msg (SE, _("RECFORM must be specified with MODE=360."));
+          msg (SE, _("%s must be specified with %s."), "RECFORM", "MODE=360");
           goto exit_free_cmd;
         }
       break;
@@ -141,7 +154,10 @@ cmd_file_handle (struct lexer *lexer, struct dataset *ds)
         properties.record_width = cmd.n_lrecl[0];
     }
 
-  fh_create_file (handle_name, cmd.s_name, &properties);
+  if (cmd.s_encoding != NULL)
+    properties.encoding = cmd.s_encoding;
+
+  fh_create_file (handle_name, cmd.s_name, lex_get_encoding (lexer), &properties);
 
   result = CMD_SUCCESS;
 
@@ -233,7 +249,7 @@ fh_parse (struct lexer *lexer, enum fh_referent referent_mask,
       if (lex_token (lexer) == T_ID)
         handle = fh_from_id (lex_tokcstr (lexer));
       if (handle == NULL)
-            handle = fh_create_file (NULL, lex_tokcstr (lexer),
+       handle = fh_create_file (NULL, lex_tokcstr (lexer), lex_get_encoding (lexer),
                                      fh_default_properties ());
       lex_get (lexer);
     }