From: Ben Pfaff Date: Thu, 9 Dec 2021 23:03:45 +0000 (-0800) Subject: treewide: Replace _cnt by n_s and _cap by allocated_. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pspp;a=commitdiff_plain;h=339f1956cc727eda788638644ef93ab7852b31cd treewide: Replace _cnt by n_s and _cap by allocated_. I used to think that _cnt was a good suffix for a count representing the number of items in an array, but I haven't used that convention in a long time and it looks wrong now. This changes these to an n_ prefix instead. Similarly, but in far fewer cases, replace _cap for the allocated capacity of an array by allocated_. This doesn't change the name of ref_cnt members used as reference counts. Those are pure counts, not the length of anything. This doesn't change the Perl library because that's an external API. --- diff --git a/doc/data-io.texi b/doc/data-io.texi index 1d4b0d6b0b..738854d16c 100644 --- a/doc/data-io.texi +++ b/doc/data-io.texi @@ -484,7 +484,7 @@ DATA LIST FREE [(@{TAB,'@var{c}'@}, @dots{})] [@{NOTABLE,TABLE@}] [FILE='@var{file_name}' [ENCODING='@var{encoding}']] - [SKIP=@var{record_cnt}] + [SKIP=@var{n_records}] /@var{var_spec}@dots{} where each @var{var_spec} takes one of the forms diff --git a/doc/dev/concepts.texi b/doc/dev/concepts.texi index 64b0130e12..d1cf5f2012 100644 --- a/doc/dev/concepts.texi +++ b/doc/dev/concepts.texi @@ -2015,7 +2015,7 @@ Returns the variable at the given @var{position} in @var{dict}. (see below). @end deftypefun -@deftypefun size_t dict_get_var_cnt (const struct dictionary *@var{dict}) +@deftypefun size_t dict_get_n_vars (const struct dictionary *@var{dict}) Returns the number of variables in @var{dict}. @end deftypefun @@ -2298,7 +2298,7 @@ only if there are no split variables, returns a null pointer. The caller must not modify or free the returned array. @end deftypefun -@deftypefun size_t dict_get_split_cnt (const struct dictionary *@var{dict}) +@deftypefun size_t dict_get_n_splits (const struct dictionary *@var{dict}) Returns the number of split variables. @end deftypefun @@ -2393,7 +2393,7 @@ call to one of this function in a @func{msg_disable}/@func{msg_enable} pair. @end deftypefun -@deftypefun size_t dict_get_document_line_cnt (const struct dictionary *@var{dict}) +@deftypefun size_t dict_get_document_n_lines (const struct dictionary *@var{dict}) Returns the number of line of documents in @var{dict}. If the dictionary contains no documents, returns 0. @end deftypefun diff --git a/doc/dev/system-file-format.texi b/doc/dev/system-file-format.texi index a5a89f4ded..4f5aa7edbe 100644 --- a/doc/dev/system-file-format.texi +++ b/doc/dev/system-file-format.texi @@ -558,7 +558,7 @@ The value label record has the following format: int32 rec_type; int32 label_count; -/* @r{Repeated @code{label_cnt} times}. */ +/* @r{Repeated @code{n_label} times}. */ char value[8]; char label_len; char label[]; diff --git a/perl-module/PSPP.xs b/perl-module/PSPP.xs index 46e9ba132d..aaa4299f03 100644 --- a/perl-module/PSPP.xs +++ b/perl-module/PSPP.xs @@ -280,7 +280,7 @@ int get_var_cnt (dict) struct pspp_dict *dict CODE: - RETVAL = dict_get_var_cnt (dict->dict); + RETVAL = dict_get_n_vars (dict->dict); OUTPUT: RETVAL @@ -329,7 +329,7 @@ pxs_get_variable (dict, idx) INIT: SV *errstr = get_sv("PSPP::errstr", TRUE); sv_setpv (errstr, ""); - if ( SvIV (idx) >= dict_get_var_cnt (dict->dict)) + if ( SvIV (idx) >= dict_get_n_vars (dict->dict)) { sv_setpv (errstr, "The dictionary doesn't have that many variables."); XSRETURN_UNDEF; @@ -688,7 +688,7 @@ CODE: size_t nv; struct ccase *c; - if ( av_len (av_case) >= dict_get_var_cnt (swi->dict->dict)) + if ( av_len (av_case) >= dict_get_n_vars (swi->dict->dict)) XSRETURN_UNDEF; c = case_create (dict_get_proto (swi->dict->dict)); @@ -730,7 +730,7 @@ CODE: } /* The remaining variables must be sysmis or blank string */ - while (i < dict_get_var_cnt (swi->dict->dict)) + while (i < dict_get_n_vars (swi->dict->dict)) { const struct variable *v = vv[i++]; union value *val = case_data_rw (c, v); @@ -806,8 +806,8 @@ PPCODE: { int v; - EXTEND (SP, dict_get_var_cnt (sfr->dict->dict)); - for (v = 0; v < dict_get_var_cnt (sfr->dict->dict); ++v ) + EXTEND (SP, dict_get_n_vars (sfr->dict->dict)); + for (v = 0; v < dict_get_n_vars (sfr->dict->dict); ++v ) { const struct variable *var = dict_get_var (sfr->dict->dict, v); const union value *val = case_data (c, var); diff --git a/src/data/any-reader.c b/src/data/any-reader.c index 8ece73f62b..5a20ccef83 100644 --- a/src/data/any-reader.c +++ b/src/data/any-reader.c @@ -248,7 +248,7 @@ dataset_reader_decode (struct any_reader *r_, const char *encoding UNUSED, info->integer_format = INTEGER_NATIVE; info->float_format = FLOAT_NATIVE_DOUBLE; info->compression = ANY_COMP_NONE; - info->case_cnt = casereader_get_case_cnt (reader); + info->n_cases = casereader_get_n_cases (reader); } free (r); diff --git a/src/data/any-reader.h b/src/data/any-reader.h index 998e12441b..6e4d751f78 100644 --- a/src/data/any-reader.h +++ b/src/data/any-reader.h @@ -80,7 +80,7 @@ struct any_read_info enum integer_format integer_format; enum float_format float_format; enum any_compression compression; - casenumber case_cnt; /* -1 if unknown. */ + casenumber n_cases; /* -1 if unknown. */ char *product; /* Product name. */ char *product_ext; /* Extra product info. */ diff --git a/src/data/case-map.c b/src/data/case-map.c index f9dc678514..ed32db0d3f 100644 --- a/src/data/case-map.c +++ b/src/data/case-map.c @@ -189,7 +189,7 @@ struct case_map * case_map_to_compact_dict (const struct dictionary *d, unsigned int exclude_classes) { - size_t n_vars = dict_get_var_cnt (d); + size_t n_vars = dict_get_n_vars (d); struct caseproto *proto; struct case_map *map; size_t n_values; @@ -234,7 +234,7 @@ struct case_map_stage struct case_map_stage * case_map_stage_create (const struct dictionary *dict) { - size_t n_vars = dict_get_var_cnt (dict); + size_t n_vars = dict_get_n_vars (dict); struct case_map_stage *stage; size_t i; @@ -305,7 +305,7 @@ struct case_map * case_map_stage_get_case_map (const struct case_map_stage *stage) { struct case_map *map; - size_t n_vars = dict_get_var_cnt (stage->dict); + size_t n_vars = dict_get_n_vars (stage->dict); size_t n_values; size_t i; bool identity_map = true; @@ -343,12 +343,9 @@ struct case_map * case_map_by_name (const struct dictionary *old, const struct dictionary *new) { - struct case_map *map; - size_t var_cnt = dict_get_var_cnt (new); - size_t i; - - map = create_case_map (dict_get_proto (new)); - for (i = 0; i < var_cnt; i++) + size_t n_vars = dict_get_n_vars (new); + struct case_map *map = create_case_map (dict_get_proto (new)); + for (size_t i = 0; i < n_vars; i++) { struct variable *nv = dict_get_var (new, i); struct variable *ov = dict_lookup_var_assert (old, var_get_name (nv)); diff --git a/src/data/case-tmpfile.h b/src/data/case-tmpfile.h index 3659e5805e..b7078d4cdc 100644 --- a/src/data/case-tmpfile.h +++ b/src/data/case-tmpfile.h @@ -42,12 +42,12 @@ const struct taint *case_tmpfile_get_taint (const struct case_tmpfile *); bool case_tmpfile_get_values (const struct case_tmpfile *, casenumber, size_t start_value, - union value[], size_t value_cnt); + union value[], size_t n_values); struct ccase *case_tmpfile_get_case (const struct case_tmpfile *, casenumber); bool case_tmpfile_put_values (struct case_tmpfile *, casenumber, size_t start_value, - const union value[], size_t value_cnt); + const union value[], size_t n_values); bool case_tmpfile_put_case (struct case_tmpfile *, casenumber, struct ccase *); diff --git a/src/data/case.h b/src/data/case.h index 45fdf52c9b..256d66019d 100644 --- a/src/data/case.h +++ b/src/data/case.h @@ -67,7 +67,7 @@ struct ccase *case_ref (const struct ccase *) WARN_UNUSED_RESULT; static inline void case_unref (struct ccase *); static inline bool case_is_shared (const struct ccase *); -static inline size_t case_get_value_cnt (const struct ccase *); +static inline size_t case_get_n_values (const struct ccase *); static inline const struct caseproto *case_get_proto (const struct ccase *); size_t case_get_cost (const struct caseproto *); @@ -158,7 +158,7 @@ case_is_shared (const struct ccase *c) /* Returns the number of union values in C. */ static inline size_t -case_get_value_cnt (const struct ccase *c) +case_get_n_values (const struct ccase *c) { return caseproto_get_n_widths (c->proto); } diff --git a/src/data/casegrouper.c b/src/data/casegrouper.c index eb8d65deee..23afffbcab 100644 --- a/src/data/casegrouper.c +++ b/src/data/casegrouper.c @@ -168,19 +168,19 @@ static void casegrouper_vars_destroy (void *); /* Creates and returns a casegrouper that reads data from READER and breaks it into contiguous groups of cases that have equal - values for the VAR_CNT variables in VARS. If VAR_CNT is 0, + values for the N_VARS variables in VARS. If N_VARS is 0, then all the cases will be put in a single group. Takes ownerhip of READER. */ struct casegrouper * casegrouper_create_vars (struct casereader *reader, const struct variable *const *vars, - size_t var_cnt) + size_t n_vars) { - if (var_cnt > 0) + if (n_vars > 0) { struct subcase *sc = xmalloc (sizeof *sc); - subcase_init_vars (sc, vars, var_cnt); + subcase_init_vars (sc, vars, n_vars); return casegrouper_create_func (reader, casegrouper_vars_same_group, casegrouper_vars_destroy, sc); } @@ -201,7 +201,7 @@ casegrouper_create_splits (struct casereader *reader, { return casegrouper_create_vars (reader, dict_get_split_vars (dict), - dict_get_split_cnt (dict)); + dict_get_n_splits (dict)); } /* Creates and returns a casegrouper that reads data from READER diff --git a/src/data/casegrouper.h b/src/data/casegrouper.h index f367d23cdb..a534b93747 100644 --- a/src/data/casegrouper.h +++ b/src/data/casegrouper.h @@ -42,7 +42,7 @@ casegrouper_create_func (struct casereader *, void *aux); struct casegrouper *casegrouper_create_vars (struct casereader *, const struct variable *const *vars, - size_t var_cnt); + size_t n_vars); struct casegrouper *casegrouper_create_splits (struct casereader *, const struct dictionary *); struct casegrouper *casegrouper_create_subcase (struct casereader *, diff --git a/src/data/caseinit.c b/src/data/caseinit.c index 021db396d1..c93de34872 100644 --- a/src/data/caseinit.c +++ b/src/data/caseinit.c @@ -128,13 +128,12 @@ static void init_list_mark (struct init_list *list, const struct init_list *exclude, enum leave_class include, const struct dictionary *d) { - size_t var_cnt = dict_get_var_cnt (d); - size_t i; + size_t n_vars = dict_get_n_vars (d); assert (list != exclude); - list->values = xnrealloc (list->values, list->cnt + dict_get_var_cnt (d), + list->values = xnrealloc (list->values, list->cnt + dict_get_n_vars (d), sizeof *list->values); - for (i = 0; i < var_cnt; i++) + for (size_t i = 0; i < n_vars; i++) { struct variable *v = dict_get_var (d, i); size_t case_index = var_get_case_index (v); diff --git a/src/data/casereader-filter.c b/src/data/casereader-filter.c index a5a2dd5476..08151fadd2 100644 --- a/src/data/casereader-filter.c +++ b/src/data/casereader-filter.c @@ -243,7 +243,7 @@ casereader_filter_weight_destroy (void *cfw_) struct casereader_filter_missing { struct variable **vars; /* Variables whose values to filter. */ - size_t var_cnt; /* Number of variables. */ + size_t n_vars; /* Number of variables. */ enum mv_class class; /* Types of missing values to filter. */ casenumber *n_missing; }; @@ -253,7 +253,7 @@ static bool casereader_filter_missing_destroy (void *); /* Creates and returns a casereader that filters out cases from READER that have a missing value in the given CLASS for any of - the VAR_CNT variables in VARS. Only cases that have + the N_VARS variables in VARS. Only cases that have non-missing values for all of these variables are passed through. @@ -273,16 +273,16 @@ static bool casereader_filter_missing_destroy (void *); when the filtering casereader is destroyed. */ struct casereader * casereader_create_filter_missing (struct casereader *reader, - const struct variable *const*vars, size_t var_cnt, + const struct variable *const *vars, size_t n_vars, enum mv_class class, casenumber *n_missing, struct casewriter *exclude) { - if (var_cnt > 0 && class != MV_NEVER) + if (n_vars > 0 && class != MV_NEVER) { struct casereader_filter_missing *cfm = xmalloc (sizeof *cfm); - cfm->vars = xmemdup (vars, sizeof *vars * var_cnt); - cfm->var_cnt = var_cnt; + cfm->vars = xmemdup (vars, sizeof *vars * n_vars); + cfm->n_vars = n_vars; cfm->class = class; cfm->n_missing = n_missing; if (n_missing) *n_missing = 0; @@ -304,7 +304,7 @@ casereader_filter_missing_include (const struct ccase *c, void *cfm_) const struct casereader_filter_missing *cfm = cfm_; size_t i; - for (i = 0; i < cfm->var_cnt; i++) + for (i = 0; i < cfm->n_vars; i++) { struct variable *var = cfm->vars[i]; const union value *value = case_data (c, var); diff --git a/src/data/casereader-provider.h b/src/data/casereader-provider.h index f22cf4accf..f93a60c4e0 100644 --- a/src/data/casereader-provider.h +++ b/src/data/casereader-provider.h @@ -112,7 +112,7 @@ struct casereader_class struct casereader * casereader_create_sequential (const struct taint *, - const struct caseproto *, casenumber case_cnt, + const struct caseproto *, casenumber n_cases, const struct casereader_class *, void *); void *casereader_dynamic_cast (struct casereader *, const struct casereader_class *); @@ -160,7 +160,7 @@ struct casereader_random_class }; struct casereader * -casereader_create_random (const struct caseproto *, casenumber case_cnt, +casereader_create_random (const struct caseproto *, casenumber n_cases, const struct casereader_random_class *, void *aux); #endif /* data/casereader-provider.h */ diff --git a/src/data/casereader-shim.c b/src/data/casereader-shim.c index 9d9dd70527..eb9ee4c8fc 100644 --- a/src/data/casereader-shim.c +++ b/src/data/casereader-shim.c @@ -50,10 +50,10 @@ struct casereader_shim * casereader_shim_insert (struct casereader *reader) { const struct caseproto *proto = casereader_get_proto (reader); - casenumber case_cnt = casereader_get_case_cnt (reader); + casenumber n_cases = casereader_get_n_cases (reader); struct casereader_shim *s = xmalloc (sizeof *s); s->window = casewindow_create (proto, settings_get_workspace_cases (proto)); - s->subreader = casereader_create_random (proto, case_cnt, &shim_class, s); + s->subreader = casereader_create_random (proto, n_cases, &shim_class, s); casereader_swap (reader, s->subreader); taint_propagate (casewindow_get_taint (s->window), casereader_get_taint (reader)); @@ -107,7 +107,7 @@ casereader_shim_read (struct casereader *reader UNUSED, void *s_, { struct casereader_shim *s = s_; - while (casewindow_get_case_cnt (s->window) <= offset) + while (casewindow_get_n_cases (s->window) <= offset) if (!buffer_case (s)) return false; @@ -127,10 +127,10 @@ casereader_shim_destroy (struct casereader *reader UNUSED, void *s_) /* Discards CNT cases from the front of S's window. */ static void casereader_shim_advance (struct casereader *reader UNUSED, void *s_, - casenumber case_cnt) + casenumber n_cases) { struct casereader_shim *s = s_; - casewindow_pop_tail (s->window, case_cnt); + casewindow_pop_tail (s->window, n_cases); } /* Class for the buffered reader. */ diff --git a/src/data/casereader-translator.c b/src/data/casereader-translator.c index 831077466b..7dc344e3b8 100644 --- a/src/data/casereader-translator.c +++ b/src/data/casereader-translator.c @@ -75,7 +75,7 @@ casereader_create_translator (struct casereader *subreader, ct->destroy = destroy; ct->aux = aux; reader = casereader_create_sequential ( - NULL, output_proto, casereader_get_case_cnt (ct->subreader), + NULL, output_proto, casereader_get_n_cases (ct->subreader), &casereader_translator_class, ct); taint_propagate (casereader_get_taint (ct->subreader), casereader_get_taint (reader)); @@ -170,7 +170,7 @@ casereader_translate_stateless ( cst->destroy = destroy; cst->aux = aux; reader = casereader_create_random ( - output_proto, casereader_get_case_cnt (cst->subreader), + output_proto, casereader_get_n_cases (cst->subreader), &casereader_stateless_translator_class, cst); taint_propagate (casereader_get_taint (cst->subreader), casereader_get_taint (reader)); diff --git a/src/data/casereader.c b/src/data/casereader.c index 578a865dfd..379e351edc 100644 --- a/src/data/casereader.c +++ b/src/data/casereader.c @@ -34,7 +34,7 @@ struct casereader { struct taint *taint; /* Corrupted? */ struct caseproto *proto; /* Format of contained cases. */ - casenumber case_cnt; /* Number of cases, + casenumber n_cases; /* Number of cases, CASENUMBER_MAX if unknown. */ const struct casereader_class *class; /* Class. */ void *aux; /* Auxiliary data for class. */ @@ -52,7 +52,7 @@ struct casereader struct ccase * casereader_read (struct casereader *reader) { - if (reader->case_cnt != 0) + if (reader->n_cases != 0) { /* ->read may use casereader_swap to replace itself by another reader and then delegate to that reader by @@ -61,24 +61,24 @@ casereader_read (struct casereader *reader) ever will. To allow this to work, however, we must decrement - case_cnt before calling ->read. If we decremented - case_cnt after calling ->read, then this would actually - drop two cases from case_cnt instead of one, and we'd + n_cases before calling ->read. If we decremented + n_cases after calling ->read, then this would actually + drop two cases from n_cases instead of one, and we'd lose the last case in the casereader. */ struct ccase *c; - if (reader->case_cnt != CASENUMBER_MAX) - reader->case_cnt--; + if (reader->n_cases != CASENUMBER_MAX) + reader->n_cases--; c = reader->class->read (reader, reader->aux); if (c != NULL) { size_t n_widths UNUSED = caseproto_get_n_widths (reader->proto); - assert (case_get_value_cnt (c) >= n_widths); + assert (case_get_n_values (c) >= n_widths); expensive_assert (caseproto_equal (case_get_proto (c), 0, reader->proto, 0, n_widths)); return c; } } - reader->case_cnt = 0; + reader->n_cases = 0; return NULL; } @@ -149,7 +149,7 @@ casereader_swap (struct casereader *a, struct casereader *b) struct ccase * casereader_peek (struct casereader *reader, casenumber idx) { - if (idx < reader->case_cnt) + if (idx < reader->n_cases) { struct ccase *c; if (reader->class->peek == NULL) @@ -158,10 +158,10 @@ casereader_peek (struct casereader *reader, casenumber idx) if (c != NULL) return c; else if (casereader_error (reader)) - reader->case_cnt = 0; + reader->n_cases = 0; } - if (reader->case_cnt > idx) - reader->case_cnt = idx; + if (reader->n_cases > idx) + reader->n_cases = idx; return NULL; } @@ -173,7 +173,7 @@ casereader_peek (struct casereader *reader, casenumber idx) bool casereader_is_empty (struct casereader *reader) { - if (reader->case_cnt == 0) + if (reader->n_cases == 0) return true; else { @@ -230,9 +230,9 @@ casereader_get_taint (const struct casereader *reader) actual number of cases in such a casereader, use casereader_count_cases. */ casenumber -casereader_get_case_cnt (struct casereader *reader) +casereader_get_n_cases (struct casereader *reader) { - return reader->case_cnt; + return reader->n_cases; } static casenumber @@ -261,12 +261,12 @@ casereader_count_cases__ (const struct casereader *reader, casenumber casereader_count_cases (const struct casereader *reader) { - if (reader->case_cnt == CASENUMBER_MAX) + if (reader->n_cases == CASENUMBER_MAX) { struct casereader *reader_rw = CONST_CAST (struct casereader *, reader); - reader_rw->case_cnt = casereader_count_cases__ (reader, CASENUMBER_MAX); + reader_rw->n_cases = casereader_count_cases__ (reader, CASENUMBER_MAX); } - return reader->case_cnt; + return reader->n_cases; } /* Truncates READER to at most N cases. */ @@ -277,10 +277,10 @@ casereader_truncate (struct casereader *reader, casenumber n) "max_cases" member to struct casereader. We could also add a "truncate" function to the casereader implementation, to allow the casereader to throw away data that cannot ever be read. */ - if (reader->case_cnt == CASENUMBER_MAX) - reader->case_cnt = casereader_count_cases__ (reader, n); - if (reader->case_cnt > n) - reader->case_cnt = n; + if (reader->n_cases == CASENUMBER_MAX) + reader->n_cases = casereader_count_cases__ (reader, n); + if (reader->n_cases > n) + reader->n_cases = n; } /* Returns the prototype for the cases in READER. The caller @@ -358,13 +358,13 @@ casereader_transfer (struct casereader *reader, struct casewriter *writer) struct casereader * casereader_create_sequential (const struct taint *taint, const struct caseproto *proto, - casenumber case_cnt, + casenumber n_cases, const struct casereader_class *class, void *aux) { struct casereader *reader = xmalloc (sizeof *reader); reader->taint = taint != NULL ? taint_clone (taint) : taint_create (); reader->proto = caseproto_ref (proto); - reader->case_cnt = case_cnt; + reader->n_cases = n_cases; reader->class = class; reader->aux = aux; return reader; @@ -472,7 +472,7 @@ compare_random_readers_by_offset (const struct heap_node *a_, member functions and auxiliary data to pass to those member functions, respectively. */ struct casereader * -casereader_create_random (const struct caseproto *proto, casenumber case_cnt, +casereader_create_random (const struct caseproto *proto, casenumber n_cases, const struct casereader_random_class *class, void *aux) { @@ -481,7 +481,7 @@ casereader_create_random (const struct caseproto *proto, casenumber case_cnt, shared->class = class; shared->aux = aux; shared->min_offset = 0; - return casereader_create_sequential (NULL, proto, case_cnt, + return casereader_create_sequential (NULL, proto, n_cases, &random_reader_casereader_class, make_random_reader (shared, 0)); } @@ -550,7 +550,7 @@ random_reader_clone (struct casereader *reader, void *br_) struct random_reader_shared *shared = br->shared; return casereader_create_sequential (casereader_get_taint (reader), reader->proto, - casereader_get_case_cnt (reader), + casereader_get_n_cases (reader), &random_reader_casereader_class, make_random_reader (shared, br->offset)); diff --git a/src/data/casereader.h b/src/data/casereader.h index 45ea2c10af..680e669928 100644 --- a/src/data/casereader.h +++ b/src/data/casereader.h @@ -74,7 +74,7 @@ bool casereader_error (const struct casereader *); void casereader_force_error (struct casereader *); const struct taint *casereader_get_taint (const struct casereader *); -casenumber casereader_get_case_cnt (struct casereader *); +casenumber casereader_get_n_cases (struct casereader *); casenumber casereader_count_cases (const struct casereader *); void casereader_truncate (struct casereader *, casenumber); const struct caseproto *casereader_get_proto (const struct casereader *); @@ -98,7 +98,7 @@ casereader_create_filter_weight (struct casereader *, struct casewriter *exclude); struct casereader * casereader_create_filter_missing (struct casereader *, - const struct variable *const*vars, size_t var_cnt, + const struct variable *const *vars, size_t n_vars, enum mv_class, casenumber *n_missing, struct casewriter *exclude); diff --git a/src/data/casewindow.c b/src/data/casewindow.c index 804a58aa51..ccd2853da3 100644 --- a/src/data/casewindow.c +++ b/src/data/casewindow.c @@ -53,7 +53,7 @@ struct casewindow_class void (*push_head) (void *aux, struct ccase *); void (*pop_tail) (void *aux, casenumber cnt); struct ccase *(*get_case) (void *aux, casenumber ofs); - casenumber (*get_case_cnt) (const void *aux); + casenumber (*get_n_cases) (const void *aux); }; /* Classes. */ @@ -121,7 +121,7 @@ casewindow_to_disk (struct casewindow *old) { struct casewindow *new; new = do_casewindow_create (taint_clone (old->taint), old->proto, 0); - while (casewindow_get_case_cnt (old) > 0 && !casewindow_error (new)) + while (casewindow_get_n_cases (old) > 0 && !casewindow_error (new)) { struct ccase *c = casewindow_get_case (old, 0); if (c == NULL) @@ -143,8 +143,8 @@ casewindow_push_head (struct casewindow *cw, struct ccase *c) cw->class->push_head (cw->aux, c); if (!casewindow_error (cw)) { - casenumber case_cnt = cw->class->get_case_cnt (cw->aux); - if (case_cnt > cw->max_in_core_cases + casenumber n_cases = cw->class->get_n_cases (cw->aux); + if (n_cases > cw->max_in_core_cases && cw->class == &casewindow_memory_class) casewindow_to_disk (cw); } @@ -155,10 +155,10 @@ casewindow_push_head (struct casewindow *cw, struct ccase *c) /* Deletes CASE_CNT cases at the tail of casewindow CW. */ void -casewindow_pop_tail (struct casewindow *cw, casenumber case_cnt) +casewindow_pop_tail (struct casewindow *cw, casenumber n_cases) { if (!casewindow_error (cw)) - cw->class->pop_tail (cw->aux, case_cnt); + cw->class->pop_tail (cw->aux, n_cases); } /* Returns the case that is CASE_IDX cases away from CW's tail @@ -170,7 +170,7 @@ casewindow_get_case (const struct casewindow *cw_, casenumber case_idx) { struct casewindow *cw = CONST_CAST (struct casewindow *, cw_); - assert (case_idx >= 0 && case_idx < casewindow_get_case_cnt (cw)); + assert (case_idx >= 0 && case_idx < casewindow_get_n_cases (cw)); if (casewindow_error (cw)) return NULL; return cw->class->get_case (cw->aux, case_idx); @@ -178,9 +178,9 @@ casewindow_get_case (const struct casewindow *cw_, casenumber case_idx) /* Returns the number of cases in casewindow CW. */ casenumber -casewindow_get_case_cnt (const struct casewindow *cw) +casewindow_get_n_cases (const struct casewindow *cw) { - return cw->class->get_case_cnt (cw->aux); + return cw->class->get_n_cases (cw->aux); } /* Returns the case prototype for the cases in casewindow CW. @@ -250,11 +250,11 @@ casewindow_memory_push_head (void *cwm_, struct ccase *c) } static void -casewindow_memory_pop_tail (void *cwm_, casenumber case_cnt) +casewindow_memory_pop_tail (void *cwm_, casenumber n_cases) { struct casewindow_memory *cwm = cwm_; - assert (deque_count (&cwm->deque) >= case_cnt); - while (case_cnt-- > 0) + assert (deque_count (&cwm->deque) >= n_cases); + while (n_cases-- > 0) case_unref (cwm->cases[deque_pop_front (&cwm->deque)]); } @@ -266,7 +266,7 @@ casewindow_memory_get_case (void *cwm_, casenumber ofs) } static casenumber -casewindow_memory_get_case_cnt (const void *cwm_) +casewindow_memory_get_n_cases (const void *cwm_) { const struct casewindow_memory *cwm = cwm_; return deque_count (&cwm->deque); @@ -279,7 +279,7 @@ static const struct casewindow_class casewindow_memory_class = casewindow_memory_push_head, casewindow_memory_pop_tail, casewindow_memory_get_case, - casewindow_memory_get_case_cnt, + casewindow_memory_get_n_cases, }; /* On-disk casewindow data. */ @@ -333,7 +333,7 @@ casewindow_file_get_case (void *cwf_, casenumber ofs) } static casenumber -casewindow_file_get_case_cnt (const void *cwf_) +casewindow_file_get_n_cases (const void *cwf_) { const struct casewindow_file *cwf = cwf_; return cwf->head - cwf->tail; @@ -346,5 +346,5 @@ static const struct casewindow_class casewindow_file_class = casewindow_file_push_head, casewindow_file_pop_tail, casewindow_file_get_case, - casewindow_file_get_case_cnt, + casewindow_file_get_n_cases, }; diff --git a/src/data/casewindow.h b/src/data/casewindow.h index c7a863eaa8..5ac205480b 100644 --- a/src/data/casewindow.h +++ b/src/data/casewindow.h @@ -41,7 +41,7 @@ void casewindow_pop_tail (struct casewindow *, casenumber cnt); struct ccase *casewindow_get_case (const struct casewindow *, casenumber case_idx); const struct caseproto *casewindow_get_proto (const struct casewindow *); -casenumber casewindow_get_case_cnt (const struct casewindow *); +casenumber casewindow_get_n_cases (const struct casewindow *); bool casewindow_error (const struct casewindow *); void casewindow_force_error (struct casewindow *); diff --git a/src/data/casewriter.c b/src/data/casewriter.c index 6029fc0dbe..768a515e16 100644 --- a/src/data/casewriter.c +++ b/src/data/casewriter.c @@ -37,7 +37,7 @@ struct casewriter { struct taint *taint; struct caseproto *proto; - casenumber case_cnt; + casenumber n_cases; const struct casewriter_class *class; void *aux; }; @@ -51,7 +51,7 @@ void casewriter_write (struct casewriter *writer, struct ccase *c) { size_t n_widths UNUSED = caseproto_get_n_widths (writer->proto); - assert (case_get_value_cnt (c) >= n_widths); + assert (case_get_n_values (c) >= n_widths); expensive_assert (caseproto_equal (case_get_proto (c), 0, writer->proto, 0, n_widths)); writer->class->write (writer, writer->aux, c); @@ -160,7 +160,7 @@ casewriter_create (const struct caseproto *proto, struct casewriter *writer = xmalloc (sizeof *writer); writer->taint = taint_create (); writer->proto = caseproto_ref (proto); - writer->case_cnt = 0; + writer->n_cases = 0; writer->class = class; writer->aux = aux; return writer; @@ -253,7 +253,7 @@ casewriter_window_convert_to_reader (struct casewriter *writer UNUSED, struct casewindow *window = window_; struct casereader *reader = casereader_create_random (casewindow_get_proto (window), - casewindow_get_case_cnt (window), + casewindow_get_n_cases (window), &casereader_window_class, window); taint_propagate (casewindow_get_taint (window), @@ -271,7 +271,7 @@ casereader_window_read (struct casereader *reader UNUSED, void *window_, casenumber offset) { struct casewindow *window = window_; - if (offset >= casewindow_get_case_cnt (window)) + if (offset >= casewindow_get_n_cases (window)) return NULL; return casewindow_get_case (window, offset); } @@ -287,10 +287,10 @@ casereader_window_destroy (struct casereader *reader UNUSED, void *window_) /* Discards CASE_CNT cases from the front of WINDOW. */ static void casereader_window_advance (struct casereader *reader UNUSED, void *window_, - casenumber case_cnt) + casenumber n_cases) { struct casewindow *window = window_; - casewindow_pop_tail (window, case_cnt); + casewindow_pop_tail (window, n_cases); } /* Class for casewindow writer. */ diff --git a/src/data/csv-file-writer.c b/src/data/csv-file-writer.c index d8c3e000ef..77224945bc 100644 --- a/src/data/csv-file-writer.c +++ b/src/data/csv-file-writer.c @@ -110,7 +110,7 @@ csv_writer_open (struct file_handle *fh, const struct dictionary *dict, w->encoding = xstrdup (dict_get_encoding (dict)); - w->n_csv_vars = dict_get_var_cnt (dict); + w->n_csv_vars = dict_get_n_vars (dict); w->csv_vars = xnmalloc (w->n_csv_vars, sizeof *w->csv_vars); for (i = 0; i < w->n_csv_vars; i++) { diff --git a/src/data/dataset.c b/src/data/dataset.c index 4313cac875..8b3332ec0d 100644 --- a/src/data/dataset.c +++ b/src/data/dataset.c @@ -436,8 +436,8 @@ proc_open_filtering (struct dataset *ds, bool filter) if (!ds->discard_output) { struct dictionary *pd = ds->permanent_dict; - size_t compacted_value_cnt = dict_count_values (pd, 1u << DC_SCRATCH); - if (compacted_value_cnt < dict_get_next_value_idx (pd)) + size_t compacted_n_values = dict_count_values (pd, 1u << DC_SCRATCH); + if (compacted_n_values < dict_get_next_value_idx (pd)) { struct caseproto *compacted_proto; compacted_proto = dict_get_compacted_proto (pd, 1u << DC_SCRATCH); diff --git a/src/data/datasheet.c b/src/data/datasheet.c index f18cf8bdc2..74da1116a5 100644 --- a/src/data/datasheet.c +++ b/src/data/datasheet.c @@ -625,37 +625,37 @@ datasheet_insert_rows (struct datasheet *ds, while (cnt > 0) { unsigned long first_phy; - unsigned long phy_cnt; + unsigned long n_phys; unsigned long i; /* Allocate physical rows from the pool of available rows. */ - if (!axis_allocate (ds->rows, cnt, &first_phy, &phy_cnt)) + if (!axis_allocate (ds->rows, cnt, &first_phy, &n_phys)) { /* No rows were available. Extend the row axis to make some new ones available. */ - phy_cnt = cnt; + n_phys = cnt; first_phy = axis_extend (ds->rows, cnt); } /* Insert the new rows into the row mapping. */ - axis_insert (ds->rows, before, first_phy, phy_cnt); + axis_insert (ds->rows, before, first_phy, n_phys); /* Initialize the new rows. */ - for (i = 0; i < phy_cnt; i++) + for (i = 0; i < n_phys; i++) if (!datasheet_put_row (ds, before + i, c[i])) { while (++i < cnt) case_unref (c[i]); - datasheet_delete_rows (ds, before - added, phy_cnt + added); + datasheet_delete_rows (ds, before - added, n_phys + added); return false; } /* Advance. */ - c += phy_cnt; - cnt -= phy_cnt; - before += phy_cnt; - added += phy_cnt; + c += n_phys; + cnt -= n_phys; + before += n_phys; + added += n_phys; } return true; } @@ -734,10 +734,10 @@ datasheet_reader_destroy (struct casereader *reader UNUSED, void *ds_) /* "advance" function for the datasheet random casereader. */ static void datasheet_reader_advance (struct casereader *reader UNUSED, void *ds_, - casenumber case_cnt) + casenumber n_cases) { struct datasheet *ds = ds_; - datasheet_delete_rows (ds, 0, case_cnt); + datasheet_delete_rows (ds, 0, n_cases); } /* Random casereader class for a datasheet. */ diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 4fbcdf2a1e..054445a5e4 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -58,21 +58,22 @@ struct dictionary { int ref_cnt; - struct vardict_info *var; /* Variables. */ - size_t var_cnt, var_cap; /* Number of variables, capacity. */ + struct vardict_info *vars; /* Variables. */ + size_t n_vars; /* Number of variables. */ + size_t allocated_vars; /* Allocated space in 'vars'. */ struct caseproto *proto; /* Prototype for dictionary cases (updated lazily). */ struct hmap name_map; /* Variable index by name. */ int next_value_idx; /* Index of next `union value' to allocate. */ const struct variable **split; /* SPLIT FILE vars. */ - size_t split_cnt; /* SPLIT FILE count. */ + size_t n_splits; /* SPLIT FILE count. */ struct variable *weight; /* WEIGHT variable. */ struct variable *filter; /* FILTER variable. */ casenumber case_limit; /* Current case limit (N command). */ char *label; /* File label. */ struct string_array documents; /* Documents. */ struct vector **vector; /* Vectors of variables. */ - size_t vector_cnt; /* Number of vectors. */ + size_t n_vectors; /* Number of vectors. */ struct attrset attributes; /* Custom attributes. */ struct mrset **mrsets; /* Multiple response sets. */ size_t n_mrsets; /* Number of multiple response sets. */ @@ -153,7 +154,7 @@ unindex_vars (struct dictionary *d, size_t from, size_t to) size_t i; for (i = from; i < to; i++) - unindex_var (d, &d->var[i]); + unindex_var (d, &d->vars[i]); } /* Re-sets the dict_index in the dictionary variables with @@ -164,7 +165,7 @@ reindex_vars (struct dictionary *d, size_t from, size_t to, bool skip_callbacks) size_t i; for (i = from; i < to; i++) - reindex_var (d, &d->var[i], skip_callbacks); + reindex_var (d, &d->vars[i], skip_callbacks); } @@ -212,9 +213,9 @@ void dict_dump (const struct dictionary *d) { int i; - for (i = 0 ; i < d->var_cnt ; ++i) + for (i = 0 ; i < d->n_vars ; ++i) { - const struct variable *v = d->var[i].var; + const struct variable *v = d->vars[i].var; printf ("Name: %s;\tdict_idx: %zu; case_idx: %zu\n", var_get_name (v), var_get_dict_index (v), @@ -280,13 +281,13 @@ dict_clone (const struct dictionary *s) d = dict_create (s->encoding); dict_set_names_must_be_ids (d, dict_get_names_must_be_ids (s)); - for (i = 0; i < s->var_cnt; i++) + for (i = 0; i < s->n_vars; i++) { - struct variable *sv = s->var[i].var; + struct variable *sv = s->vars[i].var; struct variable *dv = dict_clone_var_assert (d, sv); size_t i; - for (i = 0; i < var_get_short_name_cnt (sv); i++) + for (i = 0; i < var_get_n_short_names (sv); i++) var_set_short_name (dv, i, var_get_short_name (sv, i)); var_get_vardict (dv)->case_index = var_get_vardict (sv)->case_index; @@ -294,11 +295,11 @@ dict_clone (const struct dictionary *s) d->next_value_idx = s->next_value_idx; - d->split_cnt = s->split_cnt; - if (d->split_cnt > 0) + d->n_splits = s->n_splits; + if (d->n_splits > 0) { - d->split = xnmalloc (d->split_cnt, sizeof *d->split); - for (i = 0; i < d->split_cnt; i++) + d->split = xnmalloc (d->n_splits, sizeof *d->split); + for (i = 0; i < d->n_splits; i++) d->split[i] = dict_lookup_var_assert (d, var_get_name (s->split[i])); } @@ -312,9 +313,9 @@ dict_clone (const struct dictionary *s) dict_set_label (d, dict_get_label (s)); dict_set_documents (d, dict_get_documents (s)); - d->vector_cnt = s->vector_cnt; - d->vector = xnmalloc (d->vector_cnt, sizeof *d->vector); - for (i = 0; i < s->vector_cnt; i++) + d->n_vectors = s->n_vectors; + d->vector = xnmalloc (d->n_vectors, sizeof *d->vector); + for (i = 0; i < s->n_vectors; i++) d->vector[i] = vector_clone (s->vector[i], s, d); dict_set_attributes (d, dict_get_attributes (s)); @@ -339,7 +340,7 @@ dict_clone (const struct dictionary *s) /* Returns the SPLIT FILE vars (see cmd_split_file()). Call - dict_get_split_cnt() to determine how many SPLIT FILE vars + dict_get_n_splits() to determine how many SPLIT FILE vars there are. Returns a null pointer if and only if there are no SPLIT FILE vars. */ const struct variable *const * @@ -350,9 +351,9 @@ dict_get_split_vars (const struct dictionary *d) /* Returns the number of SPLIT FILE vars. */ size_t -dict_get_split_cnt (const struct dictionary *d) +dict_get_n_splits (const struct dictionary *d) { - return d->split_cnt; + return d->n_splits; } /* Removes variable V, which must be in D, from D's set of split @@ -364,10 +365,10 @@ dict_unset_split_var (struct dictionary *d, struct variable *v, bool skip_callba assert (dict_contains_var (d, v)); - orig_count = d->split_cnt; - d->split_cnt = remove_equal (d->split, d->split_cnt, sizeof *d->split, + orig_count = d->n_splits; + d->n_splits = remove_equal (d->split, d->n_splits, sizeof *d->split, &v, compare_var_ptrs, NULL); - if (orig_count != d->split_cnt && !skip_callbacks) + if (orig_count != d->n_splits && !skip_callbacks) { if (d->changed) d->changed (d, d->changed_data); /* We changed the set of split variables so invoke the @@ -378,18 +379,19 @@ dict_unset_split_var (struct dictionary *d, struct variable *v, bool skip_callba } -/* Sets CNT split vars SPLIT in dictionary D. */ +/* Sets N split vars SPLIT in dictionary D. */ static void dict_set_split_vars__ (struct dictionary *d, - struct variable *const *split, size_t cnt, bool skip_callbacks) + struct variable *const *split, size_t n, + bool skip_callbacks) { - assert (cnt == 0 || split != NULL); + assert (n == 0 || split != NULL); - d->split_cnt = cnt; - if (cnt > 0) + d->n_splits = n; + if (n > 0) { - d->split = xnrealloc (d->split, cnt, sizeof *d->split) ; - memcpy (d->split, split, cnt * sizeof *d->split); + d->split = xnrealloc (d->split, n, sizeof *d->split) ; + memcpy (d->split, split, n * sizeof *d->split); } else { @@ -405,12 +407,12 @@ dict_set_split_vars__ (struct dictionary *d, } } -/* Sets CNT split vars SPLIT in dictionary D. */ +/* Sets N split vars SPLIT in dictionary D. */ void dict_set_split_vars (struct dictionary *d, - struct variable *const *split, size_t cnt) + struct variable *const *split, size_t n) { - dict_set_split_vars__ (d, split, cnt, false); + dict_set_split_vars__ (d, split, n, false); } @@ -448,12 +450,12 @@ dict_delete_var__ (struct dictionary *d, struct variable *v, bool skip_callbacks dict_clear_vectors (d); /* Remove V from var array. */ - unindex_vars (d, dict_index, d->var_cnt); - remove_element (d->var, d->var_cnt, sizeof *d->var, dict_index); - d->var_cnt--; + unindex_vars (d, dict_index, d->n_vars); + remove_element (d->vars, d->n_vars, sizeof *d->vars, dict_index); + d->n_vars--; /* Update dict_index for each affected variable. */ - reindex_vars (d, dict_index, d->var_cnt, skip_callbacks); + reindex_vars (d, dict_index, d->n_vars, skip_callbacks); /* Free memory. */ var_clear_vardict (v); @@ -508,14 +510,14 @@ dict_delete_vars (struct dictionary *d, details. Deleting consecutive vars will result in less callbacks compared to iterating over dict_delete_var. A simple while loop over dict_delete_var will - produce (d->var_cnt - IDX) * COUNT variable changed callbacks + produce (d->n_vars - IDX) * COUNT variable changed callbacks plus COUNT variable delete callbacks. - This here produces d->var_cnt - IDX variable changed callbacks + This here produces d->n_vars - IDX variable changed callbacks plus COUNT variable delete callbacks. */ void dict_delete_consecutive_vars (struct dictionary *d, size_t idx, size_t count) { - assert (idx + count <= d->var_cnt); + assert (idx + count <= d->n_vars); /* We need to store the variable and the corresponding case_index for the delete callbacks later. We store them in a linked list.*/ @@ -530,7 +532,7 @@ dict_delete_consecutive_vars (struct dictionary *d, size_t idx, size_t count) { struct delvar *dv = xmalloc (sizeof (struct delvar)); assert (dv); - struct variable *v = d->var[i].var; + struct variable *v = d->vars[i].var; dict_unset_split_var (d, v, false); dict_unset_mrset_var (d, v); @@ -549,12 +551,12 @@ dict_delete_consecutive_vars (struct dictionary *d, size_t idx, size_t count) dict_clear_vectors (d); /* Remove variables from var array. */ - unindex_vars (d, idx, d->var_cnt); - remove_range (d->var, d->var_cnt, sizeof *d->var, idx, count); - d->var_cnt -= count; + unindex_vars (d, idx, d->n_vars); + remove_range (d->vars, d->n_vars, sizeof *d->vars, idx, count); + d->n_vars -= count; /* Reindexing will result variable-changed callback */ - reindex_vars (d, idx, d->var_cnt, false); + reindex_vars (d, idx, d->n_vars, false); invalidate_proto (d); if (d->changed) d->changed (d, d->changed_data); @@ -582,9 +584,9 @@ dict_delete_scratch_vars (struct dictionary *d) /* FIXME: this can be done in O(count) time, but this algorithm is O(count**2). */ - for (i = 0; i < d->var_cnt;) - if (var_get_dict_class (d->var[i].var) == DC_SCRATCH) - dict_delete_var (d, d->var[i].var); + for (i = 0; i < d->n_vars;) + if (var_get_dict_class (d->vars[i].var) == DC_SCRATCH) + dict_delete_var (d, d->vars[i].var); else i++; } @@ -598,14 +600,14 @@ dict_clear__ (struct dictionary *d, bool skip_callbacks) { /* FIXME? Should we really clear case_limit, label, documents? Others are necessarily cleared by deleting all the variables.*/ - while (d->var_cnt > 0) + while (d->n_vars > 0) { - dict_delete_var__ (d, d->var[d->var_cnt - 1].var, skip_callbacks); + dict_delete_var__ (d, d->vars[d->n_vars - 1].var, skip_callbacks); } - free (d->var); - d->var = NULL; - d->var_cnt = d->var_cap = 0; + free (d->vars); + d->vars = NULL; + d->n_vars = d->allocated_vars = 0; invalidate_proto (d); hmap_clear (&d->name_map); d->next_value_idx = 0; @@ -674,42 +676,42 @@ dict_unref (struct dictionary *d) /* Returns the number of variables in D. */ size_t -dict_get_var_cnt (const struct dictionary *d) +dict_get_n_vars (const struct dictionary *d) { - return d->var_cnt; + return d->n_vars; } /* Returns the variable in D with dictionary index IDX, which must be between 0 and the count returned by - dict_get_var_cnt(), exclusive. */ + dict_get_n_vars(), exclusive. */ struct variable * dict_get_var (const struct dictionary *d, size_t idx) { - assert (idx < d->var_cnt); + assert (idx < d->n_vars); - return d->var[idx].var; + return d->vars[idx].var; } -/* Sets *VARS to an array of pointers to variables in D and *CNT +/* Sets *VARS to an array of pointers to variables in D and *N to the number of variables in *D. All variables are returned except for those, if any, in the classes indicated by EXCLUDE. (There is no point in putting DC_SYSTEM in EXCLUDE as dictionaries never include system variables.) */ void dict_get_vars (const struct dictionary *d, const struct variable ***vars, - size_t *cnt, enum dict_class exclude) + size_t *n, enum dict_class exclude) { - dict_get_vars_mutable (d, (struct variable ***) vars, cnt, exclude); + dict_get_vars_mutable (d, (struct variable ***) vars, n, exclude); } -/* Sets *VARS to an array of pointers to variables in D and *CNT +/* Sets *VARS to an array of pointers to variables in D and *N to the number of variables in *D. All variables are returned except for those, if any, in the classes indicated by EXCLUDE. (There is no point in putting DC_SYSTEM in EXCLUDE as dictionaries never include system variables.) */ void dict_get_vars_mutable (const struct dictionary *d, struct variable ***vars, - size_t *cnt, enum dict_class exclude) + size_t *n, enum dict_class exclude) { size_t count; size_t i; @@ -717,22 +719,22 @@ dict_get_vars_mutable (const struct dictionary *d, struct variable ***vars, assert (exclude == (exclude & DC_ALL)); count = 0; - for (i = 0; i < d->var_cnt; i++) + for (i = 0; i < d->n_vars; i++) { - enum dict_class class = var_get_dict_class (d->var[i].var); + enum dict_class class = var_get_dict_class (d->vars[i].var); if (!(class & exclude)) count++; } *vars = xnmalloc (count, sizeof **vars); - *cnt = 0; - for (i = 0; i < d->var_cnt; i++) + *n = 0; + for (i = 0; i < d->n_vars; i++) { - enum dict_class class = var_get_dict_class (d->var[i].var); + enum dict_class class = var_get_dict_class (d->vars[i].var); if (!(class & exclude)) - (*vars)[(*cnt)++] = d->var[i].var; + (*vars)[(*n)++] = d->vars[i].var; } - assert (*cnt == count); + assert (*n == count); } static struct variable * @@ -744,21 +746,21 @@ add_var_with_case_index (struct dictionary *d, struct variable *v, assert (case_index >= d->next_value_idx); /* Update dictionary. */ - if (d->var_cnt >= d->var_cap) + if (d->n_vars >= d->allocated_vars) { size_t i; - d->var = x2nrealloc (d->var, &d->var_cap, sizeof *d->var); + d->vars = x2nrealloc (d->vars, &d->allocated_vars, sizeof *d->vars); hmap_clear (&d->name_map); - for (i = 0; i < d->var_cnt; i++) + for (i = 0; i < d->n_vars; i++) { - var_set_vardict (d->var[i].var, &d->var[i]); - hmap_insert_fast (&d->name_map, &d->var[i].name_node, - d->var[i].name_node.hash); + var_set_vardict (d->vars[i].var, &d->vars[i]); + hmap_insert_fast (&d->name_map, &d->vars[i].name_node, + d->vars[i].name_node.hash); } } - vardict = &d->var[d->var_cnt++]; + vardict = &d->vars[d->n_vars++]; vardict->dict = d; vardict->var = v; hmap_insert (&d->name_map, &vardict->name_node, @@ -904,10 +906,10 @@ dict_reorder_var (struct dictionary *d, struct variable *v, size_t new_index) { size_t old_index = var_get_dict_index (v); - assert (new_index < d->var_cnt); + assert (new_index < d->n_vars); unindex_vars (d, MIN (old_index, new_index), MAX (old_index, new_index) + 1); - move_element (d->var, d->var_cnt, sizeof *d->var, old_index, new_index); + move_element (d->vars, d->n_vars, sizeof *d->vars, old_index, new_index); reindex_vars (d, MIN (old_index, new_index), MAX (old_index, new_index) + 1, false); } @@ -923,9 +925,9 @@ dict_reorder_vars (struct dictionary *d, size_t i; assert (count == 0 || order != NULL); - assert (count <= d->var_cnt); + assert (count <= d->n_vars); - new_var = xnmalloc (d->var_cap, sizeof *new_var); + new_var = xnmalloc (d->allocated_vars, sizeof *new_var); /* Add variables in ORDER to new_var. */ for (i = 0; i < count; i++) @@ -940,17 +942,17 @@ dict_reorder_vars (struct dictionary *d, } /* Add remaining variables to new_var. */ - for (i = 0; i < d->var_cnt; i++) - if (d->var[i].dict != NULL) - new_var[count++] = d->var[i]; - assert (count == d->var_cnt); + for (i = 0; i < d->n_vars; i++) + if (d->vars[i].dict != NULL) + new_var[count++] = d->vars[i]; + assert (count == d->n_vars); /* Replace old vardicts by new ones. */ - free (d->var); - d->var = new_var; + free (d->vars); + d->vars = new_var; hmap_clear (&d->name_map); - reindex_vars (d, 0, d->var_cnt, false); + reindex_vars (d, 0, d->n_vars, false); } /* Changes the name of variable V that is currently in a dictionary to @@ -1337,11 +1339,11 @@ dict_get_proto (const struct dictionary *d_) size_t i; d->proto = caseproto_create (); - d->proto = caseproto_reserve (d->proto, d->var_cnt); - for (i = 0; i < d->var_cnt; i++) + d->proto = caseproto_reserve (d->proto, d->n_vars); + for (i = 0; i < d->n_vars; i++) d->proto = caseproto_set_width (d->proto, - var_get_case_index (d->var[i].var), - var_get_width (d->var[i].var)); + var_get_case_index (d->vars[i].var), + var_get_width (d->vars[i].var)); } return d->proto; } @@ -1371,9 +1373,9 @@ dict_compact_values (struct dictionary *d) size_t i; d->next_value_idx = 0; - for (i = 0; i < d->var_cnt; i++) + for (i = 0; i < d->n_vars; i++) { - struct variable *v = d->var[i].var; + struct variable *v = d->vars[i].var; set_var_case_index (v, d->next_value_idx++); } invalidate_proto (d); @@ -1392,21 +1394,18 @@ dict_compact_values (struct dictionary *d) size_t dict_count_values (const struct dictionary *d, unsigned int exclude_classes) { - size_t i; - size_t cnt; - assert ((exclude_classes & ~((1u << DC_ORDINARY) | (1u << DC_SYSTEM) | (1u << DC_SCRATCH))) == 0); - cnt = 0; - for (i = 0; i < d->var_cnt; i++) + size_t n = 0; + for (size_t i = 0; i < d->n_vars; i++) { - enum dict_class class = var_get_dict_class (d->var[i].var); + enum dict_class class = var_get_dict_class (d->vars[i].var); if (!(exclude_classes & (1u << class))) - cnt++; + n++; } - return cnt; + return n; } /* Returns the case prototype that would result after deleting @@ -1428,9 +1427,9 @@ dict_get_compacted_proto (const struct dictionary *d, | (1u << DC_SCRATCH))) == 0); proto = caseproto_create (); - for (i = 0; i < d->var_cnt; i++) + for (i = 0; i < d->n_vars; i++) { - struct variable *v = d->var[i].var; + struct variable *v = d->vars[i].var; if (!(exclude_classes & (1u << var_get_dict_class (v)))) proto = caseproto_add_width (proto, var_get_width (v)); } @@ -1537,7 +1536,7 @@ dict_add_document_line (struct dictionary *d, const char *line, /* Returns the number of document lines in dictionary D. */ size_t -dict_get_document_line_cnt (const struct dictionary *d) +dict_get_document_n_lines (const struct dictionary *d) { return d->documents.n; } @@ -1551,57 +1550,55 @@ dict_get_document_line (const struct dictionary *d, size_t idx) return d->documents.strings[idx]; } -/* Creates in D a vector named NAME that contains the CNT +/* Creates in D a vector named NAME that contains the N variables in VAR. Returns true if successful, or false if a vector named NAME already exists in D. */ bool dict_create_vector (struct dictionary *d, const char *name, - struct variable **var, size_t cnt) + struct variable **var, size_t n) { - size_t i; - - assert (cnt > 0); - for (i = 0; i < cnt; i++) + assert (n > 0); + for (size_t i = 0; i < n; i++) assert (dict_contains_var (d, var[i])); if (dict_lookup_vector (d, name) == NULL) { - d->vector = xnrealloc (d->vector, d->vector_cnt + 1, sizeof *d->vector); - d->vector[d->vector_cnt++] = vector_create (name, var, cnt); + d->vector = xnrealloc (d->vector, d->n_vectors + 1, sizeof *d->vector); + d->vector[d->n_vectors++] = vector_create (name, var, n); return true; } else return false; } -/* Creates in D a vector named NAME that contains the CNT +/* Creates in D a vector named NAME that contains the N variables in VAR. A vector named NAME must not already exist in D. */ void dict_create_vector_assert (struct dictionary *d, const char *name, - struct variable **var, size_t cnt) + struct variable **var, size_t n) { assert (dict_lookup_vector (d, name) == NULL); - dict_create_vector (d, name, var, cnt); + dict_create_vector (d, name, var, n); } /* Returns the vector in D with index IDX, which must be less - than dict_get_vector_cnt (D). */ + than dict_get_n_vectors (D). */ const struct vector * dict_get_vector (const struct dictionary *d, size_t idx) { - assert (idx < d->vector_cnt); + assert (idx < d->n_vectors); return d->vector[idx]; } /* Returns the number of vectors in D. */ size_t -dict_get_vector_cnt (const struct dictionary *d) +dict_get_n_vectors (const struct dictionary *d) { - return d->vector_cnt; + return d->n_vectors; } /* Looks up and returns the vector within D with the given @@ -1610,7 +1607,7 @@ const struct vector * dict_lookup_vector (const struct dictionary *d, const char *name) { size_t i; - for (i = 0; i < d->vector_cnt; i++) + for (i = 0; i < d->n_vectors; i++) if (!utf8_strcasecmp (vector_get_name (d->vector[i]), name)) return d->vector[i]; return NULL; @@ -1622,12 +1619,12 @@ dict_clear_vectors (struct dictionary *d) { size_t i; - for (i = 0; i < d->vector_cnt; i++) + for (i = 0; i < d->n_vectors; i++) vector_destroy (d->vector[i]); free (d->vector); d->vector = NULL; - d->vector_cnt = 0; + d->n_vectors = 0; } /* Multiple response sets. */ @@ -1855,7 +1852,7 @@ dict_destroy_internal_var (struct variable *var) /* Destroy internal_dict if it has no variables left, just so that valgrind --leak-check --show-reachable won't show internal_dict. */ - if (dict_get_var_cnt (internal_dict) == 0) + if (dict_get_n_vars (internal_dict) == 0) { dict_unref (internal_dict); internal_dict = NULL; @@ -1866,5 +1863,5 @@ dict_destroy_internal_var (struct variable *var) int vardict_get_dict_index (const struct vardict_info *vardict) { - return vardict - vardict->dict->var; + return vardict - vardict->dict->vars; } diff --git a/src/data/dictionary.h b/src/data/dictionary.h index 0eb175063d..d1f7f2828b 100644 --- a/src/data/dictionary.h +++ b/src/data/dictionary.h @@ -40,15 +40,15 @@ struct variable *dict_lookup_var (const struct dictionary *, const char *); struct variable *dict_lookup_var_assert (const struct dictionary *, const char *); struct variable *dict_get_var (const struct dictionary *, size_t position); -size_t dict_get_var_cnt (const struct dictionary *); +size_t dict_get_n_vars (const struct dictionary *); /* Other access to variables. */ bool dict_contains_var (const struct dictionary *, const struct variable *); void dict_get_vars (const struct dictionary *, - const struct variable ***vars, size_t *cnt, + const struct variable ***vars, size_t *n_vars, enum dict_class exclude); void dict_get_vars_mutable (const struct dictionary *, - struct variable ***vars, size_t *cnt, + struct variable ***vars, size_t *n_vars, enum dict_class exclude); /* Creating variables. */ @@ -125,9 +125,9 @@ struct caseproto *dict_get_compacted_proto (const struct dictionary *, /* SPLIT FILE variables. */ const struct variable *const *dict_get_split_vars (const struct dictionary *); -size_t dict_get_split_cnt (const struct dictionary *); +size_t dict_get_n_splits (const struct dictionary *); void dict_set_split_vars (struct dictionary *, - struct variable *const *, size_t cnt); + struct variable *const *, size_t n); /* File label. */ const char *dict_get_label (const struct dictionary *); @@ -143,16 +143,16 @@ void dict_clear_documents (struct dictionary *); bool dict_add_document_line (struct dictionary *, const char *, bool issue_warning); -size_t dict_get_document_line_cnt (const struct dictionary *); +size_t dict_get_document_n_lines (const struct dictionary *); const char *dict_get_document_line (const struct dictionary *, size_t); /* Vectors. */ bool dict_create_vector (struct dictionary *, const char *name, - struct variable **, size_t cnt); + struct variable **, size_t n); void dict_create_vector_assert (struct dictionary *, const char *name, - struct variable **, size_t cnt); + struct variable **, size_t n); const struct vector *dict_get_vector (const struct dictionary *, size_t idx); -size_t dict_get_vector_cnt (const struct dictionary *); +size_t dict_get_n_vectors (const struct dictionary *); const struct vector *dict_lookup_vector (const struct dictionary *, const char *name); void dict_clear_vectors (struct dictionary *); diff --git a/src/data/format-guesser.c b/src/data/format-guesser.c index 7475b2946f..a9953a532c 100644 --- a/src/data/format-guesser.c +++ b/src/data/format-guesser.c @@ -70,7 +70,7 @@ struct date_syntax { enum fmt_type format; /* Format type. */ #define MAX_TOKENS 11 - size_t token_cnt; /* Number of tokens. */ + size_t n_tokens; /* Number of tokens. */ enum date_token tokens[MAX_TOKENS]; /* Tokens. */ }; @@ -491,27 +491,27 @@ add_date_time (struct fmt_guesser *g, struct substring s) enum date_token token; enum date_token tokens[MAX_TOKENS]; enum date_token tokens_seen; - size_t token_cnt; + size_t n_tokens; int decimals; bool is_date; int i; /* Break S into tokens. */ - token_cnt = 0; + n_tokens = 0; tokens_seen = 0; decimals = 0; while (!ss_is_empty (s)) { - if (token_cnt >= MAX_TOKENS) + if (n_tokens >= MAX_TOKENS) return; token = parse_date_token (&s, tokens_seen, &decimals); if (token == 0) return; - tokens[token_cnt++] = token; + tokens[n_tokens++] = token; tokens_seen |= token; } - if (token_cnt == 0) + if (n_tokens == 0) return; /* Find matching date formats, if any, and increment the @@ -520,7 +520,7 @@ add_date_time (struct fmt_guesser *g, struct substring s) for (i = 0; i < DATE_SYNTAX_CNT; i++) { struct date_syntax *s = &syntax[i]; - if (match_date_syntax (tokens, token_cnt, s->tokens, s->token_cnt)) + if (match_date_syntax (tokens, n_tokens, s->tokens, s->n_tokens)) { is_date = true; g->date[i]++; @@ -589,7 +589,7 @@ guess_date_time (struct fmt_guesser *g, struct fmt_spec *f) { for (i = 0; i < DATE_SYNTAX_CNT; i++) if (g->date[i] - && syntax[i].tokens[syntax[i].token_cnt - 1] == DT_SECOND) + && syntax[i].tokens[syntax[i].n_tokens - 1] == DT_SECOND) { f->d = g->decimals / g->count; f->w = MAX (f->w, fmt_min_input_width (f->type) + 3); @@ -676,7 +676,7 @@ parse_date_number (struct substring *s, enum date_token tokens_seen, int *decimals) { long int value; - size_t digit_cnt = ss_get_long (s, &value); + size_t n_digits = ss_get_long (s, &value); enum date_token token = 0; if (ss_match_byte (s, settings_get_fmt_settings ()->decimal) @@ -703,13 +703,13 @@ parse_date_number (struct substring *s, enum date_token tokens_seen, else token = DT_DAY_COUNT; - if (digit_cnt == 2) + if (n_digits == 2) { token |= DT_YEAR; if (value <= 59) token |= DT_MINUTE | DT_SECOND; } - else if (digit_cnt == 4) + else if (n_digits == 4) token |= DT_YEAR; } diff --git a/src/data/identifier.c b/src/data/identifier.c index baa0abd1c5..d9d9b2a644 100644 --- a/src/data/identifier.c +++ b/src/data/identifier.c @@ -316,14 +316,14 @@ static const struct keyword keywords[] = { T_TO, SS_LITERAL_INITIALIZER ("TO") }, { T_WITH, SS_LITERAL_INITIALIZER ("WITH") }, }; -static const size_t keyword_cnt = sizeof keywords / sizeof *keywords; +static const size_t n_keywords = sizeof keywords / sizeof *keywords; /* Returns true if TOKEN is representable as a keyword. */ bool lex_is_keyword (enum token_type token) { const struct keyword *kw; - for (kw = keywords; kw < &keywords[keyword_cnt]; kw++) + for (kw = keywords; kw < &keywords[n_keywords]; kw++) if (kw->token == token) return true; return false; @@ -337,7 +337,7 @@ lex_id_to_token (struct substring id) if (ss_length (id) >= 2 && ss_length (id) <= 4) { const struct keyword *kw; - for (kw = keywords; kw < &keywords[keyword_cnt]; kw++) + for (kw = keywords; kw < &keywords[n_keywords]; kw++) if (ss_equals_case (kw->identifier, id)) return kw->token; } diff --git a/src/data/lazy-casereader.c b/src/data/lazy-casereader.c index bc68b938d5..7663180863 100644 --- a/src/data/lazy-casereader.c +++ b/src/data/lazy-casereader.c @@ -52,7 +52,7 @@ static const struct casereader_class lazy_casereader_class; data source or CASENUMBER_MAX if the number of cases cannot be predicted in advance. */ struct casereader * -lazy_casereader_create (const struct caseproto *proto, casenumber case_cnt, +lazy_casereader_create (const struct caseproto *proto, casenumber n_cases, struct casereader *(*callback) (void *aux), void *aux, unsigned long int *serial) { @@ -63,7 +63,7 @@ lazy_casereader_create (const struct caseproto *proto, casenumber case_cnt, *serial = lc->serial = next_serial++; lc->callback = callback; lc->aux = aux; - return casereader_create_sequential (NULL, proto, case_cnt, + return casereader_create_sequential (NULL, proto, n_cases, &lazy_casereader_class, lc); } diff --git a/src/data/lazy-casereader.h b/src/data/lazy-casereader.h index ed0e37b4f9..1e0a985865 100644 --- a/src/data/lazy-casereader.h +++ b/src/data/lazy-casereader.h @@ -30,7 +30,7 @@ #include "data/case.h" struct casereader *lazy_casereader_create (const struct caseproto *, - casenumber case_cnt, + casenumber n_cases, struct casereader *(*) (void *aux), void *aux, unsigned long int *serial); diff --git a/src/data/mdd-writer.c b/src/data/mdd-writer.c index 10728e8cbd..3fd651eb01 100644 --- a/src/data/mdd-writer.c +++ b/src/data/mdd-writer.c @@ -122,7 +122,7 @@ all_variables (struct dictionary *dict); struct all_dict_variables all_variables (struct dictionary *dict) { - size_t n_vars = dict_get_var_cnt (dict); + size_t n_vars = dict_get_n_vars (dict); /* Start with a set of all variable names. */ struct string_set var_names = STRING_SET_INITIALIZER (var_names); @@ -449,7 +449,7 @@ mdd_write (struct file_handle *fh, struct dictionary *dict, const char *sav_name) { struct mdd_writer *w = XZALLOC (struct mdd_writer); - size_t n_vars = dict_get_var_cnt (dict); + size_t n_vars = dict_get_n_vars (dict); /* Open file handle as an exclusive writer. */ /* TRANSLATORS: this fragment will be interpolated into @@ -624,7 +624,7 @@ mdd_write (struct file_handle *fh, struct dictionary *dict, /* We reserve ids 1...N_VARS for variables and then start other ids after that. */ - int id = dict_get_var_cnt (dict) + 1; + int id = dict_get_n_vars (dict) + 1; /* */ xmlTextWriterStartElement (w->writer, _xml ("definition")); diff --git a/src/data/ods-reader.c b/src/data/ods-reader.c index 2ff12fe109..b2efe2c573 100644 --- a/src/data/ods-reader.c +++ b/src/data/ods-reader.c @@ -1094,7 +1094,7 @@ ods_file_casereader_read (struct casereader *reader UNUSED, void *r_) continue; if (r->spreadsheet.stop_col != -1 && idx > r->spreadsheet.stop_col - r->spreadsheet.start_col) break; - if (idx >= dict_get_var_cnt (r->spreadsheet.dict)) + if (idx >= dict_get_n_vars (r->spreadsheet.dict)) break; var = dict_get_var (r->spreadsheet.dict, idx); diff --git a/src/data/pc+-file-reader.c b/src/data/pc+-file-reader.c index 4753881a67..72d9fe1d01 100644 --- a/src/data/pc+-file-reader.c +++ b/src/data/pc+-file-reader.c @@ -810,7 +810,7 @@ parse_header (struct pcp_reader *r, const struct pcp_main_header *header, info->integer_format = INTEGER_LSB_FIRST; info->float_format = FLOAT_IEEE_DOUBLE_LE; info->compression = r->compressed ? ANY_COMP_SIMPLE : ANY_COMP_NONE; - info->case_cnt = r->n_cases; + info->n_cases = r->n_cases; /* Convert file label to UTF-8 and put it into DICT. */ label = recode_and_trim_string (r->pool, dict_encoding, header->file_label); @@ -1200,11 +1200,11 @@ pcp_error (struct pcp_reader *r, off_t offset, const char *format, ...) an error. */ static inline int read_bytes_internal (struct pcp_reader *r, bool eof_is_ok, - void *buf, size_t byte_cnt) + void *buf, size_t n_bytes) { - size_t bytes_read = fread (buf, 1, byte_cnt, r->file); + size_t bytes_read = fread (buf, 1, n_bytes, r->file); r->pos += bytes_read; - if (bytes_read == byte_cnt) + if (bytes_read == n_bytes) return 1; else if (ferror (r->file)) { @@ -1224,9 +1224,9 @@ read_bytes_internal (struct pcp_reader *r, bool eof_is_ok, Returns true if successful. Returns false upon I/O error or if end-of-file is encountered. */ static bool -read_bytes (struct pcp_reader *r, void *buf, size_t byte_cnt) +read_bytes (struct pcp_reader *r, void *buf, size_t n_bytes) { - return read_bytes_internal (r, false, buf, byte_cnt) == 1; + return read_bytes_internal (r, false, buf, n_bytes) == 1; } /* Reads BYTE_CNT bytes into BUF. @@ -1234,9 +1234,9 @@ read_bytes (struct pcp_reader *r, void *buf, size_t byte_cnt) Returns 0 if an immediate end-of-file is encountered. Returns -1 if an I/O error or a partial read occurs. */ static int -try_read_bytes (struct pcp_reader *r, void *buf, size_t byte_cnt) +try_read_bytes (struct pcp_reader *r, void *buf, size_t n_bytes) { - return read_bytes_internal (r, true, buf, byte_cnt); + return read_bytes_internal (r, true, buf, n_bytes); } /* Reads a 16-bit signed integer from R and stores its value in host format in diff --git a/src/data/por-file-reader.c b/src/data/por-file-reader.c index b5cc35b825..94a2faf33b 100644 --- a/src/data/por-file-reader.c +++ b/src/data/por-file-reader.c @@ -77,7 +77,7 @@ struct pfm_reader int line_length; /* Number of characters so far on this line. */ char cc; /* Current character. */ char *trans; /* 256-byte character set translation table. */ - int var_cnt; /* Number of variables. */ + int n_vars; /* Number of variables. */ int weight_index; /* 0-based index of weight variable, or -1. */ struct caseproto *proto; /* Format of output cases. */ bool ok; /* Set false on I/O error. */ @@ -265,7 +265,7 @@ pfm_open (struct file_handle *fh) r->line_length = 0; r->weight_index = -1; r->trans = NULL; - r->var_cnt = 0; + r->n_vars = 0; r->proto = NULL; r->ok = true; if (setjmp (r->bail_out)) @@ -588,7 +588,7 @@ read_version_data (struct pfm_reader *r, struct any_read_info *info) info->float_format = FLOAT_NATIVE_DOUBLE; info->integer_format = INTEGER_NATIVE; info->compression = ANY_COMP_NONE; - info->case_cnt = -1; + info->n_cases = -1; /* Date. */ info->creation_date = xmalloc (11); @@ -680,9 +680,9 @@ read_variables (struct pfm_reader *r, struct dictionary *dict) if (!match (r, '4')) error (r, _("Expected variable count record.")); - r->var_cnt = read_int (r); - if (r->var_cnt <= 0) - error (r, _("Invalid number of variables %d."), r->var_cnt); + r->n_vars = read_int (r); + if (r->n_vars <= 0) + error (r, _("Invalid number of variables %d."), r->n_vars); if (match (r, '5')) read_int (r); @@ -694,7 +694,7 @@ read_variables (struct pfm_reader *r, struct dictionary *dict) error (r, _("Weight variable name (%s) truncated."), weight_name); } - for (i = 0; i < r->var_cnt; i++) + for (i = 0; i < r->n_vars; i++) { int width; char name[256]; @@ -859,11 +859,8 @@ read_value_label (struct pfm_reader *r, struct dictionary *dict) static void read_documents (struct pfm_reader *r, struct dictionary *dict) { - int line_cnt; - int i; - - line_cnt = read_int (r); - for (i = 0; i < line_cnt; i++) + int n_lines = read_int (r); + for (int i = 0; i < n_lines; i++) { char line[256]; read_string (r, line); @@ -896,7 +893,7 @@ por_file_casereader_read (struct casereader *reader, void *r_) return NULL; } - for (i = 0; i < r->var_cnt; i++) + for (i = 0; i < r->n_vars; i++) { int width = caseproto_get_width (r->proto, i); @@ -920,28 +917,28 @@ pfm_detect (FILE *file) { unsigned char header[464]; char trans[256]; - int cooked_cnt, raw_cnt, line_len; + int n_cooked, n_raws, line_len; int i; - cooked_cnt = raw_cnt = 0; + n_cooked = n_raws = 0; line_len = 0; - while (cooked_cnt < sizeof header) + while (n_cooked < sizeof header) { int c = getc (file); - if (c == EOF || raw_cnt++ > 512) + if (c == EOF || n_raws++ > 512) return ferror (file) ? -errno : 0; else if (c == '\n') { - while (line_len < 80 && cooked_cnt < sizeof header) + while (line_len < 80 && n_cooked < sizeof header) { - header[cooked_cnt++] = ' '; + header[n_cooked++] = ' '; line_len++; } line_len = 0; } else if (c != '\r') { - header[cooked_cnt++] = c; + header[n_cooked++] = c; line_len++; } } diff --git a/src/data/por-file-writer.c b/src/data/por-file-writer.c index 672add4101..be35418ce7 100644 --- a/src/data/por-file-writer.c +++ b/src/data/por-file-writer.c @@ -63,7 +63,7 @@ struct pfm_writer int lc; /* Number of characters on this line so far. */ - size_t var_cnt; /* Number of variables. */ + size_t n_vars; /* Number of variables. */ struct pfm_var *vars; /* Variables. */ int digits; /* Digits of precision. */ @@ -120,12 +120,12 @@ pfm_open_writer (struct file_handle *fh, struct dictionary *dict, w->file = NULL; w->rf = NULL; w->lc = 0; - w->var_cnt = 0; + w->n_vars = 0; w->vars = NULL; - w->var_cnt = dict_get_var_cnt (dict); - w->vars = xnmalloc (w->var_cnt, sizeof *w->vars); - for (i = 0; i < w->var_cnt; i++) + w->n_vars = dict_get_n_vars (dict); + w->vars = xnmalloc (w->n_vars, sizeof *w->vars); + for (i = 0; i < w->n_vars; i++) { const struct variable *dv = dict_get_var (dict, i); struct pfm_var *pv = &w->vars[i]; @@ -166,7 +166,7 @@ pfm_open_writer (struct file_handle *fh, struct dictionary *dict, write_version_data (w); write_variables (w, dict); write_value_labels (w, dict); - if (dict_get_document_line_cnt (dict) > 0) + if (dict_get_document_n_lines (dict) > 0) write_documents (w, dict); buf_write (w, "F", 1); if (ferror (w->file)) @@ -335,12 +335,12 @@ write_variables (struct pfm_writer *w, struct dictionary *dict) } buf_write (w, "4", 1); - write_int (w, dict_get_var_cnt (dict)); + write_int (w, dict_get_n_vars (dict)); buf_write (w, "5", 1); write_int (w, ceil (w->digits * (log (10) / log (30)))); - for (i = 0; i < dict_get_var_cnt (dict); i++) + for (i = 0; i < dict_get_n_vars (dict); i++) { struct variable *v = dict_get_var (dict, i); struct missing_values mv; @@ -400,7 +400,7 @@ write_value_labels (struct pfm_writer *w, const struct dictionary *dict) { int i; - for (i = 0; i < dict_get_var_cnt (dict); i++) + for (i = 0; i < dict_get_n_vars (dict); i++) { struct variable *v = dict_get_var (dict, i); const struct val_labs *val_labs = var_get_value_labels (v); @@ -432,13 +432,13 @@ write_value_labels (struct pfm_writer *w, const struct dictionary *dict) static void write_documents (struct pfm_writer *w, const struct dictionary *dict) { - size_t line_cnt = dict_get_document_line_cnt (dict); + size_t n_lines = dict_get_document_n_lines (dict); struct string line = DS_EMPTY_INITIALIZER; int i; buf_write (w, "E", 1); - write_int (w, line_cnt); - for (i = 0; i < line_cnt; i++) + write_int (w, n_lines); + for (i = 0; i < n_lines; i++) write_string (w, dict_get_document_line (dict, i)); ds_destroy (&line); } @@ -453,7 +453,7 @@ por_file_casewriter_write (struct casewriter *writer, void *w_, if (!ferror (w->file)) { - for (i = 0; i < w->var_cnt; i++) + for (i = 0; i < w->n_vars; i++) { struct pfm_var *v = &w->vars[i]; @@ -606,7 +606,7 @@ trig_to_char (int trig) character after the formatted number. */ static char * format_trig_digits (char *string, - const char trigs[], int trig_cnt, int trig_places) + const char trigs[], int n_trigs, int trig_places) { if (trig_places < 0) { @@ -615,7 +615,7 @@ format_trig_digits (char *string, *string++ = '0'; trig_places = -1; } - while (trig_cnt-- > 0) + while (n_trigs-- > 0) { if (trig_places-- == 0) *string++ = '.'; @@ -669,9 +669,9 @@ format_trig_int (int value, bool force_sign, char string[]) is exactly half, examines TRIGS[-1] and returns true if odd, false if even ("round to even"). */ static bool -should_round_up (const char trigs[], int trig_cnt) +should_round_up (const char trigs[], int n_trigs) { - assert (trig_cnt > 0); + assert (n_trigs > 0); if (*trigs < BASE / 2) { @@ -687,7 +687,7 @@ should_round_up (const char trigs[], int trig_cnt) { /* Approximately half: look more closely. */ int i; - for (i = 1; i < trig_cnt; i++) + for (i = 1; i < n_trigs; i++) if (trigs[i] > 0) { /* Slightly greater than half: round up. */ @@ -704,11 +704,11 @@ should_round_up (const char trigs[], int trig_cnt) successful, false on failure (due to a carry out of the leftmost position). */ static bool -try_round_up (char *trigs, int trig_cnt) +try_round_up (char *trigs, int n_trigs) { - while (trig_cnt > 0) + while (n_trigs > 0) { - char *round_trig = trigs + --trig_cnt; + char *round_trig = trigs + --n_trigs; if (*round_trig != BASE - 1) { /* Round this trig up to the next value. */ @@ -745,7 +745,7 @@ format_trig_double (long double value, int base_10_precision, char output[]) /* VALUE as a set of trigesimals. */ char buffer[DBL_DIG + 16]; char *trigs; - int trig_cnt; + int n_trigs; /* Number of trigesimal places for trigs. trigs[0] has coefficient 30**(trig_places - 1), @@ -794,7 +794,7 @@ format_trig_double (long double value, int base_10_precision, char output[]) /* Dump all the trigs to buffer[], CHUNK_SIZE at a time. */ trigs = buffer; - trig_cnt = 0; + n_trigs = 0; for (trigs_to_output = DIV_RND_UP (DBL_DIG * 2, 3) + 1 + (CHUNK_SIZE / 2); trigs_to_output > 0; trigs_to_output -= CHUNK_SIZE) @@ -814,12 +814,12 @@ format_trig_double (long double value, int base_10_precision, char output[]) /* Append the chunk, in base 30, to trigs[]. */ for (trigs_left = CHUNK_SIZE; chunk > 0 && trigs_left > 0;) { - trigs[trig_cnt + --trigs_left] = chunk % 30; + trigs[n_trigs + --trigs_left] = chunk % 30; chunk /= 30; } while (trigs_left > 0) - trigs[trig_cnt + --trigs_left] = 0; - trig_cnt += CHUNK_SIZE; + trigs[n_trigs + --trigs_left] = 0; + n_trigs += CHUNK_SIZE; /* Proceed to the next chunk. */ if (value == 0.) @@ -828,10 +828,10 @@ format_trig_double (long double value, int base_10_precision, char output[]) } /* Strip leading zeros. */ - while (trig_cnt > 1 && *trigs == 0) + while (n_trigs > 1 && *trigs == 0) { trigs++; - trig_cnt--; + n_trigs--; trig_places--; } @@ -842,30 +842,30 @@ format_trig_double (long double value, int base_10_precision, char output[]) if (base_10_precision > LDBL_DIG) base_10_precision = LDBL_DIG; base_30_precision = DIV_RND_UP (base_10_precision * 2, 3); - if (trig_cnt > base_30_precision) + if (n_trigs > base_30_precision) { if (should_round_up (trigs + base_30_precision, - trig_cnt - base_30_precision)) + n_trigs - base_30_precision)) { /* Try to round up. */ if (try_round_up (trigs, base_30_precision)) { /* Rounding up worked. */ - trig_cnt = base_30_precision; + n_trigs = base_30_precision; } else { /* Couldn't round up because we ran out of trigs to carry into. Do the carry here instead. */ *trigs = 1; - trig_cnt = 1; + n_trigs = 1; trig_places++; } } else { /* Round down. */ - trig_cnt = base_30_precision; + n_trigs = base_30_precision; } } else @@ -875,23 +875,23 @@ format_trig_double (long double value, int base_10_precision, char output[]) } /* Strip trailing zeros. */ - while (trig_cnt > 1 && trigs[trig_cnt - 1] == 0) - trig_cnt--; + while (n_trigs > 1 && trigs[n_trigs - 1] == 0) + n_trigs--; /* Write output. */ if (negative) *output++ = '-'; - if (trig_places >= -1 && trig_places < trig_cnt + 3) + if (trig_places >= -1 && trig_places < n_trigs + 3) { /* Use conventional notation. */ - format_trig_digits (output, trigs, trig_cnt, trig_places); + format_trig_digits (output, trigs, n_trigs, trig_places); } else { /* Use scientific notation. */ char *op; - op = format_trig_digits (output, trigs, trig_cnt, trig_cnt); - op = format_trig_int (trig_places - trig_cnt, true, op); + op = format_trig_digits (output, trigs, n_trigs, n_trigs); + op = format_trig_int (trig_places - n_trigs, true, op); } return; diff --git a/src/data/psql-reader.c b/src/data/psql-reader.c index a38c9e9030..ae56d18212 100644 --- a/src/data/psql-reader.c +++ b/src/data/psql-reader.c @@ -615,7 +615,7 @@ set_value (struct psql_reader *r) case INTERVALOID: case TIMESTAMPTZOID: case TIMETZOID: - if (i < r->vmapsize && var_get_dict_index(v) + 1 < dict_get_var_cnt (r->dict)) + if (i < r->vmapsize && var_get_dict_index(v) + 1 < dict_get_n_vars (r->dict)) { const struct variable *v1 = NULL; v1 = dict_get_var (r->dict, var_get_dict_index (v) + 1); diff --git a/src/data/short-names.c b/src/data/short-names.c index ea8df782b4..ff6b4ff773 100644 --- a/src/data/short-names.c +++ b/src/data/short-names.c @@ -89,18 +89,17 @@ assign_short_name (struct variable *v, size_t i, void short_names_assign (struct dictionary *d) { - size_t var_cnt = dict_get_var_cnt (d); + size_t n_vars = dict_get_n_vars (d); struct stringi_set short_names; - size_t i, j; stringi_set_init (&short_names); /* Clear short names that conflict with a variable name. */ - for (i = 0; i < var_cnt; i++) + for (size_t i = 0; i < n_vars; i++) { struct variable *v = dict_get_var (d, i); - int segment_cnt = sfm_width_to_segments (var_get_width (v)); - for (j = 0; j < segment_cnt; j++) + int n_segments = sfm_width_to_segments (var_get_width (v)); + for (size_t j = 0; j < n_segments; j++) { const char *name = var_get_short_name (v, j); if (name != NULL) @@ -114,7 +113,7 @@ short_names_assign (struct dictionary *d) /* Give variables whose names are short the corresponding short name. */ - for (i = 0; i < var_cnt; i++) + for (size_t i = 0; i < n_vars; i++) { struct variable *v = dict_get_var (d, i); const char *name = var_get_name (v); @@ -128,31 +127,31 @@ short_names_assign (struct dictionary *d) conflict, the claimant earlier in dictionary order wins. Then similarly for additional segments of very long strings. */ - for (i = 0; i < var_cnt; i++) + for (size_t i = 0; i < n_vars; i++) { struct variable *v = dict_get_var (d, i); claim_short_name (v, 0, &short_names); } - for (i = 0; i < var_cnt; i++) + for (size_t i = 0; i < n_vars; i++) { struct variable *v = dict_get_var (d, i); - int segment_cnt = sfm_width_to_segments (var_get_width (v)); - for (j = 1; j < segment_cnt; j++) + int n_segments = sfm_width_to_segments (var_get_width (v)); + for (size_t j = 1; j < n_segments; j++) claim_short_name (v, j, &short_names); } /* Assign short names to first segment of remaining variables, then similarly for additional segments. */ - for (i = 0; i < var_cnt; i++) + for (size_t i = 0; i < n_vars; i++) { struct variable *v = dict_get_var (d, i); assign_short_name (v, 0, &short_names); } - for (i = 0; i < var_cnt; i++) + for (size_t i = 0; i < n_vars; i++) { struct variable *v = dict_get_var (d, i); - int segment_cnt = sfm_width_to_segments (var_get_width (v)); - for (j = 1; j < segment_cnt; j++) + int n_segments = sfm_width_to_segments (var_get_width (v)); + for (size_t j = 1; j < n_segments; j++) assign_short_name (v, j, &short_names); } diff --git a/src/data/sys-file-private.c b/src/data/sys-file-private.c index 9114f54e2f..74b0208b93 100644 --- a/src/data/sys-file-private.c +++ b/src/data/sys-file-private.c @@ -191,32 +191,32 @@ sfm_segment_effective_offset (int width, int segment) user. The array is allocated with malloc and stored in *SFM_VARS, - and its number of elements is stored in *SFM_VAR_CNT. The + and its number of elements is stored in *SFM_N_VARS. The caller is responsible for freeing it when it is no longer needed. */ int sfm_dictionary_to_sfm_vars (const struct dictionary *dict, - struct sfm_var **sfm_vars, size_t *sfm_var_cnt) + struct sfm_var **sfm_vars, size_t *sfm_n_vars) { - size_t var_cnt = dict_get_var_cnt (dict); - size_t segment_cnt; + size_t n_vars = dict_get_n_vars (dict); + size_t n_segments; size_t i; /* Estimate the number of sfm_vars that will be needed. We might not need all of these, because very long string variables can have segments that are all padding, which do not need sfm_vars of their own. */ - segment_cnt = 0; - for (i = 0; i < var_cnt; i++) + n_segments = 0; + for (i = 0; i < n_vars; i++) { const struct variable *v = dict_get_var (dict, i); - segment_cnt += sfm_width_to_segments (var_get_width (v)); + n_segments += sfm_width_to_segments (var_get_width (v)); } /* Compose the sfm_vars. */ - *sfm_vars = xnmalloc (segment_cnt, sizeof **sfm_vars); - *sfm_var_cnt = 0; - for (i = 0; i < var_cnt; i++) + *sfm_vars = xnmalloc (n_segments, sizeof **sfm_vars); + *sfm_n_vars = 0; + for (i = 0; i < n_vars; i++) { const struct variable *dv = dict_get_var (dict, i); int width = var_get_width (dv); @@ -229,7 +229,7 @@ sfm_dictionary_to_sfm_vars (const struct dictionary *dict, struct sfm_var *sv; if (used_bytes != 0) { - sv = &(*sfm_vars)[(*sfm_var_cnt)++]; + sv = &(*sfm_vars)[(*sfm_n_vars)++]; sv->var_width = width; sv->segment_width = width == 0 ? 0 : used_bytes; sv->case_index = var_get_case_index (dv); @@ -240,14 +240,14 @@ sfm_dictionary_to_sfm_vars (const struct dictionary *dict, { /* Segment is all padding. Just add it to the previous segment. */ - sv = &(*sfm_vars)[*sfm_var_cnt - 1]; + sv = &(*sfm_vars)[*sfm_n_vars - 1]; sv->padding += padding; } assert ((sv->segment_width + sv->padding) % 8 == 0); } } - return segment_cnt; + return n_segments; } /* Given the name of an encoding, returns the codepage number to use in the diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 109b0dd16e..7684acbc57 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -200,8 +200,8 @@ struct sfm_reader enum integer_format integer_format; /* On-disk integer format. */ enum float_format float_format; /* On-disk floating point format. */ struct sfm_var *sfm_vars; /* Variables. */ - size_t sfm_var_cnt; /* Number of variables. */ - int case_cnt; /* Number of cases */ + size_t sfm_n_vars; /* Number of variables. */ + int n_cases; /* Number of cases */ const char *encoding; /* String encoding. */ bool written_by_readstat; /* From https://github.com/WizardMac/ReadStat? */ @@ -331,7 +331,7 @@ static bool parse_variable_records (struct sfm_reader *, struct dictionary *, struct sfm_var_record *, size_t n); static void parse_format_spec (struct sfm_reader *, off_t pos, unsigned int format, enum which_format, - struct variable *, int *format_warning_cnt); + struct variable *, int *format_n_warnings); static void parse_document (struct dictionary *, struct sfm_document_record *); static void parse_display_parameters (struct sfm_reader *, const struct sfm_extension_record *, @@ -856,7 +856,7 @@ sfm_decode (struct any_reader *r_, const char *encoding, sfm_read_case to use. We cannot use the `struct variable's from the dictionary we created, because the caller owns the dictionary and may destroy or modify its variables. */ - sfm_dictionary_to_sfm_vars (dict, &r->sfm_vars, &r->sfm_var_cnt); + sfm_dictionary_to_sfm_vars (dict, &r->sfm_vars, &r->sfm_n_vars); pool_register (r->pool, free, r->sfm_vars); r->proto = caseproto_ref_pool (dict_get_proto (dict), r->pool); @@ -868,9 +868,8 @@ sfm_decode (struct any_reader *r_, const char *encoding, } return casereader_create_sequential - (NULL, r->proto, - r->case_cnt == -1 ? CASENUMBER_MAX: r->case_cnt, - &sys_file_casereader_class, r); + (NULL, r->proto, r->n_cases == -1 ? CASENUMBER_MAX : r->n_cases, + &sys_file_casereader_class, r); error: sfm_close (r_); @@ -1016,10 +1015,10 @@ read_header (struct sfm_reader *r, struct any_read_info *info, if (!read_int (r, &header->weight_idx)) return false; - if (!read_int (r, &r->case_cnt)) + if (!read_int (r, &r->n_cases)) return false; - if (r->case_cnt > INT_MAX / 2) - r->case_cnt = -1; + if (r->n_cases > INT_MAX / 2) + r->n_cases = -1; /* Identify floating-point format and obtain compression bias. */ if (!read_bytes (r, raw_bias, sizeof raw_bias)) @@ -1058,7 +1057,7 @@ read_header (struct sfm_reader *r, struct any_read_info *info, info->integer_format = r->integer_format; info->float_format = r->float_format; info->compression = r->compression; - info->case_cnt = r->case_cnt; + info->n_cases = r->n_cases; return true; } @@ -1918,7 +1917,7 @@ parse_display_parameters (struct sfm_reader *r, size_t ofs; size_t i; - n_vars = dict_get_var_cnt (dict); + n_vars = dict_get_n_vars (dict); if (record->count == 3 * n_vars) includes_width = true; else if (record->count == 2 * n_vars) @@ -1993,7 +1992,7 @@ rename_var_and_save_short_names (struct sfm_reader *r, off_t pos, /* Renaming a variable may clear its short names, but we want to retain them, so we save them and re-set them afterward. */ - n_short_names = var_get_short_name_cnt (var); + n_short_names = var_get_n_short_names (var); short_names = xnmalloc (n_short_names, sizeof *short_names); for (i = 0; i < n_short_names; i++) { @@ -2031,7 +2030,7 @@ parse_long_var_name_map (struct sfm_reader *r, converted to lowercase, as the long variable names. */ size_t i; - for (i = 0; i < dict_get_var_cnt (dict); i++) + for (i = 0; i < dict_get_n_vars (dict); i++) { struct variable *var = dict_get_var (dict, i); char *new_name; @@ -2083,7 +2082,6 @@ parse_long_string_map (struct sfm_reader *r, { size_t idx = var_get_dict_index (var); long int length; - int segment_cnt; int i; /* Get length. */ @@ -2098,8 +2096,8 @@ parse_long_string_map (struct sfm_reader *r, } /* Check segments. */ - segment_cnt = sfm_width_to_segments (length); - if (segment_cnt == 1) + int n_segments = sfm_width_to_segments (length); + if (n_segments == 1) { sys_warn (r, record->pos, _("%s listed in very long string record with width %s, " @@ -2107,7 +2105,7 @@ parse_long_string_map (struct sfm_reader *r, var_get_name (var), length_s); continue; } - if (idx + segment_cnt > dict_get_var_cnt (dict)) + if (idx + n_segments > dict_get_n_vars (dict)) { sys_error (r, record->pos, _("Very long string %s overflows dictionary."), @@ -2117,7 +2115,7 @@ parse_long_string_map (struct sfm_reader *r, /* Get the short names from the segments and check their lengths. */ - for (i = 0; i < segment_cnt; i++) + for (i = 0; i < n_segments; i++) { struct variable *seg = dict_get_var (dict, idx + i); int alloc_width = sfm_segment_alloc_width (length, i); @@ -2134,7 +2132,7 @@ parse_long_string_map (struct sfm_reader *r, return false; } } - dict_delete_consecutive_vars (dict, idx + 1, segment_cnt - 1); + dict_delete_consecutive_vars (dict, idx + 1, n_segments - 1); var_set_width (var, length); } close_text_record (r, text); @@ -2427,7 +2425,7 @@ assign_variable_roles (struct sfm_reader *r, struct dictionary *dict) size_t n_warnings = 0; size_t i; - for (i = 0; i < dict_get_var_cnt (dict); i++) + for (i = 0; i < dict_get_n_vars (dict); i++) { struct variable *var = dict_get_var (dict, i); struct attrset *attrs = var_get_attributes (var); @@ -2724,12 +2722,12 @@ sys_file_casereader_read (struct casereader *reader, void *r_) int retval; int i; - if (r->error || !r->sfm_var_cnt) + if (r->error || !r->sfm_n_vars) return NULL; c = case_create (r->proto); - for (i = 0; i < r->sfm_var_cnt; i++) + for (i = 0; i < r->sfm_n_vars; i++) { struct sfm_var *sv = &r->sfm_vars[i]; union value *v = case_data_rw_idx (c, sv->case_index); @@ -2755,7 +2753,7 @@ sys_file_casereader_read (struct casereader *reader, void *r_) eof: if (i != 0) partial_record (r); - if (r->case_cnt != -1) + if (r->n_cases != -1) read_error (reader, r); case_unref (c); return NULL; @@ -3284,11 +3282,11 @@ sys_error (struct sfm_reader *r, off_t offset, const char *format, ...) an error. */ static inline int read_bytes_internal (struct sfm_reader *r, bool eof_is_ok, - void *buf, size_t byte_cnt) + void *buf, size_t n_bytes) { - size_t bytes_read = fread (buf, 1, byte_cnt, r->file); + size_t bytes_read = fread (buf, 1, n_bytes, r->file); r->pos += bytes_read; - if (bytes_read == byte_cnt) + if (bytes_read == n_bytes) return 1; else if (ferror (r->file)) { @@ -3308,9 +3306,9 @@ read_bytes_internal (struct sfm_reader *r, bool eof_is_ok, Returns true if successful. Returns false upon I/O error or if end-of-file is encountered. */ static bool -read_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) +read_bytes (struct sfm_reader *r, void *buf, size_t n_bytes) { - return read_bytes_internal (r, false, buf, byte_cnt) == 1; + return read_bytes_internal (r, false, buf, n_bytes) == 1; } /* Reads BYTE_CNT bytes into BUF. @@ -3318,9 +3316,9 @@ read_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) Returns 0 if an immediate end-of-file is encountered. Returns -1 if an I/O error or a partial read occurs. */ static int -try_read_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) +try_read_bytes (struct sfm_reader *r, void *buf, size_t n_bytes) { - return read_bytes_internal (r, true, buf, byte_cnt); + return read_bytes_internal (r, true, buf, n_bytes); } /* Reads a 32-bit signed integer from R and stores its value in host format in @@ -3711,11 +3709,11 @@ close_zstream (struct sfm_reader *r) } static int -read_bytes_zlib (struct sfm_reader *r, void *buf_, size_t byte_cnt) +read_bytes_zlib (struct sfm_reader *r, void *buf_, size_t n_bytes) { uint8_t *buf = buf_; - if (byte_cnt == 0) + if (n_bytes == 0) return 1; for (;;) @@ -3725,13 +3723,13 @@ read_bytes_zlib (struct sfm_reader *r, void *buf_, size_t byte_cnt) /* Use already inflated data if there is any. */ if (r->zout_pos < r->zout_end) { - unsigned int n = MIN (byte_cnt, r->zout_end - r->zout_pos); + unsigned int n = MIN (n_bytes, r->zout_end - r->zout_pos); memcpy (buf, &r->zout_buf[r->zout_pos], n); r->zout_pos += n; - byte_cnt -= n; + n_bytes -= n; buf += n; - if (byte_cnt == 0) + if (n_bytes == 0) return 1; } @@ -3778,13 +3776,13 @@ read_bytes_zlib (struct sfm_reader *r, void *buf_, size_t byte_cnt) } static int -read_compressed_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) +read_compressed_bytes (struct sfm_reader *r, void *buf, size_t n_bytes) { if (r->compression == ANY_COMP_SIMPLE) - return read_bytes (r, buf, byte_cnt); + return read_bytes (r, buf, n_bytes); else { - int retval = read_bytes_zlib (r, buf, byte_cnt); + int retval = read_bytes_zlib (r, buf, n_bytes); if (retval == 0) sys_error (r, r->pos, _("Unexpected end of ZLIB compressed data.")); return retval; @@ -3792,12 +3790,12 @@ read_compressed_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) } static int -try_read_compressed_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) +try_read_compressed_bytes (struct sfm_reader *r, void *buf, size_t n_bytes) { if (r->compression == ANY_COMP_SIMPLE) - return try_read_bytes (r, buf, byte_cnt); + return try_read_bytes (r, buf, n_bytes); else - return read_bytes_zlib (r, buf, byte_cnt); + return read_bytes_zlib (r, buf, n_bytes); } /* Reads a 64-bit floating-point number from R and returns its diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index 54282a95f3..c94d13d859 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -73,7 +73,7 @@ struct sfm_writer struct replace_file *rf; /* Ticket for replacing output file. */ enum any_compression compression; - casenumber case_cnt; /* Number of cases written so far. */ + casenumber n_cases; /* Number of cases written so far. */ uint8_t space; /* ' ' in the file's character encoding. */ /* Simple compression buffering. @@ -97,8 +97,8 @@ struct sfm_writer /* Variables. */ struct sfm_var *sfm_vars; /* Variables. */ - size_t sfm_var_cnt; /* Number of variables. */ - size_t segment_cnt; /* Number of variables including extra segments + size_t sfm_n_vars; /* Number of variables. */ + size_t n_segments; /* Number of variables including extra segments for long string variables. */ }; @@ -226,7 +226,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, && is_encoding_ebcdic_compatible (dict_get_encoding (d))) w->compression = ANY_COMP_SIMPLE; - w->case_cnt = 0; + w->n_cases = 0; w->n_opcodes = w->n_elements = 0; memset (w->cbuf[0], 0, 8); @@ -235,8 +235,7 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, data. Also count the number of segments. Very long strings occupy multiple segments, otherwise each variable only takes one segment. */ - w->segment_cnt = sfm_dictionary_to_sfm_vars (d, &w->sfm_vars, - &w->sfm_var_cnt); + w->n_segments = sfm_dictionary_to_sfm_vars (d, &w->sfm_vars, &w->sfm_n_vars); /* Open file handle as an exclusive writer. */ /* TRANSLATORS: this fragment will be interpolated into @@ -265,12 +264,12 @@ sfm_open_writer (struct file_handle *fh, struct dictionary *d, /* Write basic variable info. */ short_names_assign (d); - for (i = 0; i < dict_get_var_cnt (d); i++) + for (i = 0; i < dict_get_n_vars (d); i++) write_variable (w, dict_get_var (d, i)); write_value_labels (w, d); - if (dict_get_document_line_cnt (d) > 0) + if (dict_get_document_n_lines (d) > 0) write_documents (w, d); write_integer_info_record (w, d); @@ -348,7 +347,7 @@ calc_oct_idx (const struct dictionary *d, struct variable *target_var) int i; oct_idx = 0; - for (i = 0; i < dict_get_var_cnt (d); i++) + for (i = 0; i < dict_get_n_vars (d); i++) { struct variable *var = dict_get_var (d, i); if (var == target_var) @@ -486,7 +485,7 @@ static void write_variable (struct sfm_writer *w, const struct variable *v) { int width = var_get_width (v); - int segment_cnt = sfm_width_to_segments (width); + int n_segments = sfm_width_to_segments (width); int seg0_width = sfm_segment_alloc_width (width, 0); const char *encoding = var_get_encoding (v); int i; @@ -556,7 +555,7 @@ write_variable (struct sfm_writer *w, const struct variable *v) write_variable_continuation_records (w, seg0_width); /* Write additional segments for very long string variables. */ - for (i = 1; i < segment_cnt; i++) + for (i = 1; i < n_segments; i++) { int seg_width = sfm_segment_alloc_width (width, i); struct fmt_spec fmt = fmt_for_output (FMT_A, MAX (seg_width, 1), 0); @@ -599,7 +598,7 @@ write_value_labels (struct sfm_writer *w, const struct dictionary *d) hmap_init (&same_sets); idx = 0; - for (i = 0; i < dict_get_var_cnt (d); i++) + for (i = 0; i < dict_get_n_vars (d); i++) { struct variable *v = dict_get_var (d, i); @@ -782,7 +781,7 @@ static void write_variable_attributes (struct sfm_writer *w, const struct dictionary *d) { struct string s = DS_EMPTY_INITIALIZER; - size_t n_vars = dict_get_var_cnt (d); + size_t n_vars = dict_get_n_vars (d); size_t n_attrsets = 0; size_t i; @@ -898,13 +897,13 @@ write_variable_display_parameters (struct sfm_writer *w, write_int (w, 7); /* Record type. */ write_int (w, 11); /* Record subtype. */ write_int (w, 4); /* Data item (int32) size. */ - write_int (w, w->segment_cnt * 3); /* Number of data items. */ + write_int (w, w->n_segments * 3); /* Number of data items. */ - for (i = 0; i < dict_get_var_cnt (dict); ++i) + for (i = 0; i < dict_get_n_vars (dict); ++i) { struct variable *v = dict_get_var (dict, i); int width = var_get_width (v); - int segment_cnt = sfm_width_to_segments (width); + int n_segments = sfm_width_to_segments (width); int measure = (var_get_measure (v) == MEASURE_NOMINAL ? 1 : var_get_measure (v) == MEASURE_ORDINAL ? 2 : 3); @@ -913,7 +912,7 @@ write_variable_display_parameters (struct sfm_writer *w, : 2); int i; - for (i = 0; i < segment_cnt; i++) + for (i = 0; i < n_segments; i++) { int width_left = width - sfm_segment_effective_offset (width, i); write_int (w, measure); @@ -933,7 +932,7 @@ write_vls_length_table (struct sfm_writer *w, int i; ds_init_empty (&map); - for (i = 0; i < dict_get_var_cnt (dict); ++i) + for (i = 0; i < dict_get_n_vars (dict); ++i) { const struct variable *v = dict_get_var (dict, i); if (sfm_width_to_segments (var_get_width (v)) > 1) @@ -950,7 +949,7 @@ write_long_string_value_labels (struct sfm_writer *w, const struct dictionary *dict) { const char *encoding = dict_get_encoding (dict); - size_t n_vars = dict_get_var_cnt (dict); + size_t n_vars = dict_get_n_vars (dict); size_t size, i; /* Figure out the size in advance. */ @@ -1025,7 +1024,7 @@ write_long_string_missing_values (struct sfm_writer *w, const struct dictionary *dict) { const char *encoding = dict_get_encoding (dict); - size_t n_vars = dict_get_var_cnt (dict); + size_t n_vars = dict_get_n_vars (dict); size_t size, i; /* Figure out the size in advance. */ @@ -1106,7 +1105,7 @@ write_longvar_table (struct sfm_writer *w, const struct dictionary *dict) size_t i; ds_init_empty (&map); - for (i = 0; i < dict_get_var_cnt (dict); i++) + for (i = 0; i < dict_get_n_vars (dict); i++) { struct variable *v = dict_get_var (dict, i); if (i) @@ -1204,7 +1203,7 @@ sys_file_casewriter_write (struct casewriter *writer, void *w_, return; } - w->case_cnt++; + w->n_cases++; if (w->compression == ANY_COMP_NONE) write_case_uncompressed (w, c); @@ -1257,9 +1256,9 @@ close_writer (struct sfm_writer *w) /* Seek back to the beginning and update the number of cases. This is just a courtesy to later readers, so there's no need to check return values or report errors. */ - if (ok && w->case_cnt <= INT32_MAX && !fseeko (w->file, 80, SEEK_SET)) + if (ok && w->n_cases <= INT32_MAX && !fseeko (w->file, 80, SEEK_SET)) { - write_int (w, w->case_cnt); + write_int (w, w->n_cases); clearerr (w->file); } @@ -1299,7 +1298,7 @@ write_case_uncompressed (struct sfm_writer *w, const struct ccase *c) { size_t i; - for (i = 0; i < w->sfm_var_cnt; i++) + for (i = 0; i < w->sfm_n_vars; i++) { struct sfm_var *v = &w->sfm_vars[i]; @@ -1320,7 +1319,7 @@ write_case_compressed (struct sfm_writer *w, const struct ccase *c) { size_t i; - for (i = 0; i < w->sfm_var_cnt; i++) + for (i = 0; i < w->sfm_n_vars; i++) { struct sfm_var *v = &w->sfm_vars[i]; diff --git a/src/data/transformations.c b/src/data/transformations.c index c0fc35c2c8..cd5c6a188c 100644 --- a/src/data/transformations.c +++ b/src/data/transformations.c @@ -42,8 +42,8 @@ struct transformation struct trns_chain { struct transformation *trns; /* Array of transformations. */ - size_t trns_cnt; /* Number of transformations. */ - size_t trns_cap; /* Allocated capacity. */ + size_t n_trns; /* Number of transformations. */ + size_t allocated_trns; /* Allocated capacity. */ bool finalized; /* Finalize functions called? */ }; @@ -53,8 +53,8 @@ trns_chain_create (void) { struct trns_chain *chain = xmalloc (sizeof *chain); chain->trns = NULL; - chain->trns_cnt = 0; - chain->trns_cap = 0; + chain->n_trns = 0; + chain->allocated_trns = 0; chain->finalized = false; return chain; } @@ -69,7 +69,7 @@ trns_chain_finalize (struct trns_chain *chain) size_t i; chain->finalized = true; - for (i = 0; i < chain->trns_cnt; i++) + for (i = 0; i < chain->n_trns; i++) { struct transformation *trns = &chain->trns[i]; trns_finalize_func *finalize = trns->finalize; @@ -95,7 +95,7 @@ trns_chain_destroy (struct trns_chain *chain) /* Needed to ensure that the control stack gets cleared. */ trns_chain_finalize (chain); - for (i = 0; i < chain->trns_cnt; i++) + for (i = 0; i < chain->n_trns; i++) { struct transformation *trns = &chain->trns[i]; if (trns->free != NULL) @@ -113,7 +113,7 @@ trns_chain_destroy (struct trns_chain *chain) bool trns_chain_is_empty (const struct trns_chain *chain) { - return chain->trns_cnt == 0; + return chain->n_trns == 0; } /* Adds a transformation to CHAIN with finalize function @@ -128,11 +128,11 @@ trns_chain_append (struct trns_chain *chain, trns_finalize_func *finalize, chain->finalized = false; - if (chain->trns_cnt == chain->trns_cap) - chain->trns = x2nrealloc (chain->trns, &chain->trns_cap, + if (chain->n_trns == chain->allocated_trns) + chain->trns = x2nrealloc (chain->trns, &chain->allocated_trns, sizeof *chain->trns); - trns = &chain->trns[chain->trns_cnt++]; + trns = &chain->trns[chain->n_trns++]; trns->idx_ofs = 0; trns->finalize = finalize; trns->execute = execute; @@ -151,22 +151,22 @@ trns_chain_splice (struct trns_chain *dst, struct trns_chain *src) assert (dst->finalized); assert (src->finalized); - if (dst->trns_cnt + src->trns_cnt > dst->trns_cap) + if (dst->n_trns + src->n_trns > dst->allocated_trns) { - dst->trns_cap = dst->trns_cnt + src->trns_cnt; - dst->trns = xnrealloc (dst->trns, dst->trns_cap, sizeof *dst->trns); + dst->allocated_trns = dst->n_trns + src->n_trns; + dst->trns = xnrealloc (dst->trns, dst->allocated_trns, sizeof *dst->trns); } - for (i = 0; i < src->trns_cnt; i++) + for (i = 0; i < src->n_trns; i++) { - struct transformation *d = &dst->trns[i + dst->trns_cnt]; + struct transformation *d = &dst->trns[i + dst->n_trns]; const struct transformation *s = &src->trns[i]; *d = *s; - d->idx_ofs += src->trns_cnt; + d->idx_ofs += src->n_trns; } - dst->trns_cnt += src->trns_cnt; + dst->n_trns += src->n_trns; - src->trns_cnt = 0; + src->n_trns = 0; trns_chain_destroy (src); } @@ -175,7 +175,7 @@ trns_chain_splice (struct trns_chain *dst, struct trns_chain *src) size_t trns_chain_next (struct trns_chain *chain) { - return chain->trns_cnt; + return chain->n_trns; } /* Executes the given CHAIN of transformations on *C, @@ -191,7 +191,7 @@ trns_chain_execute (const struct trns_chain *chain, enum trns_result start, size_t i; assert (chain->finalized); - for (i = start < 0 ? 0 : start; i < chain->trns_cnt;) + for (i = start < 0 ? 0 : start; i < chain->n_trns;) { struct transformation *trns = &chain->trns[i]; int retval = trns->execute (trns->aux, c, case_nr); diff --git a/src/data/variable.c b/src/data/variable.c index 3f32fa5d02..5115d4a6e4 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -109,7 +109,7 @@ struct variable /* Used only for system and portable file input and output. See short-names.h. */ char **short_names; - size_t short_name_cnt; + size_t n_short_names; /* Custom attributes. */ struct attrset attributes; @@ -1122,9 +1122,9 @@ var_must_leave (const struct variable *v) all if it hasn't been saved to or read from a system or portable file. */ size_t -var_get_short_name_cnt (const struct variable *var) +var_get_n_short_names (const struct variable *var) { - return var->short_name_cnt; + return var->n_short_names; } /* Returns VAR's short name with the given IDX, if it has one @@ -1134,7 +1134,7 @@ var_get_short_name_cnt (const struct variable *var) const char * var_get_short_name (const struct variable *var, size_t idx) { - return idx < var->short_name_cnt ? var->short_names[idx] : NULL; + return idx < var->n_short_names ? var->short_names[idx] : NULL; } /* Sets VAR's short name with the given IDX to the UTF-8 string SHORT_NAME. @@ -1149,7 +1149,7 @@ var_set_short_name (struct variable *var, size_t idx, const char *short_name) struct variable *ov = var_clone (var); /* Clear old short name numbered IDX, if any. */ - if (idx < var->short_name_cnt) + if (idx < var->n_short_names) { free (var->short_names[idx]); var->short_names[idx] = NULL; @@ -1158,14 +1158,14 @@ var_set_short_name (struct variable *var, size_t idx, const char *short_name) /* Install new short name for IDX. */ if (short_name != NULL) { - if (idx >= var->short_name_cnt) + if (idx >= var->n_short_names) { - size_t old_cnt = var->short_name_cnt; + size_t n_old = var->n_short_names; size_t i; - var->short_name_cnt = MAX (idx * 2, 1); - var->short_names = xnrealloc (var->short_names, var->short_name_cnt, + var->n_short_names = MAX (idx * 2, 1); + var->short_names = xnrealloc (var->short_names, var->n_short_names, sizeof *var->short_names); - for (i = old_cnt; i < var->short_name_cnt; i++) + for (i = n_old; i < var->n_short_names; i++) var->short_names[i] = NULL; } var->short_names[idx] = utf8_to_upper (short_name); @@ -1180,11 +1180,11 @@ var_clear_short_names (struct variable *v) { size_t i; - for (i = 0; i < v->short_name_cnt; i++) + for (i = 0; i < v->n_short_names; i++) free (v->short_names[i]); free (v->short_names); v->short_names = NULL; - v->short_name_cnt = 0; + v->n_short_names = 0; } /* Relationship with dictionary. */ diff --git a/src/data/variable.h b/src/data/variable.h index a17470f26b..d5056f3165 100644 --- a/src/data/variable.h +++ b/src/data/variable.h @@ -191,7 +191,7 @@ void var_set_leave (struct variable *, bool leave); bool var_must_leave (const struct variable *); /* Short names. */ -size_t var_get_short_name_cnt (const struct variable *); +size_t var_get_n_short_names (const struct variable *); const char *var_get_short_name (const struct variable *, size_t idx); void var_set_short_name (struct variable *, size_t, const char *); void var_clear_short_names (struct variable *); diff --git a/src/data/vector.c b/src/data/vector.c index 7c8ec4178d..c88d236df6 100644 --- a/src/data/vector.c +++ b/src/data/vector.c @@ -33,7 +33,7 @@ struct vector { char *name; /* Name. */ struct variable **vars; /* Set of variables. */ - size_t var_cnt; /* Number of variables. */ + size_t n_vars; /* Number of variables. */ }; /* Checks that all the variables in VECTOR have consistent @@ -44,24 +44,24 @@ check_widths (const struct vector *vector) int width = var_get_width (vector->vars[0]); size_t i; - for (i = 1; i < vector->var_cnt; i++) + for (i = 1; i < vector->n_vars; i++) assert (width == var_get_width (vector->vars[i])); } /* Creates and returns a new vector with the given UTF-8 encoded NAME - that contains the VAR_CNT variables in VARS. + that contains the N_VARS variables in VARS. All variables in VARS must have the same type and width. */ struct vector * -vector_create (const char *name, struct variable **vars, size_t var_cnt) +vector_create (const char *name, struct variable **vars, size_t n_vars) { struct vector *vector = xmalloc (sizeof *vector); - assert (var_cnt > 0); + assert (n_vars > 0); assert (id_is_plausible (name, false)); vector->name = xstrdup (name); - vector->vars = xmemdup (vars, var_cnt * sizeof *vector->vars); - vector->var_cnt = var_cnt; + vector->vars = xmemdup (vars, n_vars * sizeof *vector->vars); + vector->n_vars = n_vars; check_widths (vector); return vector; @@ -81,9 +81,9 @@ vector_clone (const struct vector *old, size_t i; new->name = xstrdup (old->name); - new->vars = xnmalloc (old->var_cnt, sizeof *new->vars); - new->var_cnt = old->var_cnt; - for (i = 0; i < new->var_cnt; i++) + new->vars = xnmalloc (old->n_vars, sizeof *new->vars); + new->n_vars = old->n_vars; + for (i = 0; i < new->n_vars; i++) { assert (dict_contains_var (old_dict, old->vars[i])); new->vars[i] = dict_get_var (new_dict, @@ -120,15 +120,15 @@ enum val_type vector_get_type (const struct vector *vector) struct variable * vector_get_var (const struct vector *vector, size_t index) { - assert (index < vector->var_cnt); + assert (index < vector->n_vars); return vector->vars[index]; } /* Returns the number of variables in VECTOR. */ size_t -vector_get_var_cnt (const struct vector *vector) +vector_get_n_vars (const struct vector *vector) { - return vector->var_cnt; + return vector->n_vars; } /* Compares two pointers to vectors represented by A and B and diff --git a/src/data/vector.h b/src/data/vector.h index f8fe088849..b586421c82 100644 --- a/src/data/vector.h +++ b/src/data/vector.h @@ -23,7 +23,7 @@ struct dictionary; struct vector *vector_create (const char *name, - struct variable **var, size_t var_cnt); + struct variable **var, size_t n_vars); struct vector *vector_clone (const struct vector *old, const struct dictionary *old_dict, const struct dictionary *new_dict); @@ -32,7 +32,7 @@ void vector_destroy (struct vector *); const char *vector_get_name (const struct vector *); enum val_type vector_get_type (const struct vector *); struct variable *vector_get_var (const struct vector *, size_t idx); -size_t vector_get_var_cnt (const struct vector *); +size_t vector_get_n_vars (const struct vector *); bool vector_is_valid_name (const char *name, bool issue_error); diff --git a/src/language/command.c b/src/language/command.c index 068ae0ea63..924b221b22 100644 --- a/src/language/command.c +++ b/src/language/command.c @@ -123,7 +123,7 @@ static const struct command commands[] = #undef DEF_CMD #undef UNIMPL_CMD -static const size_t command_cnt = sizeof commands / sizeof *commands; +static const size_t n_commands = sizeof commands / sizeof *commands; static bool in_correct_state (const struct command *, enum cmd_state); static bool report_state_mismatch (const struct command *, enum cmd_state); @@ -162,7 +162,7 @@ cmd_parse (struct lexer *lexer, struct dataset *ds) const struct dictionary *dict = dataset_dict (ds); return cmd_parse_in_state (lexer, ds, dataset_has_source (ds) && - dict_get_var_cnt (dict) > 0 ? + dict_get_n_vars (dict) > 0 ? CMD_STATE_DATA : CMD_STATE_INITIAL); } @@ -262,7 +262,7 @@ find_best_match (struct substring s, const struct command **matchp) int missing_words; command_matcher_init (&cm, s); - for (cmd = commands; cmd < &commands[command_cnt]; cmd++) + for (cmd = commands; cmd < &commands[n_commands]; cmd++) command_matcher_add (&cm, ss_cstr (cmd->name), CONST_CAST (void *, cmd)); *matchp = command_matcher_get_match (&cm); @@ -471,7 +471,7 @@ cmd_complete (const char *prefix, const struct command **cmd) if (*cmd == NULL) *cmd = commands; - for (; *cmd < commands + command_cnt; (*cmd)++) + for (; *cmd < commands + n_commands; (*cmd)++) if (!memcasecmp ((*cmd)->name, prefix, strlen (prefix)) && (!((*cmd)->flags & F_TESTING) || settings_get_testing_mode ()) && (!((*cmd)->flags & F_ENHANCED) || settings_get_syntax () == ENHANCED) diff --git a/src/language/control/do-if.c b/src/language/control/do-if.c index ccda670658..b361fba920 100644 --- a/src/language/control/do-if.c +++ b/src/language/control/do-if.c @@ -75,7 +75,7 @@ struct do_if_trns { struct dataset *ds; /* The dataset */ struct clause *clauses; /* Clauses. */ - size_t clause_cnt; /* Number of clauses. */ + size_t n_clauses; /* Number of clauses. */ int past_END_IF_index; /* Transformation just past last clause. */ }; @@ -99,7 +99,7 @@ cmd_do_if (struct lexer *lexer, struct dataset *ds) { struct do_if_trns *do_if = xmalloc (sizeof *do_if); do_if->clauses = NULL; - do_if->clause_cnt = 0; + do_if->n_clauses = 0; do_if->ds = ds; ctl_stack_push (&do_if_class, do_if); @@ -189,8 +189,8 @@ must_not_have_else (struct do_if_trns *do_if) static bool has_else (struct do_if_trns *do_if) { - return (do_if->clause_cnt != 0 - && do_if->clauses[do_if->clause_cnt - 1].condition == NULL); + return (do_if->n_clauses != 0 + && do_if->clauses[do_if->n_clauses - 1].condition == NULL); } /* Parses a DO IF or ELSE IF expression and appends the @@ -218,12 +218,12 @@ add_clause (struct do_if_trns *do_if, struct expression *condition) { struct clause *clause; - if (do_if->clause_cnt > 0) + if (do_if->n_clauses > 0) add_transformation (do_if->ds, break_trns_proc, NULL, do_if); do_if->clauses = xnrealloc (do_if->clauses, - do_if->clause_cnt + 1, sizeof *do_if->clauses); - clause = &do_if->clauses[do_if->clause_cnt++]; + do_if->n_clauses + 1, sizeof *do_if->clauses); + clause = &do_if->clauses[do_if->n_clauses++]; clause->condition = condition; clause->target_index = next_transformation (do_if->ds); } @@ -248,7 +248,7 @@ do_if_trns_proc (void *do_if_, struct ccase **c, casenumber case_num UNUSED) struct do_if_trns *do_if = do_if_; struct clause *clause; - for (clause = do_if->clauses; clause < do_if->clauses + do_if->clause_cnt; + for (clause = do_if->clauses; clause < do_if->clauses + do_if->n_clauses; clause++) { if (clause->condition != NULL) @@ -272,7 +272,7 @@ do_if_trns_free (void *do_if_) struct do_if_trns *do_if = do_if_; struct clause *clause; - for (clause = do_if->clauses; clause < do_if->clauses + do_if->clause_cnt; + for (clause = do_if->clauses; clause < do_if->clauses + do_if->n_clauses; clause++) expr_free (clause->condition); free (do_if->clauses); diff --git a/src/language/data-io/combine-files.c b/src/language/data-io/combine-files.c index c51f04aaa9..490a984a7d 100644 --- a/src/language/data-io/combine-files.c +++ b/src/language/data-io/combine-files.c @@ -414,11 +414,11 @@ combine_files (enum comb_command_type command, for (i = 0; i < proc.n_files; i++) { struct comb_file *file = &proc.files[i]; - size_t src_var_cnt = dict_get_var_cnt (file->dict); + size_t src_n_vars = dict_get_n_vars (file->dict); size_t j; - file->mv = xnmalloc (src_var_cnt, sizeof *file->mv); - for (j = 0; j < src_var_cnt; j++) + file->mv = xnmalloc (src_n_vars, sizeof *file->mv); + for (j = 0; j < src_n_vars; j++) { struct variable *src_var = dict_get_var (file->dict, j); struct variable *dst_var = dict_lookup_var (proc.dict, @@ -543,7 +543,7 @@ merge_dictionary (struct dictionary *const m, struct comb_file *f) } } - for (i = 0; i < dict_get_var_cnt (d); i++) + for (i = 0; i < dict_get_n_vars (d); i++) { struct variable *dv = dict_get_var (d, i); struct variable *mv = dict_lookup_var (m, var_get_name (dv)); @@ -821,7 +821,7 @@ scan_table (struct comb_file *file, union value by[]) static struct ccase * create_output_case (const struct comb_proc *proc) { - size_t n_vars = dict_get_var_cnt (proc->dict); + size_t n_vars = dict_get_n_vars (proc->dict); struct ccase *output; size_t i; diff --git a/src/language/data-io/data-list.c b/src/language/data-io/data-list.c index a6ed956302..02cabd8cde 100644 --- a/src/language/data-io/data-list.c +++ b/src/language/data-io/data-list.c @@ -331,21 +331,21 @@ parse_fixed (struct lexer *lexer, struct dictionary *dict, while (lex_token (lexer) != T_ENDCMD) { char **names; - size_t name_cnt, name_idx; + size_t n_names, name_idx; struct fmt_spec *formats, *f; - size_t format_cnt; + size_t n_formats; /* Parse everything. */ if (!parse_record_placement (lexer, &record, &column) || !parse_DATA_LIST_vars_pool (lexer, dict, tmp_pool, - &names, &name_cnt, PV_NONE) - || !parse_var_placements (lexer, tmp_pool, name_cnt, FMT_FOR_INPUT, - &formats, &format_cnt)) + &names, &n_names, PV_NONE) + || !parse_var_placements (lexer, tmp_pool, n_names, FMT_FOR_INPUT, + &formats, &n_formats)) return false; /* Create variables and var specs. */ name_idx = 0; - for (f = formats; f < &formats[format_cnt]; f++) + for (f = formats; f < &formats[n_formats]; f++) if (!execute_placement_format (f, &record, &column)) { char *name; @@ -407,7 +407,7 @@ parse_fixed (struct lexer *lexer, struct dictionary *dict, column += f->w; } - assert (name_idx == name_cnt); + assert (name_idx == n_names); } return true; @@ -427,11 +427,11 @@ parse_free (struct lexer *lexer, struct dictionary *dict, { struct fmt_spec input, output; char **name; - size_t name_cnt; + size_t n_names; size_t i; if (!parse_DATA_LIST_vars_pool (lexer, dict, tmp_pool, - &name, &name_cnt, PV_NONE)) + &name, &n_names, PV_NONE)) return false; if (lex_match (lexer, T_LPAREN)) @@ -475,7 +475,7 @@ parse_free (struct lexer *lexer, struct dictionary *dict, output = *settings_get_format (); } - for (i = 0; i < name_cnt; i++) + for (i = 0; i < n_names; i++) { struct variable *v; diff --git a/src/language/data-io/data-parser.c b/src/language/data-io/data-parser.c index c42daba4f1..359f2df64c 100644 --- a/src/language/data-io/data-parser.c +++ b/src/language/data-io/data-parser.c @@ -48,7 +48,7 @@ struct data_parser int skip_records; /* Records to skip before first real data. */ struct field *fields; /* Fields to parse. */ - size_t field_cnt; /* Number of fields. */ + size_t n_fields; /* Number of fields. */ size_t field_allocated; /* Number of fields spaced allocated for. */ /* DP_DELIMITED parsers only. */ @@ -89,7 +89,7 @@ data_parser_create (struct dictionary *dict) parser->skip_records = 0; parser->fields = NULL; - parser->field_cnt = 0; + parser->n_fields = 0; parser->field_allocated = 0; parser->dict = dict_ref (dict); @@ -117,7 +117,7 @@ data_parser_destroy (struct data_parser *parser) size_t i; dict_unref (parser->dict); - for (i = 0; i < parser->field_cnt; i++) + for (i = 0; i < parser->n_fields; i++) free (parser->fields[i].name); free (parser->fields); ss_dealloc (&parser->quotes); @@ -140,7 +140,7 @@ data_parser_get_type (const struct data_parser *parser) void data_parser_set_type (struct data_parser *parser, enum data_parser_type type) { - assert (parser->field_cnt == 0); + assert (parser->n_fields == 0); assert (type == DP_FIXED || type == DP_DELIMITED); parser->type = type; } @@ -291,9 +291,9 @@ add_field (struct data_parser *p, const struct fmt_spec *format, int case_idx, { struct field *field; - if (p->field_cnt == p->field_allocated) + if (p->n_fields == p->field_allocated) p->fields = x2nrealloc (p->fields, &p->field_allocated, sizeof *p->fields); - field = &p->fields[p->field_cnt++]; + field = &p->fields[p->n_fields++]; field->format = *format; field->case_idx = case_idx; field->name = xstrdup (name); @@ -335,8 +335,8 @@ data_parser_add_fixed_field (struct data_parser *parser, int record, int first_column) { assert (parser->type == DP_FIXED); - assert (parser->field_cnt == 0 - || record >= parser->fields[parser->field_cnt - 1].record); + assert (parser->n_fields == 0 + || record >= parser->fields[parser->n_fields - 1].record); if (record > parser->records_per_case) parser->records_per_case = record; add_field (parser, format, case_idx, name, record, first_column); @@ -347,7 +347,7 @@ data_parser_add_fixed_field (struct data_parser *parser, bool data_parser_any_fields (const struct data_parser *parser) { - return parser->field_cnt > 0; + return parser->n_fields > 0; } static void @@ -545,7 +545,7 @@ parse_fixed (const struct data_parser *parser, struct dfm_reader *reader, dfm_expand_tabs (reader); line = dfm_get_record (reader); - for (; f < &parser->fields[parser->field_cnt] && f->record == row; f++) + for (; f < &parser->fields[parser->n_fields] && f->record == row; f++) { struct substring s = ss_substr (line, f->first_column - 1, f->format.w); @@ -581,7 +581,7 @@ parse_delimited_span (const struct data_parser *parser, struct string tmp = DS_EMPTY_INITIALIZER; struct field *f; - for (f = parser->fields; f < &parser->fields[parser->field_cnt]; f++) + for (f = parser->fields; f < &parser->fields[parser->n_fields]; f++) { struct substring s; int first_column, last_column; @@ -630,7 +630,7 @@ parse_delimited_no_span (const struct data_parser *parser, if (dfm_eof (reader)) return false; - end = &parser->fields[parser->field_cnt]; + end = &parser->fields[parser->n_fields]; for (f = parser->fields; f < end; f++) { int first_column, last_column; @@ -691,7 +691,7 @@ dump_fixed_table (const struct data_parser *parser, struct pivot_dimension *variables = pivot_dimension_create ( table, PIVOT_AXIS_ROW, N_("Variable")); variables->root->show_label = true; - for (size_t i = 0; i < parser->field_cnt; i++) + for (size_t i = 0; i < parser->n_fields; i++) { struct field *f = &parser->fields[i]; @@ -736,7 +736,7 @@ dump_delimited_table (const struct data_parser *parser, struct pivot_dimension *variables = pivot_dimension_create ( table, PIVOT_AXIS_ROW, N_("Variable")); variables->root->show_label = true; - for (size_t i = 0; i < parser->field_cnt; i++) + for (size_t i = 0; i < parser->n_fields; i++) { struct field *f = &parser->fields[i]; diff --git a/src/language/data-io/data-reader.c b/src/language/data-io/data-reader.c index 89e84da0b3..70ff2756df 100644 --- a/src/language/data-io/data-reader.c +++ b/src/language/data-io/data-reader.c @@ -67,7 +67,7 @@ struct dfm_reader enum dfm_reader_flags flags; /* Zero or more of DFM_*. */ FILE *file; /* Associated file. */ size_t pos; /* Offset in line of current character. */ - unsigned eof_cnt; /* # of attempts to advance past EOF. */ + unsigned n_eofs; /* # of attempts to advance past EOF. */ struct lexer *lexer; /* The lexer reading the file */ char *encoding; /* Current encoding. */ @@ -149,7 +149,7 @@ dfm_open_reader (struct file_handle *fh, struct lexer *lexer, ds_init_empty (&r->line); ds_init_empty (&r->scratch); r->flags = DFM_ADVANCE; - r->eof_cnt = 0; + r->n_eofs = 0; r->block_left = 0; if (fh_get_referent (fh) != FH_REF_INLINE) { @@ -554,14 +554,14 @@ dfm_eof (struct dfm_reader *r) { r->flags &= ~DFM_ADVANCE; - if (r->eof_cnt == 0 && read_record (r)) + if (r->n_eofs == 0 && read_record (r)) { r->pos = 0; return 0; } - r->eof_cnt++; - if (r->eof_cnt == 2) + r->n_eofs++; + if (r->n_eofs == 2) { if (r->fh != fh_inline_file ()) msg (ME, _("Attempt to read beyond end-of-file on file %s."), @@ -571,7 +571,7 @@ dfm_eof (struct dfm_reader *r) } } - return r->eof_cnt; + return r->n_eofs; } /* Returns the current record in the file corresponding to @@ -581,7 +581,7 @@ struct substring dfm_get_record (struct dfm_reader *r) { assert ((r->flags & DFM_ADVANCE) == 0); - assert (r->eof_cnt == 0); + assert (r->n_eofs == 0); return ds_substr (&r->line, r->pos, SIZE_MAX); } @@ -596,7 +596,7 @@ dfm_expand_tabs (struct dfm_reader *r) size_t ofs, new_pos, tab_width; assert ((r->flags & DFM_ADVANCE) == 0); - assert (r->eof_cnt == 0); + assert (r->n_eofs == 0); if (r->flags & DFM_TABS_EXPANDED) return; diff --git a/src/language/data-io/get.c b/src/language/data-io/get.c index 00e78c8f00..e1bad76b93 100644 --- a/src/language/data-io/get.c +++ b/src/language/data-io/get.c @@ -127,7 +127,7 @@ parse_read_command (struct lexer *lexer, struct dataset *ds, if (reader == NULL) goto error; - if (dict_get_var_cnt (dict) == 0) + if (dict_get_n_vars (dict) == 0) { msg (SE, _("%s: Data file dictionary has no variables."), fh_get_name (fh)); diff --git a/src/language/data-io/matrix-data.c b/src/language/data-io/matrix-data.c index fbf82c084c..f510ec2516 100644 --- a/src/language/data-io/matrix-data.c +++ b/src/language/data-io/matrix-data.c @@ -911,7 +911,7 @@ cmd_matrix_data (struct lexer *lexer, struct dataset *ds) if (!dict) return CMD_FAILURE; - size_t n_input_vars = dict_get_var_cnt (dict); + size_t n_input_vars = dict_get_n_vars (dict); struct variable **input_vars = xnmalloc (n_input_vars, sizeof *input_vars); for (size_t i = 0; i < n_input_vars; i++) input_vars[i] = dict_get_var (dict, i); @@ -1144,7 +1144,7 @@ cmd_matrix_data (struct lexer *lexer, struct dataset *ds) goto error; } - struct variable **order = xnmalloc (dict_get_var_cnt (dict), sizeof *order); + struct variable **order = xnmalloc (dict_get_n_vars (dict), sizeof *order); size_t n_order = 0; for (size_t i = 0; i < mf.n_svars; i++) order[n_order++] = mf.svars[i]; @@ -1154,7 +1154,7 @@ cmd_matrix_data (struct lexer *lexer, struct dataset *ds) order[n_order++] = mf.varname; for (size_t i = 0; i < mf.n_cvars; i++) order[n_order++] = mf.cvars[i]; - assert (n_order == dict_get_var_cnt (dict)); + assert (n_order == dict_get_n_vars (dict)); dict_reorder_vars (dict, order, n_order); free (order); diff --git a/src/language/data-io/matrix-reader.c b/src/language/data-io/matrix-reader.c index a9dd4f4952..05be57efcb 100644 --- a/src/language/data-io/matrix-reader.c +++ b/src/language/data-io/matrix-reader.c @@ -130,7 +130,7 @@ matrix_reader_create (const struct dictionary *dict, return NULL; } - for (size_t i = 0; i < dict_get_var_cnt (dict); i++) + for (size_t i = 0; i < dict_get_n_vars (dict); i++) { const struct variable *v = dict_get_var (dict, i); if (!var_is_numeric (v) && v != rowtype && v != varname) diff --git a/src/language/data-io/placement-parser.c b/src/language/data-io/placement-parser.c index 6fa4e20388..dddbb05767 100644 --- a/src/language/data-io/placement-parser.c +++ b/src/language/data-io/placement-parser.c @@ -43,7 +43,7 @@ enum PRS_TYPE_NEW_REC /* Next record. */ }; -static bool fixed_parse_columns (struct lexer *, struct pool *, size_t var_cnt, +static bool fixed_parse_columns (struct lexer *, struct pool *, size_t n_vars, enum fmt_use, struct fmt_spec **, size_t *); static bool fixed_parse_fortran (struct lexer *l, struct pool *, enum fmt_use, struct fmt_spec **, size_t *); @@ -60,42 +60,42 @@ static bool fixed_parse_fortran (struct lexer *l, struct pool *, enum fmt_use, in addition to regular formats. If USE is FMT_FOR_OUTPUT, then T and X "formats" are parsed but not /. - If successful, formats for VAR_CNT variables are stored in + If successful, formats for N_VARS variables are stored in *FORMATS, and the number of formats required is stored in - *FORMAT_CNT. *FORMAT_CNT may be greater than VAR_CNT because + *FORMAT_CNT. *FORMAT_CNT may be greater than N_VARS because of T, X, and / "formats", but success guarantees that exactly - VAR_CNT variables will be placed by the output formats. The + N_VARS variables will be placed by the output formats. The caller should call execute_placement_format to process those "formats" in interpreting the output. Uses POOL for allocation. When the caller is finished interpreting *FORMATS, POOL may be destroyed. */ bool -parse_var_placements (struct lexer *lexer, struct pool *pool, size_t var_cnt, +parse_var_placements (struct lexer *lexer, struct pool *pool, size_t n_vars, enum fmt_use use, - struct fmt_spec **formats, size_t *format_cnt) + struct fmt_spec **formats, size_t *n_formats) { - assert (var_cnt > 0); + assert (n_vars > 0); if (lex_is_number (lexer)) - return fixed_parse_columns (lexer, pool, var_cnt, use, - formats, format_cnt); + return fixed_parse_columns (lexer, pool, n_vars, use, + formats, n_formats); else if (lex_match (lexer, T_LPAREN)) { - size_t assignment_cnt; + size_t n_assignments; size_t i; - if (!fixed_parse_fortran (lexer, pool, use, formats, format_cnt)) + if (!fixed_parse_fortran (lexer, pool, use, formats, n_formats)) return false; - assignment_cnt = 0; - for (i = 0; i < *format_cnt; i++) - assignment_cnt += (*formats)[i].type < FMT_NUMBER_OF_FORMATS; + n_assignments = 0; + for (i = 0; i < *n_formats; i++) + n_assignments += (*formats)[i].type < FMT_NUMBER_OF_FORMATS; - if (assignment_cnt != var_cnt) + if (n_assignments != n_vars) { msg (SE, _("Number of variables specified (%zu) " "differs from number of variable formats (%zu)."), - var_cnt, assignment_cnt); + n_vars, n_assignments); return false; } @@ -111,9 +111,9 @@ parse_var_placements (struct lexer *lexer, struct pool *pool, size_t var_cnt, /* Implements parse_var_placements for column-based formats. */ static bool -fixed_parse_columns (struct lexer *lexer, struct pool *pool, size_t var_cnt, +fixed_parse_columns (struct lexer *lexer, struct pool *pool, size_t n_vars, enum fmt_use use, - struct fmt_spec **formats, size_t *format_cnt) + struct fmt_spec **formats, size_t *n_formats) { struct fmt_spec format; int fc, lc; @@ -123,12 +123,12 @@ fixed_parse_columns (struct lexer *lexer, struct pool *pool, size_t var_cnt, return false; /* Divide columns evenly. */ - format.w = (lc - fc + 1) / var_cnt; - if ((lc - fc + 1) % var_cnt) + format.w = (lc - fc + 1) / n_vars; + if ((lc - fc + 1) % n_vars) { msg (SE, _("The %d columns %d-%d " "can't be evenly divided into %zu fields."), - lc - fc + 1, fc, lc, var_cnt); + lc - fc + 1, fc, lc, n_vars); return false; } @@ -165,11 +165,11 @@ fixed_parse_columns (struct lexer *lexer, struct pool *pool, size_t var_cnt, if (!fmt_check (&format, use)) return false; - *formats = pool_nalloc (pool, var_cnt + 1, sizeof **formats); - *format_cnt = var_cnt + 1; + *formats = pool_nalloc (pool, n_vars + 1, sizeof **formats); + *n_formats = n_vars + 1; (*formats)[0].type = (enum fmt_type) PRS_TYPE_T; (*formats)[0].w = fc; - for (i = 1; i <= var_cnt; i++) + for (i = 1; i <= n_vars; i++) (*formats)[i] = format; return true; } @@ -177,7 +177,7 @@ fixed_parse_columns (struct lexer *lexer, struct pool *pool, size_t var_cnt, /* Implements parse_var_placements for Fortran-like formats. */ static bool fixed_parse_fortran (struct lexer *lexer, struct pool *pool, enum fmt_use use, - struct fmt_spec **formats, size_t *format_cnt) + struct fmt_spec **formats, size_t *n_formats) { size_t formats_allocated = 0; size_t formats_used = 0; @@ -187,7 +187,7 @@ fixed_parse_fortran (struct lexer *lexer, struct pool *pool, enum fmt_use use, { struct fmt_spec f; struct fmt_spec *new_formats; - size_t new_format_cnt; + size_t n_new_formats; size_t count; size_t formats_needed; @@ -205,13 +205,13 @@ fixed_parse_fortran (struct lexer *lexer, struct pool *pool, enum fmt_use use, { /* Call ourselves recursively to handle parentheses. */ if (!fixed_parse_fortran (lexer, pool, use, - &new_formats, &new_format_cnt)) + &new_formats, &n_new_formats)) return false; } else { new_formats = &f; - new_format_cnt = 1; + n_new_formats = 1; if (use == FMT_FOR_INPUT && lex_match (lexer, T_SLASH)) f.type = (enum fmt_type) PRS_TYPE_NEW_REC; else @@ -244,12 +244,12 @@ fixed_parse_fortran (struct lexer *lexer, struct pool *pool, enum fmt_use use, /* Add COUNT copies of the NEW_FORMAT_CNT formats in NEW_FORMATS to FORMATS. */ - if (new_format_cnt != 0 + if (n_new_formats != 0 && size_overflow_p (xtimes (xsum (formats_used, - xtimes (count, new_format_cnt)), + xtimes (count, n_new_formats)), sizeof *formats))) xalloc_die (); - formats_needed = count * new_format_cnt; + formats_needed = count * n_new_formats; if (formats_used + formats_needed > formats_allocated) { formats_allocated = formats_used + formats_needed; @@ -259,14 +259,14 @@ fixed_parse_fortran (struct lexer *lexer, struct pool *pool, enum fmt_use use, for (; count > 0; count--) { memcpy (&(*formats)[formats_used], new_formats, - sizeof **formats * new_format_cnt); - formats_used += new_format_cnt; + sizeof **formats * n_new_formats); + formats_used += n_new_formats; } lex_match (lexer, T_COMMA); } - *format_cnt = formats_used; + *n_formats = formats_used; return true; } diff --git a/src/language/data-io/placement-parser.h b/src/language/data-io/placement-parser.h index 8f8d68c4ce..19711d04be 100644 --- a/src/language/data-io/placement-parser.h +++ b/src/language/data-io/placement-parser.h @@ -25,9 +25,9 @@ struct pool; struct lexer; bool parse_record_placement (struct lexer *, int *record, int *column); -bool parse_var_placements (struct lexer *, struct pool *, size_t var_cnt, +bool parse_var_placements (struct lexer *, struct pool *, size_t n_vars, enum fmt_use, - struct fmt_spec **, size_t *format_cnt); + struct fmt_spec **, size_t *n_formats); bool execute_placement_format (const struct fmt_spec *, int *record, int *column); bool parse_column (struct lexer *lexer, int base, int *column); diff --git a/src/language/data-io/print.c b/src/language/data-io/print.c index c0fc3d84f1..5c9ef7af99 100644 --- a/src/language/data-io/print.c +++ b/src/language/data-io/print.c @@ -87,7 +87,7 @@ struct print_trns const char *encoding; /* Encoding to use for output. */ struct dfm_writer *writer; /* Output file, NULL=listing file. */ struct ll_list specs; /* List of struct prt_out_specs. */ - size_t record_cnt; /* Number of records to write. */ + size_t n_records; /* Number of records to write. */ }; enum which_formats @@ -144,7 +144,7 @@ internal_cmd_print (struct lexer *lexer, struct dataset *ds, trns = pool_create_container (struct print_trns, pool); trns->eject = eject; trns->writer = NULL; - trns->record_cnt = 0; + trns->n_records = 0; ll_init (&trns->specs); tmp_pool = pool_create_subpool (trns->pool); @@ -177,7 +177,7 @@ internal_cmd_print (struct lexer *lexer, struct dataset *ds, lex_match (lexer, T_LPAREN); if (!lex_force_int_range (lexer, "RECORDS", 0, INT_MAX)) goto error; - trns->record_cnt = lex_integer (lexer); + trns->n_records = lex_integer (lexer); lex_get (lexer); lex_match (lexer, T_RPAREN); } @@ -277,7 +277,7 @@ parse_specs (struct lexer *lexer, struct pool *tmp_pool, struct print_trns *trns if (lex_token (lexer) == T_ENDCMD) { - trns->record_cnt = 1; + trns->n_records = 1; return true; } @@ -299,11 +299,11 @@ parse_specs (struct lexer *lexer, struct pool *tmp_pool, struct print_trns *trns lex_match (lexer, T_COMMA); } - if (trns->record_cnt != 0 && trns->record_cnt != record) + if (trns->n_records != 0 && trns->n_records != record) msg (SW, _("Output calls for %d records but %zu specified on RECORDS " "subcommand."), - record, trns->record_cnt); - trns->record_cnt = record; + record, trns->n_records); + trns->n_records = record; return true; } @@ -354,19 +354,19 @@ parse_variable_argument (struct lexer *lexer, const struct dictionary *dict, enum which_formats which_formats) { const struct variable **vars; - size_t var_cnt, var_idx; + size_t n_vars, var_idx; struct fmt_spec *formats, *f; - size_t format_cnt; + size_t n_formats; bool add_space; if (!parse_variables_const_pool (lexer, tmp_pool, dict, - &vars, &var_cnt, PV_DUPLICATE)) + &vars, &n_vars, PV_DUPLICATE)) return false; if (lex_is_number (lexer) || lex_token (lexer) == T_LPAREN) { - if (!parse_var_placements (lexer, tmp_pool, var_cnt, FMT_FOR_OUTPUT, - &formats, &format_cnt)) + if (!parse_var_placements (lexer, tmp_pool, n_vars, FMT_FOR_OUTPUT, + &formats, &n_formats)) return false; add_space = false; } @@ -376,9 +376,9 @@ parse_variable_argument (struct lexer *lexer, const struct dictionary *dict, lex_match (lexer, T_ASTERISK); - formats = pool_nmalloc (tmp_pool, var_cnt, sizeof *formats); - format_cnt = var_cnt; - for (i = 0; i < var_cnt; i++) + formats = pool_nmalloc (tmp_pool, n_vars, sizeof *formats); + n_formats = n_vars; + for (i = 0; i < n_vars; i++) { const struct variable *v = vars[i]; formats[i] = (which_formats == PRINT @@ -389,7 +389,7 @@ parse_variable_argument (struct lexer *lexer, const struct dictionary *dict, } var_idx = 0; - for (f = formats; f < &formats[format_cnt]; f++) + for (f = formats; f < &formats[n_formats]; f++) if (!execute_placement_format (f, record, column)) { const struct variable *var; @@ -420,7 +420,7 @@ parse_variable_argument (struct lexer *lexer, const struct dictionary *dict, *column += f->w + add_space; } - assert (var_idx == var_cnt); + assert (var_idx == n_vars); return true; } @@ -462,7 +462,7 @@ dump_table (struct print_trns *trns) int row = pivot_category_create_leaf ( variables->root, pivot_value_new_text (N_("N of Records"))); pivot_table_put2 (table, 0, row, - pivot_value_new_integer (trns->record_cnt)); + pivot_value_new_integer (trns->n_records)); pivot_table_submit (table); } @@ -531,7 +531,7 @@ print_text_trns_proc (void *trns_, struct ccase **c, ds_data (s), ds_length (s)); } } - print_text_flush_records (trns, &line, trns->record_cnt + 1, + print_text_flush_records (trns, &line, trns->n_records + 1, &eject, &record); u8_line_destroy (&line); @@ -630,7 +630,7 @@ print_binary_trns_proc (void *trns_, struct ccase **c, } } } - print_binary_flush_records (trns, &line, trns->record_cnt + 1, + print_binary_flush_records (trns, &line, trns->n_records + 1, &eject, &record); ds_destroy (&line); diff --git a/src/language/data-io/trim.c b/src/language/data-io/trim.c index b9983ef49e..4616b431d2 100644 --- a/src/language/data-io/trim.c +++ b/src/language/data-io/trim.c @@ -276,7 +276,7 @@ parse_dict_drop (struct lexer *lexer, struct dictionary *dict) dict_delete_vars (dict, v, nv); free (v); - if (dict_get_var_cnt (dict) == 0) + if (dict_get_n_vars (dict) == 0) { msg (SE, _("Cannot DROP all variables from dictionary.")); return false; @@ -302,16 +302,16 @@ parse_dict_keep (struct lexer *lexer, struct dictionary *dict) dict_reorder_vars (dict, v, nv); /* Delete the remaining variables. */ - if (dict_get_var_cnt (dict) == nv) + if (dict_get_n_vars (dict) == nv) { free (v); return true; } - v = xnrealloc (v, dict_get_var_cnt (dict) - nv, sizeof *v); - for (i = nv; i < dict_get_var_cnt (dict); i++) + v = xnrealloc (v, dict_get_n_vars (dict) - nv, sizeof *v); + for (i = nv; i < dict_get_n_vars (dict); i++) v[i - nv] = dict_get_var (dict, i); - dict_delete_vars (dict, v, dict_get_var_cnt (dict) - nv); + dict_delete_vars (dict, v, dict_get_n_vars (dict) - nv); free (v); return true; diff --git a/src/language/dictionary/apply-dictionary.c b/src/language/dictionary/apply-dictionary.c index d09f8a8721..eae06df76c 100644 --- a/src/language/dictionary/apply-dictionary.c +++ b/src/language/dictionary/apply-dictionary.c @@ -60,7 +60,7 @@ cmd_apply_dictionary (struct lexer *lexer, struct dataset *ds) casereader_destroy (reader); - for (i = 0; i < dict_get_var_cnt (dict); i++) + for (i = 0; i < dict_get_n_vars (dict); i++) { const struct variable *s = dict_get_var (dict, i); struct variable *t = dict_lookup_var (dataset_dict (ds), diff --git a/src/language/dictionary/delete-variables.c b/src/language/dictionary/delete-variables.c index ded5c48ad3..1c38074f63 100644 --- a/src/language/dictionary/delete-variables.c +++ b/src/language/dictionary/delete-variables.c @@ -33,7 +33,7 @@ int cmd_delete_variables (struct lexer *lexer, struct dataset *ds) { struct variable **vars; - size_t var_cnt; + size_t n_vars; bool ok; if (proc_make_temporary_transformations_permanent (ds)) @@ -41,9 +41,9 @@ cmd_delete_variables (struct lexer *lexer, struct dataset *ds) "Temporary transformations will be made permanent."), "DELETE VARIABLES", "TEMPORARY"); - if (!parse_variables (lexer, dataset_dict (ds), &vars, &var_cnt, PV_NONE)) + if (!parse_variables (lexer, dataset_dict (ds), &vars, &n_vars, PV_NONE)) goto error; - if (var_cnt == dict_get_var_cnt (dataset_dict (ds))) + if (n_vars == dict_get_n_vars (dataset_dict (ds))) { msg (SE, _("%s may not be used to delete all variables " "from the active dataset dictionary. " @@ -56,7 +56,7 @@ cmd_delete_variables (struct lexer *lexer, struct dataset *ds) if (!ok) goto error; - dict_delete_vars (dataset_dict (ds), vars, var_cnt); + dict_delete_vars (dataset_dict (ds), vars, n_vars); /* XXX A bunch of bugs conspire to make executing transformations again here necessary, even though it shouldn't be. diff --git a/src/language/dictionary/modify-variables.c b/src/language/dictionary/modify-variables.c index ab73bbb899..e022586dac 100644 --- a/src/language/dictionary/modify-variables.c +++ b/src/language/dictionary/modify-variables.c @@ -307,7 +307,7 @@ cmd_modify_vars (struct lexer *lexer, struct dataset *ds) vm.drop_vars = drop_vars; vm.n_drop = n_drop; - if (n_drop == dict_get_var_cnt (dataset_dict (ds))) + if (n_drop == dict_get_n_vars (dataset_dict (ds))) { msg (SE, _("%s may not be used to delete all variables " "from the active dataset dictionary. " diff --git a/src/language/dictionary/split-file.c b/src/language/dictionary/split-file.c index 48eec29581..1ebd7ae9ca 100644 --- a/src/language/dictionary/split-file.c +++ b/src/language/dictionary/split-file.c @@ -68,7 +68,7 @@ void output_split_file_values (const struct dataset *ds, const struct ccase *c) { const struct dictionary *dict = dataset_dict (ds); - size_t n_vars = dict_get_split_cnt (dict); + size_t n_vars = dict_get_n_splits (dict); if (n_vars == 0) return; diff --git a/src/language/dictionary/sys-file-info.c b/src/language/dictionary/sys-file-info.c index 68efb8ee7b..e871dfd59b 100644 --- a/src/language/dictionary/sys-file-info.c +++ b/src/language/dictionary/sys-file-info.c @@ -215,12 +215,12 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds) : N_("Unknown"))); add_row (table, N_("Variables"), - pivot_value_new_integer (dict_get_var_cnt (d))); + pivot_value_new_integer (dict_get_n_vars (d))); add_row (table, N_("Cases"), - (info.case_cnt == -1 + (info.n_cases == -1 ? pivot_value_new_text (N_("Unknown")) - : pivot_value_new_integer (info.case_cnt))); + : pivot_value_new_integer (info.n_cases))); add_row (table, N_("Type"), pivot_value_new_text (info.klass->name)); @@ -240,15 +240,15 @@ cmd_sysfile_info (struct lexer *lexer, struct dataset *ds) add_row (table, N_("Encoding"), pivot_value_new_user_text (dict_get_encoding (d), -1)); - if (dict_get_document_line_cnt (d) > 0) + if (dict_get_document_n_lines (d) > 0) add_row (table, N_("Documents"), pivot_value_new_user_text_nocopy (get_documents_as_string (d))); pivot_table_submit (table); - size_t n_vars = dict_get_var_cnt (d); + size_t n_vars = dict_get_n_vars (d); const struct variable **vars = xnmalloc (n_vars, sizeof *vars); - for (size_t i = 0; i < dict_get_var_cnt (d); i++) + for (size_t i = 0; i < dict_get_n_vars (d); i++) vars[i] = dict_get_var (d, i); display_variables (vars, n_vars, DF_ALL_VARIABLE); display_value_labels (vars, n_vars); @@ -715,7 +715,7 @@ display_attributes (const struct attrset *dict_attrset, static void display_vectors (const struct dictionary *dict, int sorted) { - size_t n_vectors = dict_get_vector_cnt (dict); + size_t n_vectors = dict_get_n_vectors (dict); if (n_vectors == 0) { msg (SW, _("No vectors defined.")); @@ -743,7 +743,7 @@ display_vectors (const struct dictionary *dict, int sorted) vector_dim->root, pivot_value_new_user_text ( vector_get_name (vectors[i]), -1)); - for (size_t j = 0; j < vector_get_var_cnt (vec); j++) + for (size_t j = 0; j < vector_get_n_vars (vec); j++) { struct variable *var = vector_get_var (vec, j); diff --git a/src/language/dictionary/value-labels.c b/src/language/dictionary/value-labels.c index 2dfe0885bf..0fb8471652 100644 --- a/src/language/dictionary/value-labels.c +++ b/src/language/dictionary/value-labels.c @@ -40,8 +40,8 @@ static int do_value_labels (struct lexer *, const struct dictionary *dict, bool); -static void erase_labels (struct variable **vars, size_t var_cnt); -static int get_label (struct lexer *, struct variable **vars, size_t var_cnt, +static void erase_labels (struct variable **vars, size_t n_vars); +static int get_label (struct lexer *, struct variable **vars, size_t n_vars, const char *dict_encoding); /* Stubs. */ @@ -64,24 +64,24 @@ static int do_value_labels (struct lexer *lexer, const struct dictionary *dict, bool erase) { struct variable **vars; /* Variable list. */ - size_t var_cnt; /* Number of variables. */ + size_t n_vars; /* Number of variables. */ int parse_err=0; /* true if error parsing variables */ lex_match (lexer, T_SLASH); while (lex_token (lexer) != T_ENDCMD) { - parse_err = !parse_variables (lexer, dict, &vars, &var_cnt, + parse_err = !parse_variables (lexer, dict, &vars, &n_vars, PV_SAME_WIDTH); - if (var_cnt < 1) + if (n_vars < 1) { free(vars); return CMD_FAILURE; } if (erase) - erase_labels (vars, var_cnt); + erase_labels (vars, n_vars); while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD) - if (!get_label (lexer, vars, var_cnt, dict_get_encoding (dict))) + if (!get_label (lexer, vars, n_vars, dict_get_encoding (dict))) goto lossage; if (lex_token (lexer) != T_SLASH) @@ -102,21 +102,19 @@ do_value_labels (struct lexer *lexer, const struct dictionary *dict, bool erase) return CMD_FAILURE; } -/* Erases all the labels for the VAR_CNT variables in VARS. */ +/* Erases all the labels for the N_VARS variables in VARS. */ static void -erase_labels (struct variable **vars, size_t var_cnt) +erase_labels (struct variable **vars, size_t n_vars) { - size_t i; - /* Erase old value labels if desired. */ - for (i = 0; i < var_cnt; i++) + for (size_t i = 0; i < n_vars; i++) var_clear_value_labels (vars[i]); } -/* Parse all the labels for the VAR_CNT variables in VARS and add +/* Parse all the labels for the N_VARS variables in VARS and add the specified labels to those variables. */ static int -get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt, +get_label (struct lexer *lexer, struct variable **vars, size_t n_vars, const char *dict_encoding) { /* Parse all the labels and add them to the variables. */ @@ -155,7 +153,7 @@ get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt, ds_truncate (&label, trunc_len); } - for (i = 0; i < var_cnt; i++) + for (i = 0; i < n_vars; i++) var_replace_value_label (vars[i], &value, ds_cstr (&label)); ds_destroy (&label); diff --git a/src/language/dictionary/vector.c b/src/language/dictionary/vector.c index e7e70cecb2..16617f87e0 100644 --- a/src/language/dictionary/vector.c +++ b/src/language/dictionary/vector.c @@ -48,7 +48,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) do { char **vectors; - size_t vector_cnt, vector_cap; + size_t n_vectors, allocated_vectors; /* Get the name(s) of the new vector(s). */ if (!lex_force_id (lexer) @@ -56,7 +56,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) return CMD_CASCADING_FAILURE; vectors = NULL; - vector_cnt = vector_cap = 0; + n_vectors = allocated_vectors = 0; while (lex_token (lexer) == T_ID) { size_t i; @@ -68,7 +68,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) goto fail; } - for (i = 0; i < vector_cnt; i++) + for (i = 0; i < n_vectors; i++) if (!utf8_strcasecmp (vectors[i], lex_tokcstr (lexer))) { msg (SE, _("Vector name %s is given twice."), @@ -76,10 +76,10 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) goto fail; } - if (vector_cnt == vector_cap) - vectors = pool_2nrealloc (pool, - vectors, &vector_cap, sizeof *vectors); - vectors[vector_cnt++] = pool_strdup (pool, lex_tokcstr (lexer)); + if (n_vectors == allocated_vectors) + vectors = pool_2nrealloc (pool, vectors, &allocated_vectors, + sizeof *vectors); + vectors[n_vectors++] = pool_strdup (pool, lex_tokcstr (lexer)); lex_get (lexer); lex_match (lexer, T_COMMA); @@ -93,7 +93,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) struct variable **v; size_t nv; - if (vector_cnt > 1) + if (n_vectors > 1) { msg (SE, _("A slash must separate each vector " "specification in VECTOR's long form.")); @@ -113,20 +113,20 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) bool seen_format = false; struct variable **vars; - int var_cnt; + int n_vars; size_t i; - var_cnt = 0; + n_vars = 0; format = fmt_for_output (FMT_F, 8, 2); seen_format = false; while (!lex_match (lexer, T_RPAREN)) { - if (lex_is_integer (lexer) && var_cnt == 0) + if (lex_is_integer (lexer) && n_vars == 0) { if (!lex_force_int_range (lexer, NULL, 1, INT_MAX)) goto fail; - var_cnt = lex_integer (lexer); + n_vars = lex_integer (lexer); lex_get (lexer); } else if (lex_token (lexer) == T_ID && !seen_format) @@ -143,7 +143,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) } lex_match (lexer, T_COMMA); } - if (var_cnt == 0) + if (n_vars == 0) { lex_error (lexer, _("expecting vector length")); goto fail; @@ -151,10 +151,10 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) /* Check that none of the variables exist and that their names are not excessively long. */ - for (i = 0; i < vector_cnt; i++) + for (i = 0; i < n_vectors; i++) { int j; - for (j = 0; j < var_cnt; j++) + for (j = 0; j < n_vars; j++) { char *name = xasprintf ("%s%d", vectors[i], j + 1); if (!dict_id_is_valid (dict, name, true)) @@ -173,11 +173,11 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) } /* Finally create the variables and vectors. */ - vars = pool_nmalloc (pool, var_cnt, sizeof *vars); - for (i = 0; i < vector_cnt; i++) + vars = pool_nmalloc (pool, n_vars, sizeof *vars); + for (i = 0; i < n_vectors; i++) { int j; - for (j = 0; j < var_cnt; j++) + for (j = 0; j < n_vars; j++) { char *name = xasprintf ("%s%d", vectors[i], j + 1); vars[j] = dict_create_var_assert (dict, name, @@ -185,7 +185,7 @@ cmd_vector (struct lexer *lexer, struct dataset *ds) var_set_both_formats (vars[j], &format); free (name); } - dict_create_vector_assert (dict, vectors[i], vars, var_cnt); + dict_create_vector_assert (dict, vectors[i], vars, n_vars); } } else diff --git a/src/language/expressions/evaluate.c b/src/language/expressions/evaluate.c index d6d5738481..1ad2be802e 100644 --- a/src/language/expressions/evaluate.c +++ b/src/language/expressions/evaluate.c @@ -51,7 +51,7 @@ expr_evaluate (struct expression *e, const struct ccase *c, int case_idx, for (;;) { - assert (op < e->ops + e->op_cnt); + assert (op < e->ops + e->n_ops); switch (op++->operation) { case OP_number: @@ -248,7 +248,7 @@ expr_debug_print_postfix (const struct expression *e) { struct string s = DS_EMPTY_INITIALIZER; - for (size_t i = 0; i < e->op_cnt; i++) + for (size_t i = 0; i < e->n_ops; i++) { union operation_data *op = &e->ops[i]; if (i > 0) diff --git a/src/language/expressions/generate.pl b/src/language/expressions/generate.pl index 6f41d7e842..188d4eb11c 100644 --- a/src/language/expressions/generate.pl +++ b/src/language/expressions/generate.pl @@ -749,7 +749,7 @@ sub print_range { my ($prefix, $first, $last) = @_; print " ${prefix}_first = $first,\n"; print " ${prefix}_last = $last,\n"; - print " ${prefix}_cnt = ${prefix}_last - ${prefix}_first + 1"; + print " n_${prefix} = ${prefix}_last - ${prefix}_first + 1"; } sub print_predicate { @@ -786,7 +786,7 @@ sub generate_optimize_inc { my ($func) = "get_$type->{ATOM}_arg"; push (@decls, "${ctype}arg_$name = $func (node, $arg_idx)"); } else { - my ($decl) = "size_t arg_$idx = node->arg_cnt"; + my ($decl) = "size_t arg_$idx = node->n_args"; $decl .= " - $arg_idx" if $arg_idx; push (@decls, $decl); diff --git a/src/language/expressions/helpers.c b/src/language/expressions/helpers.c index 66a7c1a109..053ada56b5 100644 --- a/src/language/expressions/helpers.c +++ b/src/language/expressions/helpers.c @@ -167,11 +167,11 @@ recognize_unit (struct substring name, enum date_unit *unit) { DATE_MINUTES, SS_LITERAL_INITIALIZER ("minutes") }, { DATE_SECONDS, SS_LITERAL_INITIALIZER ("seconds") }, }; - const int unit_name_cnt = sizeof unit_names / sizeof *unit_names; + const int n_unit_names = sizeof unit_names / sizeof *unit_names; const struct unit_name *un; - for (un = unit_names; un < &unit_names[unit_name_cnt]; un++) + for (un = unit_names; un < &unit_names[n_unit_names]; un++) if (ss_equals_case (un->name, name)) { *unit = un->unit; @@ -430,15 +430,12 @@ compare_string_3way (const struct substring *a, const struct substring *b) } size_t -count_valid (double *d, size_t d_cnt) +count_valid (double *d, size_t n) { - size_t valid_cnt; - size_t i; - - valid_cnt = 0; - for (i = 0; i < d_cnt; i++) - valid_cnt += is_valid (d[i]); - return valid_cnt; + size_t n_valid = 0; + for (size_t i = 0; i < n; i++) + n_valid += is_valid (d[i]); + return n_valid; } struct substring diff --git a/src/language/expressions/operations.def b/src/language/expressions/operations.def index 42728e46ea..6aae2e2f05 100644 --- a/src/language/expressions/operations.def +++ b/src/language/expressions/operations.def @@ -201,22 +201,18 @@ string function MIN (string a[n]) absorb_miss function NMISS (a[n]) { - size_t i; - size_t missing_cnt = 0; - - for (i = 0; i < n; i++) - missing_cnt += a[i] == SYSMIS; - return missing_cnt; + size_t n_missings = 0; + for (size_t i = 0; i < n; i++) + n_missings += a[i] == SYSMIS; + return n_missings; } absorb_miss function NVALID (a[n]) { - size_t i; - size_t valid_cnt = 0; - - for (i = 0; i < n; i++) - valid_cnt += a[i] != SYSMIS; - return valid_cnt; + size_t n_valids = 0; + for (size_t i = 0; i < n; i++) + n_valids += a[i] != SYSMIS; + return n_valids; } absorb_miss boolean function RANGE (x != SYSMIS, a[n*2]) @@ -979,7 +975,7 @@ no_opt operator VEC_ELEM_NUM (idx) vector v; case c; { - if (idx >= 1 && idx <= vector_get_var_cnt (v)) + if (idx >= 1 && idx <= vector_get_n_vars (v)) { const struct variable *var = vector_get_var (v, (size_t) idx - 1); double value = case_num (c, var); @@ -1004,7 +1000,7 @@ absorb_miss no_opt string operator VEC_ELEM_STR (idx) vector v; case c; { - if (idx >= 1 && idx <= vector_get_var_cnt (v)) + if (idx >= 1 && idx <= vector_get_n_vars (v)) { struct variable *var = vector_get_var (v, (size_t) idx - 1); return copy_string (e, CHAR_CAST_BUG (char *, case_str (c, var)), diff --git a/src/language/expressions/optimize.c b/src/language/expressions/optimize.c index a926997d93..28ba85f206 100644 --- a/src/language/expressions/optimize.c +++ b/src/language/expressions/optimize.c @@ -44,8 +44,8 @@ static union any_node *optimize_tree (union any_node *, struct expression *); union any_node * expr_optimize (union any_node *node, struct expression *e) { - int nonconst_cnt = 0; /* Number of nonconstant children. */ - int sysmis_cnt = 0; /* Number of system-missing children. */ + int n_nonconst = 0; /* Number of nonconstant children. */ + int n_sysmis = 0; /* Number of system-missing children. */ const struct operation *op; struct composite_node *c; int i; @@ -56,21 +56,21 @@ expr_optimize (union any_node *node, struct expression *e) /* Start by optimizing all the children. */ c = &node->composite; - for (i = 0; i < c->arg_cnt; i++) + for (i = 0; i < c->n_args; i++) { c->args[i] = expr_optimize (c->args[i], e); if (c->args[i]->type == OP_number) { if (c->args[i]->number.n == SYSMIS) - sysmis_cnt++; + n_sysmis++; } if (!is_atom (c->args[i]->type)) - nonconst_cnt++; + n_nonconst++; } op = &operations[c->type]; - if (sysmis_cnt && (op->flags & OPF_ABSORB_MISS) == 0) + if (n_sysmis && (op->flags & OPF_ABSORB_MISS) == 0) { /* Most operations produce SYSMIS given any SYSMIS argument. */ @@ -80,7 +80,7 @@ expr_optimize (union any_node *node, struct expression *e) else return expr_allocate_boolean (e, SYSMIS); } - else if (!nonconst_cnt && (op->flags & OPF_NONOPTIMIZABLE) == 0) + else if (!n_nonconst && (op->flags & OPF_NONOPTIMIZABLE) == 0) { /* Evaluate constant expressions. */ return evaluate_tree (&node->composite, e); @@ -141,12 +141,12 @@ optimize_tree (union any_node *node, struct expression *e) static double get_number_arg (struct composite_node *, size_t arg_idx); static double *get_number_args (struct composite_node *, - size_t arg_idx, size_t arg_cnt, + size_t arg_idx, size_t n_args, struct expression *); static struct substring get_string_arg (struct composite_node *, size_t arg_idx); static struct substring *get_string_args (struct composite_node *, - size_t arg_idx, size_t arg_cnt, + size_t arg_idx, size_t n_args, struct expression *); static const struct fmt_spec *get_format_arg (struct composite_node *, size_t arg_idx); @@ -168,21 +168,21 @@ evaluate_tree (struct composite_node *node, struct expression *e) static double get_number_arg (struct composite_node *c, size_t arg_idx) { - assert (arg_idx < c->arg_cnt); + assert (arg_idx < c->n_args); assert (c->args[arg_idx]->type == OP_number || c->args[arg_idx]->type == OP_boolean); return c->args[arg_idx]->number.n; } static double * -get_number_args (struct composite_node *c, size_t arg_idx, size_t arg_cnt, +get_number_args (struct composite_node *c, size_t arg_idx, size_t n_args, struct expression *e) { double *d; size_t i; - d = pool_alloc (e->expr_pool, sizeof *d * arg_cnt); - for (i = 0; i < arg_cnt; i++) + d = pool_alloc (e->expr_pool, sizeof *d * n_args); + for (i = 0; i < n_args; i++) d[i] = get_number_arg (c, i + arg_idx); return d; } @@ -190,20 +190,20 @@ get_number_args (struct composite_node *c, size_t arg_idx, size_t arg_cnt, static struct substring get_string_arg (struct composite_node *c, size_t arg_idx) { - assert (arg_idx < c->arg_cnt); + assert (arg_idx < c->n_args); assert (c->args[arg_idx]->type == OP_string); return c->args[arg_idx]->string.s; } static struct substring * -get_string_args (struct composite_node *c, size_t arg_idx, size_t arg_cnt, +get_string_args (struct composite_node *c, size_t arg_idx, size_t n_args, struct expression *e) { struct substring *s; size_t i; - s = pool_alloc (e->expr_pool, sizeof *s * arg_cnt); - for (i = 0; i < arg_cnt; i++) + s = pool_alloc (e->expr_pool, sizeof *s * n_args); + for (i = 0; i < n_args; i++) s[i] = get_string_arg (c, i + arg_idx); return s; } @@ -211,7 +211,7 @@ get_string_args (struct composite_node *c, size_t arg_idx, size_t arg_cnt, static const struct fmt_spec * get_format_arg (struct composite_node *c, size_t arg_idx) { - assert (arg_idx < c->arg_cnt); + assert (arg_idx < c->n_args); assert (c->args[arg_idx]->type == OP_ni_format || c->args[arg_idx]->type == OP_no_format); return &c->args[arg_idx]->format.f; @@ -312,13 +312,13 @@ flatten_composite (union any_node *n, struct expression *e) const struct operation *op = &operations[n->type]; size_t i; - for (i = 0; i < n->composite.arg_cnt; i++) + for (i = 0; i < n->composite.n_args; i++) flatten_node (n->composite.args[i], e); if (n->type != OP_BOOLEAN_TO_NUM) emit_operation (e, n->type); - for (i = 0; i < n->composite.arg_cnt; i++) + for (i = 0; i < n->composite.n_args; i++) { union any_node *arg = n->composite.args[i]; switch (arg->type) @@ -348,7 +348,7 @@ flatten_composite (union any_node *n, struct expression *e) } if (op->flags & OPF_ARRAY_OPERAND) - emit_integer (e, n->composite.arg_cnt - op->arg_cnt + 1); + emit_integer (e, n->composite.n_args - op->n_args + 1); if (op->flags & OPF_MIN_VALID) emit_integer (e, n->composite.min_valid); } @@ -369,14 +369,15 @@ flatten_node (union any_node *n, struct expression *e) static union operation_data * allocate_aux (struct expression *e, operation_type type) { - if (e->op_cnt >= e->op_cap) + if (e->n_ops >= e->allocated_ops) { - e->op_cap = (e->op_cap + 8) * 3 / 2; - e->ops = pool_realloc (e->expr_pool, e->ops, sizeof *e->ops * e->op_cap); + e->allocated_ops = (e->allocated_ops + 8) * 3 / 2; + e->ops = pool_realloc (e->expr_pool, e->ops, + sizeof *e->ops * e->allocated_ops); e->op_types = pool_realloc (e->expr_pool, e->op_types, - sizeof *e->op_types * e->op_cap); + sizeof *e->op_types * e->allocated_ops); } - e->op_types[e->op_cnt] = type; - return &e->ops[e->op_cnt++]; + e->op_types[e->n_ops] = type; + return &e->ops[e->n_ops++]; } diff --git a/src/language/expressions/parse.c b/src/language/expressions/parse.c index f0fdafd808..ab603c0b89 100644 --- a/src/language/expressions/parse.c +++ b/src/language/expressions/parse.c @@ -243,7 +243,7 @@ measure_stack (const union any_node *n, int i; args = *height; - for (i = 0; i < n->composite.arg_cnt; i++) + for (i = 0; i < n->composite.n_args; i++) measure_stack (n->composite.args[i], &args, max); return_height = atom_type_stack (operations[n->type].returns); @@ -540,12 +540,12 @@ struct operator On failure, returns false and, if OPERATOR is non-null, sets *OPERATOR to a null pointer. */ static bool -match_operator (struct lexer *lexer, const struct operator ops[], size_t op_cnt, +match_operator (struct lexer *lexer, const struct operator ops[], size_t n_ops, const struct operator **operator) { const struct operator *op; - for (op = ops; op < ops + op_cnt; op++) + for (op = ops; op < ops + n_ops; op++) if (lex_token (lexer) == op->token) { if (op->token != T_NEG_NUM) @@ -560,27 +560,27 @@ match_operator (struct lexer *lexer, const struct operator ops[], size_t op_cnt, } static bool -check_operator (const struct operator *op, int arg_cnt, atom_type arg_type) +check_operator (const struct operator *op, int n_args, atom_type arg_type) { const struct operation *o; size_t i; assert (op != NULL); o = &operations[op->type]; - assert (o->arg_cnt == arg_cnt); + assert (o->n_args == n_args); assert ((o->flags & OPF_ARRAY_OPERAND) == 0); - for (i = 0; i < arg_cnt; i++) + for (i = 0; i < n_args; i++) assert (is_compatible (arg_type, o->args[i])); return true; } static bool -check_binary_operators (const struct operator ops[], size_t op_cnt, +check_binary_operators (const struct operator ops[], size_t n_ops, atom_type arg_type) { size_t i; - for (i = 0; i < op_cnt; i++) + for (i = 0; i < n_ops; i++) check_operator (&ops[i], 2, arg_type); return true; } @@ -599,7 +599,7 @@ get_operand_type (const struct operator *op) one operator/operand pair is parsed. */ static union any_node * parse_binary_operators (struct lexer *lexer, struct expression *e, union any_node *node, - const struct operator ops[], size_t op_cnt, + const struct operator ops[], size_t n_ops, parse_recursively_func *parse_next_level, const char *chain_warning) { @@ -607,11 +607,11 @@ parse_binary_operators (struct lexer *lexer, struct expression *e, union any_nod int op_count; const struct operator *operator; - assert (check_binary_operators (ops, op_cnt, operand_type)); + assert (check_binary_operators (ops, n_ops, operand_type)); if (node == NULL) return node; - for (op_count = 0; match_operator (lexer, ops, op_cnt, &operator); op_count++) + for (op_count = 0; match_operator (lexer, ops, n_ops, &operator); op_count++) { union any_node *rhs; @@ -1009,7 +1009,7 @@ parse_vector_element (struct lexer *lexer, struct expression *e) /* Individual function parsing. */ -const struct operation operations[OP_first + OP_cnt] = { +const struct operation operations[OP_first + n_OP] = { #include "parse.inc" }; @@ -1108,22 +1108,22 @@ extract_min_valid (const char *s) static atom_type function_arg_type (const struct operation *f, size_t arg_idx) { - assert (arg_idx < f->arg_cnt || (f->flags & OPF_ARRAY_OPERAND)); + assert (arg_idx < f->n_args || (f->flags & OPF_ARRAY_OPERAND)); - return f->args[arg_idx < f->arg_cnt ? arg_idx : f->arg_cnt - 1]; + return f->args[arg_idx < f->n_args ? arg_idx : f->n_args - 1]; } static bool -match_function (union any_node **args, int arg_cnt, const struct operation *f) +match_function (union any_node **args, int n_args, const struct operation *f) { size_t i; - if (arg_cnt < f->arg_cnt - || (arg_cnt > f->arg_cnt && (f->flags & OPF_ARRAY_OPERAND) == 0) - || arg_cnt - (f->arg_cnt - 1) < f->array_min_elems) + if (n_args < f->n_args + || (n_args > f->n_args && (f->flags & OPF_ARRAY_OPERAND) == 0) + || n_args - (f->n_args - 1) < f->array_min_elems) return false; - for (i = 0; i < arg_cnt; i++) + for (i = 0; i < n_args; i++) if (!is_coercible (function_arg_type (f, i), &args[i])) return false; @@ -1132,31 +1132,31 @@ match_function (union any_node **args, int arg_cnt, const struct operation *f) static void coerce_function_args (struct expression *e, const struct operation *f, - union any_node **args, size_t arg_cnt) + union any_node **args, size_t n_args) { int i; - for (i = 0; i < arg_cnt; i++) + for (i = 0; i < n_args; i++) type_coercion_assert (e, function_arg_type (f, i), &args[i]); } static bool -validate_function_args (const struct operation *f, int arg_cnt, int min_valid) +validate_function_args (const struct operation *f, int n_args, int min_valid) { /* Count the function arguments that go into the trailing array (if any). We know that there must be at least the minimum number because match_function() already checked. */ - int array_arg_cnt = arg_cnt - (f->arg_cnt - 1); - assert (array_arg_cnt >= f->array_min_elems); + int array_n_args = n_args - (f->n_args - 1); + assert (array_n_args >= f->array_min_elems); if ((f->flags & OPF_ARRAY_OPERAND) - && array_arg_cnt % f->array_granularity != 0) + && array_n_args % f->array_granularity != 0) { /* RANGE is the only case we have so far. It has paired arguments with one initial argument, and that's the only special case we deal with here. */ assert (f->array_granularity == 2); - assert (arg_cnt % 2 == 0); + assert (n_args % 2 == 0); msg (SE, _("%s must have an odd number of arguments."), f->prototype); return false; } @@ -1174,11 +1174,11 @@ validate_function_args (const struct operation *f, int arg_cnt, int min_valid) else { assert (f->flags & OPF_MIN_VALID); - if (min_valid > array_arg_cnt) + if (min_valid > array_n_args) { msg (SE, _("For %s with %d arguments, at most %d (not %d) may be " "required to be valid."), - f->prototype, arg_cnt, array_arg_cnt, min_valid); + f->prototype, n_args, array_n_args, min_valid); return false; } } @@ -1188,26 +1188,26 @@ validate_function_args (const struct operation *f, int arg_cnt, int min_valid) } static void -add_arg (union any_node ***args, int *arg_cnt, int *arg_cap, +add_arg (union any_node ***args, int *n_args, int *allocated_args, union any_node *arg) { - if (*arg_cnt >= *arg_cap) + if (*n_args >= *allocated_args) { - *arg_cap += 8; - *args = xrealloc (*args, sizeof **args * *arg_cap); + *allocated_args += 8; + *args = xrealloc (*args, sizeof **args * *allocated_args); } - (*args)[(*arg_cnt)++] = arg; + (*args)[(*n_args)++] = arg; } static void put_invocation (struct string *s, - const char *func_name, union any_node **args, size_t arg_cnt) + const char *func_name, union any_node **args, size_t n_args) { size_t i; ds_put_format (s, "%s(", func_name); - for (i = 0; i < arg_cnt; i++) + for (i = 0; i < n_args; i++) { if (i > 0) ds_put_cstr (s, ", "); @@ -1218,7 +1218,7 @@ put_invocation (struct string *s, static void no_match (const char *func_name, - union any_node **args, size_t arg_cnt, + union any_node **args, size_t n_args, const struct operation *first, const struct operation *last) { struct string s; @@ -1229,12 +1229,12 @@ no_match (const char *func_name, if (last - first == 1) { ds_put_format (&s, _("Type mismatch invoking %s as "), first->prototype); - put_invocation (&s, func_name, args, arg_cnt); + put_invocation (&s, func_name, args, n_args); } else { ds_put_cstr (&s, _("Function invocation ")); - put_invocation (&s, func_name, args, arg_cnt); + put_invocation (&s, func_name, args, n_args); ds_put_cstr (&s, _(" does not match any known function. Candidates are:")); for (f = first; f < last; f++) @@ -1254,8 +1254,8 @@ parse_function (struct lexer *lexer, struct expression *e) const struct operation *f, *first, *last; union any_node **args = NULL; - int arg_cnt = 0; - int arg_cap = 0; + int n_args = 0; + int allocated_args = 0; struct string func_name; @@ -1278,7 +1278,7 @@ parse_function (struct lexer *lexer, struct expression *e) } args = NULL; - arg_cnt = arg_cap = 0; + n_args = allocated_args = 0; if (lex_token (lexer) != T_RPAREN) for (;;) { @@ -1286,13 +1286,13 @@ parse_function (struct lexer *lexer, struct expression *e) && lex_next_token (lexer, 1) == T_TO) { const struct variable **vars; - size_t var_cnt; + size_t n_vars; size_t i; - if (!parse_variables_const (lexer, dataset_dict (e->ds), &vars, &var_cnt, PV_SINGLE)) + if (!parse_variables_const (lexer, dataset_dict (e->ds), &vars, &n_vars, PV_SINGLE)) goto fail; - for (i = 0; i < var_cnt; i++) - add_arg (&args, &arg_cnt, &arg_cap, + for (i = 0; i < n_vars; i++) + add_arg (&args, &n_args, &allocated_args, allocate_unary_variable (e, vars[i])); free (vars); } @@ -1302,7 +1302,7 @@ parse_function (struct lexer *lexer, struct expression *e) if (arg == NULL) goto fail; - add_arg (&args, &arg_cnt, &arg_cap, arg); + add_arg (&args, &n_args, &allocated_args, arg); } if (lex_match (lexer, T_RPAREN)) break; @@ -1314,16 +1314,16 @@ parse_function (struct lexer *lexer, struct expression *e) } for (f = first; f < last; f++) - if (match_function (args, arg_cnt, f)) + if (match_function (args, n_args, f)) break; if (f >= last) { - no_match (ds_cstr (&func_name), args, arg_cnt, first, last); + no_match (ds_cstr (&func_name), args, n_args, first, last); goto fail; } - coerce_function_args (e, f, args, arg_cnt); - if (!validate_function_args (f, arg_cnt, min_valid)) + coerce_function_args (e, f, args, n_args); + if (!validate_function_args (f, n_args, min_valid)) goto fail; if ((f->flags & OPF_EXTENSION) && settings_get_syntax () == COMPATIBLE) @@ -1341,7 +1341,7 @@ parse_function (struct lexer *lexer, struct expression *e) goto fail; } - n = expr_allocate_composite (e, f - operations, args, arg_cnt); + n = expr_allocate_composite (e, f - operations, args, n_args); n->composite.min_valid = min_valid != -1 ? min_valid : f->array_min_elems; if (n->type == OP_LAG_Vn || n->type == OP_LAG_Vs) @@ -1349,7 +1349,7 @@ parse_function (struct lexer *lexer, struct expression *e) else if (n->type == OP_LAG_Vnn || n->type == OP_LAG_Vsn) { int n_before; - assert (n->composite.arg_cnt == 2); + assert (n->composite.n_args == 2); assert (n->composite.args[1]->type == OP_pos_int); n_before = n->composite.args[1]->integer.i; dataset_need_lag (e->ds, n_before); @@ -1377,7 +1377,7 @@ expr_create (struct dataset *ds) e->eval_pool = pool_create_subpool (e->expr_pool); e->ops = NULL; e->op_types = NULL; - e->op_cnt = e->op_cap = 0; + e->n_ops = e->allocated_ops = 0; return e; } @@ -1439,14 +1439,14 @@ is_valid_node (union any_node *n) struct composite_node *c = &n->composite; assert (is_composite (n->type)); - assert (c->arg_cnt >= op->arg_cnt); - for (i = 0; i < op->arg_cnt; i++) + assert (c->n_args >= op->n_args); + for (i = 0; i < op->n_args; i++) assert (is_compatible (op->args[i], expr_node_returns (c->args[i]))); - if (c->arg_cnt > op->arg_cnt && !is_operator (n->type)) + if (c->n_args > op->n_args && !is_operator (n->type)) { assert (op->flags & OPF_ARRAY_OPERAND); - for (i = 0; i < c->arg_cnt; i++) - assert (is_compatible (op->args[op->arg_cnt - 1], + for (i = 0; i < c->n_args; i++) + assert (is_compatible (op->args[op->n_args - 1], expr_node_returns (c->args[i]))); } } @@ -1456,23 +1456,23 @@ is_valid_node (union any_node *n) union any_node * expr_allocate_composite (struct expression *e, operation_type op, - union any_node **args, size_t arg_cnt) + union any_node **args, size_t n_args) { union any_node *n; size_t i; n = pool_alloc (e->expr_pool, sizeof n->composite); n->type = op; - n->composite.arg_cnt = arg_cnt; + n->composite.n_args = n_args; n->composite.args = pool_alloc (e->expr_pool, - sizeof *n->composite.args * arg_cnt); - for (i = 0; i < arg_cnt; i++) + sizeof *n->composite.args * n_args); + for (i = 0; i < n_args; i++) { if (args[i] == NULL) return NULL; n->composite.args[i] = args[i]; } - memcpy (n->composite.args, args, sizeof *n->composite.args * arg_cnt); + memcpy (n->composite.args, args, sizeof *n->composite.args * n_args); n->composite.min_valid = 0; assert (is_valid_node (n)); return n; @@ -1569,15 +1569,15 @@ allocate_unary_variable (struct expression *e, const struct variable *v) const struct operation * expr_get_function (size_t idx) { - assert (idx < OP_function_cnt); + assert (idx < n_OP_function); return &operations[OP_function_first + idx]; } /* Returns the number of expression functions. */ size_t -expr_get_function_cnt (void) +expr_get_n_functions (void) { - return OP_function_cnt; + return n_OP_function; } /* Returns the name of operation OP. */ @@ -1596,7 +1596,7 @@ expr_operation_get_prototype (const struct operation *op) /* Returns the number of arguments for operation OP. */ int -expr_operation_get_arg_cnt (const struct operation *op) +expr_operation_get_n_args (const struct operation *op) { - return op->arg_cnt; + return op->n_args; } diff --git a/src/language/expressions/private.h b/src/language/expressions/private.h index 92adef85b3..3cf7a2c732 100644 --- a/src/language/expressions/private.h +++ b/src/language/expressions/private.h @@ -72,7 +72,7 @@ struct operation const char *prototype; enum operation_flags flags; atom_type returns; - int arg_cnt; + int n_args; atom_type args[EXPR_ARG_MAX]; int array_min_elems; int array_granularity; @@ -123,9 +123,9 @@ struct format_node struct composite_node { operation_type type; /* One of OP_*. */ - size_t arg_cnt; /* Number of arguments. */ - union any_node **args; /* Arguments. */ - size_t min_valid; /* Min valid array args to get valid result. */ + size_t n_args; /* Number of arguments. */ + union any_node **args; /* Arguments. */ + size_t min_valid; /* Min valid array args to get valid result. */ }; /* Any node. */ @@ -161,7 +161,7 @@ struct expression union operation_data *ops; /* Expression data. */ operation_type *op_types; /* ops[] element types (for debugging). */ - size_t op_cnt, op_cap; /* Number of ops, amount of allocated space. */ + size_t n_ops, allocated_ops; /* Number of ops, amount of allocated space. */ double *number_stack; /* Evaluation stack: numerics, Booleans. */ struct substring *string_stack; /* Evaluation stack: strings. */ diff --git a/src/language/expressions/public.h b/src/language/expressions/public.h index 1059713065..a4313a40c0 100644 --- a/src/language/expressions/public.h +++ b/src/language/expressions/public.h @@ -45,9 +45,9 @@ void expr_evaluate_str (struct expression *, const struct ccase *, int case_idx, char *dst, size_t dst_size); const struct operation *expr_get_function (size_t idx); -size_t expr_get_function_cnt (void); +size_t expr_get_n_functions (void); const char *expr_operation_get_name (const struct operation *); const char *expr_operation_get_prototype (const struct operation *); -int expr_operation_get_arg_cnt (const struct operation *); +int expr_operation_get_n_args (const struct operation *); #endif /* expr.h */ diff --git a/src/language/lexer/command-name.c b/src/language/lexer/command-name.c index 24443a0995..eae0b43b39 100644 --- a/src/language/lexer/command-name.c +++ b/src/language/lexer/command-name.c @@ -132,7 +132,7 @@ command_match (struct substring command, struct substring string, // Try each possible command. command_matcher_init (&cm, string); - for (cmd = commands; cmd < &commands[command_cnt]; cmd++) + for (cmd = commands; cmd < &commands[n_commands]; cmd++) command_matcher_add (&cm, cmd->name, cmd); // Get the result. diff --git a/src/language/lexer/variable-parser.c b/src/language/lexer/variable-parser.c index 3b6b96ad0e..942e2db56e 100644 --- a/src/language/lexer/variable-parser.c +++ b/src/language/lexer/variable-parser.c @@ -138,7 +138,7 @@ parse_variables (struct lexer *lexer, const struct dictionary *d, assert (cnt != NULL); vs = var_set_create_from_dict (d); - if (var_set_get_cnt (vs) == 0) + if (var_set_get_n (vs) == 0) { *cnt = 0; var_set_destroy (vs); @@ -151,13 +151,13 @@ parse_variables (struct lexer *lexer, const struct dictionary *d, /* 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 true only if + number of variables into *N_VARS. Returns true only if successful. Same behavior as parse_variables, except that all allocations are taken from the given POOL. */ bool parse_variables_pool (struct lexer *lexer, struct pool *pool, const struct dictionary *dict, - struct variable ***vars, size_t *var_cnt, int opts) + struct variable ***vars, size_t *n_vars, int opts) { int retval; @@ -167,7 +167,7 @@ parse_variables_pool (struct lexer *lexer, struct pool *pool, later. */ assert (!(opts & PV_APPEND)); - retval = parse_variables (lexer, dict, vars, var_cnt, opts); + retval = parse_variables (lexer, dict, vars, n_vars, opts); if (retval) pool_register (pool, free, *vars); return retval; @@ -295,7 +295,7 @@ parse_var_set_vars (struct lexer *lexer, const struct var_set *vs, { size_t i; - included = xcalloc (var_set_get_cnt (vs), sizeof *included); + included = xcalloc (var_set_get_n (vs), sizeof *included); for (i = 0; i < *nv; i++) { size_t index; @@ -311,7 +311,7 @@ parse_var_set_vars (struct lexer *lexer, const struct var_set *vs, { if (lex_match (lexer, T_ALL)) add_variables (v, nv, &mv, included, pv_opts, - vs, 0, var_set_get_cnt (vs) - 1, DC_ORDINARY); + vs, 0, var_set_get_n (vs) - 1, DC_ORDINARY); else { enum dict_class class; @@ -830,7 +830,7 @@ error: struct var_set { bool names_must_be_ids; - size_t (*get_cnt) (const struct var_set *); + size_t (*get_n) (const struct var_set *); struct variable *(*get_var) (const struct var_set *, size_t idx); bool (*lookup_var_idx) (const struct var_set *, const char *, size_t *); void (*destroy) (struct var_set *); @@ -839,11 +839,11 @@ struct var_set /* Returns the number of variables in VS. */ size_t -var_set_get_cnt (const struct var_set *vs) +var_set_get_n (const struct var_set *vs) { assert (vs != NULL); - return vs->get_cnt (vs); + return vs->get_n (vs); } /* Return variable with index IDX in VS. @@ -852,7 +852,7 @@ static struct variable * var_set_get_var (const struct var_set *vs, size_t idx) { assert (vs != NULL); - assert (idx < var_set_get_cnt (vs)); + assert (idx < var_set_get_n (vs)); return vs->get_var (vs, idx); } @@ -896,11 +896,11 @@ var_set_get_names_must_be_ids (const struct var_set *vs) /* Returns the number of variables in VS. */ static size_t -dict_var_set_get_cnt (const struct var_set *vs) +dict_var_set_get_n (const struct var_set *vs) { struct dictionary *d = vs->aux; - return dict_get_var_cnt (d); + return dict_get_n_vars (d); } /* Return variable with index IDX in VS. @@ -943,7 +943,7 @@ var_set_create_from_dict (const struct dictionary *d) { struct var_set *vs = xmalloc (sizeof *vs); vs->names_must_be_ids = dict_get_names_must_be_ids (d); - vs->get_cnt = dict_var_set_get_cnt; + vs->get_n = dict_var_set_get_n; vs->get_var = dict_var_set_get_var; vs->lookup_var_idx = dict_var_set_lookup_var_idx; vs->destroy = dict_var_set_destroy; @@ -955,17 +955,17 @@ var_set_create_from_dict (const struct dictionary *d) struct array_var_set { struct variable *const *var;/* Array of variables. */ - size_t var_cnt; /* Number of elements in var. */ + size_t n_vars; /* Number of elements in var. */ struct hmapx vars_by_name; /* Variables hashed by name. */ }; /* Returns the number of variables in VS. */ static size_t -array_var_set_get_cnt (const struct var_set *vs) +array_var_set_get_n (const struct var_set *vs) { struct array_var_set *avs = vs->aux; - return avs->var_cnt; + return avs->n_vars; } /* Return variable with index IDX in VS. @@ -1010,9 +1010,9 @@ array_var_set_destroy (struct var_set *vs) free (vs); } -/* Returns a variable set based on the VAR_CNT variables in VAR. */ +/* Returns a variable set based on the N_VARS variables in VAR. */ struct var_set * -var_set_create_from_array (struct variable *const *var, size_t var_cnt) +var_set_create_from_array (struct variable *const *var, size_t n_vars) { struct var_set *vs; struct array_var_set *avs; @@ -1020,15 +1020,15 @@ var_set_create_from_array (struct variable *const *var, size_t var_cnt) vs = xmalloc (sizeof *vs); vs->names_must_be_ids = true; - vs->get_cnt = array_var_set_get_cnt; + vs->get_n = array_var_set_get_n; vs->get_var = array_var_set_get_var; vs->lookup_var_idx = array_var_set_lookup_var_idx; vs->destroy = array_var_set_destroy; vs->aux = avs = xmalloc (sizeof *avs); avs->var = var; - avs->var_cnt = var_cnt; + avs->n_vars = n_vars; hmapx_init (&avs->vars_by_name); - for (i = 0; i < var_cnt; i++) + for (i = 0; i < n_vars; i++) { const char *name = var_get_name (var[i]); size_t idx; diff --git a/src/language/lexer/variable-parser.h b/src/language/lexer/variable-parser.h index 5ccb7b3d7f..c2a8506464 100644 --- a/src/language/lexer/variable-parser.h +++ b/src/language/lexer/variable-parser.h @@ -31,7 +31,7 @@ struct var_set *var_set_create_from_dict (const struct dictionary *d); struct var_set *var_set_create_from_array (struct variable *const *var, size_t); -size_t var_set_get_cnt (const struct var_set *vs); +size_t var_set_get_n (const struct var_set *vs); void var_set_destroy (struct var_set *vs); diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index 86e11e07d7..9815f1e25a 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -129,13 +129,13 @@ struct agr_proc /* Break variables. */ struct subcase sort; /* Sort criteria (break variables). */ const struct variable **break_vars; /* Break variables. */ - size_t break_var_cnt; /* Number of break variables. */ + size_t break_n_vars; /* Number of break variables. */ enum missing_treatment missing; /* How to treat missing values. */ struct agr_var *agr_vars; /* First aggregate variable. */ struct dictionary *dict; /* Aggregate dictionary. */ const struct dictionary *src_dict; /* Dict of the source */ - int case_cnt; /* Counts aggregated cases. */ + int n_cases; /* Counts aggregated cases. */ bool add_variables; /* True iff the aggregated variables should be appended to the existing dictionary */ @@ -241,10 +241,10 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds) if (!parse_sort_criteria (lexer, dict, &agr.sort, &agr.break_vars, &saw_direction)) goto error; - agr.break_var_cnt = subcase_get_n_fields (&agr.sort); + agr.break_n_vars = subcase_get_n_fields (&agr.sort); if (! agr.add_variables) - for (i = 0; i < agr.break_var_cnt; i++) + for (i = 0; i < agr.break_n_vars; i++) dict_clone_var_assert (agr.dict, agr.break_vars[i]); /* BREAK must follow the options. */ @@ -272,7 +272,7 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds) dict_set_split_vars (agr.dict, NULL, 0); /* Initialize. */ - agr.case_cnt = 0; + agr.n_cases = 0; if (out_file == NULL) { @@ -297,7 +297,7 @@ cmd_aggregate (struct lexer *lexer, struct dataset *ds) } for (grouper = casegrouper_create_vars (input, agr.break_vars, - agr.break_var_cnt); + agr.break_n_vars); casegrouper_get_next_group (grouper, &group); casereader_destroy (group)) { @@ -935,14 +935,14 @@ dump_aggregate_info (const struct agr_proc *agr, struct casewriter *output, cons if (agr->add_variables) { - case_copy (c, 0, break_case, 0, dict_get_var_cnt (agr->src_dict)); + case_copy (c, 0, break_case, 0, dict_get_n_vars (agr->src_dict)); } else { int value_idx = 0; int i; - for (i = 0; i < agr->break_var_cnt; i++) + for (i = 0; i < agr->break_n_vars; i++) { const struct variable *v = agr->break_vars[i]; value_copy (case_data_rw_idx (c, value_idx), diff --git a/src/language/stats/descriptives.c b/src/language/stats/descriptives.c index eefd0598e3..819e836d0e 100644 --- a/src/language/stats/descriptives.c +++ b/src/language/stats/descriptives.c @@ -71,9 +71,9 @@ struct dsc_z_score struct dsc_trns { struct dsc_z_score *z_scores; /* Array of Z-scores. */ - int z_score_cnt; /* Number of Z-scores. */ + int n_z_scores; /* Number of Z-scores. */ const struct variable **vars; /* Variables for listwise missing checks. */ - size_t var_cnt; /* Number of variables. */ + size_t n_vars; /* Number of variables. */ enum dsc_missing_type missing_type; /* Treatment of missing values. */ enum mv_class exclude; /* Classes of missing values to exclude. */ const struct variable *filter; /* Dictionary FILTER BY variable. */ @@ -142,7 +142,7 @@ struct dsc_proc /* Per-variable info. */ struct dictionary *dict; /* Dictionary. */ struct dsc_var *vars; /* Variables. */ - size_t var_cnt; /* Number of variables. */ + size_t n_vars; /* Number of variables. */ /* User options. */ enum dsc_missing_type missing_type; /* Treatment of missing values. */ @@ -171,7 +171,7 @@ static bool try_name (const struct dictionary *dict, struct dsc_proc *dsc, const char *name); static char *generate_z_varname (const struct dictionary *dict, struct dsc_proc *dsc, - const char *name, int *z_cnt); + const char *name, int *n_zs); static void dump_z_table (struct dsc_proc *); static void setup_z_trns (struct dsc_proc *, struct dataset *); @@ -189,9 +189,9 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) struct dictionary *dict = dataset_dict (ds); struct dsc_proc *dsc; const struct variable **vars = NULL; - size_t var_cnt = 0; + size_t n_vars = 0; int save_z_scores = 0; - int z_cnt = 0; + int n_zs = 0; size_t i; bool ok; @@ -202,7 +202,7 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) dsc = xmalloc (sizeof *dsc); dsc->dict = dict; dsc->vars = NULL; - dsc->var_cnt = 0; + dsc->n_vars = 0; dsc->missing_type = DSC_VARIABLE; dsc->exclude = MV_ANY; dsc->missing_listwise = 0.; @@ -307,7 +307,7 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) goto error; } } - else if (var_cnt == 0) + else if (n_vars == 0) { if (lex_next_token (lexer, 1) == T_EQUALS) { @@ -319,19 +319,19 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) { int i; - if (!parse_variables_const (lexer, dict, &vars, &var_cnt, + if (!parse_variables_const (lexer, dict, &vars, &n_vars, PV_APPEND | PV_NO_DUPLICATE | PV_NUMERIC)) goto error; - dsc->vars = xnrealloc ((void *)dsc->vars, var_cnt, sizeof *dsc->vars); - for (i = dsc->var_cnt; i < var_cnt; i++) + dsc->vars = xnrealloc ((void *)dsc->vars, n_vars, sizeof *dsc->vars); + for (i = dsc->n_vars; i < n_vars; i++) { struct dsc_var *dv = &dsc->vars[i]; dv->v = vars[i]; dv->z_name = NULL; dv->moments = NULL; } - dsc->var_cnt = var_cnt; + dsc->n_vars = n_vars; if (lex_match (lexer, T_LPAREN)) { @@ -342,9 +342,9 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) } if (try_name (dict, dsc, lex_tokcstr (lexer))) { - struct dsc_var *dsc_var = &dsc->vars[dsc->var_cnt - 1]; + struct dsc_var *dsc_var = &dsc->vars[dsc->n_vars - 1]; dsc_var->z_name = xstrdup (lex_tokcstr (lexer)); - z_cnt++; + n_zs++; } else msg (SE, _("Z-score variable name %s would be" @@ -363,33 +363,33 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) lex_match (lexer, T_SLASH); } - if (var_cnt == 0) + if (n_vars == 0) { msg (SE, _("No variables specified.")); goto error; } /* Construct z-score varnames, show translation table. */ - if (z_cnt || save_z_scores) + if (n_zs || save_z_scores) { struct caseproto *proto; if (save_z_scores) { - int gen_cnt = 0; + int n_gens = 0; - for (i = 0; i < dsc->var_cnt; i++) + for (i = 0; i < dsc->n_vars; i++) { struct dsc_var *dsc_var = &dsc->vars[i]; if (dsc_var->z_name == NULL) { const char *name = var_get_name (dsc_var->v); dsc_var->z_name = generate_z_varname (dict, dsc, name, - &gen_cnt); + &n_gens); if (dsc_var->z_name == NULL) goto error; - z_cnt++; + n_zs++; } } } @@ -402,7 +402,7 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) "Temporary transformations will be made permanent.")); proto = caseproto_create (); - for (i = 0; i < 1 + 2 * z_cnt; i++) + for (i = 0; i < 1 + 2 * n_zs; i++) proto = caseproto_add_width (proto, 0); dsc->z_writer = autopaging_writer_create (proto); caseproto_unref (proto); @@ -418,7 +418,7 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) /* Figure out which statistics to calculate. */ dsc->calc_stats = dsc->show_stats; - if (z_cnt > 0) + if (n_zs > 0) dsc->calc_stats |= (1ul << DSC_MEAN) | (1ul << DSC_STDDEV); if (dsc->sort_by_stat >= 0) dsc->calc_stats |= 1ul << dsc->sort_by_stat; @@ -434,7 +434,7 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) if (dsc->calc_stats & (1ul << i) && dsc_info[i].moment > dsc->max_moment) dsc->max_moment = dsc_info[i].moment; if (dsc->max_moment != MOMENT_NONE) - for (i = 0; i < dsc->var_cnt; i++) + for (i = 0; i < dsc->n_vars; i++) dsc->vars[i].moments = moments_create (dsc->max_moment); /* Data pass. */ @@ -445,7 +445,7 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds) ok = proc_commit (ds) && ok; /* Z-scoring! */ - if (ok && z_cnt) + if (ok && n_zs) setup_z_trns (dsc, ds); /* Done. */ @@ -490,7 +490,7 @@ free_dsc_proc (struct dsc_proc *dsc) if (dsc == NULL) return; - for (i = 0; i < dsc->var_cnt; i++) + for (i = 0; i < dsc->n_vars; i++) { struct dsc_var *dsc_var = &dsc->vars[i]; free (dsc_var->z_name); @@ -513,7 +513,7 @@ try_name (const struct dictionary *dict, struct dsc_proc *dsc, if (dict_lookup_var (dict, name) != NULL) return false; - for (i = 0; i < dsc->var_cnt; i++) + for (i = 0; i < dsc->n_vars; i++) { struct dsc_var *dsc_var = &dsc->vars[i]; if (dsc_var->z_name != NULL && !utf8_strcasecmp (dsc_var->z_name, name)) @@ -528,7 +528,7 @@ try_name (const struct dictionary *dict, struct dsc_proc *dsc, as a dynamically allocated string. On failure, returns NULL. */ static char * generate_z_varname (const struct dictionary *dict, struct dsc_proc *dsc, - const char *var_name, int *z_cnt) + const char *var_name, int *n_zs) { char *z_name, *trunc_name; @@ -546,16 +546,16 @@ generate_z_varname (const struct dictionary *dict, struct dsc_proc *dsc, { char name[16]; - (*z_cnt)++; + (*n_zs)++; - if (*z_cnt <= 99) - sprintf (name, "ZSC%03d", *z_cnt); - else if (*z_cnt <= 108) - sprintf (name, "STDZ%02d", *z_cnt - 99); - else if (*z_cnt <= 117) - sprintf (name, "ZZZZ%02d", *z_cnt - 108); - else if (*z_cnt <= 126) - sprintf (name, "ZQZQ%02d", *z_cnt - 117); + if (*n_zs <= 99) + sprintf (name, "ZSC%03d", *n_zs); + else if (*n_zs <= 108) + sprintf (name, "STDZ%02d", *n_zs - 99); + else if (*n_zs <= 117) + sprintf (name, "ZZZZ%02d", *n_zs - 108); + else if (*n_zs <= 126) + sprintf (name, "ZQZQ%02d", *n_zs - 117); else { msg (SE, _("Ran out of generic names for Z-score variables. " @@ -585,7 +585,7 @@ dump_z_table (struct dsc_proc *dsc) table, PIVOT_AXIS_ROW, N_("Variables")); names->hide_all_labels = true; - for (size_t i = 0; i < dsc->var_cnt; i++) + for (size_t i = 0; i < dsc->n_vars; i++) if (dsc->vars[i].z_name != NULL) { int row = pivot_category_create_leaf (names->root, @@ -605,7 +605,7 @@ descriptives_set_all_sysmis_zscores (const struct dsc_trns *t, struct ccase *c) { const struct dsc_z_score *z; - for (z = t->z_scores; z < t->z_scores + t->z_score_cnt; z++) + for (z = t->z_scores; z < t->z_scores + t->n_z_scores; z++) *case_num_rw (c, z->z_var) = SYSMIS; } @@ -645,7 +645,7 @@ descriptives_trns_proc (void *trns_, struct ccase **c, size_t z_idx = 0; t->count = case_num_idx (z_case, z_idx++); - for (z = t->z_scores; z < t->z_scores + t->z_score_cnt; z++) + for (z = t->z_scores; z < t->z_scores + t->n_z_scores; z++) { z->mean = case_num_idx (z_case, z_idx++); z->std_dev = case_num_idx (z_case, z_idx++); @@ -670,7 +670,7 @@ descriptives_trns_proc (void *trns_, struct ccase **c, if (t->missing_type == DSC_LISTWISE) { assert(t->vars); - for (vars = t->vars; vars < t->vars + t->var_cnt; vars++) + for (vars = t->vars; vars < t->vars + t->n_vars; vars++) { double score = case_num (*c, *vars); if (var_is_num_missing (*vars, score, t->exclude)) @@ -681,7 +681,7 @@ descriptives_trns_proc (void *trns_, struct ccase **c, } } - for (z = t->z_scores; z < t->z_scores + t->z_score_cnt; z++) + for (z = t->z_scores; z < t->z_scores + t->n_z_scores; z++) { double input = case_num (*c, z->src_var); double *output = case_num_rw (*c, z->z_var); @@ -718,25 +718,25 @@ setup_z_trns (struct dsc_proc *dsc, struct dataset *ds) struct dsc_trns *t; size_t cnt, i; - for (cnt = i = 0; i < dsc->var_cnt; i++) + for (cnt = i = 0; i < dsc->n_vars; i++) if (dsc->vars[i].z_name != NULL) cnt++; t = xmalloc (sizeof *t); t->z_scores = xnmalloc (cnt, sizeof *t->z_scores); - t->z_score_cnt = cnt; + t->n_z_scores = cnt; t->missing_type = dsc->missing_type; t->exclude = dsc->exclude; if (t->missing_type == DSC_LISTWISE) { - t->var_cnt = dsc->var_cnt; - t->vars = xnmalloc (t->var_cnt, sizeof *t->vars); - for (i = 0; i < t->var_cnt; i++) + t->n_vars = dsc->n_vars; + t->vars = xnmalloc (t->n_vars, sizeof *t->vars); + for (i = 0; i < t->n_vars; i++) t->vars[i] = dsc->vars[i].v; } else { - t->var_cnt = 0; + t->n_vars = 0; t->vars = NULL; } t->filter = dict_get_filter (dataset_dict (ds)); @@ -745,7 +745,7 @@ setup_z_trns (struct dsc_proc *dsc, struct dataset *ds) t->ok = true; dsc->z_writer = NULL; - for (cnt = i = 0; i < dsc->var_cnt; i++) + for (cnt = i = 0; i < dsc->n_vars; i++) { struct dsc_var *dv = &dsc->vars[i]; if (dv->z_name != NULL) @@ -802,7 +802,7 @@ calc_descriptives (struct dsc_proc *dsc, struct casereader *group, pass1 = group; pass2 = dsc->max_moment <= MOMENT_MEAN ? NULL : casereader_clone (pass1); - for (i = 0; i < dsc->var_cnt; i++) + for (i = 0; i < dsc->n_vars; i++) { struct dsc_var *dv = &dsc->vars[i]; @@ -837,7 +837,7 @@ calc_descriptives (struct dsc_proc *dsc, struct casereader *group, } dsc->valid += weight; - for (i = 0; i < dsc->var_cnt; i++) + for (i = 0; i < dsc->n_vars; i++) { struct dsc_var *dv = &dsc->vars[i]; double x = case_num (c, dv->v); @@ -883,7 +883,7 @@ calc_descriptives (struct dsc_proc *dsc, struct casereader *group, if (dsc->missing_type == DSC_LISTWISE && listwise_missing (dsc, c)) continue; - for (i = 0; i < dsc->var_cnt; i++) + for (i = 0; i < dsc->n_vars; i++) { struct dsc_var *dv = &dsc->vars[i]; double x = case_num (c, dv->v); @@ -909,7 +909,7 @@ calc_descriptives (struct dsc_proc *dsc, struct casereader *group, else c = NULL; - for (i = 0; i < dsc->var_cnt; i++) + for (i = 0; i < dsc->n_vars; i++) { struct dsc_var *dv = &dsc->vars[i]; double W; @@ -964,7 +964,7 @@ listwise_missing (struct dsc_proc *dsc, const struct ccase *c) { size_t i; - for (i = 0; i < dsc->var_cnt; i++) + for (i = 0; i < dsc->n_vars; i++) { struct dsc_var *dv = &dsc->vars[i]; double x = case_num (c, dv->v); @@ -997,12 +997,12 @@ display (struct dsc_proc *dsc) pivot_value_new_text (dsc_info[i].name)); if (dsc->sort_by_stat != DSC_NONE) - sort (dsc->vars, dsc->var_cnt, sizeof *dsc->vars, + sort (dsc->vars, dsc->n_vars, sizeof *dsc->vars, descriptives_compare_dsc_vars, dsc); struct pivot_dimension *variables = pivot_dimension_create ( table, PIVOT_AXIS_ROW, N_("Variable")); - for (size_t i = 0; i < dsc->var_cnt; i++) + for (size_t i = 0; i < dsc->n_vars; i++) { const struct dsc_var *dv = &dsc->vars[i]; diff --git a/src/language/stats/examine.c b/src/language/stats/examine.c index 1b668c2b77..bb77e9010a 100644 --- a/src/language/stats/examine.c +++ b/src/language/stats/examine.c @@ -1134,7 +1134,7 @@ calculate_n (const void *aux1, void *aux2 UNUSED, void *user_data) es[v].sorted_reader = casewriter_make_reader (es[v].sorted_writer); es[v].sorted_writer = NULL; - imax = casereader_get_case_cnt (es[v].sorted_reader); + imax = casereader_get_n_cases (es[v].sorted_reader); es[v].maxima = pool_calloc (examine->pool, examine->calc_extremes, sizeof (*es[v].maxima)); es[v].minima = pool_calloc (examine->pool, examine->calc_extremes, sizeof (*es[v].minima)); @@ -1371,7 +1371,7 @@ run_examine (struct examine *cmd, struct casereader *input) { struct ccase *c = casereader_peek (input, 0); - cmd->id_idx = case_get_value_cnt (c); + cmd->id_idx = case_get_n_values (c); input = casereader_create_arithmetic_sequence (input, 1.0, 1.0); case_unref (c); diff --git a/src/language/stats/matrix.c b/src/language/stats/matrix.c index b1ec91474d..64d8dd92f8 100644 --- a/src/language/stats/matrix.c +++ b/src/language/stats/matrix.c @@ -6148,7 +6148,7 @@ save_file_open (struct save_file *sf, gsl_matrix *m, struct stringi_set strings; stringi_set_clone (&strings, &sf->strings); - for (size_t i = 0; dict_get_var_cnt (dict) < m->size2; i++) + for (size_t i = 0; dict_get_n_vars (dict) < m->size2; i++) { char tmp_name[64]; const char *name; @@ -7431,7 +7431,7 @@ matrix_get_execute__ (struct matrix_command *cmd, struct casereader *reader, } else { - n_vars = dict_get_var_cnt (dict); + n_vars = dict_get_n_vars (dict); vars = xnmalloc (n_vars, sizeof *vars); for (size_t i = 0; i < n_vars; i++) { @@ -7545,7 +7545,7 @@ matrix_open_casereader (const struct matrix_command *cmd, } else { - if (dict_get_var_cnt (dataset_dict (dataset)) == 0) + if (dict_get_n_vars (dataset_dict (dataset)) == 0) { msg_at (ME, cmd->location, _("The %s command cannot read an empty active file."), @@ -8286,13 +8286,13 @@ matrix_mget_execute__ (struct matrix_command *cmd, struct casereader *r, _("ROWTYPE_ must precede VARNAME_ in matrix data file.")); return; } - if (var_get_dict_index (varname_) + 1 >= dict_get_var_cnt (d)) + if (var_get_dict_index (varname_) + 1 >= dict_get_n_vars (d)) { msg_at (SE, loc, _("Matrix data file contains no continuous variables.")); return; } - for (size_t i = 0; i < dict_get_var_cnt (d); i++) + for (size_t i = 0; i < dict_get_n_vars (d); i++) { const struct variable *v = dict_get_var (d, i); if (v != rowtype_ && v != varname_ && var_get_width (v) != 0) @@ -8318,7 +8318,7 @@ matrix_mget_execute__ (struct matrix_command *cmd, struct casereader *r, /* Continuous variables. */ size_t cs = var_get_dict_index (varname_) + 1; - size_t cn = dict_get_var_cnt (d) - cs; + size_t cn = dict_get_n_vars (d) - cs; struct ccase *cc = NULL; /* Pivot table. */ diff --git a/src/language/stats/rank.c b/src/language/stats/rank.c index ba7cde6183..ecf9a65914 100644 --- a/src/language/stats/rank.c +++ b/src/language/stats/rank.c @@ -1032,11 +1032,11 @@ rank_cmd (struct dataset *ds, const struct rank *cmd) subcase_add_vars_always (&projection, cmd->group_vars, cmd->n_group_vars); subcase_add_vars_always (&projection, dict_get_split_vars (d), - dict_get_split_cnt (d)); + dict_get_n_splits (d)); if (weight_var != NULL) { subcase_add_var_always (&projection, weight_var, SC_ASCEND); - weight_idx = 2 + cmd->n_group_vars + dict_get_split_cnt (d); + weight_idx = 2 + cmd->n_group_vars + dict_get_n_splits (d); } else weight_idx = -1; @@ -1057,7 +1057,7 @@ rank_cmd (struct dataset *ds, const struct rank *cmd) /* Group by split variables */ subcase_init_empty (&split_vars); - for (j = 0; j < dict_get_split_cnt (d); j++) + for (j = 0; j < dict_get_n_splits (d); j++) subcase_add_always (&split_vars, 2 + j + cmd->n_group_vars, var_get_width (dict_get_split_vars (d)[j]), SC_ASCEND); diff --git a/src/language/stats/roc.c b/src/language/stats/roc.c index 1a4fcba657..5a891dacd8 100644 --- a/src/language/stats/roc.c +++ b/src/language/stats/roc.c @@ -335,7 +335,7 @@ dump_casereader (struct casereader *reader) for (; (c = casereader_read (r)); case_unref (c)) { int i; - for (i = 0 ; i < case_get_value_cnt (c); ++i) + for (i = 0 ; i < case_get_n_values (c); ++i) printf ("%g ", case_num_idx (c, i)); printf ("\n"); } diff --git a/src/language/stats/sort-criteria.c b/src/language/stats/sort-criteria.c index 965e7d09dd..36466cd410 100644 --- a/src/language/stats/sort-criteria.c +++ b/src/language/stats/sort-criteria.c @@ -42,7 +42,7 @@ parse_sort_criteria (struct lexer *lexer, const struct dictionary *dict, const struct variable ***vars, bool *saw_direction) { const struct variable **local_vars = NULL; - size_t var_cnt = 0; + size_t n_vars = 0; if (vars == NULL) vars = &local_vars; @@ -53,12 +53,12 @@ parse_sort_criteria (struct lexer *lexer, const struct dictionary *dict, do { - size_t prev_var_cnt = var_cnt; + size_t prev_n_vars = n_vars; enum subcase_direction direction; size_t i; /* Variables. */ - if (!parse_variables_const (lexer, dict, vars, &var_cnt, + if (!parse_variables_const (lexer, dict, vars, &n_vars, PV_APPEND | PV_NO_SCRATCH)) goto error; @@ -82,7 +82,7 @@ parse_sort_criteria (struct lexer *lexer, const struct dictionary *dict, else direction = SC_ASCEND; - for (i = prev_var_cnt; i < var_cnt; i++) + for (i = prev_n_vars; i < n_vars; i++) { const struct variable *var = (*vars)[i]; if (!subcase_add_var (ordering, var, direction)) diff --git a/src/language/tests/float-format.c b/src/language/tests/float-format.c index b7a428b104..e1d91168b0 100644 --- a/src/language/tests/float-format.c +++ b/src/language/tests/float-format.c @@ -61,7 +61,7 @@ static const struct assoc fp_formats[] = {"X", FLOAT_HEX}, {"FP", FLOAT_FP}, }; -static const size_t format_cnt = sizeof fp_formats / sizeof *fp_formats; +static const size_t n_formats = sizeof fp_formats / sizeof *fp_formats; /* Parses a floating-point format name into *FORMAT, and returns success. */ @@ -70,7 +70,7 @@ parse_float_format (struct lexer *lexer, enum float_format *format) { size_t i; - for (i = 0; i < format_cnt; i++) + for (i = 0; i < n_formats; i++) if (lex_match_id (lexer, fp_formats[i].name)) { *format = fp_formats[i].format; @@ -86,7 +86,7 @@ get_float_format_name (enum float_format format) { size_t i; - for (i = 0; i < format_cnt; i++) + for (i = 0; i < n_formats; i++) if (fp_formats[i].format == format) return fp_formats[i].name; @@ -275,26 +275,26 @@ int cmd_debug_float_format (struct lexer *lexer, struct dataset *ds UNUSED) { struct fp fp[16]; - size_t fp_cnt = 0; + size_t n_fps = 0; bool bijective = false; bool ok; for (;;) { - if (fp_cnt >= sizeof fp / sizeof *fp) + if (n_fps >= sizeof fp / sizeof *fp) { msg (SE, "Too many values in single command."); return CMD_FAILURE; } - if (!parse_fp (lexer, &fp[fp_cnt++])) + if (!parse_fp (lexer, &fp[n_fps++])) return CMD_FAILURE; - if (lex_token (lexer) == T_ENDCMD && fp_cnt > 1) + if (lex_token (lexer) == T_ENDCMD && n_fps > 1) break; else if (!lex_force_match (lexer, T_EQUALS)) return CMD_FAILURE; - if (fp_cnt == 1) + if (n_fps == 1) { if (lex_match (lexer, T_EQUALS)) bijective = true; @@ -319,8 +319,8 @@ cmd_debug_float_format (struct lexer *lexer, struct dataset *ds UNUSED) { size_t i, j; - for (i = 0; i < fp_cnt; i++) - for (j = 0; j < fp_cnt; j++) + for (i = 0; i < n_fps; i++) + for (j = 0; j < n_fps; j++) if (!verify_conversion (&fp[i], &fp[j])) ok = false; } @@ -328,7 +328,7 @@ cmd_debug_float_format (struct lexer *lexer, struct dataset *ds UNUSED) { size_t i; - for (i = 1; i < fp_cnt; i++) + for (i = 1; i < n_fps; i++) if (!verify_conversion (&fp[i - 1], &fp[i])) ok = false; } diff --git a/src/language/xforms/compute.c b/src/language/xforms/compute.c index 8e0ce85d61..9193dbc71e 100644 --- a/src/language/xforms/compute.c +++ b/src/language/xforms/compute.c @@ -156,7 +156,7 @@ compute_num_vec (void *compute_, struct ccase **c, casenumber case_num) index = expr_evaluate_num (compute->element, *c, case_num); rindx = floor (index + EPSILON); if (index == SYSMIS - || rindx < 1 || rindx > vector_get_var_cnt (compute->vector)) + || rindx < 1 || rindx > vector_get_n_vars (compute->vector)) { if (index == SYSMIS) msg (SW, _("When executing COMPUTE: SYSMIS is not a valid value " @@ -219,7 +219,7 @@ compute_str_vec (void *compute_, struct ccase **c, casenumber case_num) vector_get_name (compute->vector)); return TRNS_CONTINUE; } - else if (rindx < 1 || rindx > vector_get_var_cnt (compute->vector)) + else if (rindx < 1 || rindx > vector_get_n_vars (compute->vector)) { msg (SW, _("When executing COMPUTE: %.*g is not a valid value as " "an index into vector %s."), diff --git a/src/language/xforms/count.c b/src/language/xforms/count.c index 1f35045290..0369af1e5d 100644 --- a/src/language/xforms/count.c +++ b/src/language/xforms/count.c @@ -58,14 +58,14 @@ struct criteria /* Variables to count. */ const struct variable **vars; - size_t var_cnt; + size_t n_vars; /* Count special values? */ bool count_system_missing; /* Count system missing? */ bool count_user_missing; /* Count user missing? */ /* Criterion values. */ - size_t value_cnt; + size_t n_values; union { struct num_value *num; @@ -142,7 +142,7 @@ cmd_count (struct lexer *lexer, struct dataset *ds) crit->next = NULL; crit->vars = NULL; if (!parse_variables_const (lexer, dict, &crit->vars, - &crit->var_cnt, + &crit->n_vars, PV_DUPLICATE | PV_SAME_TYPE)) goto fail; pool_register (trns->pool, free, crit->vars); @@ -150,7 +150,7 @@ cmd_count (struct lexer *lexer, struct dataset *ds) if (!lex_force_match (lexer, T_LPAREN)) goto fail; - crit->value_cnt = 0; + crit->n_values = 0; if (var_is_numeric (crit->vars[0])) ok = parse_numeric_criteria (lexer, trns->pool, crit); else @@ -214,11 +214,11 @@ parse_numeric_criteria (struct lexer *lexer, struct pool *pool, struct criteria { struct num_value *cur; - if (crit->value_cnt >= allocated) + if (crit->n_values >= allocated) crit->values.num = pool_2nrealloc (pool, crit->values.num, &allocated, sizeof *crit->values.num); - cur = &crit->values.num[crit->value_cnt++]; + cur = &crit->values.num[crit->n_values++]; cur->type = low == high ? CNT_SINGLE : CNT_RANGE; cur->a = low; cur->b = high; @@ -242,7 +242,7 @@ parse_string_criteria (struct lexer *lexer, struct pool *pool, size_t allocated = 0; size_t i; - for (i = 0; i < crit->var_cnt; i++) + for (i = 0; i < crit->n_vars; i++) if (var_get_width (crit->vars[i]) > len) len = var_get_width (crit->vars[i]); @@ -252,7 +252,7 @@ parse_string_criteria (struct lexer *lexer, struct pool *pool, char **cur; char *s; - if (crit->value_cnt >= allocated) + if (crit->n_values >= allocated) crit->values.str = pool_2nrealloc (pool, crit->values.str, &allocated, sizeof *crit->values.str); @@ -263,7 +263,7 @@ parse_string_criteria (struct lexer *lexer, struct pool *pool, s = recode_string (dict_encoding, "UTF-8", lex_tokcstr (lexer), ss_length (lex_tokss (lexer))); - cur = &crit->values.str[crit->value_cnt++]; + cur = &crit->values.str[crit->n_values++]; *cur = pool_alloc (pool, len + 1); str_copy_rpad (*cur, len + 1, s); lex_get (lexer); @@ -287,12 +287,12 @@ count_numeric (struct criteria *crit, const struct ccase *c) int counter = 0; size_t i; - for (i = 0; i < crit->var_cnt; i++) + for (i = 0; i < crit->n_vars; i++) { double x = case_num (c, crit->vars[i]); struct num_value *v; - for (v = crit->values.num; v < crit->values.num + crit->value_cnt; + for (v = crit->values.num; v < crit->values.num + crit->n_values; v++) if (v->type == CNT_SINGLE ? x == v->a : x >= v->a && x <= v->b) { @@ -321,10 +321,10 @@ count_string (struct criteria *crit, const struct ccase *c) int counter = 0; size_t i; - for (i = 0; i < crit->var_cnt; i++) + for (i = 0; i < crit->n_vars; i++) { char **v; - for (v = crit->values.str; v < crit->values.str + crit->value_cnt; v++) + for (v = crit->values.str; v < crit->values.str + crit->n_values; v++) if (!memcmp (case_str (c, crit->vars[i]), *v, var_get_width (crit->vars[i]))) { diff --git a/src/language/xforms/recode.c b/src/language/xforms/recode.c index f1834cc8a5..a2d963188a 100644 --- a/src/language/xforms/recode.c +++ b/src/language/xforms/recode.c @@ -94,11 +94,11 @@ struct recode_trns const struct variable **dst_vars; /* Destination variables. */ const struct dictionary *dst_dict; /* Dictionary of dst_vars */ char **dst_names; /* Name of dest variables, if they're new. */ - size_t var_cnt; /* Number of variables. */ + size_t n_vars; /* Number of variables. */ /* Mappings. */ struct mapping *mappings; /* Value mappings. */ - size_t map_cnt; /* Number of mappings. */ + size_t n_maps; /* Number of mappings. */ int max_src_width; /* Maximum width of src_vars[*]. */ int max_dst_width; /* Maximum width of any map_out in mappings. */ }; @@ -182,13 +182,13 @@ cmd_recode (struct lexer *lexer, struct dataset *ds) } /* Parses a set of variables to recode into TRNS->src_vars and - TRNS->var_cnt. Sets TRNS->src_type. Returns true if + TRNS->n_vars. Sets TRNS->src_type. Returns true if successful, false on parse error. */ static bool parse_src_vars (struct lexer *lexer, struct recode_trns *trns, const struct dictionary *dict) { - if (!parse_variables_const (lexer, dict, &trns->src_vars, &trns->var_cnt, + if (!parse_variables_const (lexer, dict, &trns->src_vars, &trns->n_vars, PV_SAME_TYPE)) return false; pool_register (trns->pool, free, trns->src_vars); @@ -197,7 +197,7 @@ parse_src_vars (struct lexer *lexer, } /* Parses a set of mappings, which take the form (input=output), - into TRNS->mappings and TRNS->map_cnt. Sets TRNS->dst_type. + into TRNS->mappings and TRNS->n_maps. Sets TRNS->dst_type. Returns true if successful, false on parse error. */ static bool parse_mappings (struct lexer *lexer, struct recode_trns *trns, @@ -209,7 +209,7 @@ parse_mappings (struct lexer *lexer, struct recode_trns *trns, /* Find length of longest source variable. */ trns->max_src_width = var_get_width (trns->src_vars[0]); - for (i = 1; i < trns->var_cnt; i++) + for (i = 1; i < trns->n_vars; i++) { size_t var_width = var_get_width (trns->src_vars[i]); if (var_width > trns->max_src_width) @@ -218,7 +218,7 @@ parse_mappings (struct lexer *lexer, struct recode_trns *trns, /* Parse the mappings in parentheses. */ trns->mappings = NULL; - trns->map_cnt = 0; + trns->n_maps = 0; map_allocated = 0; have_dst_type = false; if (!lex_force_match (lexer, T_LPAREN)) @@ -233,7 +233,7 @@ parse_mappings (struct lexer *lexer, struct recode_trns *trns, size_t first_map_idx; size_t i; - first_map_idx = trns->map_cnt; + first_map_idx = trns->n_maps; /* Parse source specifications. */ do @@ -264,7 +264,7 @@ parse_mappings (struct lexer *lexer, struct recode_trns *trns, return false; } - for (i = first_map_idx; i < trns->map_cnt; i++) + for (i = first_map_idx; i < trns->n_maps; i++) trns->mappings[i].out = out; } else @@ -273,7 +273,7 @@ parse_mappings (struct lexer *lexer, struct recode_trns *trns, struct map_in in; set_map_in_generic (&in, MAP_CONVERT); add_mapping (trns, &map_allocated, &in); - set_map_out_num (&trns->mappings[trns->map_cnt - 1].out, 0.0); + set_map_out_num (&trns->mappings[trns->n_maps - 1].out, 0.0); dst_type = VAL_NUMERIC; if (trns->src_type != VAL_STRING @@ -353,11 +353,11 @@ add_mapping (struct recode_trns *trns, size_t *map_allocated, const struct map_in *in) { struct mapping *m; - if (trns->map_cnt >= *map_allocated) + if (trns->n_maps >= *map_allocated) trns->mappings = pool_2nrealloc (trns->pool, trns->mappings, map_allocated, sizeof *trns->mappings); - m = &trns->mappings[trns->map_cnt++]; + m = &trns->mappings[trns->n_maps++]; m->in = *in; } @@ -466,26 +466,26 @@ parse_dst_vars (struct lexer *lexer, struct recode_trns *trns, if (lex_match_id (lexer, "INTO")) { - size_t name_cnt; + size_t n_names; size_t i; if (!parse_mixed_vars_pool (lexer, dict, trns->pool, - &trns->dst_names, &name_cnt, + &trns->dst_names, &n_names, PV_NONE)) return false; - if (name_cnt != trns->var_cnt) + if (n_names != trns->n_vars) { msg (SE, _("%zu variable(s) cannot be recoded into " "%zu variable(s). Specify the same number " "of variables as source and target variables."), - trns->var_cnt, name_cnt); + trns->n_vars, n_names); return false; } trns->dst_vars = pool_nalloc (trns->pool, - trns->var_cnt, sizeof *trns->dst_vars); - for (i = 0; i < trns->var_cnt; i++) + trns->n_vars, sizeof *trns->dst_vars); + for (i = 0; i < trns->n_vars; i++) { const struct variable *v; v = trns->dst_vars[i] = dict_lookup_var (dict, trns->dst_names[i]); @@ -515,7 +515,7 @@ parse_dst_vars (struct lexer *lexer, struct recode_trns *trns, } } - for (i = 0; i < trns->var_cnt; i++) + for (i = 0; i < trns->n_vars; i++) { const struct variable *v = trns->dst_vars[i]; if (v != NULL && var_get_type (v) != trns->dst_type) @@ -542,7 +542,7 @@ enlarge_dst_widths (struct recode_trns *trns) int min_dst_width = INT_MAX; trns->max_dst_width = 0; - for (i = 0; i < trns->var_cnt; i++) + for (i = 0; i < trns->n_vars; i++) { const struct variable *v = trns->dst_vars[i]; if (var_get_width (v) > trns->max_dst_width) @@ -555,7 +555,7 @@ enlarge_dst_widths (struct recode_trns *trns) } } - for (i = 0; i < trns->map_cnt; i++) + for (i = 0; i < trns->n_maps; i++) { struct map_out *out = &trns->mappings[i].out; if (!out->copy_input) @@ -582,7 +582,7 @@ create_dst_vars (struct recode_trns *trns, struct dictionary *dict) { size_t i; - for (i = 0; i < trns->var_cnt; i++) + for (i = 0; i < trns->n_vars; i++) { const struct variable **var = &trns->dst_vars[i]; const char *name = trns->dst_names[i]; @@ -603,7 +603,7 @@ find_src_numeric (struct recode_trns *trns, double value, const struct variable { struct mapping *m; - for (m = trns->mappings; m < trns->mappings + trns->map_cnt; m++) + for (m = trns->mappings; m < trns->mappings + trns->n_maps; m++) { const struct map_in *in = &m->in; const struct map_out *out = &m->out; @@ -647,7 +647,7 @@ find_src_string (struct recode_trns *trns, const uint8_t *value, int width = var_get_width (src_var); struct mapping *m; - for (m = trns->mappings; m < trns->mappings + trns->map_cnt; m++) + for (m = trns->mappings; m < trns->mappings + trns->n_maps; m++) { const struct map_in *in = &m->in; struct map_out *out = &m->out; @@ -697,7 +697,7 @@ recode_trns_proc (void *trns_, struct ccase **c, casenumber case_idx UNUSED) size_t i; *c = case_unshare (*c); - for (i = 0; i < trns->var_cnt; i++) + for (i = 0; i < trns->n_vars; i++) { const struct variable *src_var = trns->src_vars[i]; const struct variable *dst_var = trns->dst_vars[i]; diff --git a/src/libpspp/array.c b/src/libpspp/array.c index 376bd681db..9ae278027b 100644 --- a/src/libpspp/array.c +++ b/src/libpspp/array.c @@ -129,17 +129,17 @@ count_equal (const void *array, size_t count, size_t size, algo_compare_func *compare, const void *aux) { const char *first = array; - size_t equal_cnt = 0; + size_t n_equals = 0; while (count-- > 0) { if (compare (element, first, aux) == 0) - equal_cnt++; + n_equals++; first += size; } - return equal_cnt; + return n_equals; } /* Counts and return the number of elements in ARRAY, which @@ -151,17 +151,17 @@ count_if (const void *array, size_t count, size_t size, algo_predicate_func *predicate, const void *aux) { const char *first = array; - size_t true_cnt = 0; + size_t n_trues = 0; while (count-- > 0) { if (predicate (first, aux) != 0) - true_cnt++; + n_trues++; first += size; } - return true_cnt; + return n_trues; } /* Byte-wise swap objects A and B, each SIZE bytes. */ @@ -229,9 +229,9 @@ size_t partition (void *array, size_t count, size_t size, algo_predicate_func *predicate, const void *aux) { - size_t true_cnt = count; + size_t n_trues = count; char *first = array; - char *last = first + true_cnt * size; + char *last = first + n_trues * size; for (;;) { @@ -246,7 +246,7 @@ partition (void *array, size_t count, size_t size, first += size; } - true_cnt--; + n_trues--; /* Move LAST backward to point to last element that passes PREDICATE. */ @@ -259,7 +259,7 @@ partition (void *array, size_t count, size_t size, else if (predicate (last, aux)) break; else - true_cnt--; + n_trues--; } /* By swapping FIRST and LAST we extend the starting and @@ -270,8 +270,8 @@ partition (void *array, size_t count, size_t size, } done: - assert (is_partitioned (array, count, size, true_cnt, predicate, aux)); - return true_cnt; + assert (is_partitioned (array, count, size, n_trues, predicate, aux)); + return n_trues; } /* Checks whether ARRAY, which contains COUNT elements of SIZE @@ -280,17 +280,17 @@ partition (void *array, size_t count, size_t size, elements. AUX is passed as auxiliary data to PREDICATE. */ bool is_partitioned (const void *array, size_t count, size_t size, - size_t true_cnt, + size_t n_trues, algo_predicate_func *predicate, const void *aux) { const char *first = array; size_t idx; - assert (true_cnt <= count); - for (idx = 0; idx < true_cnt; idx++) + assert (n_trues <= count); + for (idx = 0; idx < n_trues; idx++) if (predicate (first + idx * size, aux) == 0) return false; - for (idx = true_cnt; idx < count; idx++) + for (idx = n_trues; idx < count; idx++) if (predicate (first + idx * size, aux) != 0) return false; return true; @@ -308,7 +308,7 @@ copy_if (const void *array, size_t count, size_t size, const char *input = array; const char *last = input + size * count; char *output = result; - size_t nonzero_cnt = 0; + size_t n_nonzeros = 0; while (input < last) { @@ -316,16 +316,16 @@ copy_if (const void *array, size_t count, size_t size, { memcpy (output, input, size); output += size; - nonzero_cnt++; + n_nonzeros++; } input += size; } - assert (nonzero_cnt == count_if (array, count, size, predicate, aux)); - assert (nonzero_cnt == count_if (result, nonzero_cnt, size, predicate, aux)); + assert (n_nonzeros == count_if (array, count, size, predicate, aux)); + assert (n_nonzeros == count_if (result, n_nonzeros, size, predicate, aux)); - return nonzero_cnt; + return n_nonzeros; } /* Removes N elements starting at IDX from ARRAY, which consists diff --git a/src/libpspp/array.h b/src/libpspp/array.h index 968fb56579..eab98dcaa9 100644 --- a/src/libpspp/array.h +++ b/src/libpspp/array.h @@ -96,7 +96,7 @@ size_t partition (void *array, size_t count, size_t size, for the first TRUE_CNT elements and zero for the remaining elements. AUX is passed as auxiliary data to PREDICATE. */ bool is_partitioned (const void *array, size_t count, size_t size, - size_t true_cnt, + size_t n_trues, algo_predicate_func *predicate, const void *aux); /* Randomly reorders ARRAY, which contains COUNT elements of SIZE diff --git a/src/libpspp/deque.c b/src/libpspp/deque.c index 732f09da82..a511cf3ad0 100644 --- a/src/libpspp/deque.c +++ b/src/libpspp/deque.c @@ -60,15 +60,15 @@ deque_expand (struct deque *deque, void *old_data_, size_t elem_size) size_t new_capacity = MAX (4, old_capacity * 2); char *old_data = old_data_; char *new_data = xnmalloc (new_capacity, elem_size); - size_t idx, copy_cnt; - for (idx = deque->back; idx != deque->front; idx += copy_cnt) + size_t idx, n_copy; + for (idx = deque->back; idx != deque->front; idx += n_copy) { size_t can_copy = old_capacity - (idx & (old_capacity - 1)); size_t want_copy = deque->front - idx; - copy_cnt = MIN (can_copy, want_copy); + n_copy = MIN (can_copy, want_copy); memcpy (new_data + (idx & (new_capacity - 1)) * elem_size, old_data + (idx & (old_capacity - 1)) * elem_size, - copy_cnt * elem_size); + n_copy * elem_size); } deque->capacity = new_capacity; free (old_data); diff --git a/src/libpspp/float-format.c b/src/libpspp/float-format.c index 623d299ca6..80924e8315 100644 --- a/src/libpspp/float-format.c +++ b/src/libpspp/float-format.c @@ -167,22 +167,22 @@ float_identify (double expected_value, const void *number, size_t length, FLOAT_Z_SHORT, FLOAT_Z_LONG, }; - const size_t candidate_cnt = sizeof candidates / sizeof *candidates; + const size_t n_candidates = sizeof candidates / sizeof *candidates; enum float_format *p; - int match_cnt; + int n_matches; - match_cnt = 0; - for (p = candidates; p < candidates + candidate_cnt; p++) + n_matches = 0; + for (p = candidates; p < candidates + n_candidates; p++) if (float_get_size (*p) == length) { char tmp[8]; assert (sizeof tmp >= float_get_size (*p)); float_convert (FLOAT_NATIVE_DOUBLE, &expected_value, *p, tmp); - if (!memcmp (tmp, number, length) && match_cnt++ == 0) + if (!memcmp (tmp, number, length) && n_matches++ == 0) *best_guess = *p; } - return match_cnt; + return n_matches; } /* Returns the double value that is just greater than -DBL_MAX, diff --git a/src/libpspp/ll.c b/src/libpspp/ll.c index 619adfac24..887b58039e 100644 --- a/src/libpspp/ll.c +++ b/src/libpspp/ll.c @@ -434,7 +434,7 @@ void ll_sort (struct ll *r0, struct ll *r1, ll_compare_func *compare, void *aux) { struct ll *pre_r0; - size_t output_run_cnt; + size_t output_run_len; if (r0 == r1 || ll_next (r0) == r1) return; @@ -443,7 +443,7 @@ ll_sort (struct ll *r0, struct ll *r1, ll_compare_func *compare, void *aux) do { struct ll *a0 = ll_next (pre_r0); - for (output_run_cnt = 1; ; output_run_cnt++) + for (output_run_len = 1; ; output_run_len++) { struct ll *a1 = ll_find_run (a0, r1, compare, aux); struct ll *a2 = ll_find_run (a1, r1, compare, aux); @@ -453,7 +453,7 @@ ll_sort (struct ll *r0, struct ll *r1, ll_compare_func *compare, void *aux) a0 = ll_merge (a0, a1, a1, a2, compare, aux); } } - while (output_run_cnt > 1); + while (output_run_len > 1); } /* Finds the extent of a run of nodes of increasing value diff --git a/src/libpspp/llx.c b/src/libpspp/llx.c index 43704e314e..eb4e5d400f 100644 --- a/src/libpspp/llx.c +++ b/src/libpspp/llx.c @@ -493,7 +493,7 @@ void llx_sort (struct llx *r0, struct llx *r1, llx_compare_func *compare, void *aux) { struct llx *pre_r0; - size_t output_run_cnt; + size_t output_run_len; if (r0 == r1 || llx_next (r0) == r1) return; @@ -502,7 +502,7 @@ llx_sort (struct llx *r0, struct llx *r1, llx_compare_func *compare, void *aux) do { struct llx *a0 = llx_next (pre_r0); - for (output_run_cnt = 1; ; output_run_cnt++) + for (output_run_len = 1; ; output_run_len++) { struct llx *a1 = llx_find_run (a0, r1, compare, aux); struct llx *a2 = llx_find_run (a1, r1, compare, aux); @@ -512,7 +512,7 @@ llx_sort (struct llx *r0, struct llx *r1, llx_compare_func *compare, void *aux) a0 = llx_merge (a0, a1, a1, a2, compare, aux); } } - while (output_run_cnt > 1); + while (output_run_len > 1); } /* Finds the extent of a run of nodes of increasing value diff --git a/src/libpspp/str.c b/src/libpspp/str.c index b40cb4b4ab..3c09490250 100644 --- a/src/libpspp/str.c +++ b/src/libpspp/str.c @@ -144,9 +144,9 @@ buf_copy_str_lpad (char *dst, size_t dst_size, const char *src, char pad) memcpy (dst, src, dst_size); else { - size_t pad_cnt = dst_size - src_len; - memset (&dst[0], pad, pad_cnt); - memcpy (dst + pad_cnt, src, src_len); + size_t n_pad = dst_size - src_len; + memset (&dst[0], pad, n_pad); + memcpy (dst + n_pad, src, src_len); } } diff --git a/src/math/merge.c b/src/math/merge.c index b5745ceeea..c9ef201e88 100644 --- a/src/math/merge.c +++ b/src/math/merge.c @@ -43,7 +43,7 @@ struct merge { struct subcase ordering; struct merge_input inputs[MAX_MERGE_ORDER]; - size_t input_cnt; + size_t n_inputs; struct caseproto *proto; }; @@ -54,7 +54,7 @@ merge_create (const struct subcase *ordering, const struct caseproto *proto) { struct merge *m = xmalloc (sizeof *m); subcase_clone (&m->ordering, ordering); - m->input_cnt = 0; + m->n_inputs = 0; m->proto = caseproto_ref (proto); return m; } @@ -67,7 +67,7 @@ merge_destroy (struct merge *m) size_t i; subcase_destroy (&m->ordering); - for (i = 0; i < m->input_cnt; i++) + for (i = 0; i < m->n_inputs; i++) casereader_destroy (m->inputs[i].reader); caseproto_unref (m->proto); free (m); @@ -78,8 +78,8 @@ void merge_append (struct merge *m, struct casereader *r) { r = casereader_rename (r); - m->inputs[m->input_cnt++].reader = r; - if (m->input_cnt >= MAX_MERGE_ORDER) + m->inputs[m->n_inputs++].reader = r; + if (m->n_inputs >= MAX_MERGE_ORDER) do_merge (m); } @@ -88,15 +88,15 @@ merge_make_reader (struct merge *m) { struct casereader *r = NULL; - if (m->input_cnt > 1) + if (m->n_inputs > 1) do_merge (m); - if (m->input_cnt == 1) + if (m->n_inputs == 1) { r = m->inputs[0].reader; - m->input_cnt = 0; + m->n_inputs = 0; } - else if (m->input_cnt == 0) + else if (m->n_inputs == 0) { struct casewriter *writer = mem_writer_create (m->proto); r = casewriter_make_reader (writer); @@ -118,8 +118,8 @@ read_input_case (struct merge *m, size_t idx) else { casereader_destroy (i->reader); - remove_element (m->inputs, m->input_cnt, sizeof *m->inputs, idx); - m->input_cnt--; + remove_element (m->inputs, m->n_inputs, sizeof *m->inputs, idx); + m->n_inputs--; return false; } } @@ -130,22 +130,22 @@ do_merge (struct merge *m) struct casewriter *w; size_t i; - assert (m->input_cnt > 1); + assert (m->n_inputs > 1); w = tmpfile_writer_create (m->proto); - for (i = 0; i < m->input_cnt; i++) + for (i = 0; i < m->n_inputs; i++) taint_propagate (casereader_get_taint (m->inputs[i].reader), casewriter_get_taint (w)); - for (i = 0; i < m->input_cnt;) + for (i = 0; i < m->n_inputs;) if (read_input_case (m, i)) i++; - while (m->input_cnt > 0) + while (m->n_inputs > 0) { size_t min; min = 0; - for (i = 1; i < m->input_cnt; i++) + for (i = 1; i < m->n_inputs; i++) if (subcase_compare_3way (&m->ordering, m->inputs[i].c, &m->ordering, m->inputs[min].c) < 0) min = i; @@ -154,7 +154,7 @@ do_merge (struct merge *m) read_input_case (m, min); } - m->input_cnt = 1; + m->n_inputs = 1; m->inputs[0].reader = casewriter_make_reader (w); } diff --git a/src/math/sort.c b/src/math/sort.c index 88aab2e3f9..a784960420 100644 --- a/src/math/sort.c +++ b/src/math/sort.c @@ -197,9 +197,9 @@ struct pqueue { struct subcase ordering; struct pqueue_record *records; - size_t record_cnt; /* Current number of records. */ - size_t record_cap; /* Space currently allocated for records. */ - size_t record_max; /* Max space we are willing to allocate. */ + size_t n_records; /* Current number of records. */ + size_t allocated_records; /* Space currently allocated for records. */ + size_t max_records; /* Max space we are willing to allocate. */ casenumber idx; }; @@ -220,13 +220,13 @@ pqueue_create (const struct subcase *ordering, const struct caseproto *proto) pq = xmalloc (sizeof *pq); subcase_clone (&pq->ordering, ordering); - pq->record_max = settings_get_workspace_cases (proto); - if (pq->record_max > max_buffers) - pq->record_max = max_buffers; - else if (pq->record_max < min_buffers) - pq->record_max = min_buffers; - pq->record_cnt = 0; - pq->record_cap = 0; + pq->max_records = settings_get_workspace_cases (proto); + if (pq->max_records > max_buffers) + pq->max_records = max_buffers; + else if (pq->max_records < min_buffers) + pq->max_records = min_buffers; + pq->n_records = 0; + pq->allocated_records = 0; pq->records = NULL; pq->idx = 0; @@ -253,13 +253,13 @@ pqueue_destroy (struct pqueue *pq) static bool pqueue_is_full (const struct pqueue *pq) { - return pq->record_cnt >= pq->record_max; + return pq->n_records >= pq->max_records; } static bool pqueue_is_empty (const struct pqueue *pq) { - return pq->record_cnt == 0; + return pq->n_records == 0; } static void @@ -269,23 +269,23 @@ pqueue_push (struct pqueue *pq, struct ccase *c, casenumber id) assert (!pqueue_is_full (pq)); - if (pq->record_cnt >= pq->record_cap) + if (pq->n_records >= pq->allocated_records) { - pq->record_cap = pq->record_cap * 2; - if (pq->record_cap < 16) - pq->record_cap = 16; - else if (pq->record_cap > pq->record_max) - pq->record_cap = pq->record_max; + pq->allocated_records = pq->allocated_records * 2; + if (pq->allocated_records < 16) + pq->allocated_records = 16; + else if (pq->allocated_records > pq->max_records) + pq->allocated_records = pq->max_records; pq->records = xrealloc (pq->records, - pq->record_cap * sizeof *pq->records); + pq->allocated_records * sizeof *pq->records); } - r = &pq->records[pq->record_cnt++]; + r = &pq->records[pq->n_records++]; r->id = id; r->c = c; r->idx = pq->idx++; - push_heap (pq->records, pq->record_cnt, sizeof *pq->records, + push_heap (pq->records, pq->n_records, sizeof *pq->records, compare_pqueue_records_minheap, pq); } @@ -296,10 +296,10 @@ pqueue_pop (struct pqueue *pq, casenumber *id) assert (!pqueue_is_empty (pq)); - pop_heap (pq->records, pq->record_cnt--, sizeof *pq->records, + pop_heap (pq->records, pq->n_records--, sizeof *pq->records, compare_pqueue_records_minheap, pq); - r = &pq->records[pq->record_cnt]; + r = &pq->records[pq->n_records]; *id = r->id; return r->c; } diff --git a/src/output/ascii.c b/src/output/ascii.c index a6bcb106d6..6535121d8c 100644 --- a/src/output/ascii.c +++ b/src/output/ascii.c @@ -310,8 +310,8 @@ struct ascii_driver bool error; /* Output error? */ struct u8_line *lines; /* Page content. */ int allocated_lines; /* Number of lines allocated. */ - int chart_cnt; /* Number of charts so far. */ - int object_cnt; /* Number of objects so far. */ + int n_charts; /* Number of charts so far. */ + int n_objects; /* Number of objects so far. */ const struct pivot_table *pt; struct render_params params; }; @@ -403,8 +403,8 @@ ascii_create (struct file_handle *fh, enum settings_output_devices device_type, a->error = false; a->lines = NULL; a->allocated_lines = 0; - a->chart_cnt = 0; - a->object_cnt = 0; + a->n_charts = 0; + a->n_objects = 0; static const struct render_ops ascii_render_ops = { .draw_line = ascii_draw_line, @@ -559,7 +559,7 @@ ascii_output_table_item (struct ascii_driver *a, layer_indexes); for (int i = 0; render_pager_has_next (p); i++) { - if (a->object_cnt++) + if (a->n_objects++) putc ('\n', a->file); ascii_output_lines (a, render_pager_draw_next (p, INT_MAX)); @@ -595,7 +595,7 @@ ascii_submit (struct output_driver *driver, const struct output_item *item) if (a->chart_file_name != NULL) { char *file_name = xr_write_png_image ( - item->image, a->chart_file_name, ++a->chart_cnt); + item->image, a->chart_file_name, ++a->n_charts); if (file_name != NULL) { struct output_item *text_item = text_item_create_nocopy ( @@ -614,7 +614,7 @@ ascii_submit (struct output_driver *driver, const struct output_item *item) if (a->chart_file_name != NULL) { char *file_name = xr_draw_png_chart ( - item->chart, a->chart_file_name, ++a->chart_cnt, &a->fg, &a->bg); + item->chart, a->chart_file_name, ++a->n_charts, &a->fg, &a->bg); if (file_name != NULL) { struct output_item *text_item = text_item_create_nocopy ( diff --git a/src/output/html.c b/src/output/html.c index 0546e5d3a2..a2e63f9438 100644 --- a/src/output/html.c +++ b/src/output/html.c @@ -61,7 +61,7 @@ struct html_driver char *chart_file_name; FILE *file; - size_t chart_cnt; + size_t n_charts; bool bare; bool css; @@ -192,7 +192,7 @@ html_create (struct file_handle *fh, enum settings_output_devices device_type, html->chart_file_name = parse_chart_file_name (opt (d, o, "charts", fh_get_file_name (fh))); html->file = NULL; - html->chart_cnt = 1; + html->n_charts = 1; html->bg = parse_color (opt (d, o, "background-color", "#FFFFFFFFFFFF")); html->fg = parse_color (opt (d, o, "foreground-color", "#000000000000")); html->file = fn_open (html->handle, "w"); @@ -257,7 +257,7 @@ html_submit__ (struct output_driver *driver, const struct output_item *item, { char *file_name = xr_draw_png_chart (item->chart, html->chart_file_name, - html->chart_cnt++, + html->n_charts++, &html->fg, &html->bg); if (file_name != NULL) { @@ -278,7 +278,7 @@ html_submit__ (struct output_driver *driver, const struct output_item *item, if (html->chart_file_name) { char *file_name = xr_write_png_image ( - item->image, html->chart_file_name, ++html->chart_cnt); + item->image, html->chart_file_name, ++html->n_charts); if (file_name != NULL) { fprintf (html->file, "", file_name); diff --git a/src/output/tex.c b/src/output/tex.c index 7a09c5eae6..de111ec13f 100644 --- a/src/output/tex.c +++ b/src/output/tex.c @@ -75,7 +75,7 @@ struct tex_driver char *chart_file_name; FILE *file; - size_t chart_cnt; + size_t n_charts; struct ll_list preamble_list; struct ll_list token_list; @@ -131,7 +131,7 @@ tex_create (struct file_handle *fh, enum settings_output_devices device_type, tex->handle = fh; tex->chart_file_name = parse_chart_file_name (opt (d, o, "charts", fh_get_file_name (fh))); - tex->chart_cnt = 1; + tex->n_charts = 1; tex->bg = parse_color (opt (d, o, "background-color", "#FFFFFFFFFFFF")); tex->fg = parse_color (opt (d, o, "foreground-color", "#000000000000")); @@ -323,7 +323,7 @@ tex_submit (struct output_driver *driver, const struct output_item *item) { char *file_name = xr_draw_png_chart (item->chart, tex->chart_file_name, - tex->chart_cnt++, + tex->n_charts++, &tex->fg, &tex->bg); if (file_name != NULL) { @@ -343,7 +343,7 @@ tex_submit (struct output_driver *driver, const struct output_item *item) case OUTPUT_ITEM_IMAGE: { char *file_name = xr_write_png_image ( - item->image, tex->chart_file_name, tex->chart_cnt++); + item->image, tex->chart_file_name, tex->n_charts++); if (file_name != NULL) { shipout (&tex->token_list, "\\includegraphics{%s}\n", file_name); diff --git a/src/ui/gui/executor.c b/src/ui/gui/executor.c index d6486ee4e7..6d5af138e8 100644 --- a/src/ui/gui/executor.c +++ b/src/ui/gui/executor.c @@ -95,7 +95,7 @@ execute_syntax (PsppireDataWindow *window, struct lex_reader *lex_reader) { const struct caseproto *proto; struct casereader *reader; - casenumber case_cnt; + casenumber n_cases; /* When the user executes a number of snippets of syntax in a row, none of which read from the active dataset, the GUI becomes @@ -111,8 +111,8 @@ execute_syntax (PsppireDataWindow *window, struct lex_reader *lex_reader) it is reused the next time syntax is run, without wrapping it in another layer. */ proto = psppire_data_store_get_proto (pdw->data_store); - case_cnt = psppire_data_store_get_case_count (pdw->data_store); - reader = lazy_casereader_create (proto, case_cnt, + n_cases = psppire_data_store_get_case_count (pdw->data_store); + reader = lazy_casereader_create (proto, n_cases, create_casereader_from_data_store, pdw->data_store, &pdw->lazy_serial); dataset_set_source (pdw->dataset, reader); diff --git a/src/ui/gui/psppire-data-store.c b/src/ui/gui/psppire-data-store.c index 4662978bd3..d9ae1418e2 100644 --- a/src/ui/gui/psppire-data-store.c +++ b/src/ui/gui/psppire-data-store.c @@ -98,7 +98,7 @@ __tree_model_get_n_columns (GtkTreeModel *tree_model) { PsppireDataStore *store = PSPPIRE_DATA_STORE (tree_model); - return psppire_dict_get_var_cnt (store->dict); + return psppire_dict_get_n_vars (store->dict); } @@ -134,11 +134,11 @@ psppire_data_store_string_to_value (GtkTreeModel *model, gint col, gint row, { PsppireDataStore *store = PSPPIRE_DATA_STORE (model); - while (col >= psppire_dict_get_var_cnt (store->dict)) + while (col >= psppire_dict_get_n_vars (store->dict)) { const struct variable *var = psppire_dict_insert_variable (store->dict, - psppire_dict_get_var_cnt (store->dict), + psppire_dict_get_n_vars (store->dict), NULL); g_return_val_if_fail (var, FALSE); } @@ -332,7 +332,7 @@ psppire_data_store_get_case_count (const PsppireDataStore *store) size_t psppire_data_store_get_value_count (const PsppireDataStore *store) { - return psppire_dict_get_value_cnt (store->dict); + return psppire_dict_get_n_values (store->dict); } const struct caseproto * diff --git a/src/ui/gui/psppire-data-window.c b/src/ui/gui/psppire-data-window.c index 9202aa4344..ad7e9250f7 100644 --- a/src/ui/gui/psppire-data-window.c +++ b/src/ui/gui/psppire-data-window.c @@ -214,7 +214,7 @@ on_split_change (PsppireDict *dict, gpointer data) { PsppireDataWindow *de = PSPPIRE_DATA_WINDOW (data); - size_t n_split_vars = dict_get_split_cnt (dict->dict); + size_t n_split_vars = dict_get_n_splits (dict->dict); GtkWidget *split_status_area = get_widget_assert (de->builder, "split-file-status-area"); @@ -899,7 +899,7 @@ set_unsaved (gpointer w) static void enable_save (PsppireDataWindow *dw) { - gboolean enable = psppire_dict_get_var_cnt (dw->dict) > 0; + gboolean enable = psppire_dict_get_n_vars (dw->dict) > 0; GAction *save_as = g_action_map_lookup_action (G_ACTION_MAP (dw), "save-as"); GAction *save = g_action_map_lookup_action (G_ACTION_MAP (dw), "save"); @@ -1920,7 +1920,7 @@ psppire_data_window_new (struct dataset *ds) bool psppire_data_window_is_empty (PsppireDataWindow *dw) { - return psppire_dict_get_var_cnt (dw->dict) == 0; + return psppire_dict_get_n_vars (dw->dict) == 0; } diff --git a/src/ui/gui/psppire-dialog-action-comments.c b/src/ui/gui/psppire-dialog-action-comments.c index 600ec89741..eeb512d949 100644 --- a/src/ui/gui/psppire-dialog-action-comments.c +++ b/src/ui/gui/psppire-dialog-action-comments.c @@ -114,7 +114,7 @@ retrieve_comments (PsppireDialogAction *pda) gtk_text_buffer_set_text (buffer, "", 0); - for (i = 0 ; i < dict_get_document_line_cnt (pda->dict->dict); ++i) + for (i = 0 ; i < dict_get_document_n_lines (pda->dict->dict); ++i) add_line_to_buffer (buffer, dict_get_document_line (pda->dict->dict, i)); } diff --git a/src/ui/gui/psppire-dialog-action-compute.c b/src/ui/gui/psppire-dialog-action-compute.c index a77ea92dd7..23c0108406 100644 --- a/src/ui/gui/psppire-dialog-action-compute.c +++ b/src/ui/gui/psppire-dialog-action-compute.c @@ -159,7 +159,7 @@ function_list_populate (GtkTreeView *tv) GtkTreeIter iter; gint i; - const gint n_funcs = expr_get_function_cnt (); + const gint n_funcs = expr_get_n_functions (); liststore = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INT); @@ -172,7 +172,7 @@ function_list_populate (GtkTreeView *tv) gtk_list_store_set (liststore, &iter, COMPUTE_COL_NAME, expr_operation_get_name (op), COMPUTE_COL_USAGE, expr_operation_get_prototype (op), - COMPUTE_COL_ARITY, expr_operation_get_arg_cnt (op), + COMPUTE_COL_ARITY, expr_operation_get_n_args (op), -1); } diff --git a/src/ui/gui/psppire-dialog-action-split.c b/src/ui/gui/psppire-dialog-action-split.c index b29d2b27da..65a322c14c 100644 --- a/src/ui/gui/psppire-dialog-action-split.c +++ b/src/ui/gui/psppire-dialog-action-split.c @@ -94,7 +94,7 @@ refresh (PsppireDialogAction *pda) GtkTreeModel *liststore = gtk_tree_view_get_model (GTK_TREE_VIEW (act->tv)); - gint n_vars = dict_get_split_cnt (pda->dict->dict); + gint n_vars = dict_get_n_splits (pda->dict->dict); gtk_list_store_clear (GTK_LIST_STORE (liststore)); diff --git a/src/ui/gui/psppire-dict.c b/src/ui/gui/psppire-dict.c index 9f95f440af..215a1d3e58 100644 --- a/src/ui/gui/psppire-dict.c +++ b/src/ui/gui/psppire-dict.c @@ -74,7 +74,7 @@ gni (GListModel *list) { PsppireDict *dict = PSPPIRE_DICT (list); - return psppire_dict_get_var_cnt (dict); + return psppire_dict_get_n_vars (dict); } static GType @@ -90,7 +90,7 @@ gi (GListModel *list, guint id) PsppireDict *dict = PSPPIRE_DICT (list); - if (id >= psppire_dict_get_var_cnt (dict)) + if (id >= psppire_dict_get_n_vars (dict)) { gtk_button_set_label (GTK_BUTTON (button), _("Var")); } @@ -345,8 +345,8 @@ psppire_dict_replace_dictionary (PsppireDict *dict, struct dictionary *d) struct dictionary *old_dict = dict->dict; - guint old_n = dict_get_var_cnt (dict->dict); - guint new_n = dict_get_var_cnt (d); + guint old_n = dict_get_n_vars (dict->dict); + guint new_n = dict_get_n_vars (d); dict->dict = dict_ref (d); dict_unref (old_dict); @@ -438,7 +438,7 @@ psppire_dict_delete_variables (PsppireDict *d, gint first, gint n) g_return_if_fail (d); g_return_if_fail (d->dict); g_return_if_fail (PSPPIRE_IS_DICT (d)); - size_t varcnt = dict_get_var_cnt (d->dict); + size_t varcnt = dict_get_n_vars (d->dict); g_return_if_fail (first < varcnt); g_return_if_fail (first >= 0); g_return_if_fail (n > 0); @@ -457,7 +457,7 @@ psppire_dict_set_name (PsppireDict* d, gint idx, const gchar *name) if (! dict_id_is_valid (d->dict, name, false)) return FALSE; - if (idx < dict_get_var_cnt (d->dict)) + if (idx < dict_get_n_vars (d->dict)) { /* This is an existing variable? */ struct variable * var = dict_get_var (d->dict, idx); @@ -483,7 +483,7 @@ psppire_dict_get_variable (const PsppireDict *d, gint idx) g_return_val_if_fail (d, NULL); g_return_val_if_fail (d->dict, NULL); - if (dict_get_var_cnt (d->dict) <= idx) + if (dict_get_n_vars (d->dict) <= idx) return NULL; return dict_get_var (d->dict, idx); @@ -492,18 +492,18 @@ psppire_dict_get_variable (const PsppireDict *d, gint idx) /* Return the number of variables in the dictionary */ gint -psppire_dict_get_var_cnt (const PsppireDict *d) +psppire_dict_get_n_vars (const PsppireDict *d) { g_return_val_if_fail (d, -1); g_return_val_if_fail (d->dict, -1); - return dict_get_var_cnt (d->dict); + return dict_get_n_vars (d->dict); } /* Return the number of `union value's in the dictionary */ size_t -psppire_dict_get_value_cnt (const PsppireDict *d) +psppire_dict_get_n_values (const PsppireDict *d) { g_return_val_if_fail (d, -1); g_return_val_if_fail (d->dict, -1); @@ -714,7 +714,7 @@ tree_model_get_iter (GtkTreeModel *model, GtkTreeIter *iter, GtkTreePath *path) n = indices [0]; - if (n < 0 || n >= psppire_dict_get_var_cnt (dict)) + if (n < 0 || n >= psppire_dict_get_n_vars (dict)) { iter->stamp = 0; iter->user_data = NULL; @@ -748,7 +748,7 @@ tree_model_iter_next (GtkTreeModel *model, GtkTreeIter *iter) idx = var_get_dict_index (var); - if (idx + 1 >= psppire_dict_get_var_cnt (dict)) + if (idx + 1 >= psppire_dict_get_n_vars (dict)) { iter->user_data = NULL; iter->stamp = 0; @@ -856,7 +856,7 @@ tree_model_n_children (GtkTreeModel *model, PsppireDict *dict = PSPPIRE_DICT (model); if (iter == NULL) - return psppire_dict_get_var_cnt (dict); + return psppire_dict_get_n_vars (dict); return 0; } @@ -874,7 +874,7 @@ tree_model_nth_child (GtkTreeModel *model, GtkTreeIter *iter, if (parent) return FALSE; - if (n >= psppire_dict_get_var_cnt (dict)) + if (n >= psppire_dict_get_n_vars (dict)) return FALSE; iter->stamp = dict->stamp; diff --git a/src/ui/gui/psppire-dict.h b/src/ui/gui/psppire-dict.h index 2ea7e0c1a6..76c3aa42e8 100644 --- a/src/ui/gui/psppire-dict.h +++ b/src/ui/gui/psppire-dict.h @@ -81,10 +81,10 @@ gboolean psppire_dict_set_name (PsppireDict* s, gint idx, const gchar *nam void psppire_dict_delete_var (PsppireDict *s, gint idx); /* Return the number of variables in the dictionary */ -gint psppire_dict_get_var_cnt (const PsppireDict *d); +gint psppire_dict_get_n_vars (const PsppireDict *d); /* Return the number of `union value's in the dictionary */ -size_t psppire_dict_get_value_cnt (const PsppireDict *d); +size_t psppire_dict_get_n_values (const PsppireDict *d); /* Returns the prototype for the cases that match the dictionary */ const struct caseproto *psppire_dict_get_proto (const PsppireDict *d); diff --git a/src/ui/gui/psppire-import-textfile.c b/src/ui/gui/psppire-import-textfile.c index d9dcccef28..af10780a93 100644 --- a/src/ui/gui/psppire-import-textfile.c +++ b/src/ui/gui/psppire-import-textfile.c @@ -420,8 +420,8 @@ intro_on_enter (PsppireImportAssistant *ia, GtkWidget *page, enum IMPORT_ASSISTA "preview purposes in the following screens. ", "Only the first %zu lines of the file will be shown for " "preview purposes in the following screens. ", - ia->text_file->line_cnt), - ia->text_file->line_cnt); + ia->text_file->n_lines), + ia->text_file->n_lines); } } @@ -750,7 +750,7 @@ my_advance (struct casereader *reader, void *aux, casenumber cnt) static struct casereader * textfile_create_reader (PsppireImportAssistant *ia) { - int n_vars = dict_get_var_cnt (ia->dict); + int n_vars = dict_get_n_vars (ia->dict); int i; @@ -824,7 +824,7 @@ ia_variable_changed_cb (GObject *obj, gint var_num, guint what, PsppireImportAssistant *ia = PSPPIRE_IMPORT_ASSISTANT (data); struct caseproto *proto = caseproto_create(); - for (int i = 0; i < dict_get_var_cnt (ia->dict); i++) + for (int i = 0; i < dict_get_n_vars (ia->dict); i++) { const struct variable *var = dict_get_var (ia->dict, i); int width = var_get_width (var); @@ -881,9 +881,9 @@ first_line_append_syntax (const PsppireImportAssistant *ia, struct string *s) static void apply_dict (const struct dictionary *dict, struct string *s) { - size_t var_cnt = dict_get_var_cnt (dict); + size_t n_vars = dict_get_n_vars (dict); - for (size_t i = 0; i < var_cnt; i++) + for (size_t i = 0; i < n_vars; i++) { struct variable *var = dict_get_var (dict, i); const char *name = var_get_name (var); @@ -972,22 +972,19 @@ intro_append_syntax (const PsppireImportAssistant *ia, struct string *s) static void formats_append_syntax (const PsppireImportAssistant *ia, struct string *s) { - int i; - int var_cnt; - g_return_if_fail (ia->dict); ds_put_cstr (s, " /VARIABLES=\n"); - var_cnt = dict_get_var_cnt (ia->dict); - for (i = 0; i < var_cnt; i++) + int n_vars = dict_get_n_vars (ia->dict); + for (int i = 0; i < n_vars; i++) { struct variable *var = dict_get_var (ia->dict, i); char format_string[FMT_STRING_LEN_MAX + 1]; fmt_to_string (var_get_print_format (var), format_string); ds_put_format (s, " %s %s%s\n", var_get_name (var), format_string, - i == var_cnt - 1 ? "." : ""); + i == n_vars - 1 ? "." : ""); } } diff --git a/src/ui/gui/psppire-text-file.c b/src/ui/gui/psppire-text-file.c index ea74fefee3..be66a2873e 100644 --- a/src/ui/gui/psppire-text-file.c +++ b/src/ui/gui/psppire-text-file.c @@ -60,7 +60,7 @@ read_lines (PsppireTextFile *tf) struct string input; ds_init_empty (&input); - for (tf->line_cnt = 0; tf->line_cnt < MAX_PREVIEW_LINES; tf->line_cnt++) + for (tf->n_lines = 0; tf->n_lines < MAX_PREVIEW_LINES; tf->n_lines++) { ds_clear (&input); if (!line_reader_read (reader, &input, MAX_LINE_LEN + 1) @@ -78,34 +78,34 @@ read_lines (PsppireTextFile *tf) "a text file."), tf->file_name, MAX_LINE_LEN); line_reader_close (reader); - for (i = 0; i < tf->line_cnt; i++) + for (i = 0; i < tf->n_lines; i++) g_free (tf->lines[i].string); - tf->line_cnt = 0; + tf->n_lines = 0; ds_destroy (&input); return; } - tf->lines[tf->line_cnt] + tf->lines[tf->n_lines] = recode_substring_pool ("UTF-8", line_reader_get_encoding (reader), input.ss, NULL); } ds_destroy (&input); - if (tf->line_cnt == 0) + if (tf->n_lines == 0) { int i; msg (ME, _("`%s' is empty."), tf->file_name); line_reader_close (reader); - for (i = 0; i < tf->line_cnt; i++) + for (i = 0; i < tf->n_lines; i++) g_free (tf->lines[i].string); - tf->line_cnt = 0; + tf->n_lines = 0; goto done; } - if (tf->line_cnt < MAX_PREVIEW_LINES) + if (tf->n_lines < MAX_PREVIEW_LINES) { - tf->total_lines = tf->line_cnt; + tf->total_lines = tf->n_lines; tf->total_is_exact = true; } else @@ -115,7 +115,7 @@ read_lines (PsppireTextFile *tf) off_t position = line_reader_tell (reader); if (fstat (line_reader_fileno (reader), &s) == 0 && position > 0) { - tf->total_lines = (double) tf->line_cnt / position * s.st_size; + tf->total_lines = (double) tf->n_lines / position * s.st_size; tf->total_is_exact = false; } else @@ -172,7 +172,7 @@ psppire_text_file_get_property (GObject *object, g_value_set_int (value, text_file->maximum_lines); break; case PROP_LINE_COUNT: - g_value_set_int (value, text_file->line_cnt); + g_value_set_int (value, text_file->n_lines); break; case PROP_FILE_NAME: g_value_set_string (value, text_file->file_name); @@ -205,7 +205,7 @@ __tree_get_iter (GtkTreeModel *tree_model, gint n = *indices; - if (n >= file->line_cnt) + if (n >= file->n_lines) return FALSE; iter->user_data = GINT_TO_POINTER (n); @@ -224,7 +224,7 @@ __tree_iter_next (GtkTreeModel *tree_model, gint n = GPOINTER_TO_INT (iter->user_data) + 1; - if (n >= file->line_cnt) + if (n >= file->n_lines) return FALSE; iter->user_data = GINT_TO_POINTER (n); @@ -287,7 +287,7 @@ __tree_model_iter_n_children (GtkTreeModel *tree_model, { PsppireTextFile *file = PSPPIRE_TEXT_FILE (tree_model); g_assert (iter == NULL); - return file->line_cnt; + return file->n_lines; } static GtkTreeModelFlags @@ -317,7 +317,7 @@ __iter_nth_child (GtkTreeModel *tree_model, g_return_val_if_fail (file, FALSE); - if (n >= file->line_cnt) + if (n >= file->n_lines) { iter->stamp = -1; iter->user_data = NULL; @@ -343,7 +343,7 @@ __get_value (GtkTreeModel *tree_model, gint n = GPOINTER_TO_INT (iter->user_data); - g_return_if_fail (n < file->line_cnt); + g_return_if_fail (n < file->n_lines); if (column == 0) { @@ -475,7 +475,7 @@ psppire_text_file_finalize (GObject *object) { PsppireTextFile *tf = PSPPIRE_TEXT_FILE (object); - for (int i = 0; i < tf->line_cnt; i++) + for (int i = 0; i < tf->n_lines; i++) g_free (tf->lines[i].string); g_free (tf->encoding); diff --git a/src/ui/gui/psppire-text-file.h b/src/ui/gui/psppire-text-file.h index 486cefb4cc..320b621b18 100644 --- a/src/ui/gui/psppire-text-file.h +++ b/src/ui/gui/psppire-text-file.h @@ -62,7 +62,7 @@ struct _PsppireTextFile /* The first several lines of the file. These copies which are UTF8 encoded, regardless of the file encoding. */ struct substring lines[MAX_PREVIEW_LINES]; - size_t line_cnt; + size_t n_lines; gulong total_lines; /* Number of lines in file. */ gboolean total_is_exact; /* Is total_lines exact (or an estimate)? */ diff --git a/src/ui/gui/psppire-variable-sheet.c b/src/ui/gui/psppire-variable-sheet.c index 859803f612..486d85c4ca 100644 --- a/src/ui/gui/psppire-variable-sheet.c +++ b/src/ui/gui/psppire-variable-sheet.c @@ -325,7 +325,7 @@ change_var_property (PsppireVariableSheet *var_sheet, gint col, gint row, const PsppireDict *dict = NULL; g_object_get (var_sheet, "data-model", &dict, NULL); - int n_rows = psppire_dict_get_var_cnt (dict); + int n_rows = psppire_dict_get_n_vars (dict); if (row > n_rows) return; diff --git a/tests/data/datasheet-test.c b/tests/data/datasheet-test.c index 1310f51337..09dc3d8e75 100644 --- a/tests/data/datasheet-test.c +++ b/tests/data/datasheet-test.c @@ -117,15 +117,15 @@ check_datasheet_casereader (struct mc *mc, struct casereader *reader, if (!check_caseproto (mc, proto, casereader_get_proto (reader), "casereader")) return; - else if (casereader_get_case_cnt (reader) != n_rows) + else if (casereader_get_n_cases (reader) != n_rows) { - if (casereader_get_case_cnt (reader) == CASENUMBER_MAX + if (casereader_get_n_cases (reader) == CASENUMBER_MAX && casereader_count_cases (reader) == n_rows) mc_error (mc, "datasheet casereader has unknown case count"); else mc_error (mc, "casereader row count (%lu) does not match " "expected (%zu)", - (unsigned long int) casereader_get_case_cnt (reader), + (unsigned long int) casereader_get_n_cases (reader), n_rows); } else diff --git a/tests/libpspp/abt-test.c b/tests/libpspp/abt-test.c index 1b0d00998b..7ba395c638 100644 --- a/tests/libpspp/abt-test.c +++ b/tests/libpspp/abt-test.c @@ -480,7 +480,7 @@ test_insert_any_remove_any (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int ins_perm_cnt; + unsigned int ins_n_perms; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -488,24 +488,24 @@ test_insert_any_remove_any (void) for (i = 0; i < cnt; i++) insertions[i] = i; - for (ins_perm_cnt = 0; - ins_perm_cnt == 0 || next_permutation (insertions, cnt); - ins_perm_cnt++) + for (ins_n_perms = 0; + ins_n_perms == 0 || next_permutation (insertions, cnt); + ins_n_perms++) { - unsigned int del_perm_cnt; + unsigned int del_n_perms; int i; for (i = 0; i < cnt; i++) deletions[i] = i; - for (del_perm_cnt = 0; - del_perm_cnt == 0 || next_permutation (deletions, cnt); - del_perm_cnt++) + for (del_n_perms = 0; + del_n_perms == 0 || next_permutation (deletions, cnt); + del_n_perms++) test_insert_delete (insertions, deletions, cnt); - check (del_perm_cnt == factorial (cnt)); + check (del_n_perms == factorial (cnt)); } - check (ins_perm_cnt == factorial (cnt)); + check (ins_n_perms == factorial (cnt)); free (insertions); free (deletions); @@ -524,18 +524,18 @@ test_insert_any_remove_same (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) test_insert_delete (values, values, cnt); - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); } @@ -553,7 +553,7 @@ test_insert_any_remove_reverse (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -561,16 +561,16 @@ test_insert_any_remove_reverse (void) for (i = 0; i < cnt; i++) insertions[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (insertions, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (insertions, cnt); + n_permutations++) { memcpy (deletions, insertions, sizeof *insertions * cnt); reverse (deletions, cnt); test_insert_delete (insertions, deletions, cnt); } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (insertions); free (deletions); @@ -681,7 +681,7 @@ test_changed (void) { int *values, *changed_values; struct element *elements; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); @@ -690,9 +690,9 @@ test_changed (void) for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) { for (i = 0; i < cnt; i++) { @@ -736,7 +736,7 @@ test_changed (void) } } } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); free (changed_values); diff --git a/tests/libpspp/bt-test.c b/tests/libpspp/bt-test.c index f9f0c9b3ea..b6922d5bf6 100644 --- a/tests/libpspp/bt-test.c +++ b/tests/libpspp/bt-test.c @@ -243,10 +243,10 @@ calculate_h_alpha (size_t n) 94906266, 134217728, 189812532, 268435456, 379625063, 536870912, 759250125, 1073741824, 1518500250, 2147483648, 3037000500, }; - size_t threshold_cnt = sizeof thresholds / sizeof *thresholds; + size_t n_thresholds = sizeof thresholds / sizeof *thresholds; size_t i; - for (i = 0; i < threshold_cnt; i++) + for (i = 0; i < n_thresholds; i++) if (thresholds[i] > n) break; return i - 1; @@ -381,7 +381,7 @@ test_insert_any_remove_any (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int ins_perm_cnt; + unsigned int ins_n_perms; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -389,24 +389,24 @@ test_insert_any_remove_any (void) for (i = 0; i < cnt; i++) insertions[i] = i; - for (ins_perm_cnt = 0; - ins_perm_cnt == 0 || next_permutation (insertions, cnt); - ins_perm_cnt++) + for (ins_n_perms = 0; + ins_n_perms == 0 || next_permutation (insertions, cnt); + ins_n_perms++) { - unsigned int del_perm_cnt; + unsigned int del_n_perms; int i; for (i = 0; i < cnt; i++) deletions[i] = i; - for (del_perm_cnt = 0; - del_perm_cnt == 0 || next_permutation (deletions, cnt); - del_perm_cnt++) + for (del_n_perms = 0; + del_n_perms == 0 || next_permutation (deletions, cnt); + del_n_perms++) test_insert_delete (insertions, deletions, cnt); - check (del_perm_cnt == factorial (cnt)); + check (del_n_perms == factorial (cnt)); } - check (ins_perm_cnt == factorial (cnt)); + check (ins_n_perms == factorial (cnt)); free (insertions); free (deletions); @@ -425,18 +425,18 @@ test_insert_any_remove_same (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) test_insert_delete (values, values, cnt); - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); } @@ -454,7 +454,7 @@ test_insert_any_remove_reverse (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -462,16 +462,16 @@ test_insert_any_remove_reverse (void) for (i = 0; i < cnt; i++) insertions[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (insertions, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (insertions, cnt); + n_permutations++) { memcpy (deletions, insertions, sizeof *insertions * cnt); reverse (deletions, cnt); test_insert_delete (insertions, deletions, cnt); } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (insertions); free (deletions); @@ -549,7 +549,7 @@ test_find_ge_le (void) for (inc_pat = 0; inc_pat < (1u << max_elems); inc_pat++) { struct bt bt; - int elem_cnt = 0; + int n_elems = 0; int i; /* Insert the values in the pattern into BT. */ @@ -557,11 +557,11 @@ test_find_ge_le (void) for (i = 0; i < max_elems; i++) if (inc_pat & (1u << i)) { - values[elem_cnt] = elements[elem_cnt].data = i; - check (bt_insert (&bt, &elements[elem_cnt].node) == NULL); - elem_cnt++; + values[n_elems] = elements[n_elems].data = i; + check (bt_insert (&bt, &elements[n_elems].node) == NULL); + n_elems++; } - check_bt (&bt, values, elem_cnt); + check_bt (&bt, values, n_elems); /* Try find_ge and find_le for each possible element value. */ for (i = -1; i <= max_elems; i++) @@ -571,7 +571,7 @@ test_find_ge_le (void) int j; ge = le = NULL; - for (j = 0; j < elem_cnt; j++) + for (j = 0; j < n_elems; j++) { if (ge == NULL && values[j] >= i) ge = &elements[j].node; @@ -635,7 +635,7 @@ test_changed (void) { int *values, *changed_values; struct element *elements; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); @@ -644,9 +644,9 @@ test_changed (void) for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) { for (i = 0; i < cnt; i++) { @@ -689,7 +689,7 @@ test_changed (void) } } } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); free (changed_values); diff --git a/tests/libpspp/heap-test.c b/tests/libpspp/heap-test.c index 639bf94002..8f4ce1600a 100644 --- a/tests/libpspp/heap-test.c +++ b/tests/libpspp/heap-test.c @@ -179,17 +179,17 @@ static unsigned int expected_perms (int *values, size_t cnt) { size_t i, j; - unsigned int perm_cnt; + unsigned int n_perms; - perm_cnt = factorial (cnt); + n_perms = factorial (cnt); for (i = 0; i < cnt; i = j) { for (j = i + 1; j < cnt; j++) if (values[i] != values[j]) break; - perm_cnt /= factorial (j - i); + n_perms /= factorial (j - i); } - return perm_cnt; + return n_perms; } /* Tests whether PARTS is a K-part integer composition of N. @@ -281,7 +281,7 @@ test_insert_no_dups_delete_min (void) struct heap *h; struct element *elements; int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); @@ -290,8 +290,8 @@ test_insert_no_dups_delete_min (void) values[i] = i; h = heap_create (compare_elements, &aux_data); - permutation_cnt = 0; - while (permutation_cnt == 0 || next_permutation (values, cnt)) + n_permutations = 0; + while (n_permutations == 0 || next_permutation (values, cnt)) { int i; @@ -313,9 +313,9 @@ test_insert_no_dups_delete_min (void) heap_delete (h, heap_minimum (h)); } check (heap_is_empty (h)); - permutation_cnt++; + n_permutations++; } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); heap_destroy (h); free (values); free (elements); @@ -337,9 +337,9 @@ test_insert_with_dups_delete_min (void) for (cnt = 1; cnt <= max_elems; cnt++) { - unsigned int composition_cnt; + unsigned int n_compositions; int *dups; - int unique_cnt; + int n_uniques; int *values; int *sorted_values; struct element *elements; @@ -350,16 +350,16 @@ test_insert_with_dups_delete_min (void) sorted_values = xnmalloc (cnt, sizeof *sorted_values); elements = xnmalloc (cnt, sizeof *elements); - unique_cnt = 0; - composition_cnt = 0; - while (next_composition (cnt, &unique_cnt, dups)) + n_uniques = 0; + n_compositions = 0; + while (next_composition (cnt, &n_uniques, dups)) { struct heap *h; int i, j, k; - unsigned int permutation_cnt; + unsigned int n_permutations; k = 0; - for (i = 0; i < unique_cnt; i++) + for (i = 0; i < n_uniques; i++) for (j = 0; j < dups[i]; j++) { values[k] = i; @@ -369,8 +369,8 @@ test_insert_with_dups_delete_min (void) check (k == cnt); h = heap_create (compare_elements, &aux_data); - permutation_cnt = 0; - while (permutation_cnt == 0 || next_permutation (values, cnt)) + n_permutations = 0; + while (n_permutations == 0 || next_permutation (values, cnt)) { int min = INT_MAX; @@ -395,14 +395,14 @@ test_insert_with_dups_delete_min (void) heap_delete (h, heap_minimum (h)); } check (heap_is_empty (h)); - permutation_cnt++; + n_permutations++; } - check (permutation_cnt == expected_perms (values, cnt)); + check (n_permutations == expected_perms (values, cnt)); heap_destroy (h); - composition_cnt++; + n_compositions++; } - check (composition_cnt == 1 << (cnt - 1)); + check (n_compositions == 1 << (cnt - 1)); free (dups); free (values); @@ -424,7 +424,7 @@ test_insert_no_dups_delete_random (void) struct heap *h; struct element *elements; int *insert, *delete; - unsigned int insert_perm_cnt; + unsigned int insert_n_perms; int i; insert = xnmalloc (cnt, sizeof *insert); @@ -438,12 +438,12 @@ test_insert_no_dups_delete_random (void) } h = heap_create (compare_elements, &aux_data); - insert_perm_cnt = 0; - while (insert_perm_cnt == 0 || next_permutation (insert, cnt)) + insert_n_perms = 0; + while (insert_n_perms == 0 || next_permutation (insert, cnt)) { - unsigned int delete_perm_cnt = 0; + unsigned int delete_n_perms = 0; - while (delete_perm_cnt == 0 || next_permutation (delete, cnt)) + while (delete_n_perms == 0 || next_permutation (delete, cnt)) { int min; int i; @@ -468,12 +468,12 @@ test_insert_no_dups_delete_random (void) check (heap_node_to_element (heap_minimum (h))->x == new_min); } check (heap_is_empty (h)); - delete_perm_cnt++; + delete_n_perms++; } - check (delete_perm_cnt == factorial (cnt)); - insert_perm_cnt++; + check (delete_n_perms == factorial (cnt)); + insert_n_perms++; } - check (insert_perm_cnt == factorial (cnt)); + check (insert_n_perms == factorial (cnt)); heap_destroy (h); free (insert); free (delete); @@ -495,7 +495,7 @@ test_inc_dec (void) struct heap *h; struct element *elements; int *insert, *delete; - unsigned int insert_perm_cnt; + unsigned int insert_n_perms; int i; insert = xnmalloc (cnt, sizeof *insert); @@ -505,8 +505,8 @@ test_inc_dec (void) insert[i] = i; h = heap_create (compare_elements, &aux_data); - insert_perm_cnt = 0; - while (insert_perm_cnt == 0 || next_permutation (insert, cnt)) + insert_n_perms = 0; + while (insert_n_perms == 0 || next_permutation (insert, cnt)) { for (i = 0; i < cnt; i++) elements[i].x = insert[i]; @@ -539,9 +539,9 @@ test_inc_dec (void) check (heap_node_to_element (heap_minimum (h))->x == new_min); } check (heap_is_empty (h)); - insert_perm_cnt++; + insert_n_perms++; } - check (insert_perm_cnt == factorial (cnt)); + check (insert_n_perms == factorial (cnt)); heap_destroy (h); free (insert); free (delete); diff --git a/tests/libpspp/hmap-test.c b/tests/libpspp/hmap-test.c index ccc3349e98..fd568aec12 100644 --- a/tests/libpspp/hmap-test.c +++ b/tests/libpspp/hmap-test.c @@ -447,7 +447,7 @@ test_insert_any_remove_any (hash_function *hash) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int ins_perm_cnt; + unsigned int ins_n_perms; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -455,24 +455,24 @@ test_insert_any_remove_any (hash_function *hash) for (i = 0; i < cnt; i++) insertions[i] = i; - for (ins_perm_cnt = 0; - ins_perm_cnt == 0 || next_permutation (insertions, cnt); - ins_perm_cnt++) + for (ins_n_perms = 0; + ins_n_perms == 0 || next_permutation (insertions, cnt); + ins_n_perms++) { - unsigned int del_perm_cnt; + unsigned int del_n_perms; int i; for (i = 0; i < cnt; i++) deletions[i] = i; - for (del_perm_cnt = 0; - del_perm_cnt == 0 || next_permutation (deletions, cnt); - del_perm_cnt++) + for (del_n_perms = 0; + del_n_perms == 0 || next_permutation (deletions, cnt); + del_n_perms++) test_insert_delete (insertions, deletions, cnt, hash); - check (del_perm_cnt == factorial (cnt)); + check (del_n_perms == factorial (cnt)); } - check (ins_perm_cnt == factorial (cnt)); + check (ins_n_perms == factorial (cnt)); free (insertions); free (deletions); @@ -509,18 +509,18 @@ test_insert_any_remove_same (hash_function *hash) for (cnt = 0; cnt <= max_elems; cnt++) { int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) test_insert_delete (values, values, cnt, hash); - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); } @@ -556,7 +556,7 @@ test_insert_any_remove_reverse (hash_function *hash) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -564,16 +564,16 @@ test_insert_any_remove_reverse (hash_function *hash) for (i = 0; i < cnt; i++) insertions[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (insertions, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (insertions, cnt); + n_permutations++) { memcpy (deletions, insertions, sizeof *insertions * cnt); reverse (deletions, cnt); test_insert_delete (insertions, deletions, cnt, hash); } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (insertions); free (deletions); @@ -798,7 +798,7 @@ test_changed (hash_function *hash) { int *values, *changed_values; struct element *elements; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); @@ -807,9 +807,9 @@ test_changed (hash_function *hash) for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) { for (i = 0; i < cnt; i++) { @@ -843,7 +843,7 @@ test_changed (hash_function *hash) } } } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); free (changed_values); diff --git a/tests/libpspp/hmapx-test.c b/tests/libpspp/hmapx-test.c index dfe5d22ff6..42738b28ca 100644 --- a/tests/libpspp/hmapx-test.c +++ b/tests/libpspp/hmapx-test.c @@ -383,7 +383,7 @@ test_insert_any_remove_any (hash_function *hash) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int ins_perm_cnt; + unsigned int ins_n_perms; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -391,24 +391,24 @@ test_insert_any_remove_any (hash_function *hash) for (i = 0; i < cnt; i++) insertions[i] = i; - for (ins_perm_cnt = 0; - ins_perm_cnt == 0 || next_permutation (insertions, cnt); - ins_perm_cnt++) + for (ins_n_perms = 0; + ins_n_perms == 0 || next_permutation (insertions, cnt); + ins_n_perms++) { - unsigned int del_perm_cnt; + unsigned int del_n_perms; int i; for (i = 0; i < cnt; i++) deletions[i] = i; - for (del_perm_cnt = 0; - del_perm_cnt == 0 || next_permutation (deletions, cnt); - del_perm_cnt++) + for (del_n_perms = 0; + del_n_perms == 0 || next_permutation (deletions, cnt); + del_n_perms++) test_insert_delete (insertions, deletions, cnt, hash, 1); - check (del_perm_cnt == factorial (cnt)); + check (del_n_perms == factorial (cnt)); } - check (ins_perm_cnt == factorial (cnt)); + check (ins_n_perms == factorial (cnt)); free (insertions); free (deletions); @@ -445,18 +445,18 @@ test_insert_any_remove_same (hash_function *hash) for (cnt = 0; cnt <= max_elems; cnt++) { int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) test_insert_delete (values, values, cnt, hash, cnt / 2); - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); } @@ -492,7 +492,7 @@ test_insert_any_remove_reverse (hash_function *hash) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -500,16 +500,16 @@ test_insert_any_remove_reverse (hash_function *hash) for (i = 0; i < cnt; i++) insertions[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (insertions, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (insertions, cnt); + n_permutations++) { memcpy (deletions, insertions, sizeof *insertions * cnt); reverse (deletions, cnt); test_insert_delete (insertions, deletions, cnt, hash, cnt); } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (insertions); free (deletions); @@ -732,7 +732,7 @@ test_changed (hash_function *hash) int *values, *changed_values; struct hmapx_node **nodes; struct element *elements; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); @@ -742,9 +742,9 @@ test_changed (hash_function *hash) for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) { for (i = 0; i < cnt; i++) { @@ -778,7 +778,7 @@ test_changed (hash_function *hash) } } } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); free (changed_values); @@ -819,7 +819,7 @@ test_change (hash_function *hash) struct hmapx_node **nodes; struct element *elements; struct element replacement; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); @@ -829,9 +829,9 @@ test_change (hash_function *hash) for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) { for (i = 0; i < cnt; i++) { @@ -864,7 +864,7 @@ test_change (hash_function *hash) } } } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); free (changed_values); diff --git a/tests/libpspp/ll-test.c b/tests/libpspp/ll-test.c index f92bc6cba8..0d501a8504 100644 --- a/tests/libpspp/ll-test.c +++ b/tests/libpspp/ll-test.c @@ -1031,17 +1031,17 @@ static unsigned int expected_perms (int *values, size_t cnt) { size_t i, j; - unsigned int perm_cnt; + unsigned int n_perms; - perm_cnt = factorial (cnt); + n_perms = factorial (cnt); for (i = 0; i < cnt; i = j) { for (j = i + 1; j < cnt; j++) if (values[i] != values[j]) break; - perm_cnt /= factorial (j - i); + n_perms /= factorial (j - i); } - return perm_cnt; + return n_perms; } /* Tests ll_min and ll_max. */ @@ -1059,11 +1059,11 @@ test_min_max (void) int *values; int *new_values = xnmalloc (cnt, sizeof *values); - size_t perm_cnt; + size_t n_perms; allocate_ascending (cnt, &list, &elems, &elemp, &values); - perm_cnt = 1; + n_perms = 1; while (ll_next_permutation (ll_head (&list), ll_null (&list), compare_elements, &aux_data)) { @@ -1110,9 +1110,9 @@ test_min_max (void) && ll_to_element (max)->x == max_int); } } - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); check_list_contents (&list, values, cnt); free_elements (cnt, elems, elemp, values); @@ -1271,11 +1271,11 @@ test_permutations_no_dups (void) int *old_values = xnmalloc (cnt, sizeof *values); int *new_values = xnmalloc (cnt, sizeof *values); - size_t perm_cnt; + size_t n_perms; allocate_ascending (cnt, &list, &elems, NULL, &values); - perm_cnt = 1; + n_perms = 1; extract_values (&list, old_values, cnt); while (ll_next_permutation (ll_head (&list), ll_null (&list), compare_elements, &aux_data)) @@ -1286,12 +1286,12 @@ test_permutations_no_dups (void) sizeof *new_values, compare_ints, NULL) > 0); memcpy (old_values, new_values, (cnt) * sizeof *old_values); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); check_list_contents (&list, values, cnt); - perm_cnt = 1; + n_perms = 1; ll_reverse (ll_head (&list), ll_null (&list)); extract_values (&list, old_values, cnt); while (ll_prev_permutation (ll_head (&list), ll_null (&list), @@ -1303,9 +1303,9 @@ test_permutations_no_dups (void) sizeof *new_values, compare_ints, NULL) < 0); memcpy (old_values, new_values, (cnt) * sizeof *old_values); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); ll_reverse (ll_head (&list), ll_null (&list)); check_list_contents (&list, values, cnt); @@ -1335,7 +1335,7 @@ test_permutations_with_dups (void) int *old_values = xnmalloc (max_elems, sizeof *values); int *new_values = xnmalloc (max_elems, sizeof *values); - unsigned int permutation_cnt; + unsigned int n_permutations; int left = cnt; int value = 0; @@ -1354,7 +1354,7 @@ test_permutations_with_dups (void) value++; } - permutation_cnt = 1; + n_permutations = 1; extract_values (&list, old_values, cnt); while (ll_next_permutation (ll_head (&list), ll_null (&list), compare_elements, &aux_data)) @@ -1365,12 +1365,12 @@ test_permutations_with_dups (void) sizeof *new_values, compare_ints, NULL) > 0); memcpy (old_values, new_values, cnt * sizeof *old_values); - permutation_cnt++; + n_permutations++; } - check (permutation_cnt == expected_perms (values, cnt)); + check (n_permutations == expected_perms (values, cnt)); check_list_contents (&list, values, cnt); - permutation_cnt = 1; + n_permutations = 1; ll_reverse (ll_head (&list), ll_null (&list)); extract_values (&list, old_values, cnt); while (ll_prev_permutation (ll_head (&list), ll_null (&list), @@ -1381,10 +1381,10 @@ test_permutations_with_dups (void) old_values, cnt, sizeof *new_values, compare_ints, NULL) < 0); - permutation_cnt++; + n_permutations++; } ll_reverse (ll_head (&list), ll_null (&list)); - check (permutation_cnt == expected_perms (values, cnt)); + check (n_permutations == expected_perms (values, cnt)); check_list_contents (&list, values, cnt); free_elements (cnt, elems, NULL, values); @@ -1400,10 +1400,10 @@ test_merge_no_dups (void) const int max_elems = 8; const int max_filler = 3; - int merge_cnt, pattern, pfx, gap, sfx, order; + int n_merges, pattern, pfx, gap, sfx, order; - for (merge_cnt = 0; merge_cnt < max_elems; merge_cnt++) - for (pattern = 0; pattern <= (1 << merge_cnt); pattern++) + for (n_merges = 0; n_merges < max_elems; n_merges++) + for (pattern = 0; pattern <= (1 << n_merges); pattern++) for (pfx = 0; pfx < max_filler; pfx++) for (gap = 0; gap < max_filler; gap++) for (sfx = 0; sfx < max_filler; sfx++) @@ -1414,46 +1414,46 @@ test_merge_no_dups (void) struct ll **elemp; int *values; - int list_cnt = pfx + merge_cnt + gap + sfx; + int n_lists = pfx + n_merges + gap + sfx; int a0, a1, b0, b1; int i, j; - allocate_elements (list_cnt, &list, + allocate_elements (n_lists, &list, &elems, &elemp, &values); j = 0; for (i = 0; i < pfx; i++) elems[j++]->x = 100 + i; a0 = j; - for (i = 0; i < merge_cnt; i++) + for (i = 0; i < n_merges; i++) if (pattern & (1u << i)) elems[j++]->x = i; a1 = j; for (i = 0; i < gap; i++) elems[j++]->x = 200 + i; b0 = j; - for (i = 0; i < merge_cnt; i++) + for (i = 0; i < n_merges; i++) if (!(pattern & (1u << i))) elems[j++]->x = i; b1 = j; for (i = 0; i < sfx; i++) elems[j++]->x = 300 + i; - check (list_cnt == j); + check (n_lists == j); j = 0; for (i = 0; i < pfx; i++) values[j++] = 100 + i; if (order == 0) - for (i = 0; i < merge_cnt; i++) + for (i = 0; i < n_merges; i++) values[j++] = i; for (i = 0; i < gap; i++) values[j++] = 200 + i; if (order == 1) - for (i = 0; i < merge_cnt; i++) + for (i = 0; i < n_merges; i++) values[j++] = i; for (i = 0; i < sfx; i++) values[j++] = 300 + i; - check (list_cnt == j); + check (n_lists == j); if (order == 0) ll_merge (elemp[a0], elemp[a1], elemp[b0], elemp[b1], @@ -1462,9 +1462,9 @@ test_merge_no_dups (void) ll_merge (elemp[b0], elemp[b1], elemp[a0], elemp[a1], compare_elements, &aux_data); - check_list_contents (&list, values, list_cnt); + check_list_contents (&list, values, n_lists); - free_elements (list_cnt, elems, elemp, values); + free_elements (n_lists, elems, elemp, values); } } @@ -1563,12 +1563,12 @@ test_sort_exhaustive (void) struct element **perm_elems; int *perm_values; - size_t perm_cnt; + size_t n_perms; allocate_ascending (cnt, &list, &elems, NULL, &values); allocate_elements (cnt, NULL, &perm_elems, NULL, &perm_values); - perm_cnt = 1; + n_perms = 1; while (ll_next_permutation (ll_head (&list), ll_null (&list), compare_elements, &aux_data)) { @@ -1587,9 +1587,9 @@ test_sort_exhaustive (void) check_list_contents (&perm_list, values, cnt); check (ll_is_sorted (ll_head (&perm_list), ll_null (&perm_list), compare_elements, &aux_data)); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); free_elements (cnt, elems, NULL, values); free_elements (cnt, perm_elems, NULL, perm_values); @@ -1614,7 +1614,7 @@ test_sort_stable (void) struct element **perm_elems; int *perm_values; - size_t perm_cnt; + size_t n_perms; int i, j; allocate_elements (cnt, &list, &elems, NULL, &values); @@ -1629,7 +1629,7 @@ test_sort_stable (void) elems[i]->y = i; } - perm_cnt = 1; + n_perms = 1; while (ll_next_permutation (ll_head (&list), ll_null (&list), compare_elements_y, &aux_data)) { @@ -1648,9 +1648,9 @@ test_sort_stable (void) check_list_contents (&perm_list, values, cnt); check (ll_is_sorted (ll_head (&perm_list), ll_null (&perm_list), compare_elements_x_y, &aux_data)); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); free_elements (cnt, elems, NULL, values); free_elements (cnt, perm_elems, NULL, perm_values); @@ -1775,29 +1775,29 @@ test_sort_unique (void) struct element **perm_elems; int *perm_values; - int unique_cnt; + int n_uniques; int *unique_values; - size_t perm_cnt; + size_t n_perms; int i, j; allocate_elements (cnt, &list, &elems, NULL, &values); allocate_elements (cnt, NULL, &perm_elems, NULL, &perm_values); - j = unique_cnt = 0; + j = n_uniques = 0; for (i = 0; i < cnt; i++) { elems[i]->x = values[i] = j; - unique_cnt = j + 1; + n_uniques = j + 1; if (inc_pat & (1 << i)) j++; } - unique_values = xnmalloc (unique_cnt, sizeof *unique_values); - for (i = 0; i < unique_cnt; i++) + unique_values = xnmalloc (n_uniques, sizeof *unique_values); + for (i = 0; i < n_uniques; i++) unique_values[i] = i; - perm_cnt = 1; + n_perms = 1; while (ll_next_permutation (ll_head (&list), ll_null (&list), compare_elements, &aux_data)) { @@ -1813,12 +1813,12 @@ test_sort_unique (void) } ll_sort_unique (ll_head (&perm_list), ll_null (&perm_list), NULL, compare_elements, &aux_data); - check_list_contents (&perm_list, unique_values, unique_cnt); + check_list_contents (&perm_list, unique_values, n_uniques); check (ll_is_sorted (ll_head (&perm_list), ll_null (&perm_list), compare_elements_x_y, &aux_data)); - perm_cnt++; + n_perms++; } - check (perm_cnt == expected_perms (values, cnt)); + check (n_perms == expected_perms (values, cnt)); free_elements (cnt, elems, NULL, values); free_elements (cnt, perm_elems, NULL, perm_values); @@ -1843,7 +1843,7 @@ test_insert_ordered (void) struct element **perm_elems; int *perm_values; - size_t perm_cnt; + size_t n_perms; int i, j; allocate_elements (cnt, &list, &elems, NULL, &values); @@ -1858,7 +1858,7 @@ test_insert_ordered (void) elems[i]->y = i; } - perm_cnt = 1; + n_perms = 1; while (ll_next_permutation (ll_head (&list), ll_null (&list), compare_elements_y, &aux_data)) { @@ -1876,9 +1876,9 @@ test_insert_ordered (void) } check (ll_is_sorted (ll_head (&perm_list), ll_null (&perm_list), compare_elements_x_y, &aux_data)); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); free_elements (cnt, elems, NULL, values); free_elements (cnt, perm_elems, NULL, perm_values); diff --git a/tests/libpspp/llx-test.c b/tests/libpspp/llx-test.c index 95b549fd8c..4a2defbc01 100644 --- a/tests/libpspp/llx-test.c +++ b/tests/libpspp/llx-test.c @@ -1048,17 +1048,17 @@ static unsigned int expected_perms (int *values, size_t cnt) { size_t i, j; - unsigned int perm_cnt; + unsigned int n_perms; - perm_cnt = factorial (cnt); + n_perms = factorial (cnt); for (i = 0; i < cnt; i = j) { for (j = i + 1; j < cnt; j++) if (values[i] != values[j]) break; - perm_cnt /= factorial (j - i); + n_perms /= factorial (j - i); } - return perm_cnt; + return n_perms; } /* Tests llx_min and llx_max. */ @@ -1076,11 +1076,11 @@ test_min_max (void) int *values; int *new_values = xnmalloc (cnt, sizeof *values); - size_t perm_cnt; + size_t n_perms; allocate_ascending (cnt, &list, &elems, &elemp, &values); - perm_cnt = 1; + n_perms = 1; while (llx_next_permutation (llx_head (&list), llx_null (&list), compare_elements, &aux_data)) { @@ -1127,9 +1127,9 @@ test_min_max (void) check (max != elemp[r1] && max_elem->x == max_int); } } - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); check_list_contents (&list, values, cnt); free_elements (cnt, &list, elems, elemp, values); @@ -1322,11 +1322,11 @@ test_permutations_no_dups (void) int *old_values = xnmalloc (cnt, sizeof *values); int *new_values = xnmalloc (cnt, sizeof *values); - size_t perm_cnt; + size_t n_perms; allocate_ascending (cnt, &list, &elems, NULL, &values); - perm_cnt = 1; + n_perms = 1; extract_values (&list, old_values, cnt); while (llx_next_permutation (llx_head (&list), llx_null (&list), compare_elements, &aux_data)) @@ -1337,12 +1337,12 @@ test_permutations_no_dups (void) sizeof *new_values, compare_ints, NULL) > 0); memcpy (old_values, new_values, (cnt) * sizeof *old_values); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); check_list_contents (&list, values, cnt); - perm_cnt = 1; + n_perms = 1; llx_reverse (llx_head (&list), llx_null (&list)); extract_values (&list, old_values, cnt); while (llx_prev_permutation (llx_head (&list), llx_null (&list), @@ -1354,9 +1354,9 @@ test_permutations_no_dups (void) sizeof *new_values, compare_ints, NULL) < 0); memcpy (old_values, new_values, (cnt) * sizeof *old_values); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); llx_reverse (llx_head (&list), llx_null (&list)); check_list_contents (&list, values, cnt); @@ -1387,7 +1387,7 @@ test_permutations_with_dups (void) int *old_values = xnmalloc (max_elems, sizeof *values); int *new_values = xnmalloc (max_elems, sizeof *values); - unsigned int permutation_cnt; + unsigned int n_permutations; int left = cnt; int value = 0; @@ -1406,7 +1406,7 @@ test_permutations_with_dups (void) value++; } - permutation_cnt = 1; + n_permutations = 1; extract_values (&list, old_values, cnt); while (llx_next_permutation (llx_head (&list), llx_null (&list), compare_elements, &aux_data)) @@ -1417,12 +1417,12 @@ test_permutations_with_dups (void) sizeof *new_values, compare_ints, NULL) > 0); memcpy (old_values, new_values, cnt * sizeof *old_values); - permutation_cnt++; + n_permutations++; } - check (permutation_cnt == expected_perms (values, cnt)); + check (n_permutations == expected_perms (values, cnt)); check_list_contents (&list, values, cnt); - permutation_cnt = 1; + n_permutations = 1; llx_reverse (llx_head (&list), llx_null (&list)); extract_values (&list, old_values, cnt); while (llx_prev_permutation (llx_head (&list), llx_null (&list), @@ -1433,10 +1433,10 @@ test_permutations_with_dups (void) old_values, cnt, sizeof *new_values, compare_ints, NULL) < 0); - permutation_cnt++; + n_permutations++; } llx_reverse (llx_head (&list), llx_null (&list)); - check (permutation_cnt == expected_perms (values, cnt)); + check (n_permutations == expected_perms (values, cnt)); check_list_contents (&list, values, cnt); free_elements (cnt, &list, elems, elemp, values); @@ -1452,10 +1452,10 @@ test_merge_no_dups (void) const int max_elems = 8; const int max_fillxer = 3; - int merge_cnt, pattern, pfx, gap, sfx, order; + int n_merges, pattern, pfx, gap, sfx, order; - for (merge_cnt = 0; merge_cnt < max_elems; merge_cnt++) - for (pattern = 0; pattern <= (1 << merge_cnt); pattern++) + for (n_merges = 0; n_merges < max_elems; n_merges++) + for (pattern = 0; pattern <= (1 << n_merges); pattern++) for (pfx = 0; pfx < max_fillxer; pfx++) for (gap = 0; gap < max_fillxer; gap++) for (sfx = 0; sfx < max_fillxer; sfx++) @@ -1466,46 +1466,46 @@ test_merge_no_dups (void) struct llx **elemp; int *values; - int list_cnt = pfx + merge_cnt + gap + sfx; + int n_lists = pfx + n_merges + gap + sfx; int a0, a1, b0, b1; int i, j; - allocate_elements (list_cnt, &list, + allocate_elements (n_lists, &list, &elems, &elemp, &values); j = 0; for (i = 0; i < pfx; i++) elems[j++]->x = 100 + i; a0 = j; - for (i = 0; i < merge_cnt; i++) + for (i = 0; i < n_merges; i++) if (pattern & (1u << i)) elems[j++]->x = i; a1 = j; for (i = 0; i < gap; i++) elems[j++]->x = 200 + i; b0 = j; - for (i = 0; i < merge_cnt; i++) + for (i = 0; i < n_merges; i++) if (!(pattern & (1u << i))) elems[j++]->x = i; b1 = j; for (i = 0; i < sfx; i++) elems[j++]->x = 300 + i; - check (list_cnt == j); + check (n_lists == j); j = 0; for (i = 0; i < pfx; i++) values[j++] = 100 + i; if (order == 0) - for (i = 0; i < merge_cnt; i++) + for (i = 0; i < n_merges; i++) values[j++] = i; for (i = 0; i < gap; i++) values[j++] = 200 + i; if (order == 1) - for (i = 0; i < merge_cnt; i++) + for (i = 0; i < n_merges; i++) values[j++] = i; for (i = 0; i < sfx; i++) values[j++] = 300 + i; - check (list_cnt == j); + check (n_lists == j); if (order == 0) llx_merge (elemp[a0], elemp[a1], elemp[b0], elemp[b1], @@ -1514,9 +1514,9 @@ test_merge_no_dups (void) llx_merge (elemp[b0], elemp[b1], elemp[a0], elemp[a1], compare_elements, &aux_data); - check_list_contents (&list, values, list_cnt); + check_list_contents (&list, values, n_lists); - free_elements (list_cnt, &list, elems, elemp, values); + free_elements (n_lists, &list, elems, elemp, values); } } @@ -1615,12 +1615,12 @@ test_sort_exhaustive (void) struct element **perm_elems; int *perm_values; - size_t perm_cnt; + size_t n_perms; allocate_ascending (cnt, &list, &elems, NULL, &values); allocate_elements (cnt, NULL, &perm_elems, NULL, &perm_values); - perm_cnt = 1; + n_perms = 1; while (llx_next_permutation (llx_head (&list), llx_null (&list), compare_elements, &aux_data)) { @@ -1640,9 +1640,9 @@ test_sort_exhaustive (void) check (llx_is_sorted (llx_head (&perm_list), llx_null (&perm_list), compare_elements, &aux_data)); llx_destroy (&perm_list, NULL, NULL, &llx_malloc_mgr); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); free_elements (cnt, &list, elems, NULL, values); free_elements (cnt, NULL, perm_elems, NULL, perm_values); @@ -1667,7 +1667,7 @@ test_sort_stable (void) struct element **perm_elems; int *perm_values; - size_t perm_cnt; + size_t n_perms; int i, j; allocate_elements (cnt, &list, &elems, NULL, &values); @@ -1682,7 +1682,7 @@ test_sort_stable (void) elems[i]->y = i; } - perm_cnt = 1; + n_perms = 1; while (llx_next_permutation (llx_head (&list), llx_null (&list), compare_elements_y, &aux_data)) { @@ -1702,9 +1702,9 @@ test_sort_stable (void) check (llx_is_sorted (llx_head (&perm_list), llx_null (&perm_list), compare_elements_x_y, &aux_data)); llx_destroy (&perm_list, NULL, NULL, &llx_malloc_mgr); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); free_elements (cnt, &list, elems, NULL, values); free_elements (cnt, NULL, perm_elems, NULL, perm_values); @@ -1832,29 +1832,29 @@ test_sort_unique (void) struct element **perm_elems; int *perm_values; - int unique_cnt; + int n_uniques; int *unique_values; - size_t perm_cnt; + size_t n_perms; int i, j; allocate_elements (cnt, &list, &elems, NULL, &values); allocate_elements (cnt, NULL, &perm_elems, NULL, &perm_values); - j = unique_cnt = 0; + j = n_uniques = 0; for (i = 0; i < cnt; i++) { elems[i]->x = values[i] = j; - unique_cnt = j + 1; + n_uniques = j + 1; if (inc_pat & (1 << i)) j++; } - unique_values = xnmalloc (unique_cnt, sizeof *unique_values); - for (i = 0; i < unique_cnt; i++) + unique_values = xnmalloc (n_uniques, sizeof *unique_values); + for (i = 0; i < n_uniques; i++) unique_values[i] = i; - perm_cnt = 1; + n_perms = 1; while (llx_next_permutation (llx_head (&list), llx_null (&list), compare_elements, &aux_data)) { @@ -1871,13 +1871,13 @@ test_sort_unique (void) llx_sort_unique (llx_head (&perm_list), llx_null (&perm_list), NULL, compare_elements, &aux_data, &llx_malloc_mgr); - check_list_contents (&perm_list, unique_values, unique_cnt); + check_list_contents (&perm_list, unique_values, n_uniques); check (llx_is_sorted (llx_head (&perm_list), llx_null (&perm_list), compare_elements_x_y, &aux_data)); llx_destroy (&perm_list, NULL, NULL, &llx_malloc_mgr); - perm_cnt++; + n_perms++; } - check (perm_cnt == expected_perms (values, cnt)); + check (n_perms == expected_perms (values, cnt)); free_elements (cnt, &list, elems, NULL, values); free_elements (cnt, NULL, perm_elems, NULL, perm_values); @@ -1902,7 +1902,7 @@ test_insert_ordered (void) struct element **perm_elems; int *perm_values; - size_t perm_cnt; + size_t n_perms; int i, j; allocate_elements (cnt, &list, &elems, NULL, &values); @@ -1917,7 +1917,7 @@ test_insert_ordered (void) elems[i]->y = i; } - perm_cnt = 1; + n_perms = 1; while (llx_next_permutation (llx_head (&list), llx_null (&list), compare_elements_y, &aux_data)) { @@ -1938,9 +1938,9 @@ test_insert_ordered (void) check (llx_is_sorted (llx_head (&perm_list), llx_null (&perm_list), compare_elements_x_y, &aux_data)); llx_destroy (&perm_list, NULL, NULL, &llx_malloc_mgr); - perm_cnt++; + n_perms++; } - check (perm_cnt == factorial (cnt)); + check (n_perms == factorial (cnt)); free_elements (cnt, &list, elems, NULL, values); free_elements (cnt, NULL, perm_elems, NULL, perm_values); diff --git a/tests/libpspp/range-map-test.c b/tests/libpspp/range-map-test.c index 6a710a5550..5377f2bda2 100644 --- a/tests/libpspp/range-map-test.c +++ b/tests/libpspp/range-map-test.c @@ -248,19 +248,19 @@ compare_expected_element (const void *a_, const void *b_) ELEMENTS[]. */ static void check_range_map (struct range_map *rm, - struct expected_element elements[], size_t elem_cnt) + struct expected_element elements[], size_t n_elems) { struct expected_element *sorted; struct range_map_node *node; size_t i; - sorted = xnmalloc (elem_cnt, sizeof *sorted); - memcpy (sorted, elements, elem_cnt * sizeof *elements); - qsort (sorted, elem_cnt, sizeof *sorted, compare_expected_element); + sorted = xnmalloc (n_elems, sizeof *sorted); + memcpy (sorted, elements, n_elems * sizeof *elements); + qsort (sorted, n_elems, sizeof *sorted, compare_expected_element); - check (range_map_is_empty (rm) == (elem_cnt == 0)); + check (range_map_is_empty (rm) == (n_elems == 0)); - for (i = 0; i < elem_cnt; i++) + for (i = 0; i < n_elems; i++) { struct expected_element *e = &sorted[i]; unsigned long int position; @@ -282,7 +282,7 @@ check_range_map (struct range_map *rm, range_map_lookup doesn't find any there. */ if (e->start > 0 && (i == 0 || e[-1].end < e->start)) check (range_map_lookup (rm, e->start - 1) == NULL); - if (i == elem_cnt - 1 || e->end < e[1].start) + if (i == n_elems - 1 || e->end < e[1].start) check (range_map_lookup (rm, e->end) == NULL); } @@ -294,7 +294,7 @@ check_range_map (struct range_map *rm, struct expected_element *e = &sorted[i]; check (range_map_node_to_element (node)->x == e->x); } - check (i == elem_cnt); + check (i == n_elems); free (sorted); } @@ -310,10 +310,10 @@ test_insert (void) for (cnt = 1; cnt <= max_range; cnt++) { - unsigned int composition_cnt; + unsigned int n_compositions; struct expected_element *expected; int *widths; - int elem_cnt; + int n_elems; int *order; struct element *elements; @@ -322,25 +322,25 @@ test_insert (void) order = xnmalloc (cnt, sizeof *order); elements = xnmalloc (cnt, sizeof *elements); - elem_cnt = 0; - composition_cnt = 0; - while (next_composition (cnt, &elem_cnt, widths)) + n_elems = 0; + n_compositions = 0; + while (next_composition (cnt, &n_elems, widths)) { int i, j; - unsigned int permutation_cnt; + unsigned int n_permutations; - for (i = 0; i < elem_cnt; i++) + for (i = 0; i < n_elems; i++) order[i] = i; - permutation_cnt = 0; - while (permutation_cnt == 0 || next_permutation (order, elem_cnt)) + n_permutations = 0; + while (n_permutations == 0 || next_permutation (order, n_elems)) { struct range_map rm; - /* Inserts the elem_cnt elements with the given + /* Inserts the n_elems elements with the given widths[] into T in the order given by order[]. */ range_map_init (&rm); - for (i = 0; i < elem_cnt; i++) + for (i = 0; i < n_elems; i++) { unsigned long int start, end; int idx; @@ -364,13 +364,13 @@ test_insert (void) expected[i].end = end; check_range_map (&rm, expected, i + 1); } - permutation_cnt++; + n_permutations++; } - check (permutation_cnt == factorial (elem_cnt)); + check (n_permutations == factorial (n_elems)); - composition_cnt++; + n_compositions++; } - check (composition_cnt == 1 << (cnt - 1)); + check (n_compositions == 1 << (cnt - 1)); free (expected); free (widths); @@ -389,10 +389,10 @@ test_delete (int gap) for (cnt = 1; cnt <= max_range; cnt++) { - unsigned int composition_cnt; + unsigned int n_compositions; struct expected_element *expected; int *widths; - int elem_cnt; + int n_elems; int *order; struct element *elements; @@ -401,18 +401,18 @@ test_delete (int gap) order = xnmalloc (cnt, sizeof *order); elements = xnmalloc (cnt, sizeof *elements); - elem_cnt = 0; - composition_cnt = 0; - while (next_composition (cnt, &elem_cnt, widths)) + n_elems = 0; + n_compositions = 0; + while (next_composition (cnt, &n_elems, widths)) { int i, j; - unsigned int permutation_cnt; + unsigned int n_permutations; - for (i = 0; i < elem_cnt; i++) + for (i = 0; i < n_elems; i++) order[i] = i; - permutation_cnt = 0; - while (permutation_cnt == 0 || next_permutation (order, elem_cnt)) + n_permutations = 0; + while (n_permutations == 0 || next_permutation (order, n_elems)) { struct range_map rm; unsigned long int start; @@ -420,7 +420,7 @@ test_delete (int gap) /* Insert all the elements. */ range_map_init (&rm); start = 0; - for (i = 0; i < elem_cnt; i++) + for (i = 0; i < n_elems; i++) { int width = widths[i] > gap ? widths[i] - gap : widths[i]; unsigned long int end = start + width; @@ -431,7 +431,7 @@ test_delete (int gap) for (j = 0; ; j++) { - assert (j < elem_cnt); + assert (j < n_elems); if (order[j] == i) { expected[j].x = i; @@ -443,22 +443,22 @@ test_delete (int gap) start += widths[i]; } - check_range_map (&rm, expected, elem_cnt); + check_range_map (&rm, expected, n_elems); /* Delete the elements in the specified order. */ - for (i = 0; i < elem_cnt; i++) + for (i = 0; i < n_elems; i++) { range_map_delete (&rm, &elements[order[i]].node); - check_range_map (&rm, expected + i + 1, elem_cnt - i - 1); + check_range_map (&rm, expected + i + 1, n_elems - i - 1); } - permutation_cnt++; + n_permutations++; } - check (permutation_cnt == factorial (elem_cnt)); + check (n_permutations == factorial (n_elems)); - composition_cnt++; + n_compositions++; } - check (composition_cnt == 1 << (cnt - 1)); + check (n_compositions == 1 << (cnt - 1)); free (expected); free (widths); diff --git a/tests/libpspp/sparse-array-test.c b/tests/libpspp/sparse-array-test.c index dd0e95fbf3..5fdf5ae465 100644 --- a/tests/libpspp/sparse-array-test.c +++ b/tests/libpspp/sparse-array-test.c @@ -265,7 +265,7 @@ test_insert_delete_strides (void) 1, 2, 4, 16, 64, 4096, 262144, 16777216, 3, 5, 17, 67, 4099, 262147, 16777259, }; - const size_t stride_cnt = sizeof strides / sizeof *strides; + const size_t n_strides = sizeof strides / sizeof *strides; static const unsigned long offsets[] = { @@ -274,7 +274,7 @@ test_insert_delete_strides (void) 1024ul * 1024 * 512 + 23, ULONG_MAX - 59, }; - const size_t offset_cnt = sizeof offsets / sizeof *offsets; + const size_t n_offsets = sizeof offsets / sizeof *offsets; int cnt = 100; unsigned long *insertions, *deletions; @@ -282,10 +282,10 @@ test_insert_delete_strides (void) insertions = xnmalloc (cnt, sizeof *insertions); deletions = xnmalloc (cnt, sizeof *deletions); - for (stride = strides; stride < strides + stride_cnt; stride++) + for (stride = strides; stride < strides + n_strides; stride++) { printf ("%lu\n", *stride); - for (offset = offsets; offset < offsets + offset_cnt; offset++) + for (offset = offsets; offset < offsets + n_offsets; offset++) { int k; diff --git a/tests/libpspp/string-map-test.c b/tests/libpspp/string-map-test.c index 68fde9c1a3..0a1420d73d 100644 --- a/tests/libpspp/string-map-test.c +++ b/tests/libpspp/string-map-test.c @@ -375,7 +375,7 @@ test_insert_any_remove_any (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int ins_perm_cnt; + unsigned int ins_n_perms; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -383,24 +383,24 @@ test_insert_any_remove_any (void) for (i = 0; i < cnt; i++) insertions[i] = i | random_value (i, basis); - for (ins_perm_cnt = 0; - ins_perm_cnt == 0 || next_permutation (insertions, cnt); - ins_perm_cnt++) + for (ins_n_perms = 0; + ins_n_perms == 0 || next_permutation (insertions, cnt); + ins_n_perms++) { - unsigned int del_perm_cnt; + unsigned int del_n_perms; int i; for (i = 0; i < cnt; i++) deletions[i] = i | random_value (i, basis); - for (del_perm_cnt = 0; - del_perm_cnt == 0 || next_permutation (deletions, cnt); - del_perm_cnt++) + for (del_n_perms = 0; + del_n_perms == 0 || next_permutation (deletions, cnt); + del_n_perms++) test_insert_delete (insertions, deletions, cnt); - check (del_perm_cnt == factorial (cnt)); + check (del_n_perms == factorial (cnt)); } - check (ins_perm_cnt == factorial (cnt)); + check (ins_n_perms == factorial (cnt)); free (insertions); free (deletions); @@ -418,18 +418,18 @@ test_insert_any_remove_same (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); for (i = 0; i < cnt; i++) values[i] = i | random_value (i, 1); - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) test_insert_delete (values, values, cnt); - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); } @@ -447,7 +447,7 @@ test_insert_any_remove_reverse (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -455,16 +455,16 @@ test_insert_any_remove_reverse (void) for (i = 0; i < cnt; i++) insertions[i] = i | random_value (i, 2); - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (insertions, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (insertions, cnt); + n_permutations++) { memcpy (deletions, insertions, sizeof *insertions * cnt); reverse (deletions, cnt); test_insert_delete (insertions, deletions, cnt); } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (insertions); free (deletions); diff --git a/tests/libpspp/string-set-test.c b/tests/libpspp/string-set-test.c index 7f136a66c4..95d6abc95a 100644 --- a/tests/libpspp/string-set-test.c +++ b/tests/libpspp/string-set-test.c @@ -326,7 +326,7 @@ test_insert_any_remove_any (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int ins_perm_cnt; + unsigned int ins_n_perms; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -334,24 +334,24 @@ test_insert_any_remove_any (void) for (i = 0; i < cnt; i++) insertions[i] = i; - for (ins_perm_cnt = 0; - ins_perm_cnt == 0 || next_permutation (insertions, cnt); - ins_perm_cnt++) + for (ins_n_perms = 0; + ins_n_perms == 0 || next_permutation (insertions, cnt); + ins_n_perms++) { - unsigned int del_perm_cnt; + unsigned int del_n_perms; int i; for (i = 0; i < cnt; i++) deletions[i] = i; - for (del_perm_cnt = 0; - del_perm_cnt == 0 || next_permutation (deletions, cnt); - del_perm_cnt++) + for (del_n_perms = 0; + del_n_perms == 0 || next_permutation (deletions, cnt); + del_n_perms++) test_insert_delete (insertions, deletions, cnt); - check (del_perm_cnt == factorial (cnt)); + check (del_n_perms == factorial (cnt)); } - check (ins_perm_cnt == factorial (cnt)); + check (ins_n_perms == factorial (cnt)); free (insertions); free (deletions); @@ -369,18 +369,18 @@ test_insert_any_remove_same (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) test_insert_delete (values, values, cnt); - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); } @@ -398,7 +398,7 @@ test_insert_any_remove_reverse (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -406,16 +406,16 @@ test_insert_any_remove_reverse (void) for (i = 0; i < cnt; i++) insertions[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (insertions, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (insertions, cnt); + n_permutations++) { memcpy (deletions, insertions, sizeof *insertions * cnt); reverse (deletions, cnt); test_insert_delete (insertions, deletions, cnt); } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (insertions); free (deletions); diff --git a/tests/libpspp/stringi-map-test.c b/tests/libpspp/stringi-map-test.c index eaf4102bb1..63b70ba80d 100644 --- a/tests/libpspp/stringi-map-test.c +++ b/tests/libpspp/stringi-map-test.c @@ -347,7 +347,7 @@ test_insert_any_remove_any (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int ins_perm_cnt; + unsigned int ins_n_perms; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -355,24 +355,24 @@ test_insert_any_remove_any (void) for (i = 0; i < cnt; i++) insertions[i] = i | random_value (i, basis); - for (ins_perm_cnt = 0; - ins_perm_cnt == 0 || next_permutation (insertions, cnt); - ins_perm_cnt++) + for (ins_n_perms = 0; + ins_n_perms == 0 || next_permutation (insertions, cnt); + ins_n_perms++) { - unsigned int del_perm_cnt; + unsigned int del_n_perms; int i; for (i = 0; i < cnt; i++) deletions[i] = i | random_value (i, basis); - for (del_perm_cnt = 0; - del_perm_cnt == 0 || next_permutation (deletions, cnt); - del_perm_cnt++) + for (del_n_perms = 0; + del_n_perms == 0 || next_permutation (deletions, cnt); + del_n_perms++) test_insert_delete (insertions, deletions, cnt); - check (del_perm_cnt == factorial (cnt)); + check (del_n_perms == factorial (cnt)); } - check (ins_perm_cnt == factorial (cnt)); + check (ins_n_perms == factorial (cnt)); free (insertions); free (deletions); @@ -390,18 +390,18 @@ test_insert_any_remove_same (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); for (i = 0; i < cnt; i++) values[i] = i | random_value (i, 1); - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) test_insert_delete (values, values, cnt); - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); } @@ -419,7 +419,7 @@ test_insert_any_remove_reverse (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -427,16 +427,16 @@ test_insert_any_remove_reverse (void) for (i = 0; i < cnt; i++) insertions[i] = i | random_value (i, 2); - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (insertions, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (insertions, cnt); + n_permutations++) { memcpy (deletions, insertions, sizeof *insertions * cnt); reverse (deletions, cnt); test_insert_delete (insertions, deletions, cnt); } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (insertions); free (deletions); diff --git a/tests/libpspp/stringi-set-test.c b/tests/libpspp/stringi-set-test.c index 74f1ba11e6..d7526bbf59 100644 --- a/tests/libpspp/stringi-set-test.c +++ b/tests/libpspp/stringi-set-test.c @@ -312,7 +312,7 @@ test_insert_any_remove_any (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int ins_perm_cnt; + unsigned int ins_n_perms; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -320,24 +320,24 @@ test_insert_any_remove_any (void) for (i = 0; i < cnt; i++) insertions[i] = i; - for (ins_perm_cnt = 0; - ins_perm_cnt == 0 || next_permutation (insertions, cnt); - ins_perm_cnt++) + for (ins_n_perms = 0; + ins_n_perms == 0 || next_permutation (insertions, cnt); + ins_n_perms++) { - unsigned int del_perm_cnt; + unsigned int del_n_perms; int i; for (i = 0; i < cnt; i++) deletions[i] = i; - for (del_perm_cnt = 0; - del_perm_cnt == 0 || next_permutation (deletions, cnt); - del_perm_cnt++) + for (del_n_perms = 0; + del_n_perms == 0 || next_permutation (deletions, cnt); + del_n_perms++) test_insert_delete (insertions, deletions, cnt); - check (del_perm_cnt == factorial (cnt)); + check (del_n_perms == factorial (cnt)); } - check (ins_perm_cnt == factorial (cnt)); + check (ins_n_perms == factorial (cnt)); free (insertions); free (deletions); @@ -355,18 +355,18 @@ test_insert_any_remove_same (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *values; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; values = xnmalloc (cnt, sizeof *values); for (i = 0; i < cnt; i++) values[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (values, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (values, cnt); + n_permutations++) test_insert_delete (values, values, cnt); - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (values); } @@ -384,7 +384,7 @@ test_insert_any_remove_reverse (void) for (cnt = 0; cnt <= max_elems; cnt++) { int *insertions, *deletions; - unsigned int permutation_cnt; + unsigned int n_permutations; int i; insertions = xnmalloc (cnt, sizeof *insertions); @@ -392,16 +392,16 @@ test_insert_any_remove_reverse (void) for (i = 0; i < cnt; i++) insertions[i] = i; - for (permutation_cnt = 0; - permutation_cnt == 0 || next_permutation (insertions, cnt); - permutation_cnt++) + for (n_permutations = 0; + n_permutations == 0 || next_permutation (insertions, cnt); + n_permutations++) { memcpy (deletions, insertions, sizeof *insertions * cnt); reverse (deletions, cnt); test_insert_delete (insertions, deletions, cnt); } - check (permutation_cnt == factorial (cnt)); + check (n_permutations == factorial (cnt)); free (insertions); free (deletions); diff --git a/tests/libpspp/tower-test.c b/tests/libpspp/tower-test.c index 8eae829407..0fc0467c1a 100644 --- a/tests/libpspp/tower-test.c +++ b/tests/libpspp/tower-test.c @@ -249,17 +249,17 @@ struct expected_block BLOCKS[]. */ static void check_tower (struct tower *t, - struct expected_block blocks[], size_t block_cnt) + struct expected_block blocks[], size_t n_blocks) { int total_height; struct tower_node *node; size_t i; - check (tower_count (t) == block_cnt); - check (tower_is_empty (t) == (block_cnt == 0)); + check (tower_count (t) == n_blocks); + check (tower_is_empty (t) == (n_blocks == 0)); total_height = 0; - for (i = 0; i < block_cnt; i++) + for (i = 0; i < n_blocks; i++) { unsigned long int level; for (level = total_height; @@ -287,9 +287,9 @@ check_tower (struct tower *t, check (tower_node_get_size (node) == blocks[i].size); check (tower_node_to_block (node)->x == blocks[i].x); } - check (i == block_cnt); + check (i == n_blocks); - for (node = tower_last (t), i = block_cnt - 1; + for (node = tower_last (t), i = n_blocks - 1; node != NULL; node = tower_prev (t, node), i--) { @@ -310,10 +310,10 @@ test_insert (void) for (cnt = 1; cnt <= max_height; cnt++) { - unsigned int composition_cnt; + unsigned int n_compositions; struct expected_block *expected; int *sizes; - int block_cnt; + int n_blocks; int *order; struct block *blocks; @@ -322,25 +322,25 @@ test_insert (void) order = xnmalloc (cnt, sizeof *order); blocks = xnmalloc (cnt, sizeof *blocks); - block_cnt = 0; - composition_cnt = 0; - while (next_composition (cnt, &block_cnt, sizes)) + n_blocks = 0; + n_compositions = 0; + while (next_composition (cnt, &n_blocks, sizes)) { int i, j; - unsigned int permutation_cnt; + unsigned int n_permutations; - for (i = 0; i < block_cnt; i++) + for (i = 0; i < n_blocks; i++) order[i] = i; - permutation_cnt = 0; - while (permutation_cnt == 0 || next_permutation (order, block_cnt)) + n_permutations = 0; + while (n_permutations == 0 || next_permutation (order, n_blocks)) { struct tower t; - /* Inserts the block_cnt blocks with the given + /* Inserts the n_blocks blocks with the given sizes[] into T in the order given by order[]. */ tower_init (&t); - for (i = 0; i < block_cnt; i++) + for (i = 0; i < n_blocks; i++) { struct block *under; int idx; @@ -359,20 +359,20 @@ test_insert (void) } /* Check that the result is what we expect. */ - for (i = 0; i < block_cnt; i++) + for (i = 0; i < n_blocks; i++) { expected[i].size = sizes[i]; expected[i].x = i; } - check_tower (&t, expected, block_cnt); + check_tower (&t, expected, n_blocks); - permutation_cnt++; + n_permutations++; } - check (permutation_cnt == factorial (block_cnt)); + check (n_permutations == factorial (n_blocks)); - composition_cnt++; + n_compositions++; } - check (composition_cnt == 1 << (cnt - 1)); + check (n_compositions == 1 << (cnt - 1)); free (expected); free (sizes); @@ -392,10 +392,10 @@ test_delete (void) for (cnt = 1; cnt <= max_height; cnt++) { - unsigned int composition_cnt; + unsigned int n_compositions; struct expected_block *expected; int *sizes; - int block_cnt; + int n_blocks; int *order; struct block *blocks; @@ -404,59 +404,59 @@ test_delete (void) order = xnmalloc (cnt, sizeof *order); blocks = xnmalloc (cnt, sizeof *blocks); - block_cnt = 0; - composition_cnt = 0; - while (next_composition (cnt, &block_cnt, sizes)) + n_blocks = 0; + n_compositions = 0; + while (next_composition (cnt, &n_blocks, sizes)) { int i; - unsigned int permutation_cnt; + unsigned int n_permutations; - for (i = 0; i < block_cnt; i++) + for (i = 0; i < n_blocks; i++) order[i] = i; - permutation_cnt = 0; - while (permutation_cnt == 0 || next_permutation (order, block_cnt)) + n_permutations = 0; + while (n_permutations == 0 || next_permutation (order, n_blocks)) { struct tower t; /* Insert blocks into tower in ascending order. */ tower_init (&t); - for (i = 0; i < block_cnt; i++) + for (i = 0; i < n_blocks; i++) { blocks[i].x = i; tower_insert (&t, sizes[i], &blocks[i].node, NULL); expected[i].x = i; expected[i].size = sizes[i]; } - check_tower (&t, expected, block_cnt); + check_tower (&t, expected, n_blocks); /* Delete blocks from tower in the order of order[]. */ - for (i = 0; i < block_cnt; i++) + for (i = 0; i < n_blocks; i++) { int idx = order[i]; int j; tower_delete (&t, &blocks[idx].node); for (j = 0; ; j++) { - assert (j < block_cnt - i); + assert (j < n_blocks - i); if (expected[j].x == idx) { memmove (&expected[j], &expected[j + 1], - sizeof *expected * (block_cnt - i - j - 1)); + sizeof *expected * (n_blocks - i - j - 1)); break; } } - check_tower (&t, expected, block_cnt - i - 1); + check_tower (&t, expected, n_blocks - i - 1); } - permutation_cnt++; + n_permutations++; } - check (permutation_cnt == factorial (block_cnt)); + check (n_permutations == factorial (n_blocks)); - composition_cnt++; + n_compositions++; } - check (composition_cnt == 1 << (cnt - 1)); + check (n_compositions == 1 << (cnt - 1)); free (expected); free (sizes); @@ -476,10 +476,10 @@ test_resize (void) for (cnt = 1; cnt <= max_height; cnt++) { - unsigned int composition_cnt; + unsigned int n_compositions; struct expected_block *expected; int *sizes, *new_sizes; - int block_cnt; + int n_blocks; int *order; struct block *blocks; @@ -489,45 +489,45 @@ test_resize (void) order = xnmalloc (cnt, sizeof *order); blocks = xnmalloc (cnt, sizeof *blocks); - block_cnt = 0; - composition_cnt = 0; - while (next_composition (cnt, &block_cnt, sizes)) + n_blocks = 0; + n_compositions = 0; + while (next_composition (cnt, &n_blocks, sizes)) { int i; unsigned int resizes = 0; - for (resizes = 0, first_k_composition (cnt, block_cnt, new_sizes); + for (resizes = 0, first_k_composition (cnt, n_blocks, new_sizes); (resizes == 0 - || next_k_composition (cnt, block_cnt, new_sizes)); + || next_k_composition (cnt, n_blocks, new_sizes)); resizes++) { struct tower t; /* Insert blocks into tower in ascending order. */ tower_init (&t); - for (i = 0; i < block_cnt; i++) + for (i = 0; i < n_blocks; i++) { blocks[i].x = i; tower_insert (&t, sizes[i], &blocks[i].node, NULL); expected[i].x = i; expected[i].size = sizes[i]; } - check_tower (&t, expected, block_cnt); + check_tower (&t, expected, n_blocks); /* Resize all the blocks. */ - for (i = 0; i < block_cnt; i++) + for (i = 0; i < n_blocks; i++) { if (expected[i].size != new_sizes[i] || rand () % 2) tower_resize (&t, &blocks[i].node, new_sizes[i]); expected[i].size = new_sizes[i]; } - check_tower (&t, expected, block_cnt); + check_tower (&t, expected, n_blocks); } - check (resizes == binomial_cofficient (cnt - 1, block_cnt - 1)); + check (resizes == binomial_cofficient (cnt - 1, n_blocks - 1)); - composition_cnt++; + n_compositions++; } - check (composition_cnt == 1 << (cnt - 1)); + check (n_compositions == 1 << (cnt - 1)); free (expected); free (new_sizes); @@ -547,10 +547,10 @@ test_splice_out (void) for (cnt = 1; cnt <= max_height; cnt++) { - unsigned int composition_cnt; + unsigned int n_compositions; struct expected_block *expected; int *sizes, *new_sizes; - int block_cnt; + int n_blocks; int *order; struct block *blocks; @@ -560,14 +560,14 @@ test_splice_out (void) order = xnmalloc (cnt, sizeof *order); blocks = xnmalloc (cnt, sizeof *blocks); - block_cnt = 0; - composition_cnt = 0; - while (next_composition (cnt, &block_cnt, sizes)) + n_blocks = 0; + n_compositions = 0; + while (next_composition (cnt, &n_blocks, sizes)) { int i, j; - for (i = 0; i < block_cnt; i++) - for (j = i; j <= block_cnt; j++) + for (i = 0; i < n_blocks; i++) + for (j = i; j <= n_blocks; j++) { struct tower src, dst; int k; @@ -576,26 +576,26 @@ test_splice_out (void) tower_init (&dst); /* Insert blocks into SRC and DST in ascending order. */ - for (k = 0; k < block_cnt; k++) + for (k = 0; k < n_blocks; k++) { blocks[k].x = k; tower_insert (&src, sizes[k], &blocks[k].node, NULL); expected[k].x = k; expected[k].size = sizes[k]; } - check_tower (&src, expected, block_cnt); + check_tower (&src, expected, n_blocks); /* Splice blocks I...J into DST. */ tower_splice (&dst, NULL, &src, &blocks[i].node, - j < block_cnt ? &blocks[j].node : NULL); + j < n_blocks ? &blocks[j].node : NULL); check_tower (&dst, &expected[i], j - i); memmove (&expected[i], &expected[j], - sizeof *expected * (block_cnt - j)); - check_tower (&src, expected, block_cnt - (j - i)); + sizeof *expected * (n_blocks - j)); + check_tower (&src, expected, n_blocks - (j - i)); } - composition_cnt++; + n_compositions++; } - check (composition_cnt == 1 << (cnt - 1)); + check (n_compositions == 1 << (cnt - 1)); free (expected); free (new_sizes); @@ -615,10 +615,10 @@ test_splice_in (void) for (cnt = 1; cnt <= max_height; cnt++) { - unsigned int composition_cnt; + unsigned int n_compositions; struct expected_block *expected; int *sizes, *new_sizes; - int block_cnt; + int n_blocks; int *order; struct block *blocks; @@ -628,14 +628,14 @@ test_splice_in (void) order = xnmalloc (cnt, sizeof *order); blocks = xnmalloc (cnt, sizeof *blocks); - block_cnt = 0; - composition_cnt = 0; - while (next_composition (cnt, &block_cnt, sizes)) + n_blocks = 0; + n_compositions = 0; + while (next_composition (cnt, &n_blocks, sizes)) { int i, j; - for (i = 0; i < block_cnt; i++) - for (j = i; j <= block_cnt; j++) + for (i = 0; i < n_blocks; i++) + for (j = i; j <= n_blocks; j++) { struct tower src, dst; int k; @@ -644,7 +644,7 @@ test_splice_in (void) tower_init (&dst); /* Insert blocks into SRC and DST in ascending order. */ - for (k = 0; k < block_cnt; k++) + for (k = 0; k < n_blocks; k++) { blocks[k].x = k; tower_insert (k >= i && k < j ? &src : &dst, @@ -654,13 +654,13 @@ test_splice_in (void) } /* Splice SRC into DST. */ - tower_splice (&dst, j < block_cnt ? &blocks[j].node : NULL, + tower_splice (&dst, j < n_blocks ? &blocks[j].node : NULL, &src, i != j ? &blocks[i].node : NULL, NULL); - check_tower (&dst, expected, block_cnt); + check_tower (&dst, expected, n_blocks); } - composition_cnt++; + n_compositions++; } - check (composition_cnt == 1 << (cnt - 1)); + check (n_compositions == 1 << (cnt - 1)); free (expected); free (new_sizes); diff --git a/utilities/pspp-convert.c b/utilities/pspp-convert.c index 1bd2e0a78d..99a254ba44 100644 --- a/utilities/pspp-convert.c +++ b/utilities/pspp-convert.c @@ -302,7 +302,7 @@ main (int argc, char *argv[]) goto error; dict_reorder_vars (dict, keep_vars, n_keep_vars); dict_delete_consecutive_vars (dict, n_keep_vars, - dict_get_var_cnt (dict) - n_keep_vars); + dict_get_n_vars (dict) - n_keep_vars); free (keep_vars); } diff --git a/utilities/pspp-dump-sav.c b/utilities/pspp-dump-sav.c index 4a44e49057..36cb285380 100644 --- a/utilities/pspp-dump-sav.c +++ b/utilities/pspp-dump-sav.c @@ -519,14 +519,14 @@ print_untyped_value (struct sfm_reader *r, char raw_value[8]) static void read_value_label_record (struct sfm_reader *r) { - int label_cnt, var_cnt; + int n_labels, n_vars; int i; printf ("%08llx: value labels record\n", (long long int) ftello (r->file)); /* Read number of labels. */ - label_cnt = read_int (r); - for (i = 0; i < label_cnt; i++) + n_labels = read_int (r); + for (i = 0; i < n_labels; i++) { char raw_value[8]; unsigned char label_len; @@ -559,8 +559,8 @@ read_value_label_record (struct sfm_reader *r) /* Read number of variables associated with value label from type 4 record. */ printf ("\t%08llx: apply to variables", (long long int) ftello (r->file)); - var_cnt = read_int (r); - for (i = 0; i < var_cnt; i++) + n_vars = read_int (r); + for (i = 0; i < n_vars; i++) printf (" #%d", read_int (r)); putchar ('\n'); } @@ -1590,10 +1590,10 @@ sys_error (struct sfm_reader *r, const char *format, ...) too. */ static inline bool read_bytes_internal (struct sfm_reader *r, bool eof_is_ok, - void *buf, size_t byte_cnt) + void *buf, size_t n_bytes) { - size_t bytes_read = fread (buf, 1, byte_cnt, r->file); - if (bytes_read == byte_cnt) + size_t bytes_read = fread (buf, 1, n_bytes, r->file); + if (bytes_read == n_bytes) return true; else if (ferror (r->file)) sys_error (r, "System error: %s.", strerror (errno)); @@ -1606,9 +1606,9 @@ read_bytes_internal (struct sfm_reader *r, bool eof_is_ok, /* Reads BYTE_CNT into BUF. Aborts upon I/O error or if end-of-file is encountered. */ static void -read_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) +read_bytes (struct sfm_reader *r, void *buf, size_t n_bytes) { - read_bytes_internal (r, false, buf, byte_cnt); + read_bytes_internal (r, false, buf, n_bytes); } /* Reads BYTE_CNT bytes into BUF. @@ -1616,9 +1616,9 @@ read_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) Returns false if an immediate end-of-file is encountered. Aborts if an I/O error or a partial read occurs. */ static bool -try_read_bytes (struct sfm_reader *r, void *buf, size_t byte_cnt) +try_read_bytes (struct sfm_reader *r, void *buf, size_t n_bytes) { - return read_bytes_internal (r, true, buf, byte_cnt); + return read_bytes_internal (r, true, buf, n_bytes); } /* Reads a 32-bit signed integer from R and returns its value in