X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdictionary%2Fsys-file-info.c;h=44278060d391d5161b58f06da64018fc932c6ccb;hb=19d0debdc5b72e1bb6c79956403a4d3bc054f300;hp=0234b833ca9fed36b8ff70336df5790dab740161;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp-builds.git diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index 0234b833..44278060 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -1,5 +1,5 @@ /* PSPP - computes sample statistics. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc. Written by Ben Pfaff . This program is free software; you can redistribute it and/or @@ -18,25 +18,32 @@ 02110-1301, USA. */ #include -#include "message.h" + #include #include -#include "array.h" -#include "alloc.h" -#include "command.h" -#include "dictionary.h" -#include "message.h" -#include "file-handle-def.h" -#include "hash.h" -#include "lexer.h" -#include "magic.h" -#include "misc.h" -#include "output.h" -#include "sys-file-reader.h" -#include "manager.h" -#include "table.h" -#include "value-labels.h" -#include "variable.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "minmax.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -65,7 +72,7 @@ sysfile_info_dim (struct tab_table *t, struct outp_driver *d) int i; for (p = max; *p; p++) - t->w[p - max] = min (tab_natural_width (t, d, p - max), + t->w[p - max] = MIN (tab_natural_width (t, d, p - max), *p * d->prop_em_width); for (i = 0; i < t->nr; i++) t->h[i] = tab_natural_height (t, d, i); @@ -73,7 +80,7 @@ sysfile_info_dim (struct tab_table *t, struct outp_driver *d) /* SYSFILE INFO utility. */ int -cmd_sysfile_info (void) +cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) { struct file_handle *h; struct dictionary *d; @@ -83,10 +90,10 @@ cmd_sysfile_info (void) int r, nr; int i; - lex_match_id ("FILE"); - lex_match ('='); + lex_match_id (lexer, "FILE"); + lex_match (lexer, '='); - h = fh_parse (FH_REF_FILE); + h = fh_parse (lexer, FH_REF_FILE); if (!h) return CMD_FAILURE; @@ -96,9 +103,9 @@ cmd_sysfile_info (void) sfm_close_reader (reader); t = tab_create (2, 9, 0); - tab_vline (t, TAL_1 | TAL_SPACING, 1, 0, 8); + tab_vline (t, TAL_GAP, 1, 0, 8); tab_text (t, 0, 0, TAB_LEFT, _("File:")); - tab_text (t, 1, 0, TAB_LEFT, fh_get_filename (h)); + tab_text (t, 1, 0, TAB_LEFT, fh_get_file_name (h)); tab_text (t, 0, 1, TAB_LEFT, _("Label:")); { const char *label = dict_get_label (d); @@ -147,7 +154,7 @@ cmd_sysfile_info (void) if (r + 10 + nvl > nr) { - nr = max (nr * dict_get_var_cnt (d) / (i + 1), nr); + nr = MAX (nr * dict_get_var_cnt (d) / (i + 1), nr); nr += 10 + nvl; tab_realloc (t, 4, nr); } @@ -165,18 +172,18 @@ cmd_sysfile_info (void) dict_destroy (d); - return lex_end_of_command (); + return lex_end_of_command (lexer); } /* DISPLAY utility. */ static void display_macros (void); -static void display_documents (void); +static void display_documents (const struct dictionary *dict); static void display_variables (struct variable **, size_t, int); -static void display_vectors (int sorted); +static void display_vectors (const struct dictionary *dict, int sorted); int -cmd_display (void) +cmd_display (struct lexer *lexer, struct dataset *ds) { /* Whether to sort the list of variables alphabetically. */ int sorted; @@ -185,22 +192,22 @@ cmd_display (void) size_t n; struct variable **vl; - if (lex_match_id ("MACROS")) + if (lex_match_id (lexer, "MACROS")) display_macros (); - else if (lex_match_id ("DOCUMENTS")) - display_documents (); - else if (lex_match_id ("FILE")) + else if (lex_match_id (lexer, "DOCUMENTS")) + display_documents (dataset_dict (ds)); + else if (lex_match_id (lexer, "FILE")) { som_blank_line (); - if (!lex_force_match_id ("LABEL")) + if (!lex_force_match_id (lexer, "LABEL")) return CMD_FAILURE; - if (dict_get_label (default_dict) == NULL) + if (dict_get_label (dataset_dict (ds)) == NULL) tab_output_text (TAB_LEFT, _("The active file does not have a file label.")); else { tab_output_text (TAB_LEFT | TAT_TITLE, _("File label:")); - tab_output_text (TAB_LEFT | TAT_FIX, dict_get_label (default_dict)); + tab_output_text (TAB_LEFT | TAB_FIX, dict_get_label (dataset_dict (ds))); } } else @@ -211,12 +218,12 @@ cmd_display (void) const char **cp; int as; - sorted = lex_match_id ("SORTED"); + sorted = lex_match_id (lexer, "SORTED"); for (cp = sbc; *cp; cp++) - if (token == T_ID && lex_id_match (*cp, tokid)) + if (lex_token (lexer) == T_ID && lex_id_match (*cp, lex_tokid (lexer))) { - lex_get (); + lex_get (lexer); break; } as = cp - sbc; @@ -226,17 +233,17 @@ cmd_display (void) if (as == AS_VECTOR) { - display_vectors (sorted); + display_vectors (dataset_dict(ds), sorted); return CMD_SUCCESS; } - lex_match ('/'); - lex_match_id ("VARIABLES"); - lex_match ('='); + lex_match (lexer, '/'); + lex_match_id (lexer, "VARIABLES"); + lex_match (lexer, '='); - if (token != '.') + if (lex_token (lexer) != '.') { - if (!parse_variables (default_dict, &vl, &n, PV_NONE)) + if (!parse_variables (lexer, dataset_dict (ds), &vl, &n, PV_NONE)) { free (vl); return CMD_FAILURE; @@ -244,7 +251,7 @@ cmd_display (void) as = AS_DICTIONARY; } else - dict_get_vars (default_dict, &vl, &n, 0); + dict_get_vars (dataset_dict (ds), &vl, &n, 0); if (as == AS_SCRATCH) { @@ -266,14 +273,14 @@ cmd_display (void) } if (sorted) - sort (vl, n, sizeof *vl, compare_var_names, NULL); + sort (vl, n, sizeof *vl, compare_var_ptr_names, NULL); display_variables (vl, n, as); free (vl); } - return lex_end_of_command (); + return lex_end_of_command (lexer); } static void @@ -284,9 +291,9 @@ display_macros (void) } static void -display_documents (void) +display_documents (const struct dictionary *dict) { - const char *documents = dict_get_documents (default_dict); + const char *documents = dict_get_documents (dict); som_blank_line (); if (documents == NULL) @@ -311,7 +318,7 @@ display_documents (void) && len > 0) len--; buf[len + 1] = 0; - tab_output_text (TAB_LEFT | TAT_FIX | TAT_NOWRAP, buf); + tab_output_text (TAB_LEFT | TAB_FIX | TAT_NOWRAP, buf); } } } @@ -329,8 +336,8 @@ variables_dim (struct tab_table *t, struct outp_driver *d) t->w[0] = tab_natural_width (t, d, 0); if (_as == AS_DICTIONARY || _as == AS_VARIABLES || _as == AS_LABELS) { - t->w[1] = max (tab_natural_width (t, d, 1), d->prop_em_width * 5); - t->w[2] = max (tab_natural_width (t, d, 2), d->prop_em_width * 35); + t->w[1] = MAX (tab_natural_width (t, d, 1), d->prop_em_width * 5); + t->w[2] = MAX (tab_natural_width (t, d, 2), d->prop_em_width * 35); pc = 3; } else pc = 1; @@ -394,7 +401,7 @@ display_variables (struct variable **vl, size_t n, int as) if (r + 10 + nvl > nr) { - nr = max (nr * n / (i + 1), nr); + nr = MAX (nr * n / (i + 1), nr); nr += 10 + nvl; tab_realloc (t, nc, nr); } @@ -449,17 +456,19 @@ describe_variable (struct variable *v, struct tab_table *t, int r, int as) && v->print.w == v->write.w && v->print.d == v->write.d) { + char str[FMT_STRING_LEN_MAX + 1]; tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, _("Format: %s"), - fmt_to_string (&v->print)); + fmt_to_string (&v->print, str)); r++; } else { + char str[FMT_STRING_LEN_MAX + 1]; tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Print Format: %s"), fmt_to_string (&v->print)); + _("Print Format: %s"), fmt_to_string (&v->print, str)); r++; tab_joint_text (t, 1, r, 2, r, TAB_LEFT | TAT_PRINTF, - _("Write Format: %s"), fmt_to_string (&v->write)); + _("Write Format: %s"), fmt_to_string (&v->write, str)); r++; } @@ -478,11 +487,11 @@ describe_variable (struct variable *v, struct tab_table *t, int r, int as) double x, y; mv_pop_range (&mv, &x, &y); if (x == LOWEST) - cp += nsprintf (cp, "LOWEST THRU %g", y); + cp += sprintf (cp, "LOWEST THRU %g", y); else if (y == HIGHEST) - cp += nsprintf (cp, "%g THRU HIGHEST", x); + cp += sprintf (cp, "%g THRU HIGHEST", x); else - cp += nsprintf (cp, "%g THRU %g", x, y); + cp += sprintf (cp, "%g THRU %g", x, y); cnt++; } while (mv_has_value (&mv)) @@ -490,9 +499,9 @@ describe_variable (struct variable *v, struct tab_table *t, int r, int as) union value value; mv_pop_value (&mv, &value); if (cnt++ > 0) - cp += nsprintf (cp, "; "); + cp += sprintf (cp, "; "); if (v->type == NUMERIC) - cp += nsprintf (cp, "%g", value.f); + cp += sprintf (cp, "%g", value.f); else { *cp++ = '"'; @@ -562,14 +571,14 @@ compare_vectors_by_name (const void *a_, const void *b_) /* Display a list of vectors. If SORTED is nonzero then they are sorted alphabetically. */ static void -display_vectors (int sorted) +display_vectors (const struct dictionary *dict, int sorted) { const struct vector **vl; int i; struct tab_table *t; size_t nvec; - nvec = dict_get_vector_cnt (default_dict); + nvec = dict_get_vector_cnt (dict); if (nvec == 0) { msg (SW, _("No vectors defined.")); @@ -578,7 +587,7 @@ display_vectors (int sorted) vl = xnmalloc (nvec, sizeof *vl); for (i = 0; i < nvec; i++) - vl[i] = dict_get_vector (default_dict, i); + vl[i] = dict_get_vector (dict, i); if (sorted) qsort (vl, nvec, sizeof *vl, compare_vectors_by_name);