X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Ftab.c;h=d9872c7214e5d3d9015a92b1101eca3702e83f99;hb=f86a0b3b5dd8be4fb750db00d829edb8c2a809f2;hp=5bde1b7c418c57d05bdbb78d42dae37ec32e09ef;hpb=fce028c380d496e42823fd24774e0159ed7cc110;p=pspp diff --git a/src/output/tab.c b/src/output/tab.c index 5bde1b7c41..d9872c7214 100644 --- a/src/output/tab.c +++ b/src/output/tab.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2013 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2010, 2011, 2013, 2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -56,6 +56,15 @@ struct tab_joined_cell static const struct table_class tab_table_class; +struct fmt_spec ugly [n_RC] = + { + {FMT_F, 8, 0}, /* INTEGER */ + {FMT_F, 8, 3}, /* WEIGHT (ignored) */ + {FMT_F, 8, 3}, /* PVALUE */ + {FMT_F, 8, 3} /* OTHER (ignored) */ + }; + + /* Creates and returns a new table with NC columns and NR rows and initially no header rows or columns. The table's cells are initially empty. */ struct tab_table * @@ -78,13 +87,27 @@ tab_create (int nc, int nr) memset (t->rh, 0, nc * (nr + 1)); t->rv = pool_nmalloc (t->container, nr, nc + 1); + memset (t->fmtmap, 0, sizeof (*t->fmtmap) * n_RC); + memset (t->rv, TAL_GAP, nr * (nc + 1)); + t->fmtmap[RC_PVALUE] = ugly[RC_PVALUE]; + t->fmtmap[RC_INTEGER] = ugly[RC_INTEGER]; + t->fmtmap[RC_OTHER] = *settings_get_format (); + t->col_ofs = t->row_ofs = 0; return t; } + +void +tab_set_format (struct tab_table *t, enum result_class rc, const struct fmt_spec *fmt) +{ + t->fmtmap[rc] = *fmt; +} + + /* Sets the width and height of a table, in columns and rows, respectively. Use only to reduce the size of a table, since it does not change the amount of allocated memory. @@ -386,51 +409,13 @@ tab_value (struct tab_table *table, int c, int r, unsigned char opt, table->ct[c + r * table->cf] = opt; } -/* Sets cell (C,R) in TABLE, with options OPT, to have value VAL - with NDEC decimal places. */ -void -tab_fixed (struct tab_table *table, int c, int r, unsigned char opt, - double val, int w, int d) -{ - struct fmt_spec f; - union value double_value; - char *s; - - assert (c >= 0); - assert (c < tab_nc (table)); - assert (r >= 0); - assert (r < tab_nr (table)); - - f = fmt_for_output (FMT_F, w, d); - -#if DEBUGGING - if (c + table->col_ofs < 0 || r + table->row_ofs < 0 - || c + table->col_ofs >= tab_nc (table) - || r + table->row_ofs >= tab_nr (table)) - { - printf ("tab_fixed(): bad cell (%d+%d=%d,%d+%d=%d) in table size " - "(%d,%d)\n", - c, table->col_ofs, c + table->col_ofs, - r, table->row_ofs, r + table->row_ofs, - tab_nc (table), tab_nr (table)); - return; - } -#endif - - double_value.f = val; - s = data_out_stretchy (&double_value, C_ENCODING, &f, table->container); - - table->cc[c + r * table->cf] = s + strspn (s, " "); - table->ct[c + r * table->cf] = opt; -} - /* Sets cell (C,R) in TABLE, with options OPT, to have value VAL as formatted by FMT. If FMT is null, then the default print format will be used. */ void tab_double (struct tab_table *table, int c, int r, unsigned char opt, - double val, const struct fmt_spec *fmt) + double val, const struct fmt_spec *fmt, enum result_class rc) { union value double_value ; char *s; @@ -440,9 +425,9 @@ tab_double (struct tab_table *table, int c, int r, unsigned char opt, assert (r >= 0); assert (r < tab_nr (table)); - if ( fmt == NULL) - fmt = settings_get_format (); - + if (fmt == NULL) + fmt = &table->fmtmap[rc]; + fmt_check_output (fmt); #if DEBUGGING