int
cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED)
{
+ struct sfm_reader *sfm_reader;
struct file_handle *h;
struct dictionary *d;
struct tab_table *t;
struct casereader *reader;
struct sfm_read_info info;
+ char *encoding;
int r, i;
- lex_match_id (lexer, "FILE");
- lex_match (lexer, T_EQUALS);
+ h = NULL;
+ encoding = NULL;
+ for (;;)
+ {
+ lex_match (lexer, T_SLASH);
- h = fh_parse (lexer, FH_REF_FILE, NULL);
- if (!h)
- return CMD_FAILURE;
+ if (lex_match_id (lexer, "FILE") || lex_is_string (lexer))
+ {
+ lex_match (lexer, T_EQUALS);
- reader = sfm_open_reader (h, NULL, &d, &info);
- if (!reader)
+ fh_unref (h);
+ h = fh_parse (lexer, FH_REF_FILE, NULL);
+ if (h == NULL)
+ goto error;
+ }
+ else if (lex_match_id (lexer, "ENCODING"))
+ {
+ lex_match (lexer, T_EQUALS);
+
+ if (!lex_force_string (lexer))
+ goto error;
+
+ free (encoding);
+ encoding = ss_xstrdup (lex_tokss (lexer));
+
+ lex_get (lexer);
+ }
+ else
+ break;
+ }
+
+ if (h == NULL)
{
- fh_unref (h);
- return CMD_FAILURE;
+ lex_sbc_missing ("FILE");
+ goto error;
}
+
+ sfm_reader = sfm_open (h);
+ if (sfm_reader == NULL)
+ goto error;
+
+ reader = sfm_decode (sfm_reader, encoding, &d, &info);
+ if (!reader)
+ goto error;
+
casereader_destroy (reader);
t = tab_create (2, 11 + (info.product_ext != NULL));
fh_unref (h);
sfm_read_info_destroy (&info);
return CMD_SUCCESS;
+
+error:
+ fh_unref (h);
+ free (encoding);
+ return CMD_FAILURE;
}
\f
/* DISPLAY utility. */