X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Flanguage%2Fdata-io%2Fprint.c;h=3c8db1cb0a1b4bd334211ee12b72c5e02d5b7338;hb=b13f17becf74e4335c7e3206e4347cac07b38c56;hp=f5e857e305b4cfebbd198654a593c9c699b6ced7;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp-builds.git diff --git a/src/language/data-io/print.c b/src/language/data-io/print.c index f5e857e3..3c8db1cb 100644 --- a/src/language/data-io/print.c +++ b/src/language/data-io/print.c @@ -20,20 +20,27 @@ /* FIXME: seems like a lot of code duplication with data-list.c. */ #include -#include "message.h" + #include -#include "alloc.h" -#include "case.h" -#include "command.h" -#include "data-writer.h" -#include "message.h" -#include "expressions/public.h" -#include "file-handle.h" -#include "lexer.h" -#include "misc.h" -#include "manager.h" -#include "table.h" -#include "variable.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "gettext.h" #define _(msgid) gettext (msgid) @@ -136,7 +143,7 @@ static int internal_cmd_print (int f) { int table = 0; /* Print table? */ - struct print_trns *trns; /* malloc()'d transformation. */ + struct print_trns *trns = NULL; /* malloc()'d transformation. */ struct file_handle *fh = NULL; /* Fill in prt to facilitate error-handling. */ @@ -345,7 +352,7 @@ parse_string_argument (void) { fx.spec.type = PRT_CONST; fx.spec.fc = fx.sc - 1; - fx.spec.u.c = xstrdup (ds_c_str (&tokstr)); + fx.spec.u.c = ds_xstrdup (&tokstr); lex_get (); /* Parse the included column range. */ @@ -809,12 +816,12 @@ dump_table (const struct file_handle *fh) { int len = strlen (spec->u.c); nspec++; - tab_text (t, 0, nspec, TAB_LEFT | TAT_FIX | TAT_PRINTF, + tab_text (t, 0, nspec, TAB_LEFT | TAB_FIX | TAT_PRINTF, "\"%s\"", spec->u.c); tab_text (t, 1, nspec, TAT_PRINTF, "%d", recno + 1); tab_text (t, 2, nspec, TAT_PRINTF, "%3d-%3d", spec->fc + 1, spec->fc + len); - tab_text (t, 3, nspec, TAB_LEFT | TAT_FIX | TAT_PRINTF, + tab_text (t, 3, nspec, TAB_LEFT | TAB_FIX | TAT_PRINTF, "A%d", len); break; } @@ -825,33 +832,26 @@ dump_table (const struct file_handle *fh) tab_text (t, 1, nspec, TAT_PRINTF, "%d", recno + 1); tab_text (t, 2, nspec, TAT_PRINTF, "%3d-%3d", spec->fc + 1, spec->fc + spec->u.v.f.w); - tab_text (t, 3, nspec, TAB_LEFT | TAT_FIX, + tab_text (t, 3, nspec, TAB_LEFT | TAB_FIX, fmt_to_string (&spec->u.v.f)); break; } case PRT_SPACE: break; case PRT_ERROR: - assert (0); + NOT_REACHED (); } if (fh != NULL) - tab_title (t, 1, ngettext ("Writing %d record to %s.", - "Writing %d records to %s.", recno), + tab_title (t, ngettext ("Writing %d record to %s.", + "Writing %d records to %s.", recno), recno, fh_get_name (fh)); else - tab_title (t, 1, ngettext ("Writing %d record.", - "Writing %d records.", recno), recno); + tab_title (t, ngettext ("Writing %d record.", + "Writing %d records.", recno), recno); tab_submit (t); } -/* PORTME: The number of characters in a line terminator. */ -#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 */ static void @@ -884,13 +884,12 @@ alloc_line (void) break; case PRT_ERROR: default: - assert (0); - abort (); + NOT_REACHED (); } if (pot_w > w) w = pot_w; } - prt.max_width = w + LINE_END_WIDTH + 1; + prt.max_width = w + 2; prt.line = xmalloc (prt.max_width); } @@ -926,19 +925,13 @@ print_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED) if (t->writer == NULL) { buf[len] = 0; - tab_output_text (TAT_FIX | TAT_NOWRAP, buf); + tab_output_text (TAB_FIX | TAT_NOWRAP, buf); } else { if ((t->options & PRT_CMD_MASK) == PRT_PRINT || !(t->options & PRT_BINARY)) - { - /* PORTME: Line ends. */ -#ifdef __MSDOS__ - buf[len++] = '\r'; -#endif - buf[len++] = '\n'; - } + buf[len++] = '\n'; dfm_put_record (t->writer, buf, len); } @@ -965,8 +958,7 @@ print_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED) break; case PRT_ERROR: - assert (0); - break; + NOT_REACHED (); } if (t->writer != NULL && dfm_write_error (t->writer)) @@ -974,7 +966,7 @@ print_trns_proc (void *trns_, struct ccase *c, int case_num UNUSED) return TRNS_CONTINUE; } -/* Frees all the data inside print_trns T. Does not free T. */ +/* Frees all the data inside print_trns PRT. Does not free PRT. */ static bool print_trns_free (void *prt_) { @@ -995,8 +987,7 @@ print_trns_free (void *prt_) /* nothing to do */ break; case PRT_ERROR: - assert (0); - break; + NOT_REACHED (); } n = i->next; free (i); @@ -1004,7 +995,6 @@ print_trns_free (void *prt_) if (prt->writer != NULL) ok = dfm_close_writer (prt->writer); free (prt->line); - free (prt); return ok; }