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.
54 cmd_file_handle (void)
56 char handle_name[LONG_NAME_LEN + 1];
57 enum file_handle_mode mode = MODE_TEXT;
61 struct cmd_file_handle cmd;
62 struct file_handle *handle;
66 str_copy_trunc (handle_name, sizeof handle_name, tokid);
68 handle = get_handle_with_name (handle_name);
71 msg (SE, _("File handle %s already refers to file %s. "
72 "File handles cannot be redefined within a session."),
73 handle_name, handle_get_filename(handle));
78 if (!lex_force_match ('/'))
81 if (!parse_file_handle (&cmd))
86 lex_error (_("expecting end of command"));
90 if (cmd.s_name == NULL)
92 msg (SE, _("The FILE HANDLE required subcommand NAME "
101 if (cmd.sbc_tabwidth)
102 tab_width = cmd.n_tabwidth[0];
108 if (cmd.n_lrecl[0] == NOT_LONG)
110 msg (SE, _("Fixed-length records were specified on /RECFORM, but "
111 "record length was not specified on /LRECL. "
112 "Assuming 1024-character records."));
115 else if (cmd.n_lrecl[0] < 1)
117 msg (SE, _("Record length (%ld) must be at least one byte. "
118 "1-character records will be assumed."), cmd.n_lrecl[0]);
122 length = cmd.n_lrecl[0];
128 handle = create_file_handle (handle_name, cmd.s_name,
129 mode, length, tab_width);
131 free_file_handle (&cmd);
135 free_file_handle (&cmd);
141 static struct linked_list *handle_list;
144 /* Parses a file handle name, which may be a filename as a string or
145 a file handle name as an identifier. Returns the file handle or
150 struct file_handle *handle;
152 if (token != T_ID && token != T_STRING)
154 lex_error (_("expecting a file name or handle name"));
158 /* Check for named handles first, then go by filename. */
161 handle = get_handle_with_name (tokid);
163 handle = get_handle_for_filename (ds_c_str (&tokstr));
166 char *filename = ds_c_str (&tokstr);
167 char *handle_name = xmalloc (strlen (filename) + 3);
168 sprintf (handle_name, "\"%s\"", filename);
169 handle = create_file_handle_with_defaults (handle_name, filename);
170 ll_push_front(handle_list, handle);
185 handle_list = ll_create(destroy_file_handle,0);
193 ll_destroy(handle_list);