Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */
+/* FIXME: seems like a lot of code duplication with data-list.c. */
+
#include <config.h>
-#include <assert.h>
+#include "error.h"
#include <stdlib.h>
#include "alloc.h"
#include "command.h"
#include "tab.h"
#include "var.h"
-#include "debug-print.h"
-
/* Describes what to do when an output field is encountered. */
enum
{
static void dump_table (void);
static void append_var_spec (struct prt_out_spec *spec);
static void alloc_line (void);
-
-#if DEBUGGING
-void debug_print (void);
-#endif
\f
/* Basic parsing. */
int
cmd_print (void)
{
- lex_match_id ("PRINT");
return internal_cmd_print (PRT_PRINT);
}
int
cmd_print_eject (void)
{
- lex_match_id ("EJECT");
return internal_cmd_print (PRT_PRINT | PRT_EJECT);
}
int
cmd_write (void)
{
- lex_match_id ("WRITE");
return internal_cmd_print (PRT_WRITE);
}
if (!parse_specs ())
goto lossage;
+ if (prt.handle != NULL && !dfm_open_for_writing (prt.handle))
+ goto lossage;
+
/* Output the variable table if requested. */
if (table)
dump_table ();
memcpy (trns, &prt, sizeof *trns);
add_transformation ((struct trns_header *) trns);
-#if 0 && DEBUGGING
- debug_print ();
-#endif
-
return CMD_SUCCESS;
lossage:
dump_table (void)
{
struct prt_out_spec *spec;
- const char *filename;
struct tab_table *t;
int recno;
int nspec;
assert (0);
}
- filename = fh_handle_name (prt.handle);
- tab_title (t, 1, (prt.handle != NULL
- ? _("Writing %3d records to file %s.")
- : _("Writing %3d records to the listing file.")),
- recno, filename);
+ if (prt.handle != NULL)
+ tab_title (t, 1, _("Writing %d record(s) to file %s."),
+ recno, handle_get_filename (prt.handle));
+ else
+ tab_title (t, 1, _("Writing %d record(s) to the listing file."), recno);
tab_submit (t);
- fh_handle_name (NULL);
}
/* PORTME: The number of characters in a line terminator. */
case PRT_ERROR:
default:
assert (0);
+ abort ();
}
if (pot_w > w)
w = pot_w;
else
{
if ((t->options & PRT_CMD_MASK) == PRT_PRINT
- || t->handle->mode != FH_MD_BINARY)
+ || handle_get_mode (t->handle) != MODE_BINARY)
{
/* PORTME: Line ends. */
#ifdef __MSDOS__
struct file_handle *handle;
struct expression *e;
- lex_match_id ("SPACE");
if (lex_match_id ("OUTFILE"))
{
lex_match ('=');
- if (token == T_ID)
- handle = fh_get_handle_by_name (tokid);
- else if (token == T_STRING)
- handle = fh_get_handle_by_filename (tokid);
- else
- {
- msg (SE, _("A file name or handle was expected in the "
- "OUTFILE subcommand."));
- return CMD_FAILURE;
- }
-
- if (!handle)
+ handle = fh_parse_file_handle ();
+ if (handle == NULL)
return CMD_FAILURE;
lex_get ();
}
if (token != '.')
{
- e = expr_parse (PXP_NUMERIC);
+ e = expr_parse (EXPR_NUMERIC);
if (token != '.')
{
expr_free (e);
else
e = NULL;
+ if (handle != NULL && !dfm_open_for_writing (handle))
+ {
+ expr_free (e);
+ return CMD_FAILURE;
+ }
+
t = xmalloc (sizeof *t);
t->h.proc = print_space_trns_proc;
if (e)
{
expr_free (((struct print_space_trns *) trns)->e);
}
-\f
-/* Debugging code. */
-
-#if 0 && DEBUGGING
-void
-debug_print (void)
-{
- struct prt_out_spec *p;
-
- if (prt.handle == NULL)
- {
- printf ("PRINT");
- if (prt.eject)
- printf (" EJECT");
- }
- else
- printf ("WRITE OUTFILE=%s", handle_name (prt.handle));
- printf (" MAX_WIDTH=%d", prt.max_width);
- printf (" /");
- for (p = prt.spec; p; p = p->next)
- switch (p->type)
- {
- case PRT_ERROR:
- printf (_("<ERROR>"));
- break;
- case PRT_NEWLINE:
- printf ("\n /");
- break;
- case PRT_CONST:
- printf (" \"%s\" %d-%d", p->u.c, p->fc + 1, p->fc + strlen (p->u.c));
- break;
- case PRT_VAR:
- printf (" %s %d %d-%d (%s)", p->u.v.v->name, p->u.v.v->fv, p->fc + 1,
- p->fc + p->u.v.v->print.w, fmt_to_string (&p->u.v.v->print));
- break;
- case PRT_SPACE:
- printf (" \" \" %d", p->fc + 1);
- break;
- }
- printf (".\n");
-}
-#endif /* DEBUGGING */