Apply new code format from CLion

This commit is contained in:
Thomas Jensen 2021-01-27 17:13:17 +01:00
parent dcd2328c77
commit f536d45f7a
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB
6 changed files with 1022 additions and 897 deletions

View File

@ -33,6 +33,7 @@
#include "generate.h"
static int horiz_precalc(const sentry_t *sarr,
size_t *topiltf, size_t *botiltf, size_t *hspace)
/*
@ -81,10 +82,15 @@ static int horiz_precalc (const sentry_t *sarr,
/*
* Compute number of existent shapes in top and in bottom part
*/
tnumsh = 0; bnumsh = 0;
tnumsh = 0;
bnumsh = 0;
for (i = 1; i < SHAPES_PER_SIDE - 1; ++i) {
if (!isempty(sarr+north_side[i])) tnumsh++;
if (!isempty(sarr+south_side[i])) bnumsh++;
if (!isempty(sarr + north_side[i])) {
tnumsh++;
}
if (!isempty(sarr + south_side[i])) {
bnumsh++;
}
}
#ifdef DEBUG
@ -136,8 +142,7 @@ static int horiz_precalc (const sentry_t *sarr,
if (!isempty(&(sarr[seite[i]]))) {
if (iltf[i - 1] == 0 ||
*res_hspace < target_width ||
twidth != bwidth)
{
twidth != bwidth) {
iltf[i - 1] += sarr[seite[i]].width;
*res_hspace += sarr[seite[i]].width;
}
@ -163,8 +168,7 @@ static int horiz_precalc (const sentry_t *sarr,
if (!isempty(sarr + seite[i]) && sarr[seite[i]].elastic) {
if (iltf[i - 1] == 0 ||
*res_hspace < target_width ||
twidth != bwidth)
{
twidth != bwidth) {
iltf[i - 1] += sarr[seite[i]].width;
*res_hspace += sarr[seite[i]].width;
}
@ -187,8 +191,7 @@ static int horiz_precalc (const sentry_t *sarr,
if (sarr[seite[1]].elastic && sarr[seite[3]].elastic) {
if (iltf[*stoggle - 1] == 0 ||
*res_hspace < target_width ||
twidth != bwidth)
{
twidth != bwidth) {
*res_hspace += sarr[seite[*stoggle]].width;
iltf[*stoggle - 1] += sarr[seite[*stoggle]].width;
}
@ -199,8 +202,7 @@ static int horiz_precalc (const sentry_t *sarr,
if (sarr[seite[i]].elastic) {
if (iltf[i - 1] == 0 ||
*res_hspace < target_width ||
twidth != bwidth)
{
twidth != bwidth) {
iltf[i - 1] += sarr[seite[i]].width;
*res_hspace += sarr[seite[i]].width;
}
@ -214,7 +216,6 @@ static int horiz_precalc (const sentry_t *sarr,
fprintf(stderr, "%s: internal error in horiz_precalc()\n", PROJECT);
return 1;
}
} while (twidth != bwidth || twidth < target_width || bwidth < target_width);
*hspace = twidth; /* return either one */
@ -272,10 +273,15 @@ static int vert_precalc (const sentry_t *sarr,
/*
* Compute number of existent shapes in left and right part (1..3)
*/
lnumsh = 0; rnumsh = 0;
lnumsh = 0;
rnumsh = 0;
for (i = 1; i < SHAPES_PER_SIDE - 1; ++i) {
if (!isempty(sarr+west_side[i])) lnumsh++;
if (!isempty(sarr+east_side[i])) rnumsh++;
if (!isempty(sarr + west_side[i])) {
lnumsh++;
}
if (!isempty(sarr + east_side[i])) {
rnumsh++;
}
}
lheight = 0;
@ -320,8 +326,7 @@ static int vert_precalc (const sentry_t *sarr,
if (!isempty(&(sarr[seite[i]]))) {
if (iltf[i - 1] == 0 ||
*res_vspace < target_height ||
lheight != rheight)
{
lheight != rheight) {
iltf[i - 1] += sarr[seite[i]].height;
*res_vspace += sarr[seite[i]].height;
}
@ -347,8 +352,7 @@ static int vert_precalc (const sentry_t *sarr,
if (!isempty(sarr + seite[i]) && sarr[seite[i]].elastic) {
if (iltf[i - 1] == 0 ||
*res_vspace < target_height ||
lheight != rheight)
{
lheight != rheight) {
iltf[i - 1] += sarr[seite[i]].height;
*res_vspace += sarr[seite[i]].height;
}
@ -371,8 +375,7 @@ static int vert_precalc (const sentry_t *sarr,
if (sarr[seite[1]].elastic && sarr[seite[3]].elastic) {
if (iltf[*stoggle - 1] == 0 ||
*res_vspace < target_height ||
lheight != rheight)
{
lheight != rheight) {
*res_vspace += sarr[seite[*stoggle]].height;
iltf[*stoggle - 1] += sarr[seite[*stoggle]].height;
}
@ -383,8 +386,7 @@ static int vert_precalc (const sentry_t *sarr,
if (sarr[seite[i]].elastic) {
if (iltf[i - 1] == 0 ||
*res_vspace < target_height ||
lheight != rheight)
{
lheight != rheight) {
iltf[i - 1] += sarr[seite[i]].height;
*res_vspace += sarr[seite[i]].height;
}
@ -398,7 +400,6 @@ static int vert_precalc (const sentry_t *sarr,
fprintf(stderr, "%s: internal error in vert_precalc()\n", PROJECT);
return 1;
}
} while (lheight != rheight || lheight < target_height || rheight < target_height);
*vspace = lheight; /* return either one */
@ -426,9 +427,11 @@ static int vert_assemble (const sentry_t *sarr, const shape_t *seite,
result->chars[line] = (char *) calloc(1, result->width + 1);
if (result->chars[line] == NULL) {
perror(PROJECT);
if ((long)--line >= 0) do {
if ((long) --line >= 0) {
do {
BFREE (result->chars[line--]);
} while ((long) line >= 0);
}
return 1; /* out of memory */
}
}
@ -436,10 +439,12 @@ static int vert_assemble (const sentry_t *sarr, const shape_t *seite,
cshape = (seite == north_side) ? 0 : 2;
for (j = 0; j < result->width; j += sarr[seite[cshape + 1]].width) {
while (iltf[cshape] == 0)
while (iltf[cshape] == 0) {
cshape += (seite == north_side) ? 1 : -1;
for (line=0; line<result->height; ++line)
}
for (line = 0; line < result->height; ++line) {
strcat(result->chars[line], sarr[seite[cshape + 1]].chars[line]);
}
iltf[cshape] -= sarr[seite[cshape + 1]].width;
}
@ -467,24 +472,27 @@ static void horiz_assemble (const sentry_t *sarr, const shape_t *seite,
cshape = 2;
}
for (j=0; j<sarr[ctop].height; ++j)
for (j = 0; j < sarr[ctop].height; ++j) {
result->chars[j] = sarr[ctop].chars[j];
for (j=0; j<sarr[cbottom].height; ++j)
}
for (j = 0; j < sarr[cbottom].height; ++j) {
result->chars[result->height - sarr[cbottom].height + j] =
sarr[cbottom].chars[j];
}
sc = 0;
for (j=sarr[ctop].height; j < result->height-sarr[cbottom].height; ++j)
{
for (j = sarr[ctop].height; j < result->height - sarr[cbottom].height; ++j) {
while (iltf[cshape] == 0) {
if (seite == east_side)
if (seite == east_side) {
++cshape;
else
} else {
--cshape;
}
sc = 0;
}
if (sc == sarr[seite[cshape+1]].height)
if (sc == sarr[seite[cshape + 1]].height) {
sc = 0;
}
result->chars[j] = sarr[seite[cshape + 1]].chars[sc];
++sc;
iltf[cshape] -= 1;
@ -513,7 +521,9 @@ static int horiz_generate (sentry_t *tresult, sentry_t *bresult)
SHAPES_PER_SIDE, SW, SSW, S, SSE, SE);
rc = horiz_precalc(opt.design->shape, tiltf, biltf, &(tresult->width));
if (rc) return rc;
if (rc) {
return rc;
}
bresult->width = tresult->width;
#ifdef DEBUG
@ -533,12 +543,18 @@ static int horiz_generate (sentry_t *tresult, sentry_t *bresult)
tresult->chars = (char **) calloc(tresult->height, sizeof(char *));
bresult->chars = (char **) calloc(bresult->height, sizeof(char *));
if (tresult->chars == NULL || bresult->chars == NULL) return 1;
if (tresult->chars == NULL || bresult->chars == NULL) {
return 1;
}
rc = vert_assemble(opt.design->shape, north_side, tiltf, tresult);
if (rc) return rc;
if (rc) {
return rc;
}
rc = vert_assemble(opt.design->shape, south_side, biltf, bresult);
if (rc) return rc;
if (rc) {
return rc;
}
#if defined(DEBUG) && 1
{
@ -585,7 +601,9 @@ static int vert_generate (sentry_t *lresult, sentry_t *rresult)
SHAPES_PER_SIDE, SE, ESE, E, ENE, NE);
rc = vert_precalc(opt.design->shape, leftiltf, rightiltf, &vspace);
if (rc) return rc;
if (rc) {
return rc;
}
lresult->height = vspace +
opt.design->shape[NW].height + opt.design->shape[SW].height;
@ -608,9 +626,13 @@ static int vert_generate (sentry_t *lresult, sentry_t *rresult)
#endif
lresult->chars = (char **) calloc(lresult->height, sizeof(char *));
if (lresult->chars == NULL) return 1;
if (lresult->chars == NULL) {
return 1;
}
rresult->chars = (char **) calloc(rresult->height, sizeof(char *));
if (rresult->chars == NULL) return 1;
if (rresult->chars == NULL) {
return 1;
}
horiz_assemble(opt.design->shape, west_side, leftiltf, lresult);
horiz_assemble(opt.design->shape, east_side, rightiltf, rresult);
@ -652,10 +674,14 @@ int generate_box (sentry_t *thebox)
int i;
rc = horiz_generate(&(thebox[0]), &(thebox[2]));
if (rc) goto err;
if (rc) {
goto err;
}
rc = vert_generate(&(thebox[3]), &(thebox[1]));
if (rc) goto err;
if (rc) {
goto err;
}
return 0; /* all clear */
@ -701,7 +727,8 @@ static int justify_line (line_t *line, int skew)
return 0;
}
for (p=line->text; *p==' ' || *p=='\t'; ++p);
for (p = line->text; *p == ' ' || *p == '\t'; ++p) {
}
newlen = line->len - (p - line->text);
switch (opt.justify) {
@ -725,14 +752,16 @@ static int justify_line (line_t *line, int skew)
if (opt.design->indentmode == 't') {
shift = (input.maxline - input.indent - newlen + line->invis) / 2 + input.indent;
skew -= input.indent;
if ((input.maxline-input.indent - newlen) % 2 && skew == 1)
if ((input.maxline - input.indent - newlen) % 2 && skew == 1) {
++shift;
}
}
else {
shift = (input.maxline - newlen + line->invis) / 2;
if ((input.maxline - newlen +line->invis) % 2 && skew == 1)
if ((input.maxline - newlen + line->invis) % 2 && skew == 1) {
++shift;
}
}
newtext = (char *) calloc(shift + newlen + line->invis + 1, sizeof(char));
if (newtext == NULL) {
@ -976,12 +1005,15 @@ int output_box (const sentry_t *thebox)
skip_start = 0;
skip_end = 0;
skip_left = 0;
if (empty_side (opt.design->shape, BTOP))
if (empty_side(opt.design->shape, BTOP)) {
skip_start = opt.design->shape[NW].height;
if (empty_side (opt.design->shape, BBOT))
}
if (empty_side(opt.design->shape, BBOT)) {
skip_end = opt.design->shape[SW].height;
if (empty_side (opt.design->shape, BLEF))
skip_left = opt.design->shape[NW].width; /* could simply be 1, though */
}
if (empty_side(opt.design->shape, BLEF)) {
skip_left = opt.design->shape[NW].width;
} /* could simply be 1, though */
#if defined(DEBUG)
fprintf (stderr, "skip_start = %d; skip_end = %d; skip_left = %d; "
"nol = %d;\n", skip_start, skip_end, skip_left, nol);
@ -1019,8 +1051,9 @@ int output_box (const sentry_t *thebox)
input.lines[ti].text, input.lines[ti].len, hpr-hpl);
#endif
rc = justify_line(input.lines + ti, hpr - hpl);
if (rc)
if (rc) {
return rc;
}
r = input.maxline - input.lines[ti].vischar;
trailspc[r] = '\0';
restored_indent = tabbify_indent(ti, indentspc, indentspclen);

View File

@ -27,6 +27,7 @@
int generate_box(sentry_t *thebox);
int output_box(const sentry_t *thebox);

View File

@ -90,8 +90,9 @@ static int best_match (const line_t *line,
chkline.text = cs->chars[k];
chkline.len = cs->width;
if (empty_line (&chkline) && !(quality==0 && j==numw-1))
if (empty_line(&chkline) && !(quality == 0 && j == numw - 1)) {
continue;
}
s = (char *) strdup(cs->chars[k]);
if (s == NULL) {
@ -110,15 +111,16 @@ static int best_match (const line_t *line,
break;
}
}
if (p)
if (p) {
break;
}
}
if (!p && cq) {
if (*s == ' ')
if (*s == ' ') {
memmove(s, s + 1, cq--);
else if (s[cq-1] == ' ')
} else if (s[cq - 1] == ' ') {
s[--cq] = '\0';
else {
} else {
cq = 0;
break;
}
@ -161,8 +163,9 @@ static int best_match (const line_t *line,
chkline.text = cs->chars[k];
chkline.len = cs->width;
if (empty_line (&chkline))
if (empty_line(&chkline)) {
continue;
}
s = (char *) strdup(cs->chars[k]);
if (s == NULL) {
@ -181,15 +184,16 @@ static int best_match (const line_t *line,
break;
}
}
if (p)
if (p) {
break;
}
}
if (!p && cq) {
if (*s == ' ')
if (*s == ' ') {
memmove(s, s + 1, cq--);
else if (s[cq-1] == ' ')
} else if (s[cq - 1] == ' ') {
s[--cq] = '\0';
else {
} else {
cq = 0;
break;
}
@ -248,12 +252,14 @@ static int hmm (const int aside, const size_t follow,
aside==BTOP?"BTOP":"BBOT", follow, p[0], *ecs, cnt);
#endif
if (p > ecs) /* last shape tried was too long */
if (p > ecs) { /* last shape tried was too long */
return 2;
}
sh = leftmost(aside, cnt);
if (sh == ANZ_SHAPES)
if (sh == ANZ_SHAPES) {
return 1;
}
cs = opt.design->shape + sh;
@ -261,10 +267,11 @@ 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) == ANZ_SHAPES) {
return 0; /* good! all clear, it matched */
else
return 3; /* didn't use all shapes to do it */
} else {
return 3;
} /* didn't use all shapes to do it */
}
if (cs->elastic) {
rc = hmm(aside, follow, p + cs->width, ecs, cnt);
@ -284,10 +291,11 @@ static int hmm (const int aside, const size_t follow,
fprintf (stderr, "hmm returned %d\n", rc);
#endif
}
if (rc == 0)
if (rc == 0) {
return 0; /* we're on the way back */
else
return 4; /* can't continue on this path */
} else {
return 4;
} /* can't continue on this path */
}
else {
return 5; /* no match */
@ -347,8 +355,7 @@ static int detect_horiz (const int aside, size_t *hstart, size_t *hend)
}
for (lcnt = 0; lcnt < mheight && lcnt < input.anz_lines
&& line >= input.lines; ++lcnt)
{
&& line >= input.lines; ++lcnt) {
goeast = gowest = 0;
#ifdef DEBUG
@ -366,11 +373,12 @@ static int detect_horiz (const int aside, size_t *hstart, size_t *hend)
wcs = NULL;
if (gowest) {
gowest = 0;
if (*p == ' ' || *p == '\t')
if (*p == ' ' || *p == '\t') {
++p;
else
} else {
break;
}
}
else {
p = line->text;
}
@ -386,14 +394,17 @@ static int detect_horiz (const int aside, size_t *hstart, size_t *hend)
}
if (wcs) {
for (q = wcs - 1; q >= line->text; --q) {
if (*q != ' ' && *q != '\t')
if (*q != ' ' && *q != '\t') {
break;
}
if (q >= line->text)
}
if (q >= line->text) {
wcs = NULL;
}
if (!wcs)
}
if (!wcs) {
break;
}
p = wcs + cs->width;
}
@ -402,13 +413,13 @@ static int detect_horiz (const int aside, size_t *hstart, size_t *hend)
/* or not NULL (if west side is not empty). In any case, p */
/* points to where we start searching for the east corner. */
#ifdef DEBUG
if (wcs)
if (wcs) {
fprintf (stderr, "West corner shape matched at "
"position %d.\n", wcs - line->text);
else
} else {
fprintf (stderr, "West box side is empty.\n");
}
#endif
/*
* Look for east corner shape
*/
@ -416,37 +427,37 @@ static int detect_horiz (const int aside, size_t *hstart, size_t *hend)
ecs = my_strnrstr(p, cs->chars[follow], cs->width, goeast);
if (ecs) {
for (q = ecs + cs->width; *q; ++q) {
if (*q != ' ' && *q != '\t')
if (*q != ' ' && *q != '\t') {
break;
}
if (*q)
}
if (*q) {
ecs = NULL;
}
}
if (!ecs) {
if (goeast == 0)
if (goeast == 0) {
break;
else {
} else {
goeast = 0;
gowest = 1;
continue;
}
}
#ifdef DEBUG
fprintf (stderr, "East corner shape matched at position %d.\n",
ecs-line->text);
fprintf (stderr, "East corner shape matched at position %d.\n", ecs-line->text);
#endif
/*
* Check if text between corner shapes is valid
*/
mmok = !hmm(aside, follow, p, ecs, 0);
if (!mmok)
if (!mmok) {
++goeast;
}
#ifdef DEBUG
fprintf (stderr, "Text between corner shapes is %s.\n",
mmok? "VALID": "NOT valid");
fprintf (stderr, "Text between corner shapes is %s.\n", mmok? "VALID": "NOT valid");
#endif
} while (!mmok);
/*
@ -455,20 +466,23 @@ static int detect_horiz (const int aside, size_t *hstart, size_t *hend)
if (mmok) { /* match found */
if (!result_init) {
result_init = 1;
if (aside == BTOP)
if (aside == BTOP) {
*hstart = lcnt;
else
} else {
*hend = (input.anz_lines - lcnt - 1) + 1;
}
if (aside == BTOP)
}
if (aside == BTOP) {
*hend = lcnt + 1;
else
} else {
*hstart = input.anz_lines - lcnt - 1;
}
}
else {
if (result_init)
if (result_init) {
break;
}
}
wcs = NULL;
ecs = NULL;
@ -523,8 +537,9 @@ static design_t *detect_design()
#endif
hits = 0;
for (j=0; j<ANZ_SIDES; ++j)
for (j = 0; j < ANZ_SIDES; ++j) {
empty[j] = empty_side(d->shape, j);
}
#ifdef DEBUG
fprintf (stderr, "Empty sides: TOP %d, LEFT %d, BOTTOM %d, RIGHT %d\n",
empty[BTOP], empty[BLEF], empty[BBOT], empty[BRIG]);
@ -533,80 +548,96 @@ static design_t *detect_design()
for (scnt = 0; scnt < ANZ_SHAPES; ++scnt) {
switch (scnt) {
case NW: case SW:
case NW:
case SW:
/*
* Try and find west corner shapes. Every non-empty shape
* line is searched for on every input line. A hit is
* generated whenever a match is found.
*/
if (empty[BLEF] || (empty[BTOP] && scnt == NW)
|| (empty[BBOT] && scnt == SW))
|| (empty[BBOT] && scnt == SW)) {
break;
}
for (j = 0; j < d->shape[scnt].height; ++j) {
shpln.text = d->shape[scnt].chars[j];
shpln.len = d->shape[scnt].width;
if (empty_line (&shpln))
if (empty_line(&shpln)) {
continue;
for (s=shpln.text; *s==' ' || *s=='\t'; ++s);
}
for (s = shpln.text; *s == ' ' || *s == '\t'; ++s) {
}
for (k = 0; k < d->shape[scnt].height; ++k) {
a = k;
if (scnt == SW)
if (scnt == SW) {
a += input.anz_lines - d->shape[scnt].height;
if (a >= input.anz_lines)
}
if (a >= input.anz_lines) {
break;
for (p=input.lines[a].text; *p==' '||*p=='\t'; ++p);
if (strncmp (p, s, shpln.len-(s-shpln.text)) == 0)
}
for (p = input.lines[a].text; *p == ' ' || *p == '\t'; ++p) {
}
if (strncmp(p, s, shpln.len - (s - shpln.text)) == 0) {
++hits;
}
}
}
#ifdef DEBUG
fprintf (stderr, "After %s corner check:\t%ld hits.\n",
shape_name[scnt], hits);
fprintf (stderr, "After %s corner check:\t%ld hits.\n", shape_name[scnt], hits);
#endif
break;
case NE: case SE:
case NE:
case SE:
/*
* Try and find east corner shapes. Every non-empty shape
* line is searched for on every input line. A hit is
* generated whenever a match is found.
*/
if (empty[BRIG] || (empty[BTOP] && scnt == NE)
|| (empty[BBOT] && scnt == SE))
|| (empty[BBOT] && scnt == SE)) {
break;
}
for (j = 0; j < d->shape[scnt].height; ++j) {
shpln.text = d->shape[scnt].chars[j];
shpln.len = d->shape[scnt].width;
if (empty_line (&shpln))
if (empty_line(&shpln)) {
continue;
}
for (s = shpln.text + shpln.len - 1;
(*s == ' ' || *s == '\t') && shpln.len;
--s, --(shpln.len));
--s, --(shpln.len)) {
}
for (k = 0; k < d->shape[scnt].height; ++k) {
a = k;
if (scnt == SE)
if (scnt == SE) {
a += input.anz_lines - d->shape[scnt].height;
if (a >= input.anz_lines)
}
if (a >= input.anz_lines) {
break;
}
for (p = input.lines[a].text + input.lines[a].len - 1;
p >= input.lines[a].text && (*p == ' ' || *p == '\t');
--p);
--p) {
}
p = p - shpln.len + 1;
if (p < input.lines[a].text)
if (p < input.lines[a].text) {
continue;
if (strncmp (p, shpln.text, shpln.len) == 0)
}
if (strncmp(p, shpln.text, shpln.len) == 0) {
++hits;
}
}
}
#ifdef DEBUG
fprintf (stderr, "After %s corner check:\t%ld hits.\n",
shape_name[scnt], hits);
fprintf (stderr, "After %s corner check:\t%ld hits.\n", shape_name[scnt], hits);
#endif
break;
default:
if (isempty (d->shape+scnt))
if (isempty(d->shape + scnt)) {
continue;
}
if ((scnt >= NNW && scnt <= NNE)
|| (scnt >= SSE && scnt <= SSW)) {
@ -624,30 +655,37 @@ static design_t *detect_design()
for (j = 0; j < d->shape[scnt].height; ++j) {
shpln.text = d->shape[scnt].chars[j];
shpln.len = d->shape[scnt].width;
if (empty_line (&shpln))
if (empty_line(&shpln)) {
continue;
}
for (k = 0; k < d->shape[scnt].height; ++k) {
a = k;
if (scnt >= SSE && scnt <= SSW)
if (scnt >= SSE && scnt <= SSW) {
a += input.anz_lines - d->shape[scnt].height;
if (a >= input.anz_lines)
}
if (a >= input.anz_lines) {
break;
}
for (p = input.lines[a].text;
*p == ' ' || *p == '\t'; ++p);
*p == ' ' || *p == '\t'; ++p) {
}
p += d->shape[NW].width;
if (p - input.lines[a].text
>= (long) input.lines[a].len)
>= (long) input.lines[a].len) {
continue;
}
p = strstr(p, shpln.text);
if (p) {
if (d->shape[scnt].elastic) {
p += shpln.len;
if (p - input.lines[a].text
>= (long) input.lines[a].len)
>= (long) input.lines[a].len) {
continue;
if (!strncmp (p, shpln.text, shpln.len))
}
if (!strncmp(p, shpln.text, shpln.len)) {
++hits;
}
}
else {
++hits;
}
@ -678,48 +716,55 @@ static design_t *detect_design()
* non-empty shape line. If so, generate a hit.
*/
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.anz_lines) {
for (k = empty[BTOP] ? 0 : d->shape[NW].height;
k < input.anz_lines - (empty[BBOT] ? 0 : d->shape[SW].height);
++k)
{
for (p=input.lines[k].text; *p==' ' || *p=='\t'; ++p);
++k) {
for (p = input.lines[k].text; *p == ' ' || *p == '\t'; ++p) {
}
for (scnt = WSW; scnt <= WNW; ++scnt) {
a = 0;
if (isempty (d->shape + scnt))
if (isempty(d->shape + scnt)) {
continue;
}
for (j = 0; j < d->shape[scnt].height; ++j) {
shpln.text = d->shape[scnt].chars[j];
shpln.len = d->shape[scnt].width;
if (empty_line (&shpln))
if (empty_line(&shpln)) {
continue;
for (s=shpln.text; *s==' ' || *s=='\t'; ++s);
}
for (s = shpln.text; *s == ' ' || *s == '\t'; ++s) {
}
if (strncmp(p, s, shpln.len - (s - shpln.text)) == 0) {
++hits;
a = 1;
break;
}
}
if (a)
if (a) {
break;
}
}
for (scnt = ENE; scnt <= ESE; ++scnt) {
a = 0;
if (isempty (d->shape + scnt))
if (isempty(d->shape + scnt)) {
continue;
}
for (j = 0; j < d->shape[scnt].height; ++j) {
shpln.text = d->shape[scnt].chars[j];
shpln.len = d->shape[scnt].width;
if (empty_line (&shpln))
if (empty_line(&shpln)) {
continue;
}
for (p = input.lines[k].text + input.lines[k].len - 1;
p >= input.lines[a].text && (*p == ' ' || *p == '\t');
--p);
--p) {
}
for (s = shpln.text + shpln.len - 1;
(*s == ' ' || *s == '\t') && shpln.len;
--s, --(shpln.len));
--s, --(shpln.len)) {
}
p = p - shpln.len + 1;
if (strncmp(p, shpln.text, shpln.len) == 0) {
++hits;
@ -727,15 +772,15 @@ static design_t *detect_design()
break;
}
}
if (a)
if (a) {
break;
}
}
}
}
#ifdef DEBUG
fprintf (stderr, "After side checks:\t%ld hits.\n", hits);
#endif
if (hits > maxhits) {
maxhits = hits;
res = d;
@ -743,11 +788,11 @@ static design_t *detect_design()
}
#ifdef DEBUG
if (res)
fprintf (stderr, "CHOOSING \"%s\" design (%ld hits).\n",
res->name, maxhits);
else
if (res) {
fprintf (stderr, "CHOOSING \"%s\" design (%ld hits).\n", res->name, maxhits);
} else {
fprintf (stderr, "NO DESIGN FOUND WITH EVEN ONE HIT!\n");
}
#endif
return res;
@ -906,15 +951,17 @@ int remove_box()
#endif
if (ws && we) {
did_something = 1;
for (p=ws; p<we; ++p)
for (p = ws; p < we; ++p) {
*p = ' ';
}
}
if (es && ee) {
for (p=es; p<ee; ++p)
for (p = es; p < ee; ++p) {
*p = ' ';
}
}
}
}
/*
* Remove as many spaces from the left side of the line as the west side
@ -926,9 +973,10 @@ int remove_box()
size_t c;
size_t widz = opt.design->shape[NW].width + opt.design->padding[BLEF];
for (c = 0; c < widz; ++c) {
if (input.lines[j].text[c] != ' ')
if (input.lines[j].text[c] != ' ') {
break;
}
}
#ifdef DEBUG
fprintf (stderr, "memmove (\"%s\", \"%s\", %d);\n",
input.lines[j].text, input.lines[j].text + c,
@ -964,8 +1012,7 @@ int remove_box()
}
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,
(input.anz_lines - textstart) * sizeof(line_t));
input.anz_lines -= textstart - boxstart;
@ -973,8 +1020,7 @@ int remove_box()
boxend -= textstart - boxstart;
}
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) {
memmove(input.lines + textend, input.lines + boxend,
(input.anz_lines - boxend) * sizeof(line_t));
@ -1023,13 +1069,14 @@ void output_input (const int trim_only)
#ifdef DEBUG
fprintf (stderr, "output_input() - enter (trim_only=%d)\n", trim_only);
#endif
for (j=0; j<input.anz_lines; ++j)
{
if (input.lines[j].text == NULL)
for (j = 0; j < input.anz_lines; ++j) {
if (input.lines[j].text == NULL) {
continue;
}
btrim(input.lines[j].text, &(input.lines[j].len));
if (trim_only)
if (trim_only) {
continue;
}
indentspc = NULL;
if (opt.tabexp == 'u') {

View File

@ -39,12 +39,16 @@ char *shape_name[] = {
};
shape_t north_side[SHAPES_PER_SIDE] = {NW, NNW, N, NNE, NE}; /* clockwise */
shape_t east_side[SHAPES_PER_SIDE] = { NE, ENE, E, ESE, SE };
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 *sides[] = { north_side, east_side, south_side, west_side };
shape_t east_side[SHAPES_PER_SIDE] = {NE, ENE, E, ESE, SE};
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 *sides[] = {north_side, east_side, south_side, west_side};
@ -64,11 +68,12 @@ shape_t findshape (const sentry_t *sarr, const int num)
int i;
for (i = 0; i < num; ++i) {
if (isempty(sarr+i))
if (isempty(sarr + i)) {
continue;
else
} else {
break;
}
}
return (shape_t) i;
}
@ -95,13 +100,14 @@ int on_side (const shape_t s, const int idx)
for (side = 0; side < ANZ_SIDES; ++side) {
for (i = 0; i < SHAPES_PER_SIDE; ++i) {
if (sides[side][i] == s) {
if (found == idx)
if (found == idx) {
return side;
else
} else {
++found;
}
}
}
}
return ANZ_SIDES;
}
@ -141,8 +147,7 @@ int genshape (const size_t width, const size_t height, char ***chars)
(*chars)[j] = (char *) calloc(width + 1, sizeof(char));
if ((*chars)[j] == NULL) {
perror(PROJECT);
for (/*empty*/; j>0; --j)
BFREE ((*chars)[j-1]);
for (/*empty*/; j > 0; --j) BFREE ((*chars)[j - 1]);
BFREE (*chars);
return 3;
}
@ -164,8 +169,9 @@ void freeshape (sentry_t *shape)
{
size_t j;
for (j=0; j<shape->height; ++j)
for (j = 0; j < shape->height; ++j) {
BFREE (shape->chars[j]);
}
BFREE (shape->chars);
*shape = SENTRY_INITIALIZER;
@ -180,15 +186,16 @@ int isempty (const sentry_t *shape)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
{
if (shape == NULL)
if (shape == NULL) {
return 1;
else if (shape->chars == NULL)
} else if (shape->chars == NULL) {
return 1;
else if (shape->width == 0 || shape->height == 0)
} else if (shape->width == 0 || shape->height == 0) {
return 1;
else
} else {
return 0;
}
}
@ -202,15 +209,17 @@ int isdeepempty (const sentry_t *shape)
{
size_t j;
if (isempty (shape))
if (isempty(shape)) {
return 1;
}
for (j = 0; j < shape->height; ++j) {
if (shape->chars[j]) {
if (strspn (shape->chars[j], " ") != shape->width)
if (strspn(shape->chars[j], " ") != shape->width) {
return 0;
}
}
}
return 1;
}
@ -243,10 +252,11 @@ size_t highest (const sentry_t *sarr, const int n, ...)
for (i = 0; i < n; ++i) {
shape_t r = va_arg (ap, shape_t);
if (!isempty(sarr + r)) {
if (sarr[r].height > max)
if (sarr[r].height > max) {
max = sarr[r].height;
}
}
}
va_end (ap);
@ -281,10 +291,11 @@ size_t widest (const sentry_t *sarr, const int n, ...)
for (i = 0; i < n; ++i) {
shape_t r = va_arg (ap, shape_t);
if (!isempty(sarr + r)) {
if (sarr[r].width > max)
if (sarr[r].width > max) {
max = sarr[r].width;
}
}
}
va_end (ap);
@ -307,18 +318,21 @@ shape_t leftmost (const int aside, const int cnt)
int c = 0;
int s;
if (cnt < 0)
if (cnt < 0) {
return ANZ_SHAPES;
}
if (aside == BTOP) {
s = 0;
do {
++s;
while (s < SHAPES_PER_SIDE - 1 &&
isempty(opt.design->shape + north_side[s]))
isempty(opt.design->shape + north_side[s])) {
++s;
if (s == SHAPES_PER_SIDE-1)
}
if (s == SHAPES_PER_SIDE - 1) {
return ANZ_SHAPES;
}
} while (c++ < cnt);
return north_side[s];
}
@ -327,10 +341,12 @@ shape_t leftmost (const int aside, const int cnt)
s = SHAPES_PER_SIDE - 1;
do {
--s;
while (s && isempty(opt.design->shape + south_side[s]))
while (s && isempty(opt.design->shape + south_side[s])) {
--s;
if (!s)
}
if (!s) {
return ANZ_SHAPES;
}
} while (c++ < cnt);
return south_side[s];
}
@ -357,10 +373,11 @@ int empty_side (sentry_t *sarr, const int aside)
int i;
for (i = 0; i < SHAPES_PER_SIDE; ++i) {
if (isdeepempty (sarr + sides[aside][i]))
if (isdeepempty(sarr + sides[aside][i])) {
continue;
else
return 0; /* side is not empty */
} else {
return 0;
} /* side is not empty */
}
return 1; /* side is empty */

View File

@ -86,22 +86,24 @@ int strisyes (const char *s)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
{
if (s == NULL)
if (s == NULL) {
return 0;
}
if (!strncasecmp ("on", s, 3))
if (!strncasecmp("on", s, 3)) {
return 1;
else if (!strncasecmp ("yes", s, 4))
} else if (!strncasecmp("yes", s, 4)) {
return 1;
else if (!strncasecmp ("true", s, 5))
} else if (!strncasecmp("true", s, 5)) {
return 1;
else if (!strncmp ("1", s, 2))
} else if (!strncmp("1", s, 2)) {
return 1;
else if (!strncasecmp ("t", s, 2))
} else if (!strncasecmp("t", s, 2)) {
return 1;
else
} else {
return 0;
}
}
@ -117,22 +119,24 @@ int strisno (const char *s)
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
{
if (s == NULL)
if (s == NULL) {
return 0;
}
if (!strncasecmp ("off", s, 4))
if (!strncasecmp("off", s, 4)) {
return 1;
else if (!strncasecmp ("no", s, 3))
} else if (!strncasecmp("no", s, 3)) {
return 1;
else if (!strncasecmp ("false", s, 6))
} else if (!strncasecmp("false", s, 6)) {
return 1;
else if (!strncmp ("0", s, 2))
} else if (!strncmp("0", s, 2)) {
return 1;
else if (!strncasecmp ("f", s, 2))
} else if (!strncasecmp("f", s, 2)) {
return 1;
else
} else {
return 0;
}
}
@ -159,8 +163,9 @@ void concat_strings (char *dst, int max_len, int count, ...)
/*
* Sanity check.
*/
if (max_len < 1)
if (max_len < 1) {
return;
}
if (max_len == 1 || count < 1) {
*dst = '\0';
@ -178,8 +183,9 @@ void concat_strings (char *dst, int max_len, int count, ...)
*/
src = va_arg (va, const char *);
if (src == NULL)
if (src == NULL) {
continue;
}
/*
* Concatenate 'src' onto 'dst', as long as we have room.
@ -212,15 +218,18 @@ int empty_line (const line_t *line)
char *p;
size_t j;
if (!line)
if (!line) {
return 1;
if (line->text == NULL || line->len <= 0)
}
if (line->text == NULL || line->len <= 0) {
return 1;
}
for (p = line->text, j = 0; *p && j < line->len; ++j, ++p) {
if (*p != ' ' && *p != '\t' && *p != '\r')
if (*p != ' ' && *p != '\t' && *p != '\r') {
return 0;
}
}
return 1;
}
@ -257,11 +266,13 @@ size_t expand_tabs_into (const char *input_buffer, const size_t in_len,
*text = NULL;
for (ii = 0, *tabpos_len = 0; ii < in_len; ++ii) {
if (input_buffer[ii] == '\t')
if (input_buffer[ii] == '\t') {
(*tabpos_len)++;
}
if (opt.tabexp != 'k')
}
if (opt.tabexp != 'k') {
*tabpos_len = 0;
}
if (*tabpos_len > 0) {
*tabpos = (size_t *) calloc((*tabpos_len) + 1, sizeof(size_t));
if (*tabpos == NULL) {
@ -274,9 +285,10 @@ size_t expand_tabs_into (const char *input_buffer, const size_t in_len,
if (*tabpos_len > 0) {
(*tabpos)[tabnum++] = io;
}
for (jp=io+tabstop-(io%tabstop); io<jp; ++io)
for (jp = io + tabstop - (io % tabstop); io < jp; ++io) {
temp[io] = ' ';
}
}
else {
temp[io] = input_buffer[ii];
++io;
@ -285,7 +297,9 @@ size_t expand_tabs_into (const char *input_buffer, const size_t in_len,
temp[io] = '\0';
*text = (char *) strdup(temp);
if (*text == NULL) return 0;
if (*text == NULL) {
return 0;
}
return io;
}
@ -302,7 +316,7 @@ void btrim (char *text, size_t *len)
long idx = (long) (*len) - 1;
while (idx >= 0 && (text[idx] == '\n' || text[idx] == '\r'
|| text[idx] == '\t' || text[idx] == ' '))
|| text[idx] == '\t' || text[idx] == ' ')) /**/
{
text[idx--] = '\0';
}
@ -330,25 +344,30 @@ char *my_strnrstr (const char *s1, const char *s2, const size_t s2_len, int skip
char *p;
int comp;
if (!s2 || *s2 == '\0')
if (!s2 || *s2 == '\0') {
return (char *) s1;
if (!s1 || *s1 == '\0')
}
if (!s1 || *s1 == '\0') {
return NULL;
if (skip < 0)
}
if (skip < 0) {
skip = 0;
}
p = strrchr(s1, s2[0]);
if (!p)
if (!p) {
return NULL;
}
while (p >= s1) {
comp = strncmp(p, s2, s2_len);
if (comp == 0) {
if (skip--)
if (skip--) {
--p;
else
} else {
return p;
}
}
else {
--p;
}
@ -401,7 +420,7 @@ char *tabbify_indent (const size_t lineno, char *indentspc, const size_t indents
result_len = indentspc_len;
for (i = 0; i < input.lines[lineno].tabpos_len
&& input.lines[lineno].tabpos[i] < indentspc_len; ++i)
&& input.lines[lineno].tabpos[i] < indentspc_len; ++i) /**/
{
size_t tpos = input.lines[lineno].tabpos[i];
size_t nspc = opt.tabstop - (tpos % opt.tabstop); /* no of spcs covered by tab */

View File

@ -38,20 +38,28 @@
int yyerror(const char *fmt, ...);
void regerror(char *msg);
int empty_line(const line_t *line);
size_t expand_tabs_into(const char *input_buffer, const size_t in_len,
const int tabstop, char **text, size_t **tabpos, size_t *tabpos_len);
void btrim(char *text, size_t *len);
char *my_strnrstr(const char *s1, const char *s2, const size_t s2_len,
int skip);
int strisyes(const char *s);
int strisno(const char *s);
void concat_strings(char *dst, int max_len, int count, ...);
char *tabbify_indent(const size_t lineno, char *indentspc, const size_t indentspc_len);
#endif
/*EOF*/ /* vim: set cindent sw=4: */