Rename ANZ_* constants in shape.h to NUM_* #78

This is more in keeping with English standards, and hopefully
improves maintainability a small bit.
This commit is contained in:
Thomas Jensen 2021-04-14 21:27:23 +02:00
parent 2cc2bc1021
commit aa36998f77
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB
9 changed files with 43 additions and 43 deletions

View File

@ -116,7 +116,7 @@ static int build_design(design_t **adesigns, const char *cld)
}
strcpy(dp->shape[W].chars[0], cld);
for (i = 0; i < ANZ_SHAPES; ++i) {
for (i = 0; i < NUM_SHAPES; ++i) {
c = dp->shape + i;
if (i == NNW || i == NNE || i == WNW || i == ENE || i == W
@ -732,7 +732,7 @@ int main(int argc, char *argv[])
* Adjust box size to fit requested padding value
* Command line-specified box size takes precedence over padding.
*/
for (i = 0; i < ANZ_SIDES; ++i) {
for (i = 0; i < NUM_SIDES; ++i) {
if (opt.padding[i] > -1) {
opt.design->padding[i] = opt.padding[i];
}
@ -814,7 +814,7 @@ int main(int argc, char *argv[])
#ifdef DEBUG
fprintf (stderr, "Generating Box ...\n");
#endif
thebox = (sentry_t *) calloc(ANZ_SIDES, sizeof(sentry_t));
thebox = (sentry_t *) calloc(NUM_SIDES, sizeof(sentry_t));
if (thebox == NULL) {
perror(PROJECT);
exit(EXIT_FAILURE);

View File

@ -85,11 +85,11 @@ typedef struct {
char *revdate; /* date of current revision */
char *sample;
char indentmode; /* 'b', 't', or 'n' */
sentry_t shape[ANZ_SHAPES];
sentry_t shape[NUM_SHAPES];
size_t maxshapeheight; /* height of highest shape in design */
size_t minwidth;
size_t minheight;
int padding[ANZ_SIDES];
int padding[NUM_SIDES];
char **tags;
char *defined_in; /* path to config file where this was defined */
@ -120,7 +120,7 @@ typedef struct { /* Command line options: */
int l; /** `-l`: list available designs */
int mend; /** `-m`: 1 if -m is given, 2 in 2nd loop */
char *encoding; /** `-n`: character encoding override for input and output text */
int padding[ANZ_SIDES]; /** `-p`: in spaces or lines resp. */
int padding[NUM_SIDES]; /** `-p`: in spaces or lines resp. */
char **query; /** `-q`: parsed tag query expression passed in via -q; also, special handling of web UI needs */
int r; /** `-r`: remove box from input */
long reqwidth; /** `-s`: requested box width */

View File

@ -128,7 +128,7 @@ static opt_t *create_new_opt()
result->eol = "\n"; /* we must default to "\n" instead of EOL_DEFAULT as long as stdout is in text mode */
result->tabexp = 'e';
result->killblank = -1;
for (int i = 0; i < ANZ_SIDES; ++i) {
for (int i = 0; i < NUM_SIDES; ++i) {
result->padding[i] = -1;
}
}

View File

@ -690,7 +690,7 @@ int generate_box(sentry_t *thebox)
return 0; /* all clear */
err:
for (i = 0; i < ANZ_SIDES; ++i) {
for (i = 0; i < NUM_SIDES; ++i) {
if (!isempty(&(thebox[i]))) {
BFREE (thebox[i].chars); /* free only pointer array */
memset(thebox + i, 0, sizeof(sentry_t));

View File

@ -304,7 +304,7 @@ static void print_design_details(design_t *d)
fprintf(opt.outfile, "Elastic Shapes: ");
int sstart = 0;
for (int i = 0; i < ANZ_SHAPES; ++i) {
for (int i = 0; i < NUM_SHAPES; ++i) {
if (isempty(d->shape + i)) {
continue;
}
@ -323,7 +323,7 @@ static void print_design_details(design_t *d)
}
else {
int first_shape = 1;
for (int i = 0; i < ANZ_SHAPES; ++i) {
for (int i = 0; i < NUM_SHAPES; ++i) {
if (isdeepempty(d->shape + i)) {
continue;
}

View File

@ -97,7 +97,7 @@ static int check_sizes(pass_to_bison *bison_args)
fprintf (stderr, "check_sizes()\n");
#endif
for (i=0; i<ANZ_SIDES; ++i) {
for (i=0; i<NUM_SIDES; ++i) {
if (i == 0 || i == 2) {
/*
* horizontal
@ -165,7 +165,7 @@ static int corner_check(pass_to_bison *bison_args)
fprintf (stderr, "corner_check()\n");
#endif
for (c=0; c<ANZ_CORNERS; ++c) {
for (c=0; c<NUM_CORNERS; ++c) {
if (curdes.shape[corners[c]].elastic) {
yyerror(bison_args, "Corners may not be elastic (%s)", shape_name[corners[c]]);
return 1;
@ -185,13 +185,13 @@ static shape_t non_existent_elastics(pass_to_bison *bison_args)
fprintf (stderr, "non_existent_elastics()\n");
#endif
for (i=0; i<ANZ_SHAPES; ++i) {
for (i=0; i<NUM_SHAPES; ++i) {
if (curdes.shape[i].elastic && isempty(curdes.shape+i)) {
return i;
}
}
return (shape_t) ANZ_SHAPES; /* all elastic shapes exist */
return (shape_t) NUM_SHAPES; /* all elastic shapes exist */
}
@ -204,7 +204,7 @@ static int insufficient_elasticity(pass_to_bison *bison_args)
fprintf (stderr, "insufficient_elasticity()\n");
#endif
for (i=0; i<ANZ_SIDES; ++i) {
for (i=0; i<NUM_SIDES; ++i) {
for (j=1,ef=0; j<4; ++j) {
if (curdes.shape[sides[i][j]].elastic) {
++ef;
@ -228,7 +228,7 @@ static int adjoining_elastics(pass_to_bison *bison_args)
fprintf (stderr, "adjoining_elastics()\n");
#endif
for (i=0; i<ANZ_SIDES; ++i) {
for (i=0; i<NUM_SIDES; ++i) {
ef = 0;
for (j=1; j<4; ++j) {
if (isempty(curdes.shape+sides[i][j])) {
@ -257,7 +257,7 @@ int perform_se_check(pass_to_bison *bison_args)
shape_t s_rc;
s_rc = non_existent_elastics(bison_args);
if (s_rc != ANZ_SHAPES) {
if (s_rc != NUM_SHAPES) {
yyerror(bison_args, "Shape %s has been specified as elastic but doesn't exist",
shape_name[s_rc]);
return 1;
@ -493,18 +493,18 @@ int action_finalize_shapes(pass_to_bison *bison_args)
* as necessary, starting at any side which already includes at
* least one shape in order to ensure correct measurements.
*/
fshape = findshape (curdes.shape, ANZ_SHAPES);
if (fshape == ANZ_SHAPES) {
fshape = findshape (curdes.shape, NUM_SHAPES);
if (fshape == NUM_SHAPES) {
yyerror(bison_args, "internal error");
return RC_ABORT;
}
fside = on_side (fshape, 0);
if (fside == ANZ_SIDES) {
if (fside == NUM_SIDES) {
yyerror(bison_args, "internal error");
return RC_ABORT;
}
for (sc=0,side=fside; sc<ANZ_SIDES; ++sc,side=(side+1)%ANZ_SIDES) {
for (sc=0,side=fside; sc<NUM_SIDES; ++sc,side=(side+1)%NUM_SIDES) {
shape_t nshape; /* next shape */
sentry_t *c; /* corner to be processed */
c = curdes.shape + sides[side][SHAPES_PER_SIDE-1];
@ -541,7 +541,7 @@ int action_finalize_shapes(pass_to_bison *bison_args)
* For all sides whose side shapes have not been defined, generate
* an elastic middle side shape.
*/
for (side=0; side<ANZ_SIDES; ++side) {
for (side=0; side<NUM_SIDES; ++side) {
int found = 0;
for (i=1; i<SHAPES_PER_SIDE-1; ++i) {
if (isempty (curdes.shape + sides[side][i])) {
@ -582,7 +582,7 @@ int action_finalize_shapes(pass_to_bison *bison_args)
/*
* Compute minimum height/width of a box of current design
*/
for (i=0; i<ANZ_SIDES; ++i) {
for (i=0; i<NUM_SIDES; ++i) {
size_t c = 0;
if (i % 2) { /* vertical sides */
for (j=0; j<SHAPES_PER_SIDE; ++j) {
@ -609,7 +609,7 @@ int action_finalize_shapes(pass_to_bison *bison_args)
/*
* Compute height of highest shape in design
*/
for (i=0; i<ANZ_SHAPES; ++i) {
for (i=0; i<NUM_SHAPES; ++i) {
if (isempty(curdes.shape + i)) {
continue;
}

View File

@ -260,7 +260,7 @@ static int hmm(const int aside, const size_t follow,
}
sh = leftmost(aside, cnt);
if (sh == ANZ_SHAPES) {
if (sh == NUM_SHAPES) {
return 1;
}
@ -270,7 +270,7 @@ static int hmm(const int aside, const size_t follow,
if (cmp == 0) {
if (p + cs->width == ecs) {
if (leftmost(aside, cnt + 1) == ANZ_SHAPES) {
if (leftmost(aside, cnt + 1) == NUM_SHAPES) {
return 0; /* good! all clear, it matched */
} else {
return 3;
@ -529,7 +529,7 @@ static design_t *detect_design()
char *s;
line_t shpln; /* a line which is part of a shape */
size_t a;
int empty[ANZ_SIDES];
int empty[NUM_SIDES];
for (dcnt = 0; dcnt < anz_designs; ++dcnt, ++d) {
#ifdef DEBUG
@ -538,7 +538,7 @@ static design_t *detect_design()
#endif
hits = 0;
for (j = 0; j < ANZ_SIDES; ++j) {
for (j = 0; j < NUM_SIDES; ++j) {
empty[j] = empty_side(d->shape, j);
}
#ifdef DEBUG
@ -546,7 +546,7 @@ static design_t *detect_design()
empty[BTOP], empty[BLEF], empty[BBOT], empty[BRIG]);
#endif
for (scnt = 0; scnt < ANZ_SHAPES; ++scnt) {
for (scnt = 0; scnt < NUM_SHAPES; ++scnt) {
switch (scnt) {
case NW:

View File

@ -46,7 +46,7 @@ shape_t south_side[SHAPES_PER_SIDE] = {SE, SSE, S, SSW, SW};
shape_t west_side[SHAPES_PER_SIDE] = {SW, WSW, W, WNW, NW};
shape_t corners[ANZ_CORNERS] = {NW, NE, SE, SW};
shape_t corners[NUM_CORNERS] = {NW, NE, SE, SW};
shape_t *sides[] = {north_side, east_side, south_side, west_side};
@ -88,7 +88,7 @@ int on_side(const shape_t s, const int idx)
* idx which occurence to return (0 == first, 1 == second (for corners)
*
* RETURNS: side number (BTOP etc.) on success
* ANZ_SIDES on error (e.g. idx==1 && s no corner)
* NUM_SIDES on error (e.g. idx==1 && s no corner)
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
@ -97,7 +97,7 @@ int on_side(const shape_t s, const int idx)
int i;
int found = 0;
for (side = 0; side < ANZ_SIDES; ++side) {
for (side = 0; side < NUM_SIDES; ++side) {
for (i = 0; i < SHAPES_PER_SIDE; ++i) {
if (sides[side][i] == s) {
if (found == idx) {
@ -109,7 +109,7 @@ int on_side(const shape_t s, const int idx)
}
}
return ANZ_SIDES;
return NUM_SIDES;
}
@ -310,7 +310,7 @@ shape_t leftmost(const int aside, const int cnt)
* (BTOP or BBOT), skipping cnt shapes. Corners are not considered.
*
* RETURNS: shape if shape was found
* ANZ_SHAPES on error (e.g. cnt too high)
* NUM_SHAPES on error (e.g. cnt too high)
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
@ -319,7 +319,7 @@ shape_t leftmost(const int aside, const int cnt)
int s;
if (cnt < 0) {
return ANZ_SHAPES;
return NUM_SHAPES;
}
if (aside == BTOP) {
@ -331,7 +331,7 @@ shape_t leftmost(const int aside, const int cnt)
++s;
}
if (s == SHAPES_PER_SIDE - 1) {
return ANZ_SHAPES;
return NUM_SHAPES;
}
} while (c++ < cnt);
return north_side[s];
@ -345,13 +345,13 @@ shape_t leftmost(const int aside, const int cnt)
--s;
}
if (!s) {
return ANZ_SHAPES;
return NUM_SHAPES;
}
} while (c++ < cnt);
return south_side[s];
}
return ANZ_SHAPES;
return NUM_SHAPES;
}

View File

@ -32,18 +32,18 @@ typedef enum {
extern char *shape_name[];
#define ANZ_SHAPES 16
#define NUM_SHAPES 16
#define SHAPES_PER_SIDE 5
#define ANZ_SIDES 4
#define ANZ_CORNERS 4
#define NUM_SIDES 4
#define NUM_CORNERS 4
extern shape_t north_side[SHAPES_PER_SIDE]; /* groups of shapes, clockwise */
extern shape_t east_side[SHAPES_PER_SIDE];
extern shape_t south_side[SHAPES_PER_SIDE];
extern shape_t west_side[SHAPES_PER_SIDE];
extern shape_t corners[ANZ_CORNERS];
extern shape_t *sides[ANZ_SIDES];
extern shape_t corners[NUM_CORNERS];
extern shape_t *sides[NUM_SIDES];
typedef struct {