Rename anz_lines field in input_t to num_lines #78

This commit is contained in:
Thomas Jensen 2021-04-15 22:13:29 +02:00
parent a7227c8aa8
commit 9d17203f50
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB
6 changed files with 53 additions and 53 deletions

View File

@ -373,7 +373,7 @@ int main(int argc, char *argv[])
memcpy(&input, raw_input, sizeof(input_t)); memcpy(&input, raw_input, sizeof(input_t));
BFREE(raw_input); BFREE(raw_input);
} }
if (input.anz_lines == 0) { if (input.num_lines == 0) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -388,7 +388,7 @@ int main(int argc, char *argv[])
} }
pad = opt.design->padding[BTOP] + opt.design->padding[BBOT]; pad = opt.design->padding[BTOP] + opt.design->padding[BBOT];
if (pad > 0) { if (pad > 0) {
pad += input.anz_lines; pad += input.num_lines;
pad += opt.design->shape[NW].height + opt.design->shape[SW].height; pad += opt.design->shape[NW].height + opt.design->shape[SW].height;
if (pad > opt.design->minheight) { if (pad > opt.design->minheight) {
if (opt.reqheight) { if (opt.reqheight) {

View File

@ -158,7 +158,7 @@ typedef struct {
typedef struct { typedef struct {
line_t *lines; line_t *lines;
size_t anz_lines; /* number of entries in input TODO rename to num_lines */ size_t num_lines; /* number of entries in input */
size_t maxline; /* length of longest input line */ size_t maxline; /* length of longest input line */
size_t indent; /* number of leading spaces found */ size_t indent; /* number of leading spaces found */
int final_newline; /* true if the last line of input ends with newline */ int final_newline; /* true if the last line of input ends with newline */

View File

@ -265,9 +265,9 @@ static int vert_precalc(const sentry_t *sarr,
* Ensure minimum height for insides of box in order to ensure * Ensure minimum height for insides of box in order to ensure
* minimum box size required by current design * minimum box size required by current design
*/ */
if (input.anz_lines >= (opt.design->minheight - sarr[west_side[0]].height - if (input.num_lines >= (opt.design->minheight - sarr[west_side[0]].height -
sarr[west_side[SHAPES_PER_SIDE - 1]].height)) { sarr[west_side[SHAPES_PER_SIDE - 1]].height)) {
target_height = input.anz_lines; target_height = input.num_lines;
} }
else { else {
target_height = opt.design->minheight - sarr[west_side[0]].height - target_height = opt.design->minheight - sarr[west_side[0]].height -
@ -858,7 +858,7 @@ int output_box(const sentry_t *thebox)
/* /*
* Compute number of empty lines in box (vfill). * Compute number of empty lines in box (vfill).
*/ */
vfill = nol - thebox[BTOP].height - thebox[BBOT].height - input.anz_lines; vfill = nol - thebox[BTOP].height - thebox[BBOT].height - input.num_lines;
vfill -= opt.design->padding[BTOP] + opt.design->padding[BBOT]; vfill -= opt.design->padding[BTOP] + opt.design->padding[BBOT];
if (opt.valign == 'c') { if (opt.valign == 'c') {
vfill1 = vfill / 2; vfill1 = vfill / 2;
@ -972,7 +972,7 @@ int output_box(const sentry_t *thebox)
else if (j < nol - thebox[BBOT].height) { else if (j < nol - thebox[BBOT].height) {
long ti = j - thebox[BTOP].height - (vfill - vfill2); long ti = j - thebox[BTOP].height - (vfill - vfill2);
if (ti < (long) input.anz_lines) { /* box content (lines) */ if (ti < (long) input.num_lines) { /* box content (lines) */
int shift = justify_line(input.lines + ti, hpr - hpl); int shift = justify_line(input.lines + ti, hpr - hpl);
restored_indent = tabbify_indent(ti, indentspc, indentspclen); restored_indent = tabbify_indent(ti, indentspc, indentspclen);
uint32_t *mbtext_shifted = advance32(input.lines[ti].mbtext, shift < 0 ? (size_t) (-shift) : 0); uint32_t *mbtext_shifted = advance32(input.lines[ti].mbtext, shift < 0 ? (size_t) (-shift) : 0);
@ -984,7 +984,7 @@ int output_box(const sentry_t *thebox)
thebox[BRIG].chars[j]); thebox[BRIG].chars[j]);
} }
else { /* bottom vfill */ else { /* bottom vfill */
restored_indent = tabbify_indent(input.anz_lines - 1, indentspc, indentspclen); restored_indent = tabbify_indent(input.num_lines - 1, indentspc, indentspclen);
concat_strings(obuf, LINE_MAX_BYTES + 1, 4, restored_indent, concat_strings(obuf, LINE_MAX_BYTES + 1, 4, restored_indent,
skip_left ? "" : thebox[BLEF].chars[j], nspaces(thebox[BTOP].width), skip_left ? "" : thebox[BLEF].chars[j], nspaces(thebox[BTOP].width),
thebox[BRIG].chars[j]); thebox[BRIG].chars[j]);
@ -992,7 +992,7 @@ int output_box(const sentry_t *thebox)
} }
else { /* box bottom */ else { /* box bottom */
restored_indent = tabbify_indent(input.anz_lines - 1, indentspc, indentspclen); restored_indent = tabbify_indent(input.num_lines - 1, indentspc, indentspclen);
concat_strings(obuf, LINE_MAX_BYTES + 1, 4, restored_indent, concat_strings(obuf, LINE_MAX_BYTES + 1, 4, restored_indent,
skip_left ? "" : thebox[BLEF].chars[j], skip_left ? "" : thebox[BLEF].chars[j],
thebox[BBOT].chars[j - (nol - thebox[BBOT].height)], thebox[BBOT].chars[j - (nol - thebox[BBOT].height)],

View File

@ -141,7 +141,7 @@ int apply_substitutions(input_t *result, const int mode)
/* /*
* Apply regular expression substitutions to input lines * Apply regular expression substitutions to input lines
*/ */
for (k = 0; k < result->anz_lines; ++k) { for (k = 0; k < result->num_lines; ++k) {
opt.design->current_rule = rules; opt.design->current_rule = rules;
for (j = 0; j < anz_rules; ++j, ++(opt.design->current_rule)) { for (j = 0; j < anz_rules; ++j, ++(opt.design->current_rule)) {
#ifdef REGEXP_DEBUG #ifdef REGEXP_DEBUG
@ -178,7 +178,7 @@ int apply_substitutions(input_t *result, const int mode)
*/ */
if (opt.design->indentmode == 't') { if (opt.design->indentmode == 't') {
int rc; int rc;
rc = get_indent(result->lines, result->anz_lines); rc = get_indent(result->lines, result->num_lines);
if (rc >= 0) { if (rc >= 0) {
result->indent = (size_t) rc; result->indent = (size_t) rc;
} else { } else {
@ -222,7 +222,7 @@ input_t *read_all_input()
while (fgets(buf, LINE_MAX_BYTES + 2, opt.infile)) while (fgets(buf, LINE_MAX_BYTES + 2, opt.infile))
{ {
if (result->anz_lines % 100 == 0) { if (result->num_lines % 100 == 0) {
input_size += 100; input_size += 100;
line_t *tmp = (line_t *) realloc(result->lines, input_size * sizeof(line_t)); line_t *tmp = (line_t *) realloc(result->lines, input_size * sizeof(line_t));
if (tmp == NULL) { if (tmp == NULL) {
@ -233,7 +233,7 @@ input_t *read_all_input()
result->lines = tmp; result->lines = tmp;
} }
memset(result->lines + result->anz_lines, 0, sizeof(line_t)); memset(result->lines + result->num_lines, 0, sizeof(line_t));
uint32_t *mbtemp = u32_strconv_from_input(buf); uint32_t *mbtemp = u32_strconv_from_input(buf);
size_t len_chars = u32_strlen(mbtemp); size_t len_chars = u32_strlen(mbtemp);
@ -246,24 +246,24 @@ input_t *read_all_input()
if (len_chars > 0) { if (len_chars > 0) {
uint32_t *temp = NULL; uint32_t *temp = NULL;
len_chars = expand_tabs_into(mbtemp, opt.tabstop, &temp, len_chars = expand_tabs_into(mbtemp, opt.tabstop, &temp,
&(result->lines[result->anz_lines].tabpos), &(result->lines[result->num_lines].tabpos),
&(result->lines[result->anz_lines].tabpos_len)); &(result->lines[result->num_lines].tabpos_len));
if (len_chars == 0) { if (len_chars == 0) {
perror(PROJECT); perror(PROJECT);
BFREE (result->lines); BFREE (result->lines);
return NULL; return NULL;
} }
result->lines[result->anz_lines].mbtext = temp; result->lines[result->num_lines].mbtext = temp;
BFREE(mbtemp); BFREE(mbtemp);
temp = NULL; temp = NULL;
} }
else { else {
result->lines[result->anz_lines].mbtext = mbtemp; result->lines[result->num_lines].mbtext = mbtemp;
} }
result->lines[result->anz_lines].mbtext_org = result->lines[result->anz_lines].mbtext; result->lines[result->num_lines].mbtext_org = result->lines[result->num_lines].mbtext;
result->lines[result->anz_lines].num_chars = len_chars; result->lines[result->num_lines].num_chars = len_chars;
++result->anz_lines; ++result->num_lines;
} }
if (ferror(stdin)) { if (ferror(stdin)) {
@ -284,7 +284,7 @@ int analyze_input(input_t *result)
/* /*
* Build ASCII equivalent of the multi-byte string, update line stats * Build ASCII equivalent of the multi-byte string, update line stats
*/ */
for (size_t i = 0; i < result->anz_lines; ++i) { for (size_t i = 0; i < result->num_lines; ++i) {
analyze_line_ascii(result, result->lines + i); analyze_line_ascii(result, result->lines + i);
} }
@ -298,7 +298,7 @@ int analyze_input(input_t *result)
/* /*
* Compute indentation * Compute indentation
*/ */
int rc = get_indent(result->lines, result->anz_lines); int rc = get_indent(result->lines, result->num_lines);
if (rc >= 0) { if (rc >= 0) {
result->indent = (size_t) rc; result->indent = (size_t) rc;
} else { } else {
@ -310,7 +310,7 @@ int analyze_input(input_t *result)
* a box or if the user wants to retain it inside the box) * a box or if the user wants to retain it inside the box)
*/ */
if (opt.design->indentmode != 't' && opt.r == 0) { if (opt.design->indentmode != 't' && opt.r == 0) {
for (size_t i = 0; i < result->anz_lines; ++i) { for (size_t i = 0; i < result->num_lines; ++i) {
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "%2d: mbtext = \"%s\" (%d chars)\n", (int) i, fprintf(stderr, "%2d: mbtext = \"%s\" (%d chars)\n", (int) i,
u32_strconv_to_output(result->lines[i].mbtext), (int) result->lines[i].num_chars); u32_strconv_to_output(result->lines[i].mbtext), (int) result->lines[i].num_chars);

View File

@ -354,16 +354,16 @@ static int detect_horiz(const int aside, size_t *hstart, size_t *hend)
} }
else { else {
follow = mheight - 1; follow = mheight - 1;
line = input.lines + input.anz_lines - 1; line = input.lines + input.num_lines - 1;
} }
for (lcnt = 0; lcnt < mheight && lcnt < input.anz_lines for (lcnt = 0; lcnt < mheight && lcnt < input.num_lines
&& line >= input.lines; ++lcnt) { && line >= input.lines; ++lcnt) {
goeast = gowest = 0; goeast = gowest = 0;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "----- Processing line index %2d -----------------------------------------------\n", fprintf(stderr, "----- Processing line index %2d -----------------------------------------------\n",
(int) (aside == BTOP ? lcnt : input.anz_lines - lcnt - 1)); (int) (aside == BTOP ? lcnt : input.num_lines - lcnt - 1));
#endif #endif
do { do {
@ -470,13 +470,13 @@ static int detect_horiz(const int aside, size_t *hstart, size_t *hend)
if (aside == BTOP) { if (aside == BTOP) {
*hstart = lcnt; *hstart = lcnt;
} else { } else {
*hend = (input.anz_lines - lcnt - 1) + 1; *hend = (input.num_lines - lcnt - 1) + 1;
} }
} }
if (aside == BTOP) { if (aside == BTOP) {
*hend = lcnt + 1; *hend = lcnt + 1;
} else { } else {
*hstart = input.anz_lines - lcnt - 1; *hstart = input.num_lines - lcnt - 1;
} }
} }
else { else {
@ -571,9 +571,9 @@ static design_t *detect_design()
for (k = 0; k < d->shape[scnt].height; ++k) { for (k = 0; k < d->shape[scnt].height; ++k) {
a = k; a = k;
if (scnt == SW) { if (scnt == SW) {
a += input.anz_lines - d->shape[scnt].height; a += input.num_lines - d->shape[scnt].height;
} }
if (a >= input.anz_lines) { if (a >= input.num_lines) {
break; break;
} }
for (p = input.lines[a].text; *p == ' ' || *p == '\t'; ++p) { for (p = input.lines[a].text; *p == ' ' || *p == '\t'; ++p) {
@ -612,9 +612,9 @@ static design_t *detect_design()
for (k = 0; k < d->shape[scnt].height; ++k) { for (k = 0; k < d->shape[scnt].height; ++k) {
a = k; a = k;
if (scnt == SE) { if (scnt == SE) {
a += input.anz_lines - d->shape[scnt].height; a += input.num_lines - d->shape[scnt].height;
} }
if (a >= input.anz_lines) { if (a >= input.num_lines) {
break; break;
} }
for (p = input.lines[a].text + input.lines[a].len - 1; for (p = input.lines[a].text + input.lines[a].len - 1;
@ -662,9 +662,9 @@ static design_t *detect_design()
for (k = 0; k < d->shape[scnt].height; ++k) { for (k = 0; k < d->shape[scnt].height; ++k) {
a = k; a = k;
if (scnt >= SSE && scnt <= SSW) { if (scnt >= SSE && scnt <= SSW) {
a += input.anz_lines - d->shape[scnt].height; a += input.num_lines - d->shape[scnt].height;
} }
if (a >= input.anz_lines) { if (a >= input.num_lines) {
break; break;
} }
for (p = input.lines[a].text; for (p = input.lines[a].text;
@ -717,9 +717,9 @@ static design_t *detect_design()
* non-empty shape line. If so, generate a hit. * non-empty shape line. If so, generate a hit.
*/ */
if (((empty[BTOP] ? 0 : d->shape[NW].height) if (((empty[BTOP] ? 0 : d->shape[NW].height)
+ (empty[BBOT] ? 0 : d->shape[SW].height)) < input.anz_lines) { + (empty[BBOT] ? 0 : d->shape[SW].height)) < input.num_lines) {
for (k = empty[BTOP] ? 0 : d->shape[NW].height; for (k = empty[BTOP] ? 0 : d->shape[NW].height;
k < input.anz_lines - (empty[BBOT] ? 0 : d->shape[SW].height); k < input.num_lines - (empty[BBOT] ? 0 : d->shape[SW].height);
++k) { ++k) {
for (p = input.lines[k].text; *p == ' ' || *p == '\t'; ++p) { for (p = input.lines[k].text; *p == ' ' || *p == '\t'; ++p) {
} }
@ -862,7 +862,7 @@ int remove_box()
* add a number of spaces equal to the east side width. * add a number of spaces equal to the east side width.
*/ */
const size_t normalized_len = input.maxline + opt.design->shape[NE].width; const size_t normalized_len = input.maxline + opt.design->shape[NE].width;
for (j = 0; j < input.anz_lines; ++j) { for (j = 0; j < input.num_lines; ++j) {
add_spaces_to_line(input.lines + j, normalized_len - input.lines[j].len); add_spaces_to_line(input.lines + j, normalized_len - input.lines[j].len);
} }
#ifdef DEBUG #ifdef DEBUG
@ -893,10 +893,10 @@ int remove_box()
* Phase 2: Find out how many lines belong to the bottom of the box * Phase 2: Find out how many lines belong to the bottom of the box
*/ */
if (empty_side(opt.design->shape, BBOT)) { if (empty_side(opt.design->shape, BBOT)) {
textend = input.anz_lines; textend = input.num_lines;
boxend = input.anz_lines; boxend = input.num_lines;
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "----> Bottom box side is empty: boxend == textend == %d.\n", (int) input.anz_lines); fprintf(stderr, "----> Bottom box side is empty: boxend == textend == %d.\n", (int) input.num_lines);
#endif #endif
} }
else { else {
@ -904,8 +904,8 @@ int remove_box()
boxend = 0; boxend = 0;
detect_horiz(BBOT, &textend, &boxend); detect_horiz(BBOT, &textend, &boxend);
if (textend == 0 && boxend == 0) { if (textend == 0 && boxend == 0) {
textend = input.anz_lines; textend = input.num_lines;
boxend = input.anz_lines; boxend = input.num_lines;
} }
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "----> Last line of box body (text) is %d, ", (int) (textend - 1)); fprintf(stderr, "----> Last line of box body (text) is %d, ", (int) (textend - 1));
@ -1022,26 +1022,26 @@ int remove_box()
if (textstart > boxstart) { if (textstart > boxstart) {
for (j = boxstart; j < textstart; ++j) BFREE (input.lines[j].text); for (j = boxstart; j < textstart; ++j) BFREE (input.lines[j].text);
memmove(input.lines + boxstart, input.lines + textstart, memmove(input.lines + boxstart, input.lines + textstart,
(input.anz_lines - textstart) * sizeof(line_t)); (input.num_lines - textstart) * sizeof(line_t));
input.anz_lines -= textstart - boxstart; input.num_lines -= textstart - boxstart;
textend -= textstart - boxstart; textend -= textstart - boxstart;
boxend -= textstart - boxstart; boxend -= textstart - boxstart;
} }
if (boxend > textend) { if (boxend > textend) {
for (j = textend; j < boxend; ++j) BFREE (input.lines[j].text); for (j = textend; j < boxend; ++j) BFREE (input.lines[j].text);
if (boxend < input.anz_lines) { if (boxend < input.num_lines) {
memmove(input.lines + textend, input.lines + boxend, memmove(input.lines + textend, input.lines + boxend,
(input.anz_lines - boxend) * sizeof(line_t)); (input.num_lines - boxend) * sizeof(line_t));
} }
input.anz_lines -= boxend - textend; input.num_lines -= boxend - textend;
} }
input.maxline = 0; input.maxline = 0;
for (j = 0; j < input.anz_lines; ++j) { for (j = 0; j < input.num_lines; ++j) {
if (input.lines[j].len - input.lines[j].invis > input.maxline) { if (input.lines[j].len - input.lines[j].invis > input.maxline) {
input.maxline = input.lines[j].len - input.lines[j].invis; input.maxline = input.lines[j].len - input.lines[j].invis;
} }
} }
memset(input.lines + input.anz_lines, 0, memset(input.lines + input.num_lines, 0,
(BMAX (textstart - boxstart, (size_t) 0) + BMAX (boxend - textend, (size_t) 0)) * sizeof(line_t)); (BMAX (textstart - boxstart, (size_t) 0) + BMAX (boxend - textend, (size_t) 0)) * sizeof(line_t));
#ifdef DEBUG #ifdef DEBUG
@ -1069,7 +1069,7 @@ void output_input(const int trim_only)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "output_input() - enter (trim_only=%d)\n", trim_only); fprintf(stderr, "output_input() - enter (trim_only=%d)\n", trim_only);
#endif #endif
for (size_t j = 0; j < input.anz_lines; ++j) { for (size_t j = 0; j < input.num_lines; ++j) {
if (input.lines[j].text == NULL) { if (input.lines[j].text == NULL) {
continue; continue;
} }
@ -1103,7 +1103,7 @@ void output_input(const int trim_only)
} }
fprintf(opt.outfile, "%s%s%s", indentspc, u32_strconv_to_output(advance32(input.lines[j].mbtext, indent)), fprintf(opt.outfile, "%s%s%s", indentspc, u32_strconv_to_output(advance32(input.lines[j].mbtext, indent)),
(input.final_newline || j < input.anz_lines - 1 ? opt.eol : "")); (input.final_newline || j < input.num_lines - 1 ? opt.eol : ""));
BFREE (indentspc); BFREE (indentspc);
} }
} }

View File

@ -459,7 +459,7 @@ char *tabbify_indent(const size_t lineno, char *indentspc, const size_t indentsp
if (opt.tabexp != 'k') { if (opt.tabexp != 'k') {
return indentspc; return indentspc;
} }
if (lineno >= input.anz_lines) { if (lineno >= input.num_lines) {
return NULL; return NULL;
} }
if (indentspc_len == 0) { if (indentspc_len == 0) {
@ -509,7 +509,7 @@ void print_input_lines(const char *heading)
{ {
fprintf(stderr, "Input Lines%s:\n", heading != NULL ? heading : ""); fprintf(stderr, "Input Lines%s:\n", heading != NULL ? heading : "");
fprintf(stderr, " [num_chars] \"real text\" [num_cols] \"ascii_text\"\n"); fprintf(stderr, " [num_chars] \"real text\" [num_cols] \"ascii_text\"\n");
for (size_t i = 0; i < input.anz_lines; ++i) { for (size_t i = 0; i < input.num_lines; ++i) {
fprintf(stderr, "%4d [%02d] \"%s\" [%02d] \"%s\"", (int) i, fprintf(stderr, "%4d [%02d] \"%s\" [%02d] \"%s\"", (int) i,
(int) input.lines[i].num_chars, u32_strconv_to_output(input.lines[i].mbtext), (int) input.lines[i].num_chars, u32_strconv_to_output(input.lines[i].mbtext),
(int) input.lines[i].len, input.lines[i].text); (int) input.lines[i].len, input.lines[i].text);