X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fprint.c;h=1bbc5ae6f8df07af94ed6cc0cfd94cd9b07ee7f5;hb=d2f8593a1f1d39a3264682af0da898a3d67b68cf;hp=70a41763c4a5d7b52e4d3d5fec9adc6a5f43364c;hpb=4944c86a9318bc5b5578ab145a95c116ffd2c9fd;p=pspp diff --git a/src/print.c b/src/print.c index 70a41763c4..1bbc5ae6f8 100644 --- a/src/print.c +++ b/src/print.c @@ -17,27 +17,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* AIX requires this to be the first thing in the file. */ -#include -#if __GNUC__ -#define alloca __builtin_alloca -#else -#if HAVE_ALLOCA_H -#include -#else -#ifdef _AIX -#pragma alloca -#else -#ifndef alloca /* predefined by HP cc +Olibcalls */ -char *alloca (); -#endif -#endif -#endif -#endif +/* FIXME: seems like a lot of code duplication with data-list.c. */ -#include +#include +#include "error.h" #include #include "alloc.h" +#include "case.h" #include "command.h" #include "dfm.h" #include "error.h" @@ -49,10 +35,6 @@ char *alloca (); #include "tab.h" #include "var.h" -#undef DEBUGGING -/*#define DEBUGGING 1*/ -#include "debug-print.h" - /* Describes what to do when an output field is encountered. */ enum { @@ -99,9 +81,7 @@ struct print_trns int options; /* PRT_* bitmapped field. */ struct prt_out_spec *spec; /* Output specifications. */ int max_width; /* Maximum line width including null. */ -#if !PAGED_STACK char *line; /* Buffer for sticking lines in. */ -#endif }; /* PRT_PRINT or PRT_WRITE. */ @@ -117,16 +97,12 @@ static struct prt_out_spec *next; static int nrec; static int internal_cmd_print (int flags); -static int print_trns_proc (struct trns_header *, struct ccase *); -static void print_trns_free (struct trns_header *); +static trns_proc_func print_trns_proc; +static trns_free_func print_trns_free; static int parse_specs (void); 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 /* Basic parsing. */ @@ -134,7 +110,6 @@ void debug_print (void); int cmd_print (void) { - lex_match_id ("PRINT"); return internal_cmd_print (PRT_PRINT); } @@ -142,7 +117,6 @@ cmd_print (void) int cmd_print_eject (void) { - lex_match_id ("EJECT"); return internal_cmd_print (PRT_PRINT | PRT_EJECT); } @@ -150,7 +124,6 @@ cmd_print_eject (void) int cmd_write (void) { - lex_match_id ("WRITE"); return internal_cmd_print (PRT_WRITE); } @@ -171,9 +144,7 @@ internal_cmd_print (int f) prt.handle = NULL; prt.options = f; prt.spec = NULL; -#if !PAGED_STACK prt.line = NULL; -#endif next = NULL; nrec = 0; @@ -215,6 +186,9 @@ internal_cmd_print (int f) 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 (); @@ -228,10 +202,6 @@ internal_cmd_print (int f) memcpy (trns, &prt, sizeof *trns); add_transformation ((struct trns_header *) trns); -#if DEBUGGING - debug_print (); -#endif - return CMD_SUCCESS; lossage: @@ -369,7 +339,7 @@ parse_string_argument (void) { fx.spec.type = PRT_CONST; fx.spec.fc = fx.sc - 1; - fx.spec.u.c = xstrdup (ds_value (&tokstr)); + fx.spec.u.c = xstrdup (ds_c_str (&tokstr)); lex_get (); /* Parse the included column range. */ @@ -455,7 +425,7 @@ fail: static int parse_variable_argument (void) { - if (!parse_variables (NULL, &fx.v, &fx.nv, PV_DUPLICATE)) + if (!parse_variables (default_dict, &fx.v, &fx.nv, PV_DUPLICATE)) return 0; if (token == T_NUM) @@ -740,7 +710,7 @@ dump_fmt_list (struct fmt_list * f) static struct fmt_list * fixed_parse_fortran (void) { - struct fmt_list *head; + struct fmt_list *head = NULL; struct fmt_list *fl = NULL; lex_get (); /* skip opening parenthesis */ @@ -808,7 +778,6 @@ static void dump_table (void) { struct prt_out_spec *spec; - const char *filename; struct tab_table *t; int recno; int nspec; @@ -862,25 +831,23 @@ dump_table (void) 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. */ -#if __MSDOS__ +#ifdef __MSDOS__ #define LINE_END_WIDTH 2 /* \r\n */ #else #define LINE_END_WIDTH 1 /* \n */ #endif /* Calculates the maximum possible line width and allocates a buffer - big enough to contain it, if necessary (otherwise sets max_width). - (The action taken depends on compiler & OS as detected by pref.h.) */ + big enough to contain it */ static void alloc_line (void) { @@ -910,23 +877,23 @@ alloc_line (void) pot_w = i->fc + 1; break; case PRT_ERROR: + default: assert (0); - break; + abort (); } if (pot_w > w) w = pot_w; } prt.max_width = w + LINE_END_WIDTH + 1; -#if !PAGED_STACK prt.line = xmalloc (prt.max_width); -#endif } /* Transformation. */ /* Performs the transformation inside print_trns T on case C. */ static int -print_trns_proc (struct trns_header * trns, struct ccase * c) +print_trns_proc (struct trns_header * trns, struct ccase * c, + int case_num UNUSED) { /* Transformation. */ struct print_trns *t = (struct print_trns *) trns; @@ -935,15 +902,7 @@ print_trns_proc (struct trns_header * trns, struct ccase * c) struct prt_out_spec *i; /* Line buffer. */ -#if PAGED_STACK -#if __GNUC__ && !__STRICT_ANSI__ - char buf[t->max_width]; -#else /* !__GNUC__ */ - char *buf = alloca (t->max_width); -#endif /* !__GNUC__ */ -#else /* !PAGED_STACK */ char *buf = t->line; -#endif /* !PAGED_STACK */ /* Length of the line in buf. */ int len = 0; @@ -968,10 +927,10 @@ print_trns_proc (struct trns_header * trns, struct ccase * c) 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. */ -#if __MSDOS__ +#ifdef __MSDOS__ buf[len++] = '\r'; #endif buf[len++] = '\n'; @@ -992,14 +951,7 @@ print_trns_proc (struct trns_header * trns, struct ccase * c) break; case PRT_VAR: - if (i->u.v.v->type == NUMERIC) - data_out (&buf[i->fc], &i->u.v.f, &c->data[i->u.v.v->fv]); - else - { - union value t; - t.c = c->data[i->u.v.v->fv].s; - data_out (&buf[i->fc], &i->u.v.f, &t); - } + data_out (&buf[i->fc], &i->u.v.f, case_data (c, i->u.v.v->fv)); len = i->fc + i->u.v.f.w; break; @@ -1041,9 +993,7 @@ print_trns_free (struct trns_header * t) n = i->next; free (i); } -#if !PAGED_STACK free (((struct print_trns *) t)->line); -#endif } /* PRINT SPACE. */ @@ -1058,8 +1008,8 @@ struct print_space_trns } print_space_trns; -static int print_space_trns_proc (struct trns_header *, struct ccase *); -static void print_space_trns_free (struct trns_header *); +static trns_proc_func print_space_trns_proc; +static trns_free_func print_space_trns_free; int cmd_print_space (void) @@ -1068,23 +1018,12 @@ cmd_print_space (void) 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 (); } @@ -1093,7 +1032,7 @@ cmd_print_space (void) if (token != '.') { - e = expr_parse (PXP_NUMERIC); + e = expr_parse (EXPR_NUMERIC); if (token != '.') { expr_free (e); @@ -1104,6 +1043,12 @@ cmd_print_space (void) 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) @@ -1118,7 +1063,8 @@ cmd_print_space (void) } static int -print_space_trns_proc (struct trns_header * trns, struct ccase * c) +print_space_trns_proc (struct trns_header * trns, struct ccase * c, + int case_num UNUSED) { struct print_space_trns *t = (struct print_space_trns *) trns; int n; @@ -1127,7 +1073,7 @@ print_space_trns_proc (struct trns_header * trns, struct ccase * c) { union value v; - expr_evaluate (t->e, c, &v); + expr_evaluate (t->e, c, case_num, &v); n = v.f; if (n < 0) { @@ -1149,7 +1095,7 @@ print_space_trns_proc (struct trns_header * trns, struct ccase * c) char buf[LINE_END_WIDTH]; /* PORTME: Line ends. */ -#if __MSDOS__ +#ifdef __MSDOS__ buf[0] = '\r'; buf[1] = '\n'; #else @@ -1167,45 +1113,3 @@ print_space_trns_free (struct trns_header * trns) { expr_free (((struct print_space_trns *) trns)->e); } - -/* Debugging code. */ - -#if 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 (_("")); - 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 */