X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdictionary%2Fsys-file-info.c;h=ec93ea201cfc3db974284194b86a387810fa2321;hb=0097b71cac1297fba88b3c019836090dd0cf639c;hp=ebe9801545fa28d28f29a9f0935bf23e2da1ccce;hpb=59d14e5581317e3d1e37c8b92b535ba197984776;p=pspp-builds.git diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index ebe98015..ec93ea20 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -62,7 +62,7 @@ enum AS_VECTOR }; -static int describe_variable (struct variable *v, struct tab_table *t, int r, int as); +static int describe_variable (const struct variable *v, struct tab_table *t, int r, int as); /* Sets the widths of all the columns and heights of all the rows in table T for driver D. */ @@ -193,7 +193,7 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds UNUSED) static void display_macros (void); static void display_documents (const struct dictionary *dict); -static void display_variables (struct variable **, size_t, int); +static void display_variables (const struct variable **, size_t, int); static void display_vectors (const struct dictionary *dict, int sorted); int @@ -204,7 +204,7 @@ cmd_display (struct lexer *lexer, struct dataset *ds) /* Variables to display. */ size_t n; - struct variable **vl; + const struct variable **vl; if (lex_match_id (lexer, "MACROS")) display_macros (); @@ -258,7 +258,7 @@ cmd_display (struct lexer *lexer, struct dataset *ds) if (lex_token (lexer) != '.') { - if (!parse_variables (lexer, dataset_dict (ds), &vl, &n, PV_NONE)) + if (!parse_variables_const (lexer, dataset_dict (ds), &vl, &n, PV_NONE)) { free (vl); return CMD_FAILURE; @@ -316,25 +316,18 @@ display_documents (const struct dictionary *dict) "contain any documents.")); else { - size_t n_lines = strlen (documents) / 80; - char buf[81]; + struct string line = DS_EMPTY_INITIALIZER; size_t i; tab_output_text (TAB_LEFT | TAT_TITLE, _("Documents in the active file:")); som_blank_line (); - buf[80] = 0; - for (i = 0; i < n_lines; i++) - { - int len = 79; - - memcpy (buf, &documents[i * 80], 80); - while ((isspace ((unsigned char) buf[len]) || buf[len] == 0) - && len > 0) - len--; - buf[len + 1] = 0; - tab_output_text (TAB_LEFT | TAB_FIX | TAT_NOWRAP, buf); - } + for (i = 0; i < dict_get_document_line_cnt (dict); i++) + { + dict_get_document_line (dict, i, &line); + tab_output_text (TAB_LEFT | TAB_FIX | TAT_NOWRAP, ds_cstr (&line)); + } + ds_destroy (&line); } } @@ -364,9 +357,9 @@ variables_dim (struct tab_table *t, struct outp_driver *d) } static void -display_variables (struct variable **vl, size_t n, int as) +display_variables (const struct variable **vl, size_t n, int as) { - struct variable **vp = vl; /* Variable pointer. */ + const struct variable **vp = vl; /* Variable pointer. */ struct tab_table *t; int nc; /* Number of columns. */ int nr; /* Number of rows. */ @@ -404,7 +397,7 @@ display_variables (struct variable **vl, size_t n, int as) for (i = r = 1; i <= n; i++) { - struct variable *v; + const struct variable *v; while (*vp == NULL) vp++; @@ -458,7 +451,7 @@ display_variables (struct variable **vl, size_t n, int as) The variable will be described in the format AS. Returns the next row available for use in the table. */ static int -describe_variable (struct variable *v, struct tab_table *t, int r, int as) +describe_variable (const struct variable *v, struct tab_table *t, int r, int as) { const struct fmt_spec *print = var_get_print_format (v); const struct fmt_spec *write = var_get_write_format (v); @@ -588,6 +581,8 @@ display_vectors (const struct dictionary *dict, int sorted) int i; struct tab_table *t; size_t nvec; + size_t nrow; + size_t row; nvec = dict_get_vector_cnt (dict); if (nvec == 0) @@ -597,32 +592,52 @@ display_vectors (const struct dictionary *dict, int sorted) } vl = xnmalloc (nvec, sizeof *vl); - for (i = 0; i < nvec; i++) - vl[i] = dict_get_vector (dict, i); + nrow = 0; + for (i = 0; i < nvec; i++) + { + vl[i] = dict_get_vector (dict, i); + nrow += vector_get_var_cnt (vl[i]); + } if (sorted) qsort (vl, nvec, sizeof *vl, compare_vector_ptrs_by_name); - t = tab_create (1, nvec + 1, 0); + t = tab_create (4, nrow + 1, 0); tab_headers (t, 0, 0, 1, 0); tab_columns (t, TAB_COL_DOWN, 1); tab_dim (t, tab_natural_dimensions); - tab_hline (t, TAL_1, 0, 0, 1); + tab_box (t, TAL_1, TAL_1, -1, -1, 0, 0, 3, nrow); + tab_box (t, -1, -1, -1, TAL_1, 0, 0, 3, nrow); + tab_hline (t, TAL_2, 0, 3, 1); tab_text (t, 0, 0, TAT_TITLE | TAB_LEFT, _("Vector")); + tab_text (t, 1, 0, TAT_TITLE | TAB_LEFT, _("Position")); + tab_text (t, 2, 0, TAT_TITLE | TAB_LEFT, _("Variable")); + tab_text (t, 3, 0, TAT_TITLE | TAB_LEFT, _("Print Format")); tab_flags (t, SOMF_NO_TITLE); - for (i = 0; i < nvec; i++) - tab_text (t, 0, i + 1, TAB_LEFT, vector_get_name (vl[i])); - tab_submit (t); - - free (vl); -} - - - - - - - + row = 1; + for (i = 0; i < nvec; i++) + { + const struct vector *vec = vl[i]; + size_t j; + + tab_joint_text (t, 0, row, 0, row + vector_get_var_cnt (vec) - 1, + TAB_LEFT, vector_get_name (vl[i])); + for (j = 0; j < vector_get_var_cnt (vec); j++) + { + struct variable *var = vector_get_var (vec, j); + char fmt_string[FMT_STRING_LEN_MAX + 1]; + fmt_to_string (var_get_print_format (var), fmt_string); + + tab_text (t, 1, row, TAB_RIGHT | TAT_PRINTF, "%d", (int) j + 1); + tab_text (t, 2, row, TAB_LEFT, var_get_name (var)); + tab_text (t, 3, row, TAB_LEFT, fmt_string); + row++; + } + tab_hline (t, TAL_1, 0, 3, row); + } + tab_submit (t); + free (vl); +}