}
}
-/* Returns nonzero if CLASS is the class of SOURCE. */
-int
+/* Returns true if CLASS is the class of SOURCE. */
+bool
case_source_is_class (const struct case_source *source,
const struct case_source_class *class)
{
void *);
void free_case_source (struct case_source *);
-int case_source_is_class (const struct case_source *,
+bool case_source_is_class (const struct case_source *,
const struct case_source_class *);
#endif /* case-source.h */
}
/* Attempts to create C as a new case that holds VALUE_CNT
- values. Returns nonzero if successful, zero if memory
+ values. Returns true if successful, false if memory
allocation failed. */
-int
+bool
case_try_create (struct ccase *c, size_t value_cnt)
{
c->case_data = malloc (case_size (value_cnt));
{
c->case_data->value_cnt = value_cnt;
c->case_data->ref_cnt = 1;
- return 1;
+ return true;
}
- else
- return 0;
+
+ return false;
}
/* Tries to initialize CLONE as a copy of ORIG.
- Returns nonzero if successful, zero if memory allocation
+ Returns true if successful, false if memory allocation
failed. */
-int
+bool
case_try_clone (struct ccase *clone, const struct ccase *orig)
{
case_clone (clone, orig);
- return 1;
+ return true;
}
#ifdef DEBUGGING
void case_resize (struct ccase *, size_t old_cnt, size_t new_cnt);
void case_swap (struct ccase *, struct ccase *);
-int case_try_create (struct ccase *, size_t value_cnt);
-int case_try_clone (struct ccase *, const struct ccase *);
+bool case_try_create (struct ccase *, size_t value_cnt);
+bool case_try_clone (struct ccase *, const struct ccase *);
CASE_INLINE void case_copy (struct ccase *dst, size_t dst_idx,
const struct ccase *src, size_t src_idx,
i->e--;
}
-/* Returns nonzero if we're not at the end of the string being
+/* Returns true if we're not at the end of the string being
parsed. */
static inline bool
have_char (struct data_in *i)
\f
/* Find out information about files. */
-/* Returns nonzero iff NAME specifies an absolute file name. */
-int
+/* Returns true iff NAME specifies an absolute file name. */
+bool
fn_is_absolute (const char *name)
{
#ifdef unix
|| !strncmp (name, "./", 2)
|| !strncmp (name, "../", 3)
|| name[0] == '~')
- return 1;
+ return true;
#elif defined (__MSDOS__)
if (name[0] == '\\'
|| !strncmp (name, ".\\", 2)
|| !strncmp (name, "..\\", 3)
|| (name[0] && name[1] == ':'))
- return 1;
+ return true;
#endif
- return 0;
+ return false;
}
-/* Returns 1 if FILE_NAME is a virtual file that doesn't
- really exist on disk, 0 if it's a real file name. */
-int
+/* Returns true if FILE_NAME is a virtual file that doesn't
+ really exist on disk, false if it's a real file name. */
+bool
fn_is_special (const char *file_name)
{
if (!strcmp (file_name, "-") || !strcmp (file_name, "stdin")
|| (*file_name && file_name[strlen (file_name) - 1] == '|')
#endif
)
- return 1;
+ return true;
- return 0;
+ return false;
}
-/* Returns nonzero if file with name NAME exists. */
-int
+/* Returns true if file with name NAME exists. */
+bool
fn_exists (const char *name)
{
#ifdef unix
#else
FILE *f = fopen (name, "r");
if (!f)
- return 0;
+ return false;
fclose (f);
- return 1;
+ return true;
#endif
}
#define FILE_NAME_H 1
#include <stdio.h>
+#include <stdbool.h>
/* Search path for configuration files. */
extern const char *config_path;
char *fn_get_cwd (void);
-int fn_is_absolute (const char *fn);
-int fn_is_special (const char *fn);
-int fn_exists (const char *fn);
+bool fn_is_absolute (const char *fn);
+bool fn_is_special (const char *fn);
+bool fn_exists (const char *fn);
char *fn_readlink (const char *fn);
const char *fn_getenv (const char *variable);
}
/* If VLS does not already contain a value label for VALUE, adds
- LABEL for it and returns nonzero. Otherwise, returns zero.
+ LABEL for it and returns true. Otherwise, returns false.
Behavior is undefined if VLS's width is greater than
MAX_SHORT_STRING. */
-int
+bool
val_labs_add (struct val_labs *vls, union value value, const char *label)
{
struct int_val_lab *ivl;
if (*vlpp == NULL)
{
*vlpp = ivl;
- return 1;
- }
- else
- {
- free_int_val_lab (ivl, vls);
- return 0;
+ return true;
}
+ free_int_val_lab (ivl, vls);
+ return false;
}
-/* Sets LABEL as the value label for VALUE in VLS. Returns zero
- if there wasn't already a value label for VALUE, or nonzero if
+/* Sets LABEL as the value label for VALUE in VLS. Returns false
+ if there wasn't already a value label for VALUE, or true if
there was. Behavior is undefined if VLS's width is greater
than MAX_SHORT_STRING. */
-int
+bool
val_labs_replace (struct val_labs *vls, union value value, const char *label)
{
struct int_val_lab *ivl;
if (vls->labels == NULL)
{
val_labs_add (vls, value, label);
- return 0;
+ return false;
}
ivl = hsh_replace (vls->labels, create_int_val_lab (vls, value, label));
if (ivl == NULL)
- return 0;
+ return false;
else
{
free_int_val_lab (ivl, vls);
- return 1;
+ return true;
}
}
-/* Removes any value label for VALUE within VLS. Returns nonzero
+/* Removes any value label for VALUE within VLS. Returns true
if a value label was removed. Behavior is undefined if VLS's
width is greater than MAX_SHORT_STRING. */
-int
+bool
val_labs_remove (struct val_labs *vls, union value value)
{
assert (vls != NULL);
return deleted;
}
else
- return 0;
+ return false;
}
/* Searches VLS for a value label for VALUE. If successful,
bool val_labs_can_set_width (const struct val_labs *, int new_width);
void val_labs_set_width (struct val_labs *, int new_width);
-int val_labs_add (struct val_labs *, union value, const char *);
-int val_labs_replace (struct val_labs *, union value, const char *);
-int val_labs_remove (struct val_labs *, union value);
+bool val_labs_add (struct val_labs *, union value, const char *);
+bool val_labs_replace (struct val_labs *, union value, const char *);
+bool val_labs_remove (struct val_labs *, union value);
char *val_labs_find (const struct val_labs *, union value);
struct val_labs_iterator;
return string;
}
-/* Returns nonzero if strings A and B can be confused based on
+/* Returns true if strings A and B can be confused based on
their first three letters. */
-static int
+static bool
conflicting_3char_prefixes (const char *a, const char *b)
{
size_t aw_len, bw_len;
/* Words that are the same don't conflict. */
if (aw_len == bw_len && !buf_compare_case (aw, bw, aw_len))
- return 0;
+ return false;
/* Words that are otherwise the same in the first three letters
do conflict. */
|| (bw_len == 3 && aw_len > 3)) && !buf_compare_case (aw, bw, 3);
}
-/* Returns nonzero if CMD can be confused with another command
+/* Returns true if CMD can be confused with another command
based on the first three letters of its first word. */
-static int
+static bool
conflicting_3char_prefix_command (const struct command *cmd)
{
assert (cmd >= commands && cmd < commands + command_cnt);
}
/* Writes record REC having length LEN to the file corresponding to
- HANDLE. REC is not null-terminated. Returns nonzero on success,
- zero on failure. */
-int
+ HANDLE. REC is not null-terminated. Returns true on success,
+ false on failure. */
+bool
dfm_put_record (struct dfm_writer *w, const char *rec, size_t len)
{
assert (w != NULL);
if (dfm_write_error (w))
- return 0;
+ return false;
if (fh_get_mode (w->fh) == FH_MODE_BINARY
&& len < fh_get_record_width (w->fh))
struct dfm_writer *dfm_open_writer (struct file_handle *);
bool dfm_close_writer (struct dfm_writer *);
bool dfm_write_error (const struct dfm_writer *);
-int dfm_put_record (struct dfm_writer *, const char *rec, size_t len);
+bool dfm_put_record (struct dfm_writer *, const char *rec, size_t len);
#endif /* data-writer.h */
}
/* Is there at least one token left in the data file? */
-static int
+static bool
another_token (struct dfm_reader *reader)
{
for (;;)
size_t space_cnt;
if (dfm_eof (reader))
- return 0;
+ return false;
p = dfm_get_record (reader);
space_cnt = ss_span (p, ss_cstr (CC_SPACES));
if (space_cnt < ss_length (p))
{
dfm_forward_columns (reader, space_cnt);
- return 1;
+ return true;
}
dfm_forward_record (reader);
}
+ NOT_REACHED();
}
/* Parse a MATRIX DATA token from READER into TOKEN. */
double *split_values; /* SPLIT FILE variable values. */
};
-static int nr_read_splits (struct nr_aux_data *, int compare);
-static int nr_read_factors (struct nr_aux_data *, int cell);
+static bool nr_read_splits (struct nr_aux_data *, int compare);
+static bool nr_read_factors (struct nr_aux_data *, int cell);
static bool nr_output_data (struct nr_aux_data *, struct ccase *,
write_case_func *, write_case_data);
static bool matrix_data_read_without_rowtype (struct case_source *source,
}
/* Read the split file variables. If COMPARE is 1, compares the
- values read to the last values read and returns 1 if they're equal,
- 0 otherwise. */
-static int
+ values read to the last values read and returns true if they're equal,
+ false otherwise. */
+static bool
nr_read_splits (struct nr_aux_data *nr, int compare)
{
struct matrix_data_pgm *mx = nr->mx;
if (compare && just_read)
{
just_read = 0;
- return 1;
+ return true;
}
if (dict_get_split_vars (default_dict) == NULL)
- return 1;
+ return true;
if (mx->single_split)
{
struct mxd_var *mv = dict_get_split_vars (default_dict)[0]->aux;
nr->split_values[0] = ++mv->sub_type;
}
- return 1;
+ return true;
}
if (!compare)
{
struct matrix_token token;
if (!mget_token (&token, mx->reader))
- return 0;
+ return false;
if (token.type != MNUM)
{
msg (SE, _("Syntax error expecting SPLIT FILE value %s."),
context (mx->reader));
- return 0;
+ return false;
}
if (!compare)
msg (SE, _("Expecting value %g for %s."),
nr->split_values[i],
dict_get_split_vars (default_dict)[i]->name);
- return 0;
+ return false;
}
}
- return 1;
+ return true;
}
/* Read the factors for cell CELL. If COMPARE is 1, compares the
- values read to the last values read and returns 1 if they're equal,
- 0 otherwise. */
-static int
+ values read to the last values read and returns true if they're equal,
+ false otherwise. */
+static bool
nr_read_factors (struct nr_aux_data *nr, int cell)
{
struct matrix_data_pgm *mx = nr->mx;
- int compare;
+ bool compare;
if (mx->n_factors == 0)
- return 1;
+ return true;
assert (nr->max_cell_idx >= cell);
if (cell != nr->max_cell_idx)
- compare = 1;
+ compare = true;
else
{
- compare = 0;
+ compare = false;
nr->max_cell_idx++;
}
{
struct matrix_token token;
if (!mget_token (&token, mx->reader))
- return 0;
+ return false;
if (token.type != MNUM)
{
msg (SE, _("Syntax error expecting factor value %s."),
context (mx->reader));
- return 0;
+ return false;
}
if (!compare)
msg (SE, _("Syntax error expecting value %g for %s %s."),
nr->factor_values[i + mx->n_factors * cell],
mx->factors[i]->name, context (mx->reader));
- return 0;
+ return false;
}
}
}
- return 1;
+ return true;
}
/* Write the contents of a cell having content type CONTENT and data
struct factor_data *current; /* Current factor. */
};
-static int wr_read_splits (struct wr_aux_data *, struct ccase *,
+static bool wr_read_splits (struct wr_aux_data *, struct ccase *,
write_case_func *, write_case_data);
static bool wr_output_data (struct wr_aux_data *, struct ccase *,
write_case_func *, write_case_data);
-static int wr_read_rowtype (struct wr_aux_data *,
+static bool wr_read_rowtype (struct wr_aux_data *,
const struct matrix_token *, struct dfm_reader *);
-static int wr_read_factors (struct wr_aux_data *);
-static int wr_read_indeps (struct wr_aux_data *);
+static bool wr_read_factors (struct wr_aux_data *);
+static bool wr_read_indeps (struct wr_aux_data *);
static bool matrix_data_read_with_rowtype (struct case_source *,
struct ccase *,
write_case_func *,
/* Read the split file variables. If they differ from the previous
set of split variables then output the data. Returns success. */
-static int
+static bool
wr_read_splits (struct wr_aux_data *wr,
struct ccase *c,
write_case_func *write_case, write_case_data wc_data)
{
struct matrix_data_pgm *mx = wr->mx;
- int compare;
+ bool compare;
size_t split_cnt;
split_cnt = dict_get_split_cnt (default_dict);
if (split_cnt == 0)
- return 1;
+ return true;
if (wr->split_values)
- compare = 1;
+ compare = true;
else
{
- compare = 0;
+ compare = false;
wr->split_values = xnmalloc (split_cnt, sizeof *wr->split_values);
}
{
- int different = 0;
+ bool different = false;
int i;
for (i = 0; i < split_cnt; i++)
{
struct matrix_token token;
if (!mget_token (&token, mx->reader))
- return 0;
+ return false;
if (token.type != MNUM)
{
msg (SE, _("Syntax error %s expecting SPLIT FILE value."),
context (mx->reader));
- return 0;
+ return false;
}
if (compare && wr->split_values[i] != token.number && !different)
{
if (!wr_output_data (wr, c, write_case, wc_data))
return 0;
- different = 1;
+ different = true;
mx->cells = 0;
}
wr->split_values[i] = token.number;
}
}
- return 1;
+ return true;
}
/* Compares doubles A and B, treating SYSMIS as greatest. */
/* Sets ROWTYPE_ based on the given TOKEN read from READER.
Return success. */
-static int
+static bool
wr_read_rowtype (struct wr_aux_data *wr,
const struct matrix_token *token,
struct dfm_reader *reader)
if (wr->content != -1)
{
msg (SE, _("Multiply specified ROWTYPE_ %s."), context (reader));
- return 0;
+ return false;
}
if (token->type != MSTR)
{
msg (SE, _("Syntax error %s expecting ROWTYPE_ string."),
context (reader));
- return 0;
+ return false;
}
{
return 0;
}
- return 1;
+ return true;
}
/* Read the factors for the current row. Select a set of factors and
point wr_current to it. */
-static int
+static bool
wr_read_factors (struct wr_aux_data *wr)
{
struct matrix_data_pgm *mx = wr->mx;
winnage:
local_free (factor_values);
- return 1;
+ return true;
lossage:
local_free (factor_values);
- return 0;
+ return false;
}
/* Read the independent variables into wr->current. */
-static int
+static bool
wr_read_indeps (struct wr_aux_data *wr)
{
struct matrix_data_pgm *mx = wr->mx;
{
msg (SE, _("Duplicate specification for %s."),
content_names[wr->content]);
- return 0;
+ return false;
}
if (type == 0)
n_cols = mx->n_continuous;
{
msg (SE, _("Too many rows of matrix data for %s."),
content_names[wr->content]);
- return 0;
+ return false;
}
switch (mx->section)
{
struct matrix_token token;
if (!mget_token (&token, mx->reader))
- return 0;
+ return false;
if (token.type != MNUM)
{
msg (SE, _("Syntax error expecting value for %s %s."),
dict_get_var (default_dict, mx->first_continuous + j)->name,
context (mx->reader));
- return 0;
+ return false;
}
*cp++ = token.number;
}
if (mx->fmt != FREE
&& !force_eol (mx->reader, content_names[wr->content]))
- return 0;
+ return false;
}
- return 1;
+ return true;
}
\f
/* Matrix source. */
size_t rename_cnt;
};
-static int rearrange_dict (struct dictionary *d,
+static bool rearrange_dict (struct dictionary *d,
const struct var_modification *vm);
/* Performs MODIFY VARS command. */
}
/* Reoders, removes, and renames variables in dictionary D
- according to VM. Returns nonzero if successful, zero if there
+ according to VM. Returns true if successful, false if there
would have been duplicate variable names if the modifications
had been carried out. In the latter case, the dictionary is
not modified. */
-static int
+static bool
rearrange_dict (struct dictionary *d, const struct var_modification *vm)
{
char **rename_old_names;
/* Check whether the modifications will cause duplicate
names. */
if (!validate_var_modification (d, vm))
- return 0;
+ return false;
/* Record the old names of variables to rename. After
variables are deleted, we can't depend on the variables to
free (rename_vars);
free (rename_new_names);
- return 1;
+ return true;
}
/* Pointer to next token in getl_buf. */
static char *prog;
-/* Nonzero only if this line ends with a terminal dot. */
-static int dot;
+/* True only if this line ends with a terminal dot. */
+static bool dot;
-/* Nonzero only if the last token returned was T_STOP. */
-static int eof;
+/* True only if the last token returned was T_STOP. */
+static bool eof;
/* If nonzero, next token returned by lex_get().
Used only in exceptional circumstances. */
}
else if (!lex_get_line ())
{
- eof = 1;
+ eof = true;
token = T_STOP;
#if DUMP_TOKENS
dump_token ();
\f
/* Token matching functions. */
-/* If TOK is the current token, skips it and returns nonzero.
- Otherwise, returns zero. */
-int
+/* If TOK is the current token, skips it and returns true
+ Otherwise, returns false. */
+bool
lex_match (int t)
{
if (token == t)
{
lex_get ();
- return 1;
+ return true;
}
else
- return 0;
+ return false;
}
/* If the current token is the identifier S, skips it and returns
- nonzero. The identifier may be abbreviated to its first three
+ true. The identifier may be abbreviated to its first three
letters.
- Otherwise, returns zero. */
-int
+ Otherwise, returns false. */
+bool
lex_match_id (const char *s)
{
if (token == T_ID && lex_id_match (s, tokid))
{
lex_get ();
- return 1;
+ return true;
}
else
- return 0;
+ return false;
}
-/* If the current token is integer N, skips it and returns nonzero.
- Otherwise, returns zero. */
-int
+/* If the current token is integer N, skips it and returns true.
+ Otherwise, returns false. */
+bool
lex_match_int (int x)
{
if (lex_is_integer () && lex_integer () == x)
{
lex_get ();
- return 1;
+ return true;
}
else
- return 0;
+ return false;
}
\f
/* Forced matches. */
/* If this token is identifier S, fetches the next token and returns
nonzero.
Otherwise, reports an error and returns zero. */
-int
+bool
lex_force_match_id (const char *s)
{
if (token == T_ID && lex_id_match (s, tokid))
{
lex_get ();
- return 1;
+ return true;
}
else
{
lex_error (_("expecting `%s'"), s);
- return 0;
+ return false;
}
}
/* If the current token is T, skips the token. Otherwise, reports an
- error and returns from the current function with return value 0. */
-int
+ error and returns from the current function with return value false. */
+bool
lex_force_match (int t)
{
if (token == t)
{
lex_get ();
- return 1;
+ return true;
}
else
{
lex_error (_("expecting `%s'"), lex_token_name (t));
- return 0;
+ return false;
}
}
-/* If this token is a string, does nothing and returns nonzero.
- Otherwise, reports an error and returns zero. */
-int
+/* If this token is a string, does nothing and returns true.
+ Otherwise, reports an error and returns false. */
+bool
lex_force_string (void)
{
if (token == T_STRING)
- return 1;
+ return true;
else
{
lex_error (_("expecting string"));
- return 0;
+ return false;
}
}
-/* If this token is an integer, does nothing and returns nonzero.
- Otherwise, reports an error and returns zero. */
-int
+/* If this token is an integer, does nothing and returns true.
+ Otherwise, reports an error and returns false. */
+bool
lex_force_int (void)
{
if (lex_is_integer ())
- return 1;
+ return true;
else
{
lex_error (_("expecting integer"));
- return 0;
+ return false;
}
}
-/* If this token is a number, does nothing and returns nonzero.
- Otherwise, reports an error and returns zero. */
-int
+/* If this token is a number, does nothing and returns true.
+ Otherwise, reports an error and returns false. */
+bool
lex_force_num (void)
{
if (lex_is_number ())
- return 1;
+ return true;
else
{
lex_error (_("expecting number"));
- return 0;
+ return false;
}
}
-/* If this token is an identifier, does nothing and returns nonzero.
- Otherwise, reports an error and returns zero. */
-int
+/* If this token is an identifier, does nothing and returns true.
+ Otherwise, reports an error and returns false. */
+bool
lex_force_id (void)
{
if (token == T_ID)
- return 1;
+ return true;
else
{
lex_error (_("expecting identifier"));
- return 0;
+ return false;
}
}
/* Weird token functions. */
lex_discard_line (void)
{
prog = ds_end (&getl_buf);
- dot = put_token = 0;
+ dot = false;
+ put_token = 0;
}
/* Sets the current position in the current line to P, which must be
void
lex_reset_eof (void)
{
- eof = 0;
+ eof = false;
}
/* Skip a COMMENT command. */
if (!lex_get_line ())
{
put_token = T_STOP;
- eof = 1;
+ eof = true;
return;
}
long lex_integer (void);
/* Token matching functions. */
-int lex_match (int);
-int lex_match_id (const char *);
-int lex_match_int (int);
+bool lex_match (int);
+bool lex_match_id (const char *);
+bool lex_match_int (int);
/* Forcible matching functions. */
-int lex_force_match (int);
-int lex_force_match_id (const char *);
-int lex_force_int (void);
-int lex_force_num (void);
-int lex_force_id (void);
-int lex_force_string (void);
+bool lex_force_match (int);
+bool lex_force_match_id (const char *);
+bool lex_force_int (void);
+bool lex_force_num (void);
+bool lex_force_id (void);
+bool lex_force_string (void);
/* Weird token functions. */
int lex_look_ahead (void);
char *program_name;
/* Have the input and output files been opened yet? */
-int is_open;
+bool is_open;
/* Input, output files. */
FILE *in, *out;
{
if (!is_open)
return;
- is_open = 0;
+ is_open = false;
fclose (in);
fclose (out);
if (remove (ofn) == -1)
/* Read one line from the input file into buf. Lines having special
formats are handled specially. */
-static int
+static bool
get_line (void)
{
ln++;
{
if (ferror (in))
fail ("%s: fgets: %s", ifn, strerror (errno));
- return 0;
+ return false;
}
cp = strchr (buf, '\n');
*cp = '\0';
cp = buf;
- return 1;
+ return true;
}
\f
/* Symbol table manager. */
}
/* Checks whether the current token is the identifier S; if so, skips
- the token and returns 1; otherwise, returns 0. */
-static int
+ the token and returns true; otherwise, returns false. */
+static bool
match_id (const char *s)
{
if (token == T_ID && !strcmp (tokstr, s))
{
lex_get ();
- return 1;
+ return true;
}
- return 0;
+ return false;
}
/* Checks whether the current token is T. If so, skips the token and
- returns 1; otherwise, returns 0. */
-static int
+ returns true; otherwise, returns false. */
+static bool
match_token (int t)
{
if (token == t)
{
lex_get ();
- return 1;
+ return true;
}
- return 0;
+ return false;
}
/* Force the current token to be T, and skip it. */
}
}
-/* Returns 1 if string T is a PSPP keyword, 0 otherwise. */
-static int
+/* Returns true if string T is a PSPP keyword, false otherwise. */
+static bool
is_keyword (const char *t)
{
static const char *kw[] =
for (cp = kw; *cp; cp++)
if (!strcmp (t, *cp))
- return 1;
- return 0;
+ return true;
+ return false;
}
/* Transforms a string NAME into a valid C identifier: makes
/* Write out prototypes for custom_*() functions as necessary. */
{
- int seen = 0;
+ bool seen = false;
subcommand *sbc;
for (sbc = subcommands; sbc; sbc = sbc->next)
{
if (!seen)
{
- seen = 1;
+ seen = true;
dump (0, "/* Prototype for custom subcommands of %s. */",
cmdname);
}
dump (0, "int x;");
}
dump (1, "if (!lex_force_string ())");
- dump (0, "return 0;");
+ dump (0, "return false;");
outdent ();
if (sbc->restriction)
{
}
}
- dump (-1, "return 1;");
+ dump (-1, "return true;");
dump (0, nullstr);
dump (-1, "lossage:");
indent ();
dump (0, "free_%s (p);", make_identifier (cmdname));
- dump (0, "return 0;");
+ dump (0, "return false;");
dump (-1, "}");
dump (0, nullstr);
}
if (!out)
fail ("%s: open: %s.", ofn, strerror (errno));
- is_open = 1;
+ is_open = true;
buf = xmalloc (MAX_LINE_LEN);
tokstr = xmalloc (MAX_TOK_LEN);
/* Parses a set of variables from dictionary D given options
OPTS. Resulting list of variables stored in *VAR and the
- number of variables into *CNT. Returns nonzero only if
+ number of variables into *CNT. Returns true only if
successful. */
-int
+bool
parse_variables (const struct dictionary *d, struct variable ***var,
size_t *cnt, int opts)
{
/* Parses a set of variables from dictionary D given options
OPTS. Resulting list of variables stored in *VARS and the
- number of variables into *VAR_CNT. Returns nonzero only if
+ number of variables into *VAR_CNT. Returns true only if
successful. Same behavior as parse_variables, except that all
allocations are taken from the given POOL. */
-int
+bool
parse_variables_pool (struct pool *pool, const struct dictionary *dict,
struct variable ***vars, size_t *var_cnt, int opts)
{
/* Parses a variable name from VS. If successful, sets *IDX to
the variable's index in VS, *CLASS to the variable's
- dictionary class, and returns nonzero. Returns zero on
+ dictionary class, and returns true. Returns false on
failure. */
-static int
+static bool
parse_var_idx_class (const struct var_set *vs, size_t *idx,
enum dict_class *class)
{
if (!parse_vs_variable_idx (vs, idx))
- return 0;
+ return false;
*class = dict_class_from_id (var_set_get_var (vs, *idx)->name);
- return 1;
+ return true;
}
/* Add the variable from VS with index IDX to the list of
add_variable (v, nv, mv, included, pv_opts, vs, i);
}
-/* Note that if parse_variables() returns 0, *v is free()'d.
- Conversely, if parse_variables() returns non-zero, then *nv is
+/* Note that if parse_variables() returns false, *v is free()'d.
+ Conversely, if parse_variables() returns true, then *nv is
nonzero and *v is non-NULL. */
-int
+bool
parse_var_set_vars (const struct var_set *vs,
struct variable ***v, size_t *nv,
int pv_opts)
/* Parses a list of variable names according to the DATA LIST version
of the TO convention. */
-int
+bool
parse_DATA_LIST_vars (char ***names, size_t *nnames, int pv_opts)
{
int n1, n2;
version of the TO convention. Same args as
parse_DATA_LIST_vars(), except that all allocations are taken
from the given POOL. */
-int
+bool
parse_DATA_LIST_vars_pool (struct pool *pool,
char ***names, size_t *nnames, int pv_opts)
{
/* Parses a list of variables where some of the variables may be
existing and the rest are to be created. Same args as
parse_DATA_LIST_vars(). */
-int
+bool
parse_mixed_vars (char ***names, size_t *nnames, int pv_opts)
{
size_t i;
existing and the rest are to be created. Same args as
parse_mixed_vars(), except that all allocations are taken
from the given POOL. */
-int
+bool
parse_mixed_vars_pool (struct pool *pool,
char ***names, size_t *nnames, int pv_opts)
{
struct variable *parse_variable (void);
struct variable *parse_dict_variable (const struct dictionary *);
-int parse_variables (const struct dictionary *, struct variable ***, size_t *,
+bool parse_variables (const struct dictionary *, struct variable ***, size_t *,
int opts);
-int parse_variables_pool (struct pool *, const struct dictionary *,
+bool parse_variables_pool (struct pool *, const struct dictionary *,
struct variable ***, size_t *, int opts);
-int parse_var_set_vars (const struct var_set *, struct variable ***, size_t *,
+bool parse_var_set_vars (const struct var_set *, struct variable ***, size_t *,
int opts);
-int parse_DATA_LIST_vars (char ***names, size_t *cnt, int opts);
-int parse_DATA_LIST_vars_pool (struct pool *,
+bool parse_DATA_LIST_vars (char ***names, size_t *cnt, int opts);
+bool parse_DATA_LIST_vars_pool (struct pool *,
char ***names, size_t *cnt, int opts);
-int parse_mixed_vars (char ***names, size_t *cnt, int opts);
-int parse_mixed_vars_pool (struct pool *,
+bool parse_mixed_vars (char ***names, size_t *cnt, int opts);
+bool parse_mixed_vars_pool (struct pool *,
char ***names, size_t *cnt, int opts);
#endif /* variable-parser.h */
const struct ccase *);
/* Prototypes. */
-static int parse_aggregate_functions (struct agr_proc *);
+static bool parse_aggregate_functions (struct agr_proc *);
static void agr_destroy (struct agr_proc *);
-static int aggregate_single_case (struct agr_proc *agr,
+static bool aggregate_single_case (struct agr_proc *agr,
const struct ccase *input,
struct ccase *output);
static void dump_aggregate_info (struct agr_proc *agr, struct ccase *output);
}
/* Parse all the aggregate functions. */
-static int
+static bool
parse_aggregate_functions (struct agr_proc *agr)
{
struct agr_var *tail; /* Tail of linked list starting at agr->vars. */
if (!lex_match ('/'))
{
if (token == '.')
- return 1;
+ return true;
lex_error ("expecting end of command");
- return 0;
+ return false;
}
continue;
}
free (src);
- return 0;
+ return false;
}
}
static void dump_aggregate_info (struct agr_proc *, struct ccase *);
/* Processes a single case INPUT for aggregation. If output is
- warranted, writes it to OUTPUT and returns nonzero.
- Otherwise, returns zero and OUTPUT is unmodified. */
-static int
+ warranted, writes it to OUTPUT and returns true.
+ Otherwise, returns false and OUTPUT is unmodified. */
+static bool
aggregate_single_case (struct agr_proc *agr,
const struct ccase *input, struct ccase *output)
{
}
/* Put VALUE into cell (C,R) of TABLE, suffixed with character
- SUFFIX if nonzero. If MARK_MISSING is nonzero the entry is
+ SUFFIX if nonzero. If MARK_MISSING is true the entry is
additionally suffixed with a letter `M'. */
static void
format_cell_entry (struct tab_table *table, int c, int r, double value,
- char suffix, int mark_missing)
+ char suffix, bool mark_missing)
{
const struct fmt_spec f = {FMT_F, 10, 1};
union value v;
tab_hline (table, TAL_1, -1, n_cols, 0);
for (c = 0; c < n_cols; c++)
{
- int mark_missing = 0;
+ bool mark_missing = false;
double expected_value = row_tot[r] * col_tot[c] / W;
if (cmd.miss == CRS_REPORT
&& (mv_is_num_user_missing (&x->vars[COL_VAR]->miss, cols[c].f)
|| mv_is_num_user_missing (&x->vars[ROW_VAR]->miss,
rows[r].f)))
- mark_missing = 1;
+ mark_missing = true;
for (i = 0; i < num_cells; i++)
{
double v;
for (r = 0; r < n_rows; r++)
{
char suffix = 0;
- int mark_missing = 0;
+ bool mark_missing = false;
if (cmd.miss == CRS_REPORT
&& mv_is_num_user_missing (&x->vars[ROW_VAR]->miss, rows[r].f))
- mark_missing = 1;
+ mark_missing = true;
for (i = 0; i < num_cells; i++)
{
for (c = 0; c <= n_cols; c++)
{
double ct = c < n_cols ? col_tot[c] : W;
- int mark_missing = 0;
+ bool mark_missing = false;
char suffix = 0;
int i;
if (cmd.miss == CRS_REPORT && c < n_cols
&& mv_is_num_user_missing (&x->vars[COL_VAR]->miss, cols[c].f))
- mark_missing = 1;
+ mark_missing = true;
for (i = 0; i < num_cells; i++)
{
#include <libpspp/compiler.h>
#include <libpspp/magic.h>
#include <libpspp/message.h>
+#include <libpspp/assertion.h>
#include <math/moments.h>
#include <output/manager.h>
#include <output/table.h>
static void free_dsc_proc (struct dsc_proc *);
/* Z-score functions. */
-static int try_name (struct dsc_proc *dsc, char *name);
-static int generate_z_varname (struct dsc_proc *dsc, char *z_name,
+static bool try_name (struct dsc_proc *dsc, char *name);
+static bool generate_z_varname (struct dsc_proc *dsc, char *z_name,
const char *name, size_t *z_cnt);
static void dump_z_table (struct dsc_proc *);
static void setup_z_trns (struct dsc_proc *);
\f
/* Z scores. */
-/* Returns 0 if NAME is a duplicate of any existing variable name or
- of any previously-declared z-var name; otherwise returns 1. */
-static int
+/* Returns false if NAME is a duplicate of any existing variable name or
+ of any previously-declared z-var name; otherwise returns true. */
+static bool
try_name (struct dsc_proc *dsc, char *name)
{
size_t i;
if (dict_lookup_var (default_dict, name) != NULL)
- return 0;
+ return false;
for (i = 0; i < dsc->var_cnt; i++)
if (!strcasecmp (dsc->vars[i].z_name, name))
- return 0;
- return 1;
+ return false;
+ return true;
}
/* Generates a name for a Z-score variable based on a variable
named VAR_NAME, given that *Z_CNT generated variable names are
- known to already exist. If successful, returns nonzero and
- copies the new name into Z_NAME. On failure, returns zero. */
-static int
+ known to already exist. If successful, returns true and
+ copies the new name into Z_NAME. On failure, returns false. */
+static bool
generate_z_varname (struct dsc_proc *dsc, char *z_name,
const char *var_name, size_t *z_cnt)
{
if (try_name (dsc, name))
{
strcpy (z_name, name);
- return 1;
+ return true;
}
/* Generate a synthetic name. */
msg (SE, _("Ran out of generic names for Z-score variables. "
"There are only 126 generic names: ZSC001-ZSC0999, "
"STDZ01-STDZ09, ZZZZ01-ZZZZ09, ZQZQ01-ZQZQ09."));
- return 0;
+ return false;
}
if (try_name (dsc, name))
{
strcpy (z_name, name);
- return 1;
+ return true;
}
}
+ NOT_REACHED();
}
/* Outputs a table describing the mapping between source
\f
/* Statistical calculation. */
-static int listwise_missing (struct dsc_proc *dsc, const struct ccase *c);
+static bool listwise_missing (struct dsc_proc *dsc, const struct ccase *c);
/* Calculates and displays descriptive statistics for the cases
in CF. */
return true;
}
-/* Returns nonzero if any of the descriptives variables in DSC's
- variable list have missing values in case C, zero otherwise. */
-static int
+/* Returns true if any of the descriptives variables in DSC's
+ variable list have missing values in case C, false otherwise. */
+static bool
listwise_missing (struct dsc_proc *dsc, const struct ccase *c)
{
size_t i;
if (x == SYSMIS
|| (!dsc->include_user_missing
&& mv_is_num_user_missing (&dv->v->miss, x)))
- return 1;
+ return true;
}
- return 0;
+ return false;
}
\f
/* Statistical display. */
return 0;
}
-/* Returns nonzero iff the value in struct freq F is non-missing
+/* Returns true iff the value in struct freq F is non-missing
for variable V. */
-static int
+static bool
not_missing (const void *f_, void *v_)
{
const struct freq *f = f_;
/*
Is variable k the dependent variable?
*/
-static int
+static bool
is_depvar (size_t k, const struct variable *v)
{
/*
names match.
*/
if (!compare_var_names (v, v_variables[k], NULL))
- return 1;
+ return true;
- return 0;
+ return false;
}
/*
#define _(msgid) gettext (msgid)
-static int
+static bool
read_values (double **values, double **weights, size_t *cnt)
{
size_t cap = 0;
if (!lex_is_number ())
{
lex_error (_("expecting weight value"));
- return 0;
+ return false;
}
weight = tokval;
lex_get ();
(*cnt)++;
}
- return 1;
+ return true;
}
int
return lvalue->vector->var[0]->type;
}
-/* Returns nonzero if LVALUE has a vector as its target. */
+/* Returns true if LVALUE has a vector as its target. */
static bool
lvalue_is_vector (const struct lvalue *lvalue)
{
/* Counts and return the number of elements in ARRAY, which
contains COUNT elements of SIZE bytes each, for which
- PREDICATE returns nonzero. AUX is passed as auxiliary data to
+ PREDICATE returns true. AUX is passed as auxiliary data to
PREDICATE. */
size_t
count_if (const void *array, size_t count, size_t size,
algo_predicate_func *predicate, void *aux)
{
const char *first = array;
- size_t nonzero_cnt = 0;
+ size_t true_cnt = 0;
while (count-- > 0)
{
if (predicate (first, aux) != 0)
- nonzero_cnt++;
+ true_cnt++;
first += size;
}
- return nonzero_cnt;
+ return true_cnt;
}
\f
/* Byte-wise swap two items of size SIZE. */
}
\f
/* Reorders ARRAY, which contains COUNT elements of SIZE bytes
- each, so that the elements for which PREDICATE returns nonzero
+ each, so that the elements for which PREDICATE returns true
precede those for which PREDICATE returns zero. AUX is
passed to each predicate as auxiliary data. Returns the
- number of elements for which PREDICATE returns nonzero. Not
+ number of elements for which PREDICATE returns true. Not
stable. */
size_t
partition (void *array, size_t count, size_t size,
algo_predicate_func *predicate, void *aux)
{
- size_t nonzero_cnt = count;
+ size_t true_cnt = count;
char *first = array;
- char *last = first + nonzero_cnt * size;
+ char *last = first + true_cnt * size;
for (;;)
{
first += size;
}
- nonzero_cnt--;
+ true_cnt--;
/* Move LAST backward to point to last element that passes
PREDICATE. */
else if (predicate (last, aux))
break;
else
- nonzero_cnt--;
+ true_cnt--;
}
/* By swapping FIRST and LAST we extend the starting and
}
done:
- assert (is_partitioned (array, count, size, nonzero_cnt, predicate, aux));
- return nonzero_cnt;
+ assert (is_partitioned (array, count, size, true_cnt, predicate, aux));
+ return true_cnt;
}
/* Checks whether ARRAY, which contains COUNT elements of SIZE
- bytes each, is partitioned such that PREDICATE returns nonzero
- for the first NONZERO_CNT elements and zero for the remaining
+ bytes each, is partitioned such that PREDICATE returns true
+ for the first TRUE_CNT elements and zero for the remaining
elements. AUX is passed as auxiliary data to PREDICATE. */
-int
+bool
is_partitioned (const void *array, size_t count, size_t size,
- size_t nonzero_cnt,
+ size_t true_cnt,
algo_predicate_func *predicate, void *aux)
{
const char *first = array;
size_t idx;
- assert (nonzero_cnt <= count);
- for (idx = 0; idx < nonzero_cnt; idx++)
+ assert (true_cnt <= count);
+ for (idx = 0; idx < true_cnt; idx++)
if (predicate (first + idx * size, aux) == 0)
- return 0;
- for (idx = nonzero_cnt; idx < count; idx++)
+ return false;
+ for (idx = true_cnt; idx < count; idx++)
if (predicate (first + idx * size, aux) != 0)
- return 0;
- return 1;
+ return false;
+ return true;
}
\f
/* Copies the COUNT elements of SIZE bytes each from ARRAY to
void *aux;
};
-static int
+static bool
not (const void *data, void *pred_aux_)
{
const struct pred_aux *pred_aux = pred_aux_;
/* Tests whether ARRAY, which contains COUNT elements of SIZE
bytes each, is sorted in order according to COMPARE. AUX is
passed to COMPARE as auxiliary data. */
-int
+bool
is_sorted (const void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux)
{
for (idx = 0; idx + 1 < count; idx++)
if (compare (first + idx * size, first + (idx + 1) * size, aux) > 0)
- return 0;
+ return false;
- return 1;
+ return true;
}
\f
/* Computes the generalized set difference, ARRAY1 minus ARRAY2,
}
/* ARRAY contains COUNT elements of SIZE bytes each. This
- function tests whether ARRAY is a heap and returns 1 if so, 0
- otherwise. Uses COMPARE to compare elements, passing AUX as
- auxiliary data. */
-int
+ function tests whether ARRAY is a heap and returns true if so,
+ false otherwise. Uses COMPARE to compare elements, passing
+ AUX as auxiliary data. */
+bool
is_heap (const void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux)
{
size_t parent = child / 2;
if (compare (first + (parent - 1) * size,
first + (child - 1) * size, aux) < 0)
- return 0;
+ return false;
}
- return 1;
+ return true;
}
#define ALGORITHM_H 1
#include <stddef.h>
+#include <stdbool.h>
/* Compares A and B, given auxiliary data AUX, and returns a
strcmp()-type result. */
typedef int algo_compare_func (const void *a, const void *b, void *aux);
-/* Tests a predicate on DATA, given auxiliary data AUX, and
- returns nonzero if true or zero if false. */
-typedef int algo_predicate_func (const void *data, void *aux);
+/* Tests a predicate on DATA, given auxiliary data AUX */
+typedef bool algo_predicate_func (const void *data, void *aux);
/* Returns a random number in the range 0 through MAX exclusive,
given auxiliary data AUX. */
/* Counts and return the number of elements in ARRAY, which
contains COUNT elements of SIZE bytes each, for which
- PREDICATE returns nonzero. AUX is passed as auxiliary data to
+ PREDICATE returns true. AUX is passed as auxiliary data to
PREDICATE. */
size_t count_if (const void *array, size_t count, size_t size,
algo_predicate_func *predicate, void *aux);
/* Tests whether ARRAY, which contains COUNT elements of SIZE
bytes each, is sorted in order according to COMPARE. AUX is
passed to COMPARE as auxiliary data. */
-int is_sorted (const void *array, size_t count, size_t size,
+bool is_sorted (const void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux);
/* Makes the elements in ARRAY unique, by moving up duplicates,
algo_compare_func *compare, void *aux);
/* Reorders ARRAY, which contains COUNT elements of SIZE bytes
- each, so that the elements for which PREDICATE returns nonzero
- precede those for which PREDICATE returns zero. AUX is passed
+ each, so that the elements for which PREDICATE returns true
+ precede those for which PREDICATE returns false. AUX is passed
as auxiliary data to PREDICATE. Returns the number of
- elements for which PREDICATE returns nonzero. Not stable. */
+ elements for which PREDICATE returns true. Not stable. */
size_t partition (void *array, size_t count, size_t size,
algo_predicate_func *predicate, void *aux);
/* Checks whether ARRAY, which contains COUNT elements of SIZE
- bytes each, is partitioned such that PREDICATE returns nonzero
- for the first NONZERO_CNT elements and zero for the remaining
+ bytes each, is partitioned such that PREDICATE returns true
+ for the first TRUE_CNT elements and zero for the remaining
elements. AUX is passed as auxiliary data to PREDICATE. */
-int is_partitioned (const void *array, size_t count, size_t size,
- size_t nonzero_cnt,
+bool is_partitioned (const void *array, size_t count, size_t size,
+ size_t true_cnt,
algo_predicate_func *predicate, void *aux);
/* Randomly reorders ARRAY, which contains COUNT elements of SIZE
/* Finds the first pair of adjacent equal elements in ARRAY,
which has COUNT elements of SIZE bytes. Returns the first
- element in ARRAY such that COMPARE returns zero when it and
+ element in ARRAY such that COMPARE returns true when it and
its successor element are compared. AUX is passed to COMPARE
as auxiliary data. */
void *adjacent_find_equal (const void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux);
/* ARRAY contains COUNT elements of SIZE bytes each. This
- function tests whether ARRAY is a heap and returns 1 if so, 0
- otherwise. Uses COMPARE to compare elements, passing AUX as
- auxiliary data. */
-int is_heap (const void *array, size_t count, size_t size,
+ function tests whether ARRAY is a heap and returns true if so,
+ false otherwise. Uses COMPARE to compare elements, passing
+ AUX as auxiliary data. */
+bool is_heap (const void *array, size_t count, size_t size,
algo_compare_func *compare, void *aux);
02110-1301, USA. */
#include <config.h>
+#include <stdbool.h>
#include "hash.h"
#include "message.h"
#include <assert.h>
#endif
}
-/* A "algo_predicate_func" that returns nonzero if DATA points
+/* A "algo_predicate_func" that returns true if DATA points
to a non-null void. */
-static int
+static bool
not_null (const void *data_, void *aux UNUSED)
{
void *const *data = data_;
}
/* Deletes the entry in hash table H that matches TARGET.
- Returns nonzero if an entry was deleted.
+ Returns true if an entry was deleted.
Uses Knuth's Algorithm 6.4R (Deletion with linear probing).
Because our load factor is at most 1/2, the average number of
moves that this algorithm makes should be at most 2 - ln 2 ~=
1.65. */
-int
+bool
hsh_delete (struct hsh_table *h, const void *target)
{
unsigned i = locate_matching_entry (h, target);
{
i = (i - 1) & (h->size - 1);
if (h->entries[i] == NULL)
- return 1;
+ return true;
r = h->hash (h->entries[i], h->aux) & (h->size - 1);
}
}
}
else
- return 0;
+ return false;
}
\f
/* Iteration. */
#define hash_h 1
#include <stddef.h>
+#include <stdbool.h>
typedef int hsh_compare_func (const void *, const void *, void *aux);
typedef unsigned hsh_hash_func (const void *, void *aux);
void *hsh_insert (struct hsh_table *, void *);
void *hsh_replace (struct hsh_table *, void *);
void *hsh_find (struct hsh_table *, const void *);
-int hsh_delete (struct hsh_table *, const void *);
+bool hsh_delete (struct hsh_table *, const void *);
/* Iteration. */
void *hsh_first (struct hsh_table *, struct hsh_iterator *);
}
/* Unregisters previously registered P from POOL.
- Returns nonzero only if P was found to be registered in POOL. */
-int
+ Returns true only if P was found to be registered in POOL. */
+bool
pool_unregister (struct pool *pool, void *p)
{
assert (pool && p);
if (g->type == POOL_GIZMO_REGISTERED && g->p.registered.p == p)
{
delete_gizmo (pool, g);
- return 1;
+ return true;
}
}
- return 0;
+ return false;
}
\f
/* Partial freeing. */
#include <stdarg.h>
#include <stdio.h>
+#include <stdbool.h>
#include "compiler.h"
/* Maximum size of a suballocated block. Larger blocks are allocated
/* Custom allocations. */
void pool_register (struct pool *, void (*free) (void *), void *p);
-int pool_unregister (struct pool *, void *);
+bool pool_unregister (struct pool *, void *);
/* Partial freeing. */
void pool_mark (struct pool *, struct pool_mark *);
/* Stores the dimensions in 1/72000" units of paper identified by
SIZE, which is of form `HORZ x VERT' or `HORZ by VERT' where each
- of HORZ and VERT are dimensions, into *H and *V. Return nonzero on
+ of HORZ and VERT are dimensions, into *H and *V. Return true on
success. */
-static int
+static bool
internal_get_paper_size (char *size, int *h, int *v)
{
char *tail;
size++;
*h = outp_evaluate_dimension (size, &tail);
if (tail == NULL)
- return 0;
+ return false;
while (isspace ((unsigned char) *tail))
tail++;
if (*tail == 'x')
else
{
error (0, 0, _("`x' expected in paper size `%s'"), size);
- return 0;
+ return false;
}
*v = outp_evaluate_dimension (tail, &tail);
if (tail == NULL)
if (*tail)
{
error (0, 0, _("trailing garbage `%s' on paper size `%s'"), tail, size);
- return 0;
+ return false;
}
- return 1;
+ return true;
}
/* Stores the dimensions, in 1/72000" units, of paper identified by
SIZE into *H and *V. SIZE may be a pair of dimensions of form `H x
V', or it may be a case-insensitive paper identifier, which is
- looked up in the `papersize' configuration file. Returns nonzero
+ looked up in the `papersize' configuration file. Returns true
on success. May modify SIZE. */
/* Don't read further unless you've got a strong stomach. */
-int
+bool
outp_get_paper_size (char *size, int *h, int *v)
{
struct paper_size
int line_number = 0;
bool free_it = false;
- int result = 0;
+ bool result = false;
char *ep;
while (isspace ((unsigned char) *size))
int outp_match_keyword (const char *, struct outp_option *, int *);
int outp_evaluate_dimension (char *, char **);
-int outp_get_paper_size (char *, int *h, int *v);
+bool outp_get_paper_size (char *, int *h, int *v);
void outp_open_page (struct outp_driver *);
void outp_close_page (struct outp_driver *);