From: John Darrington Date: Sat, 14 Oct 2006 00:25:20 +0000 (+0000) Subject: Changed a lot of ints to bools. X-Git-Tag: v0.6.0~733 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c708736bdd0fea4b79f3ee4a10e00c3abb95d9e3;p=pspp-builds.git Changed a lot of ints to bools. --- diff --git a/src/data/case-source.c b/src/data/case-source.c index 21413fe2..f8b73f38 100644 --- a/src/data/case-source.c +++ b/src/data/case-source.c @@ -50,8 +50,8 @@ free_case_source (struct case_source *source) } } -/* 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) { diff --git a/src/data/case-source.h b/src/data/case-source.h index 4da72806..9ba1ca9f 100644 --- a/src/data/case-source.h +++ b/src/data/case-source.h @@ -59,7 +59,7 @@ struct case_source *create_case_source (const struct case_source_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 */ diff --git a/src/data/case.c b/src/data/case.c index 98de9ec6..9c42107d 100644 --- a/src/data/case.c +++ b/src/data/case.c @@ -161,9 +161,9 @@ case_swap (struct ccase *a, struct ccase *b) } /* 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)); @@ -171,20 +171,20 @@ case_try_create (struct ccase *c, size_t 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 diff --git a/src/data/case.h b/src/data/case.h index d0b9fc9d..df2f0356 100644 --- a/src/data/case.h +++ b/src/data/case.h @@ -57,8 +57,8 @@ CASE_INLINE void case_destroy (struct ccase *); 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, diff --git a/src/data/data-in.c b/src/data/data-in.c index 0b9e0623..4ee0a4f2 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -93,7 +93,7 @@ trim_whitespace (struct data_in *i) 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) diff --git a/src/data/file-name.c b/src/data/file-name.c index 8211e55d..3216ef09 100644 --- a/src/data/file-name.c +++ b/src/data/file-name.c @@ -493,8 +493,8 @@ fn_get_cwd (void) /* 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 @@ -502,21 +502,21 @@ fn_is_absolute (const char *name) || !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") @@ -526,13 +526,13 @@ fn_is_special (const char *file_name) || (*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 @@ -542,9 +542,9 @@ fn_exists (const char *name) #else FILE *f = fopen (name, "r"); if (!f) - return 0; + return false; fclose (f); - return 1; + return true; #endif } diff --git a/src/data/file-name.h b/src/data/file-name.h index f38d0f3e..333aa5a7 100644 --- a/src/data/file-name.h +++ b/src/data/file-name.h @@ -21,6 +21,7 @@ #define FILE_NAME_H 1 #include +#include /* Search path for configuration files. */ extern const char *config_path; @@ -41,9 +42,9 @@ char *fn_extension (const char *fn); 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); diff --git a/src/data/value-labels.c b/src/data/value-labels.c index 92a2db48..f3a9d24f 100644 --- a/src/data/value-labels.c +++ b/src/data/value-labels.c @@ -189,10 +189,10 @@ create_int_val_lab (struct val_labs *vls, union value value, const char *label) } /* 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; @@ -211,20 +211,17 @@ val_labs_add (struct val_labs *vls, union value value, const char *label) 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; @@ -236,23 +233,23 @@ val_labs_replace (struct val_labs *vls, union value value, const char *label) 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); @@ -266,7 +263,7 @@ val_labs_remove (struct val_labs *vls, union value value) return deleted; } else - return 0; + return false; } /* Searches VLS for a value label for VALUE. If successful, diff --git a/src/data/value-labels.h b/src/data/value-labels.h index f0ea0a6d..1085fe65 100644 --- a/src/data/value-labels.h +++ b/src/data/value-labels.h @@ -43,9 +43,9 @@ size_t val_labs_count (const struct val_labs *); 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; diff --git a/src/language/command.c b/src/language/command.c index a465aa0d..16a663c5 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -264,9 +264,9 @@ find_word (const char *string, size_t *word_len) 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; @@ -278,7 +278,7 @@ conflicting_3char_prefixes (const char *a, const char *b) /* 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. */ @@ -287,9 +287,9 @@ conflicting_3char_prefixes (const char *a, const char *b) || (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); diff --git a/src/language/data-io/data-writer.c b/src/language/data-io/data-writer.c index 652d522f..23220cd1 100644 --- a/src/language/data-io/data-writer.c +++ b/src/language/data-io/data-writer.c @@ -80,15 +80,15 @@ dfm_write_error (const struct dfm_writer *writer) } /* 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)) diff --git a/src/language/data-io/data-writer.h b/src/language/data-io/data-writer.h index 0eba2ab2..7f84a9d0 100644 --- a/src/language/data-io/data-writer.h +++ b/src/language/data-io/data-writer.h @@ -29,6 +29,6 @@ struct file_handle; 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 */ diff --git a/src/language/data-io/matrix-data.c b/src/language/data-io/matrix-data.c index 5526db91..401360de 100644 --- a/src/language/data-io/matrix-data.c +++ b/src/language/data-io/matrix-data.c @@ -795,7 +795,7 @@ context (struct dfm_reader *reader) } /* Is there at least one token left in the data file? */ -static int +static bool another_token (struct dfm_reader *reader) { for (;;) @@ -804,18 +804,19 @@ another_token (struct dfm_reader *reader) 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. */ @@ -919,8 +920,8 @@ struct nr_aux_data 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, @@ -1212,9 +1213,9 @@ 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; @@ -1225,11 +1226,11 @@ nr_read_splits (struct nr_aux_data *nr, int compare) 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) { @@ -1238,7 +1239,7 @@ nr_read_splits (struct nr_aux_data *nr, int compare) 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) @@ -1249,12 +1250,12 @@ nr_read_splits (struct nr_aux_data *nr, int 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) @@ -1264,31 +1265,31 @@ nr_read_splits (struct nr_aux_data *nr, int 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++; } @@ -1299,12 +1300,12 @@ nr_read_factors (struct nr_aux_data *nr, int cell) { 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) @@ -1314,12 +1315,12 @@ nr_read_factors (struct nr_aux_data *nr, int cell) 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 @@ -1457,14 +1458,14 @@ struct wr_aux_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 *, @@ -1523,55 +1524,55 @@ matrix_data_read_with_rowtype (struct case_source *source, /* 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. */ @@ -1714,7 +1715,7 @@ wr_output_data (struct wr_aux_data *wr, /* 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) @@ -1722,13 +1723,13 @@ wr_read_rowtype (struct wr_aux_data *wr, 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; } { @@ -1750,12 +1751,12 @@ wr_read_rowtype (struct wr_aux_data *wr, 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; @@ -1859,15 +1860,15 @@ cache_miss: 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; @@ -1899,7 +1900,7 @@ wr_read_indeps (struct wr_aux_data *wr) { msg (SE, _("Duplicate specification for %s."), content_names[wr->content]); - return 0; + return false; } if (type == 0) n_cols = mx->n_continuous; @@ -1911,7 +1912,7 @@ wr_read_indeps (struct wr_aux_data *wr) { msg (SE, _("Too many rows of matrix data for %s."), content_names[wr->content]); - return 0; + return false; } switch (mx->section) @@ -1950,23 +1951,23 @@ wr_read_indeps (struct wr_aux_data *wr) { 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; } /* Matrix source. */ diff --git a/src/language/dictionary/modify-variables.c b/src/language/dictionary/modify-variables.c index 1632f6ea..333f7704 100644 --- a/src/language/dictionary/modify-variables.c +++ b/src/language/dictionary/modify-variables.c @@ -73,7 +73,7 @@ struct var_modification 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. */ @@ -466,11 +466,11 @@ validate_var_modification (const struct dictionary *d, } /* 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; @@ -484,7 +484,7 @@ rearrange_dict (struct dictionary *d, const struct var_modification *vm) /* 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 @@ -524,5 +524,5 @@ rearrange_dict (struct dictionary *d, const struct var_modification *vm) free (rename_vars); free (rename_new_names); - return 1; + return true; } diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c index 7358c71b..a8a6cffc 100644 --- a/src/language/lexer/lexer.c +++ b/src/language/lexer/lexer.c @@ -69,11 +69,11 @@ struct string tokstr; /* 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. */ @@ -186,7 +186,7 @@ lex_get (void) } else if (!lex_get_line ()) { - eof = 1; + eof = true; token = T_STOP; #if DUMP_TOKENS dump_token (); @@ -497,48 +497,48 @@ lex_integer (void) /* 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; } /* Forced matches. */ @@ -546,91 +546,91 @@ lex_match_int (int x) /* 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. */ @@ -726,7 +726,8 @@ void 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 @@ -961,7 +962,7 @@ lex_negative_to_dash (void) void lex_reset_eof (void) { - eof = 0; + eof = false; } /* Skip a COMMENT command. */ @@ -973,7 +974,7 @@ lex_skip_comment (void) if (!lex_get_line ()) { put_token = T_STOP; - eof = 1; + eof = true; return; } diff --git a/src/language/lexer/lexer.h b/src/language/lexer/lexer.h index 36d79d3a..2ffd01c3 100644 --- a/src/language/lexer/lexer.h +++ b/src/language/lexer/lexer.h @@ -52,17 +52,17 @@ bool lex_is_integer (void); 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); diff --git a/src/language/lexer/q2c.c b/src/language/lexer/q2c.c index a6de4ac6..f503730f 100644 --- a/src/language/lexer/q2c.c +++ b/src/language/lexer/q2c.c @@ -43,7 +43,7 @@ char *program_name; /* Have the input and output files been opened yet? */ -int is_open; +bool is_open; /* Input, output files. */ FILE *in, *out; @@ -80,7 +80,7 @@ finish_up (void) { if (!is_open) return; - is_open = 0; + is_open = false; fclose (in); fclose (out); if (remove (ofn) == -1) @@ -225,7 +225,7 @@ skip_ws (const char *s) /* Read one line from the input file into buf. Lines having special formats are handled specially. */ -static int +static bool get_line (void) { ln++; @@ -233,7 +233,7 @@ get_line (void) { if (ferror (in)) fail ("%s: fgets: %s", ifn, strerror (errno)); - return 0; + return false; } cp = strchr (buf, '\n'); @@ -241,7 +241,7 @@ get_line (void) *cp = '\0'; cp = buf; - return 1; + return true; } /* Symbol table manager. */ @@ -418,29 +418,29 @@ force_string (void) } /* 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. */ @@ -948,8 +948,8 @@ dump_specifier_vars (const specifier *spec, const subcommand *sbc) } } -/* 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[] = @@ -961,8 +961,8 @@ is_keyword (const char *t) 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 @@ -1165,7 +1165,7 @@ dump_declarations (void) /* Write out prototypes for custom_*() functions as necessary. */ { - int seen = 0; + bool seen = false; subcommand *sbc; for (sbc = subcommands; sbc; sbc = sbc->next) @@ -1173,7 +1173,7 @@ dump_declarations (void) { if (!seen) { - seen = 1; + seen = true; dump (0, "/* Prototype for custom subcommands of %s. */", cmdname); } @@ -1610,7 +1610,7 @@ dump_subcommand (const subcommand *sbc) dump (0, "int x;"); } dump (1, "if (!lex_force_string ())"); - dump (0, "return 0;"); + dump (0, "return false;"); outdent (); if (sbc->restriction) { @@ -1860,12 +1860,12 @@ dump_parser (int persistent) } } - 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); } @@ -1995,7 +1995,7 @@ main (int argc, char *argv[]) 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); diff --git a/src/language/lexer/variable-parser.c b/src/language/lexer/variable-parser.c index 98b70ea2..a2068f02 100644 --- a/src/language/lexer/variable-parser.c +++ b/src/language/lexer/variable-parser.c @@ -99,9 +99,9 @@ parse_variable (void) /* 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) { @@ -122,10 +122,10 @@ parse_variables (const struct dictionary *d, struct variable ***var, /* 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) { @@ -145,17 +145,17 @@ parse_variables_pool (struct pool *pool, const struct dictionary *dict, /* 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 @@ -218,10 +218,10 @@ add_variables (struct variable ***v, size_t *nv, size_t *mv, char *included, 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) @@ -381,7 +381,7 @@ extract_num (char *s, char *r, int *n, int *d) /* 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; @@ -511,7 +511,7 @@ register_vars_pool (struct pool *pool, char **names, size_t nnames) 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) { @@ -532,7 +532,7 @@ parse_DATA_LIST_vars_pool (struct pool *pool, /* 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; @@ -579,7 +579,7 @@ fail: 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) { diff --git a/src/language/lexer/variable-parser.h b/src/language/lexer/variable-parser.h index cacb524e..f71a778e 100644 --- a/src/language/lexer/variable-parser.h +++ b/src/language/lexer/variable-parser.h @@ -57,17 +57,17 @@ enum 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 */ diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index eaaccf30..788b19b0 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -154,9 +154,9 @@ static void initialize_aggregate_info (struct agr_proc *, 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); @@ -351,7 +351,7 @@ error: } /* 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. */ @@ -642,10 +642,10 @@ parse_aggregate_functions (struct agr_proc *agr) if (!lex_match ('/')) { if (token == '.') - return 1; + return true; lex_error ("expecting end of command"); - return 0; + return false; } continue; @@ -667,7 +667,7 @@ parse_aggregate_functions (struct agr_proc *agr) } free (src); - return 0; + return false; } } @@ -713,9 +713,9 @@ static void accumulate_aggregate_info (struct agr_proc *, 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) { diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index d67fb62c..4dca0b9b 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -1702,11 +1702,11 @@ display_dimensions (struct tab_table *table, int first_difference, struct table_ } /* 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; @@ -1755,13 +1755,13 @@ display_crosstabulation (void) 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; @@ -1821,11 +1821,11 @@ display_crosstabulation (void) 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++) { @@ -1874,13 +1874,13 @@ display_crosstabulation (void) 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++) { diff --git a/src/language/stats/descriptives.c b/src/language/stats/descriptives.c index a513bc09..9813d388 100644 --- a/src/language/stats/descriptives.c +++ b/src/language/stats/descriptives.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -172,8 +173,8 @@ static enum dsc_statistic match_statistic (void); 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 *); @@ -465,26 +466,26 @@ free_dsc_proc (struct dsc_proc *dsc) /* 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) { @@ -496,7 +497,7 @@ generate_z_varname (struct dsc_proc *dsc, char *z_name, if (try_name (dsc, name)) { strcpy (z_name, name); - return 1; + return true; } /* Generate a synthetic name. */ @@ -517,15 +518,16 @@ generate_z_varname (struct dsc_proc *dsc, char *z_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 @@ -693,7 +695,7 @@ setup_z_trns (struct dsc_proc *dsc) /* 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. */ @@ -841,9 +843,9 @@ calc_descriptives (const struct ccase *first, 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; @@ -856,9 +858,9 @@ listwise_missing (struct dsc_proc *dsc, const struct ccase *c) if (x == SYSMIS || (!dsc->include_user_missing && mv_is_num_user_missing (&dv->v->miss, x))) - return 1; + return true; } - return 0; + return false; } /* Statistical display. */ diff --git a/src/language/stats/frequencies.q b/src/language/stats/frequencies.q index 7174cf4c..5e9e1893 100644 --- a/src/language/stats/frequencies.q +++ b/src/language/stats/frequencies.q @@ -712,9 +712,9 @@ get_freq_comparator (int frq_sort, int var_type) 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_; diff --git a/src/language/stats/regression.q b/src/language/stats/regression.q index 83d78144..7b0e56ed 100644 --- a/src/language/stats/regression.q +++ b/src/language/stats/regression.q @@ -949,7 +949,7 @@ cmd_regression (void) /* Is variable k the dependent variable? */ -static int +static bool is_depvar (size_t k, const struct variable *v) { /* @@ -957,9 +957,9 @@ 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; } /* diff --git a/src/language/tests/moments-test.c b/src/language/tests/moments-test.c index 619f797e..05f0981b 100644 --- a/src/language/tests/moments-test.c +++ b/src/language/tests/moments-test.c @@ -29,7 +29,7 @@ #define _(msgid) gettext (msgid) -static int +static bool read_values (double **values, double **weights, size_t *cnt) { size_t cap = 0; @@ -47,7 +47,7 @@ read_values (double **values, double **weights, size_t *cnt) if (!lex_is_number ()) { lex_error (_("expecting weight value")); - return 0; + return false; } weight = tokval; lex_get (); @@ -65,7 +65,7 @@ read_values (double **values, double **weights, size_t *cnt) (*cnt)++; } - return 1; + return true; } int diff --git a/src/language/xforms/compute.c b/src/language/xforms/compute.c index 5c13d2f2..f24ecac5 100644 --- a/src/language/xforms/compute.c +++ b/src/language/xforms/compute.c @@ -372,7 +372,7 @@ lvalue_get_type (const struct lvalue *lvalue) 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) { diff --git a/src/libpspp/array.c b/src/libpspp/array.c index f4fca27e..1349f253 100644 --- a/src/libpspp/array.c +++ b/src/libpspp/array.c @@ -148,24 +148,24 @@ count_equal (const void *array, size_t count, size_t size, /* 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; } /* Byte-wise swap two items of size SIZE. */ @@ -224,18 +224,18 @@ sort_unique (void *array, size_t count, size_t size, } /* 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 (;;) { @@ -250,7 +250,7 @@ partition (void *array, size_t count, size_t size, first += size; } - nonzero_cnt--; + true_cnt--; /* Move LAST backward to point to last element that passes PREDICATE. */ @@ -263,7 +263,7 @@ partition (void *array, size_t count, size_t size, else if (predicate (last, aux)) break; else - nonzero_cnt--; + true_cnt--; } /* By swapping FIRST and LAST we extend the starting and @@ -274,30 +274,30 @@ partition (void *array, size_t count, size_t size, } 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; } /* Copies the COUNT elements of SIZE bytes each from ARRAY to @@ -397,7 +397,7 @@ struct pred_aux void *aux; }; -static int +static bool not (const void *data, void *pred_aux_) { const struct pred_aux *pred_aux = pred_aux_; @@ -753,7 +753,7 @@ sort (void *array, size_t count, size_t size, /* 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) { @@ -762,9 +762,9 @@ is_sorted (const void *array, size_t count, size_t size, 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; } /* Computes the generalized set difference, ARRAY1 minus ARRAY2, @@ -958,10 +958,10 @@ sort_heap (void *array, size_t count, size_t size, } /* 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) { @@ -973,9 +973,9 @@ is_heap (const void *array, size_t count, size_t size, 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; } diff --git a/src/libpspp/array.h b/src/libpspp/array.h index 10e589a1..a543e5a3 100644 --- a/src/libpspp/array.h +++ b/src/libpspp/array.h @@ -2,14 +2,14 @@ #define ALGORITHM_H 1 #include +#include /* 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. */ @@ -37,7 +37,7 @@ size_t count_equal (const void *array, size_t count, size_t size, /* 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); @@ -51,7 +51,7 @@ void sort (void *array, size_t count, size_t size, /* 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, @@ -65,19 +65,19 @@ size_t sort_unique (void *array, size_t count, size_t size, 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 @@ -164,7 +164,7 @@ size_t set_difference (const void *array1, size_t count1, /* 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, @@ -202,10 +202,10 @@ void sort_heap (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); diff --git a/src/libpspp/hash.c b/src/libpspp/hash.c index dcf8d8ff..0d1bab97 100644 --- a/src/libpspp/hash.c +++ b/src/libpspp/hash.c @@ -18,6 +18,7 @@ 02110-1301, USA. */ #include +#include #include "hash.h" #include "message.h" #include @@ -304,9 +305,9 @@ rehash (struct hsh_table *h, size_t new_size) #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_; @@ -495,13 +496,13 @@ hsh_find (struct hsh_table *h, const void *target) } /* 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); @@ -522,7 +523,7 @@ hsh_delete (struct hsh_table *h, const void *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); } @@ -531,7 +532,7 @@ hsh_delete (struct hsh_table *h, const void *target) } } else - return 0; + return false; } /* Iteration. */ diff --git a/src/libpspp/hash.h b/src/libpspp/hash.h index 8ba77a98..1610a47d 100644 --- a/src/libpspp/hash.h +++ b/src/libpspp/hash.h @@ -21,6 +21,7 @@ #define hash_h 1 #include +#include typedef int hsh_compare_func (const void *, const void *, void *aux); typedef unsigned hsh_hash_func (const void *, void *aux); @@ -55,7 +56,7 @@ void **hsh_probe (struct hsh_table *, const void *); 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 *); diff --git a/src/libpspp/pool.c b/src/libpspp/pool.c index d4c00b38..213efb9c 100644 --- a/src/libpspp/pool.c +++ b/src/libpspp/pool.c @@ -777,8 +777,8 @@ pool_register (struct pool *pool, void (*free) (void *), void *p) } /* 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); @@ -790,11 +790,11 @@ pool_unregister (struct pool *pool, void *p) if (g->type == POOL_GIZMO_REGISTERED && g->p.registered.p == p) { delete_gizmo (pool, g); - return 1; + return true; } } - return 0; + return false; } /* Partial freeing. */ diff --git a/src/libpspp/pool.h b/src/libpspp/pool.h index fe4af29b..7dab5b47 100644 --- a/src/libpspp/pool.h +++ b/src/libpspp/pool.h @@ -22,6 +22,7 @@ #include #include +#include #include "compiler.h" /* Maximum size of a suballocated block. Larger blocks are allocated @@ -90,7 +91,7 @@ void pool_detach_file (struct pool *, FILE *); /* 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 *); diff --git a/src/output/output.c b/src/output/output.c index c9545761..a63f1171 100644 --- a/src/output/output.c +++ b/src/output/output.c @@ -927,9 +927,9 @@ lossage: /* 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; @@ -938,7 +938,7 @@ internal_get_paper_size (char *size, int *h, int *v) size++; *h = outp_evaluate_dimension (size, &tail); if (tail == NULL) - return 0; + return false; while (isspace ((unsigned char) *tail)) tail++; if (*tail == 'x') @@ -948,7 +948,7 @@ internal_get_paper_size (char *size, int *h, int *v) else { error (0, 0, _("`x' expected in paper size `%s'"), size); - return 0; + return false; } *v = outp_evaluate_dimension (tail, &tail); if (tail == NULL) @@ -958,19 +958,19 @@ internal_get_paper_size (char *size, int *h, int *v) 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 @@ -987,7 +987,7 @@ outp_get_paper_size (char *size, int *h, int *v) int line_number = 0; bool free_it = false; - int result = 0; + bool result = false; char *ep; while (isspace ((unsigned char) *size)) diff --git a/src/output/output.h b/src/output/output.h index a61161ab..6782a11e 100644 --- a/src/output/output.h +++ b/src/output/output.h @@ -155,7 +155,7 @@ bool outp_parse_options (struct substring options, 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 *);