1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2007, 2009 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 #include <data/datasheet.h>
25 #include <data/casereader-provider.h>
26 #include <data/casereader.h>
27 #include <data/casewriter.h>
28 #include <data/lazy-casereader.h>
29 #include <libpspp/argv-parser.h>
30 #include <libpspp/array.h>
31 #include <libpspp/assertion.h>
32 #include <libpspp/hash-functions.h>
33 #include <libpspp/model-checker.h>
34 #include <libpspp/range-map.h>
35 #include <libpspp/range-set.h>
36 #include <libpspp/str.h>
37 #include <libpspp/taint.h>
38 #include <libpspp/tower.h>
45 /* lazy_casereader callback function to instantiate a casereader
46 from the datasheet. */
47 static struct casereader *
48 lazy_callback (void *ds_)
50 struct datasheet *ds = ds_;
51 return datasheet_make_reader (ds);
55 /* Maximum size of datasheet supported for model checking
62 struct datasheet_test_params
65 int max_rows; /* Maximum number of rows. */
66 int max_cols; /* Maximum number of columns. */
67 int backing_rows; /* Number of rows of backing store. */
68 int backing_cols; /* Number of columns of backing store. */
69 int widths[MAX_WIDTHS]; /* Allowed column widths. */
73 unsigned int next_value;
77 check_caseproto (struct mc *mc, const struct caseproto *benchmark,
78 const struct caseproto *test, const char *test_name)
80 size_t n_columns = caseproto_get_n_widths (benchmark);
84 if (n_columns != caseproto_get_n_widths (test))
86 mc_error (mc, "%s column count (%zu) does not match expected (%zu)",
87 test_name, caseproto_get_n_widths (test), n_columns);
92 for (col = 0; col < n_columns; col++)
94 int benchmark_width = caseproto_get_width (benchmark, col);
95 int test_width = caseproto_get_width (test, col);
96 if (benchmark_width != test_width)
98 mc_error (mc, "%s column %zu width (%d) differs from expected (%d)",
99 test_name, col, test_width, benchmark_width);
106 /* Checks that READER contains the N_ROWS rows and N_COLUMNS
107 columns of data in ARRAY, reporting any errors via MC. */
109 check_datasheet_casereader (struct mc *mc, struct casereader *reader,
110 union value array[MAX_ROWS][MAX_COLS],
111 size_t n_rows, const struct caseproto *proto)
113 size_t n_columns = caseproto_get_n_widths (proto);
115 if (!check_caseproto (mc, proto, casereader_get_proto (reader),
118 else if (casereader_get_case_cnt (reader) != n_rows)
120 if (casereader_get_case_cnt (reader) == CASENUMBER_MAX
121 && casereader_count_cases (reader) == n_rows)
122 mc_error (mc, "datasheet casereader has unknown case count");
124 mc_error (mc, "casereader row count (%lu) does not match "
126 (unsigned long int) casereader_get_case_cnt (reader),
134 for (row = 0; row < n_rows; row++)
138 c = casereader_read (reader);
141 mc_error (mc, "casereader_read failed reading row %zu of %zu "
142 "(%zu columns)", row, n_rows, n_columns);
146 for (col = 0; col < n_columns; col++)
148 int width = caseproto_get_width (proto, col);
149 if (!value_equal (case_data_idx (c, col), &array[row][col],
153 mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
155 row, col, n_rows, n_columns,
156 case_num_idx (c, col), array[row][col].f);
158 mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
160 row, col, n_rows, n_columns,
161 width, case_str_idx (c, col),
162 width, value_str (&array[row][col], width));
169 c = casereader_read (reader);
171 mc_error (mc, "casereader has extra cases (expected %zu)", n_rows);
175 /* Checks that datasheet DS contains has N_ROWS rows, N_COLUMNS
176 columns, and the same contents as ARRAY, reporting any
177 mismatches via mc_error. Then, adds DS to MC as a new state. */
179 check_datasheet (struct mc *mc, struct datasheet *ds,
180 union value array[MAX_ROWS][MAX_COLS],
181 size_t n_rows, const struct caseproto *proto)
183 size_t n_columns = caseproto_get_n_widths (proto);
184 struct datasheet *ds2;
185 struct casereader *reader;
186 unsigned long int serial = 0;
188 assert (n_rows < MAX_ROWS);
189 assert (n_columns < MAX_COLS);
191 /* Check contents of datasheet via datasheet functions. */
192 if (!check_caseproto (mc, proto, datasheet_get_proto (ds), "datasheet"))
194 /* check_caseproto emitted errors already. */
196 else if (n_rows != datasheet_get_n_rows (ds))
197 mc_error (mc, "row count (%lu) does not match expected (%zu)",
198 (unsigned long int) datasheet_get_n_rows (ds), n_rows);
202 bool difference = false;
204 for (row = 0; row < n_rows; row++)
205 for (col = 0; col < n_columns; col++)
207 int width = caseproto_get_width (proto, col);
208 union value *av = &array[row][col];
211 value_init (&v, width);
212 if (!datasheet_get_value (ds, row, col, &v))
214 if (!value_equal (&v, av, width))
217 mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
218 "%g != %g", row, col, n_rows, n_columns,
221 mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
223 row, col, n_rows, n_columns,
224 width, value_str (&v, width),
225 width, value_str (av, width));
228 value_destroy (&v, width);
235 mc_error (mc, "expected:");
237 for (row = 0; row < n_rows; row++)
240 ds_put_format (&s, "row %zu:", row);
241 for (col = 0; col < n_columns; col++)
243 const union value *v = &array[row][col];
244 int width = caseproto_get_width (proto, col);
246 ds_put_format (&s, " %g", v->f);
248 ds_put_format (&s, " '%.*s'", width, value_str (v, width));
250 mc_error (mc, "%s", ds_cstr (&s));
253 mc_error (mc, "actual:");
255 for (row = 0; row < n_rows; row++)
258 ds_put_format (&s, "row %zu:", row);
259 for (col = 0; col < n_columns; col++)
261 int width = caseproto_get_width (proto, col);
263 value_init (&v, width);
264 if (!datasheet_get_value (ds, row, col, &v))
267 ds_put_format (&s, " %g", v.f);
269 ds_put_format (&s, " '%.*s'",
270 width, value_str (&v, width));
272 mc_error (mc, "%s", ds_cstr (&s));
279 /* Check that datasheet contents are correct when read through
281 ds2 = clone_datasheet (ds);
282 reader = datasheet_make_reader (ds2);
283 check_datasheet_casereader (mc, reader, array, n_rows, proto);
284 casereader_destroy (reader);
286 /* Check that datasheet contents are correct when read through
287 casereader with lazy_casereader wrapped around it. This is
288 valuable because otherwise there is no non-GUI code that
289 uses the lazy_casereader. */
290 ds2 = clone_datasheet (ds);
291 reader = lazy_casereader_create (datasheet_get_proto (ds2), n_rows,
292 lazy_callback, ds2, &serial);
293 check_datasheet_casereader (mc, reader, array, n_rows, proto);
294 if (lazy_casereader_destroy (reader, serial))
296 /* Lazy casereader was never instantiated. This will
297 only happen if there are no rows (because in that case
298 casereader_read never gets called). */
299 datasheet_destroy (ds2);
301 mc_error (mc, "lazy casereader not instantiated, but should "
302 "have been (size %zu,%zu)", n_rows, n_columns);
306 /* Lazy casereader was instantiated. This is the common
307 case, in which some casereader operation
308 (casereader_read in this case) was performed on the
310 casereader_destroy (reader);
312 mc_error (mc, "lazy casereader instantiated, but should not "
313 "have been (size %zu,%zu)", n_rows, n_columns);
316 if (mc_discard_dup_state (mc, hash_datasheet (ds)))
317 datasheet_destroy (ds);
319 mc_add_state (mc, ds);
322 /* Extracts the contents of DS into DATA. */
324 extract_data (const struct datasheet *ds, union value data[MAX_ROWS][MAX_COLS])
326 const struct caseproto *proto = datasheet_get_proto (ds);
327 size_t n_columns = datasheet_get_n_columns (ds);
328 size_t n_rows = datasheet_get_n_rows (ds);
331 assert (n_rows < MAX_ROWS);
332 assert (n_columns < MAX_COLS);
333 for (row = 0; row < n_rows; row++)
334 for (col = 0; col < n_columns; col++)
336 int width = caseproto_get_width (proto, col);
337 union value *v = &data[row][col];
338 value_init (v, width);
339 if (!datasheet_get_value (ds, row, col, v))
344 /* Copies the contents of ODATA into DATA. Each of the N_ROWS
345 rows of ODATA and DATA must have prototype PROTO. */
347 clone_data (size_t n_rows, const struct caseproto *proto,
348 union value odata[MAX_ROWS][MAX_COLS],
349 union value data[MAX_ROWS][MAX_COLS])
351 size_t n_columns = caseproto_get_n_widths (proto);
354 assert (n_rows < MAX_ROWS);
355 assert (n_columns < MAX_COLS);
356 for (row = 0; row < n_rows; row++)
357 for (col = 0; col < n_columns; col++)
359 int width = caseproto_get_width (proto, col);
360 const union value *ov = &odata[row][col];
361 union value *v = &data[row][col];
362 value_init (v, width);
363 value_copy (v, ov, width);
368 release_data (size_t n_rows, const struct caseproto *proto,
369 union value data[MAX_ROWS][MAX_COLS])
371 size_t n_columns = caseproto_get_n_widths (proto);
374 assert (n_rows < MAX_ROWS);
375 assert (n_columns < MAX_COLS);
376 for (col = 0; col < n_columns; col++)
378 int width = caseproto_get_width (proto, col);
379 if (value_needs_init (width))
380 for (row = 0; row < n_rows; row++)
381 value_destroy (&data[row][col], width);
385 /* Clones the structure and contents of ODS into *DS,
386 and the contents of ODATA into DATA. */
388 clone_model (const struct datasheet *ods,
389 union value odata[MAX_ROWS][MAX_COLS],
390 struct datasheet **ds,
391 union value data[MAX_ROWS][MAX_COLS])
393 *ds = clone_datasheet (ods);
394 clone_data (datasheet_get_n_rows (ods), datasheet_get_proto (ods),
398 /* "init" function for struct mc_class. */
400 datasheet_mc_init (struct mc *mc)
402 struct datasheet_test_params *params = mc_get_aux (mc);
403 struct datasheet *ds;
405 if (params->backing_rows == 0 && params->backing_cols == 0)
407 /* Create unbacked datasheet. */
408 ds = datasheet_create (NULL);
409 mc_name_operation (mc, "empty datasheet");
410 check_datasheet (mc, ds, NULL, 0, caseproto_create ());
414 /* Create datasheet with backing. */
415 struct casewriter *writer;
416 struct casereader *reader;
417 union value data[MAX_ROWS][MAX_COLS];
418 struct caseproto *proto;
421 assert (params->backing_rows > 0 && params->backing_rows <= MAX_ROWS);
422 assert (params->backing_cols > 0 && params->backing_cols <= MAX_COLS);
424 /* XXX support different backing column widths */
425 proto = caseproto_create ();
426 for (col = 0; col < params->backing_cols; col++)
427 proto = caseproto_add_width (proto, 0);
429 writer = mem_writer_create (proto);
430 for (row = 0; row < params->backing_rows; row++)
434 c = case_create (proto);
435 for (col = 0; col < params->backing_cols; col++)
437 double value = params->next_value++;
438 data[row][col].f = value;
439 case_data_rw_idx (c, col)->f = value;
441 casewriter_write (writer, c);
443 caseproto_unref (proto);
445 reader = casewriter_make_reader (writer);
446 assert (reader != NULL);
448 ds = datasheet_create (reader);
449 mc_name_operation (mc, "datasheet with (%d,%d) backing",
450 params->backing_rows, params->backing_cols);
451 check_datasheet (mc, ds, data,
452 params->backing_rows, proto);
457 value_from_param (union value *value, int width, unsigned int idx)
460 value->f = idx & 0xffff;
463 unsigned int hash = hash_int (idx, 0);
464 char *string = value_str_rw (value, width);
468 for (offset = 0; offset < width; offset++)
469 string[offset] = "ABCDEFGHIJ"[(hash >> offset) % 10];
480 resize_cb (const union value *old_value, union value *new_value, void *aux_)
482 struct resize_cb_aux *aux = aux_;
484 value_from_param (new_value, aux->new_width,
485 value_hash (old_value, aux->old_width, 0));
488 /* "mutate" function for struct mc_class. */
490 datasheet_mc_mutate (struct mc *mc, const void *ods_)
492 struct datasheet_test_params *params = mc_get_aux (mc);
494 const struct datasheet *ods = ods_;
495 union value odata[MAX_ROWS][MAX_COLS];
496 union value data[MAX_ROWS][MAX_COLS];
497 const struct caseproto *oproto = datasheet_get_proto (ods);
498 size_t n_columns = datasheet_get_n_columns (ods);
499 size_t n_rows = datasheet_get_n_rows (ods);
500 size_t pos, new_pos, cnt, width_idx;
502 extract_data (ods, odata);
504 /* Insert a column in each possible position. */
505 if (n_columns < params->max_cols)
506 for (pos = 0; pos <= n_columns; pos++)
507 for (width_idx = 0; width_idx < params->n_widths; width_idx++)
508 if (mc_include_state (mc))
510 int width = params->widths[width_idx];
511 struct caseproto *proto;
512 struct datasheet *ds;
516 mc_name_operation (mc, "insert column at %zu "
517 "(from %zu to %zu columns)",
518 pos, n_columns, n_columns + 1);
519 clone_model (ods, odata, &ds, data);
521 value_init (&new, width);
522 value_from_param (&new, width, params->next_value++);
523 if (!datasheet_insert_column (ds, &new, width, pos))
524 mc_error (mc, "datasheet_insert_column failed");
525 proto = caseproto_insert_width (caseproto_ref (oproto),
528 for (i = 0; i < n_rows; i++)
530 insert_element (&data[i][0], n_columns, sizeof data[i][0],
532 value_init (&data[i][pos], width);
533 value_copy (&data[i][pos], &new, width);
535 value_destroy (&new, width);
537 check_datasheet (mc, ds, data, n_rows, proto);
538 release_data (n_rows, proto, data);
539 caseproto_unref (proto);
542 /* Resize each column to each possible new size. */
543 for (pos = 0; pos < n_columns; pos++)
544 for (width_idx = 0; width_idx < params->n_widths; width_idx++)
546 int owidth = caseproto_get_width (oproto, pos);
547 int width = params->widths[width_idx];
548 if (mc_include_state (mc))
550 struct resize_cb_aux aux;
551 struct caseproto *proto;
552 struct datasheet *ds;
555 mc_name_operation (mc, "resize column %zu (of %zu) "
556 "from width %d to %d",
557 pos, n_columns, owidth, width);
558 clone_model (ods, odata, &ds, data);
560 aux.old_width = owidth;
561 aux.new_width = width;
562 if (!datasheet_resize_column (ds, pos, width, resize_cb, &aux))
564 proto = caseproto_set_width (caseproto_ref (oproto), pos, width);
566 for (i = 0; i < n_rows; i++)
568 union value *old_value = &data[i][pos];
569 union value new_value;
570 value_init (&new_value, width);
571 resize_cb (old_value, &new_value, &aux);
572 value_swap (old_value, &new_value);
573 value_destroy (&new_value, owidth);
576 check_datasheet (mc, ds, data, n_rows, proto);
577 release_data (n_rows, proto, data);
578 caseproto_unref (proto);
582 /* Delete all possible numbers of columns from all possible
584 for (pos = 0; pos < n_columns; pos++)
585 for (cnt = 1; cnt < n_columns - pos; cnt++)
586 if (mc_include_state (mc))
588 struct caseproto *proto;
589 struct datasheet *ds;
592 mc_name_operation (mc, "delete %zu columns at %zu "
593 "(from %zu to %zu columns)",
594 cnt, pos, n_columns, n_columns - cnt);
595 clone_model (ods, odata, &ds, data);
597 datasheet_delete_columns (ds, pos, cnt);
598 proto = caseproto_remove_widths (caseproto_ref (oproto), pos, cnt);
600 for (i = 0; i < n_rows; i++)
602 for (j = pos; j < pos + cnt; j++)
603 value_destroy (&data[i][j], caseproto_get_width (oproto, j));
604 remove_range (&data[i], n_columns, sizeof *data[i], pos, cnt);
607 check_datasheet (mc, ds, data, n_rows, proto);
608 release_data (n_rows, proto, data);
609 caseproto_unref (proto);
612 /* Move all possible numbers of columns from all possible
613 existing positions to all possible new positions. */
614 for (pos = 0; pos < n_columns; pos++)
615 for (cnt = 1; cnt < n_columns - pos; cnt++)
616 for (new_pos = 0; new_pos < n_columns - cnt; new_pos++)
617 if (mc_include_state (mc))
619 struct caseproto *proto;
620 struct datasheet *ds;
623 clone_model (ods, odata, &ds, data);
624 mc_name_operation (mc, "move %zu columns (of %zu) from %zu to %zu",
625 cnt, n_columns, pos, new_pos);
627 datasheet_move_columns (ds, pos, new_pos, cnt);
629 for (i = 0; i < n_rows; i++)
630 move_range (&data[i], n_columns, sizeof data[i][0],
632 proto = caseproto_move_widths (caseproto_ref (oproto),
635 check_datasheet (mc, ds, data, n_rows, proto);
636 release_data (n_rows, proto, data);
637 caseproto_unref (proto);
640 /* Insert all possible numbers of rows in all possible
642 for (pos = 0; pos <= n_rows; pos++)
643 for (cnt = 1; cnt <= params->max_rows - n_rows; cnt++)
644 if (mc_include_state (mc))
646 struct datasheet *ds;
647 struct ccase *c[MAX_ROWS];
650 clone_model (ods, odata, &ds, data);
651 mc_name_operation (mc, "insert %zu rows at %zu "
652 "(from %zu to %zu rows)",
653 cnt, pos, n_rows, n_rows + cnt);
655 for (i = 0; i < cnt; i++)
657 c[i] = case_create (oproto);
658 for (j = 0; j < n_columns; j++)
659 value_from_param (case_data_rw_idx (c[i], j),
660 caseproto_get_width (oproto, j),
661 params->next_value++);
664 insert_range (data, n_rows, sizeof data[pos], pos, cnt);
665 for (i = 0; i < cnt; i++)
666 for (j = 0; j < n_columns; j++)
668 int width = caseproto_get_width (oproto, j);
669 value_init (&data[i + pos][j], width);
670 value_copy (&data[i + pos][j], case_data_idx (c[i], j), width);
673 if (!datasheet_insert_rows (ds, pos, c, cnt))
674 mc_error (mc, "datasheet_insert_rows failed");
676 check_datasheet (mc, ds, data, n_rows + cnt, oproto);
677 release_data (n_rows + cnt, oproto, data);
680 /* Delete all possible numbers of rows from all possible
682 for (pos = 0; pos < n_rows; pos++)
683 for (cnt = 1; cnt < n_rows - pos; cnt++)
684 if (mc_include_state (mc))
686 struct datasheet *ds;
688 clone_model (ods, odata, &ds, data);
689 mc_name_operation (mc, "delete %zu rows at %zu "
690 "(from %zu to %zu rows)",
691 cnt, pos, n_rows, n_rows - cnt);
693 datasheet_delete_rows (ds, pos, cnt);
695 release_data (cnt, oproto, &data[pos]);
696 remove_range (&data[0], n_rows, sizeof data[0], pos, cnt);
698 check_datasheet (mc, ds, data, n_rows - cnt, oproto);
699 release_data (n_rows - cnt, oproto, data);
702 /* Move all possible numbers of rows from all possible existing
703 positions to all possible new positions. */
704 for (pos = 0; pos < n_rows; pos++)
705 for (cnt = 1; cnt < n_rows - pos; cnt++)
706 for (new_pos = 0; new_pos < n_rows - cnt; new_pos++)
707 if (mc_include_state (mc))
709 struct datasheet *ds;
711 clone_model (ods, odata, &ds, data);
712 mc_name_operation (mc, "move %zu rows (of %zu) from %zu to %zu",
713 cnt, n_rows, pos, new_pos);
715 datasheet_move_rows (ds, pos, new_pos, cnt);
717 move_range (&data[0], n_rows, sizeof data[0],
720 check_datasheet (mc, ds, data, n_rows, oproto);
721 release_data (n_rows, oproto, data);
724 release_data (n_rows, oproto, odata);
727 /* "destroy" function for struct mc_class. */
729 datasheet_mc_destroy (const struct mc *mc UNUSED, void *ds_)
731 struct datasheet *ds = ds_;
732 datasheet_destroy (ds);
746 static struct argv_option datasheet_argv_options[N_DATASHEET_OPTIONS] =
748 {"max-rows", 0, required_argument, OPT_MAX_ROWS},
749 {"max-columns", 0, required_argument, OPT_MAX_COLUMNS},
750 {"backing-rows", 0, required_argument, OPT_BACKING_ROWS},
751 {"backing-columns", 0, required_argument, OPT_BACKING_COLUMNS},
752 {"widths", 0, required_argument, OPT_WIDTHS},
753 {"help", 'h', no_argument, OPT_HELP},
756 static void usage (void);
759 datasheet_option_callback (int id, void *params_)
761 struct datasheet_test_params *params = params_;
765 params->max_rows = atoi (optarg);
768 case OPT_MAX_COLUMNS:
769 params->max_cols = atoi (optarg);
772 case OPT_BACKING_ROWS:
773 params->backing_rows = atoi (optarg);
776 case OPT_BACKING_COLUMNS:
777 params->backing_cols = atoi (optarg);
785 params->n_widths = 0;
786 for (w = strtok (optarg, ", "); w != NULL; w = strtok (NULL, ", "))
788 int value = atoi (w);
790 if (params->n_widths >= MAX_WIDTHS)
791 error (1, 0, "Too many widths on --widths (only %d are allowed)",
793 if (!isdigit (w[0]) || value < 0 || value > 31)
794 error (1, 0, "--widths argument must be a list of 1 to %d "
795 "integers between 0 and 31 in increasing order",
798 /* This is an artificial requirement merely to ensure
799 that there are no duplicates. Duplicates aren't a
800 real problem but they would waste time. */
802 error (1, 0, "--widths arguments must be in increasing order");
804 params->widths[params->n_widths++] = value;
806 if (params->n_widths == 0)
807 error (1, 0, "at least one value must be specified on --widths");
823 printf ("%s, for testing the datasheet implementation.\n"
824 "Usage: %s [OPTION]...\n"
825 "\nTest state space parameters (min...max, default):\n"
826 " --max-rows=N Maximum number of rows (0...5, 3)\n"
827 " --max-rows=N Maximum number of columns (0...5, 3)\n"
828 " --backing-rows=N Rows of backing store (0...max_rows, 0)\n"
829 " --backing-columns=N Columns of backing store (0...max_cols, 0)\n"
830 " --widths=W[,W]... Column widths to test, where 0=numeric,\n"
831 " other values are string widths (0,1,11)\n",
832 program_name, program_name);
834 fputs ("\nOther options:\n"
835 " --help Display this help message\n"
836 "\nReport bugs to <bug-gnu-pspp@gnu.org>\n",
842 main (int argc, char *argv[])
844 static const struct mc_class datasheet_mc_class =
848 datasheet_mc_destroy,
851 struct datasheet_test_params params;
852 struct mc_options *options;
853 struct mc_results *results;
854 struct argv_parser *parser;
858 set_program_name (argv[0]);
860 /* Default parameters. */
863 params.backing_rows = 0;
864 params.backing_cols = 0;
865 params.widths[0] = 0;
866 params.widths[1] = 1;
867 params.widths[2] = 11;
869 params.next_value = 1;
871 /* Parse comand line. */
872 parser = argv_parser_create ();
873 options = mc_options_create ();
874 mc_options_register_argv_parser (options, parser);
875 argv_parser_add_options (parser, datasheet_argv_options, N_DATASHEET_OPTIONS,
876 datasheet_option_callback, ¶ms);
877 if (!argv_parser_run (parser, argc, argv))
879 argv_parser_destroy (parser);
880 verbosity = mc_options_get_verbosity (options);
882 /* Force parameters into allowed ranges. */
883 params.max_rows = MIN (params.max_rows, MAX_ROWS);
884 params.max_cols = MIN (params.max_cols, MAX_COLS);
885 params.backing_rows = MIN (params.backing_rows, params.max_rows);
886 params.backing_cols = MIN (params.backing_cols, params.max_cols);
887 mc_options_set_aux (options, ¶ms);
888 results = mc_run (&datasheet_mc_class, options);
890 /* Output results. */
891 success = (mc_results_get_stop_reason (results) != MC_MAX_ERROR_COUNT
892 && mc_results_get_stop_reason (results) != MC_INTERRUPTED);
893 if (verbosity > 0 || !success)
897 printf ("Parameters: "
898 "--max-rows=%d --max-columns=%d "
899 "--backing-rows=%d --backing-columns=%d ",
900 params.max_rows, params.max_cols,
901 params.backing_rows, params.backing_cols);
902 printf ("--widths=");
903 for (i = 0; i < params.n_widths; i++)
907 printf ("%d", params.widths[i]);
910 mc_results_print (results, stdout);
912 mc_results_destroy (results);
914 return success ? 0 : EXIT_FAILURE;