X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fxforms%2Fsample.c;h=665cd4468edc370e80390441cb27d1ddb9fa3f27;hb=9d24b4fb4d831d7a2bebb51fd111726f0e682e45;hp=2aa21c22a72ce3101c6d555927f938a28afb41e8;hpb=43b1296aafe7582e7dbe6c2b6a8b478d7d9b0fcf;p=pspp diff --git a/src/language/xforms/sample.c b/src/language/xforms/sample.c index 2aa21c22a7..665cd4468e 100644 --- a/src/language/xforms/sample.c +++ b/src/language/xforms/sample.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009-2011 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 @@ -21,15 +21,16 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "data/dataset.h" +#include "data/variable.h" +#include "language/command.h" +#include "language/lexer/lexer.h" +#include "libpspp/compiler.h" +#include "libpspp/message.h" +#include "libpspp/str.h" +#include "math/random.h" + +#include "gl/xalloc.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -50,8 +51,7 @@ struct sample_trns unsigned frac; /* TYPE_FRACTION: a fraction of UINT_MAX. */ }; -static trns_proc_func sample_trns_proc; -static trns_free_func sample_trns_free; +static const struct trns_class sample_trns_class; int cmd_sample (struct lexer *lexer, struct dataset *ds) @@ -87,17 +87,9 @@ cmd_sample (struct lexer *lexer, struct dataset *ds) lex_get (lexer); if (!lex_force_match_id (lexer, "FROM")) return CMD_FAILURE; - if (!lex_force_int (lexer)) + if (!lex_force_int_range (lexer, "FROM", a + 1, INT_MAX)) return CMD_FAILURE; b = lex_integer (lexer); - if (a >= b) - { - msg (SE, _("Cannot sample %d observations from a population of " - "%d."), - a, b); - return CMD_FAILURE; - } - frac = 0; } lex_get (lexer); @@ -108,14 +100,14 @@ cmd_sample (struct lexer *lexer, struct dataset *ds) trns->N = b; trns->m = trns->t = 0; trns->frac = frac; - add_transformation (ds, sample_trns_proc, sample_trns_free, trns); + add_transformation (ds, &sample_trns_class, trns); - return lex_end_of_command (lexer); + return CMD_SUCCESS; } /* Executes a SAMPLE transformation. */ -static int -sample_trns_proc (void *t_, struct ccase *c UNUSED, +static enum trns_result +sample_trns_proc (void *t_, struct ccase **c UNUSED, casenumber case_num UNUSED) { struct sample_trns *t = t_; @@ -153,3 +145,9 @@ sample_trns_free (void *t_) free (t); return true; } + +static const struct trns_class sample_trns_class = { + .name = "SAMPLE", + .execute = sample_trns_proc, + .destroy = sample_trns_free, +};