X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utilities%2Fpspp-output.c;h=deb2000432e74e6e3a1c605fa3083866dacd4a14;hb=d950831f83004457e69c3e6e44131aef3e57efd3;hp=8362ac57ff252ef78392c2c29fd33b809f52fbdd;hpb=a22f79456929fc7edc9d65234ab05f4966c86679;p=pspp diff --git a/utilities/pspp-output.c b/utilities/pspp-output.c index 8362ac57ff..deb2000432 100644 --- a/utilities/pspp-output.c +++ b/utilities/pspp-output.c @@ -77,7 +77,7 @@ static bool raw; static bool force; /* --table-look: TableLook to replace table style for conversion. */ -static struct spv_table_look *table_look; +static struct pivot_table_look *table_look; /* Number of warnings issued. */ static size_t n_warnings; @@ -92,10 +92,14 @@ dump_item (const struct spv_item *item) { const char *x = item->xml_member; const char *b = item->bin_member; + + /* The strings below are not marked for translation because they are only + useful to developers. */ char *s = (x && b - ? xasprintf (_("%s and %s:"), x, b) + ? xasprintf ("%s and %s:", x, b) : xasprintf ("%s:", x ? x : b)); - text_item_submit (text_item_create_nocopy (TEXT_ITEM_TITLE, s)); + text_item_submit (text_item_create_nocopy (TEXT_ITEM_TITLE, s, + xstrdup ("Member Names"))); } switch (spv_item_get_type (item)) @@ -268,7 +272,8 @@ dump_heading_transition (const struct spv_item *old, group_close_item_submit (group_close_item_create ()); for (size_t i = common; i < new_path.n; i++) group_open_item_submit (group_open_item_create ( - new_path.nodes[i]->command_id)); + new_path.nodes[i]->command_id, + new_path.nodes[i]->label)); free_path (&old_path); free_path (&new_path); @@ -325,6 +330,69 @@ run_convert (int argc UNUSED, char **argv) } } +static const struct pivot_table * +get_first_table (const struct spv_reader *spv) +{ + struct spv_item **items; + size_t n_items; + spv_select (spv, criteria, n_criteria, &items, &n_items); + + for (size_t i = 0; i < n_items; i++) + if (spv_item_is_table (items[i])) + { + free (items); + return spv_item_get_table (items[i]); + } + + free (items); + return NULL; +} + +static void +run_get_table_look (int argc UNUSED, char **argv) +{ + struct pivot_table_look *look; + if (strcmp (argv[1], "-")) + { + struct spv_reader *spv; + char *err = spv_open (argv[1], &spv); + if (err) + error (1, 0, "%s", err); + + const struct pivot_table *table = get_first_table (spv); + if (!table) + error (1, 0, "%s: no tables found", argv[1]); + + look = pivot_table_look_ref (pivot_table_get_look (table)); + + spv_close (spv); + } + else + look = pivot_table_look_ref (pivot_table_look_builtin_default ()); + + char *err = spv_table_look_write (argv[2], look); + if (err) + error (1, 0, "%s", err); + + pivot_table_look_unref (look); +} + +static void +run_convert_table_look (int argc UNUSED, char **argv) +{ + struct pivot_table_look *look; + char *err = spv_table_look_read (argv[1], &look); + if (err) + error (1, 0, "%s", err); + + err = spv_table_look_write (argv[2], look); + if (err) + error (1, 0, "%s", err); + + pivot_table_look_unref (look); + free (look); +} + static void run_dump (int argc UNUSED, char **argv) { @@ -672,6 +740,8 @@ static const struct command commands[] = { "detect", 1, 1, run_detect }, { "dir", 1, 1, run_directory }, { "convert", 2, 2, run_convert }, + { "get-table-look", 2, 2, run_get_table_look }, + { "convert-table-look", 2, 2, run_convert_table_look }, /* Undocumented commands. */ { "dump", 1, 1, run_dump }, @@ -753,7 +823,7 @@ main (int argc, char **argv) c->run (argc, argv); - spv_table_look_destroy (table_look); + pivot_table_look_unref (table_look); i18n_done (); return n_warnings ? EXIT_FAILURE : EXIT_SUCCESS; @@ -883,7 +953,8 @@ parse_members (const char *arg) static void parse_table_look (const char *arg) { - spv_table_look_destroy (table_look); + pivot_table_look_unref (table_look); + char *error_s = spv_table_look_read (arg, &table_look); if (error_s) error (1, 0, "%s", error_s); @@ -1053,6 +1124,8 @@ The following commands are available:\n\ detect FILE Detect whether FILE is an SPV file.\n\ dir FILE List tables and other items in FILE.\n\ convert SOURCE DEST Convert .spv SOURCE to DEST.\n\ + get-table-look SOURCE DEST Copies first selected TableLook into DEST\n\ + convert-table-look SOURCE DEST Copies .tlo or .stt SOURCE into DEST\n\ \n\ Input selection options for \"dir\" and \"convert\":\n\ --select=CLASS... include only some kinds of objects\n\