1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 #include "file-handle.h"
33 #include "linked-list.h"
34 #include "file-handle-def.h"
37 #define _(msgid) gettext (msgid)
46 tabwidth=integer "x>=0" "%s must be nonnegative";
47 mode=mode:!character/image.
53 cmd_file_handle (void)
55 char handle_name[LONG_NAME_LEN + 1];
56 struct fh_properties properties = *fh_default_properties ();
58 struct cmd_file_handle cmd;
59 struct file_handle *handle;
63 str_copy_trunc (handle_name, sizeof handle_name, tokid);
65 handle = fh_from_name (handle_name);
68 msg (SE, _("File handle %s already refers to file %s. "
69 "File handles cannot be redefined within a session."),
70 handle_name, fh_get_filename(handle));
75 if (!lex_force_match ('/'))
78 if (!parse_file_handle (&cmd))
83 lex_error (_("expecting end of command"));
87 if (cmd.s_name == NULL)
89 msg (SE, _("The FILE HANDLE required subcommand NAME "
97 properties.mode = MODE_TEXT;
99 properties.tab_width = cmd.n_tabwidth[0];
102 properties.mode = MODE_BINARY;
103 if (cmd.n_lrecl[0] == NOT_LONG)
104 msg (SE, _("Fixed-length records were specified on /RECFORM, but "
105 "record length was not specified on /LRECL. "
106 "Assuming %d-character records."),
107 properties.record_width);
108 else if (cmd.n_lrecl[0] < 1)
109 msg (SE, _("Record length (%ld) must be at least one byte. "
110 "Assuming %d-character records."),
111 cmd.n_lrecl[0], properties.record_width);
113 properties.record_width = cmd.n_lrecl[0];
119 handle = fh_create (handle_name, cmd.s_name, &properties);
121 free_file_handle (&cmd);
125 free_file_handle (&cmd);
129 /* Parses a file handle name, which may be a filename as a string or
130 a file handle name as an identifier. Returns the file handle or
135 struct file_handle *handle;
137 if (token != T_ID && token != T_STRING)
139 lex_error (_("expecting a file name or handle name"));
143 /* Check for named handles first, then go by filename. */
146 handle = fh_from_name (tokid);
148 handle = fh_from_filename (ds_c_str (&tokstr));
151 char *filename = ds_c_str (&tokstr);
152 char *handle_name = xmalloc (strlen (filename) + 3);
153 sprintf (handle_name, "\"%s\"", filename);
154 handle = fh_create (handle_name, filename, fh_default_properties ());