Apply new code format from CLion

This commit is contained in:
Thomas Jensen 2021-02-03 20:46:48 +01:00
parent 53e7782b5f
commit 6a3d0e715c
No known key found for this signature in database
GPG Key ID: A4ACEE270D0FB7DB

View File

@ -46,6 +46,8 @@
#include "remove.h" #include "remove.h"
#include "unicode.h" #include "unicode.h"
#ifdef __MINGW32__ #ifdef __MINGW32__
#include <windows.h> #include <windows.h>
#endif #endif
@ -59,23 +61,6 @@ extern int optind, opterr, optopt; /* for getopt() */
#define BOXES_CONFIG ".boxes" #define BOXES_CONFIG ".boxes"
#endif #endif
/*
* Some source comments (AD 1999):
*
* - The decision to number box shapes in clockwise order was a
* major design mistake. Treatment of box parts of the same
* alignment (N-S and E-W) is usually combined in one function,
* which must now deal with the numbering being reversed all the
* time.
* - All shapes defined in a box design must be used in any box of
* that design at least once. In other words, there must not be
* a shape which is defined in the config file but cannot be
* found in an actual box of that design. This sort of limits
* how small your boxes can get. However, in practice it is not
* a problem, because boxes which must be small usually consist
* of small shapes which can be packed pretty tightly anyway.
*/
/* _\|/_ /* _\|/_
(o o) (o o)
@ -215,8 +200,9 @@ static int get_config_file()
char exepath[256]; /* for constructing config file path */ char exepath[256]; /* for constructing config file path */
#endif #endif
if (yyin != stdin) if (yyin != stdin) {
return 0; /* we're already ok */ return 0; /* we're already ok */
}
/* /*
* Try getting it from the BOXES environment variable * Try getting it from the BOXES environment variable
@ -288,8 +274,7 @@ static int get_config_file()
else { else {
#ifndef __MINGW32__ #ifndef __MINGW32__
/* Do not print this warning on windows. */ /* Do not print this warning on windows. */
fprintf (stderr, "%s: warning: Environment variable HOME not set!\n", fprintf(stderr, "%s: warning: Environment variable HOME not set!\n", PROJECT);
PROJECT);
#endif #endif
} }
@ -385,16 +370,16 @@ static int process_commandline (int argc, char *argv[])
opt.tabstop = DEF_TABSTOP; opt.tabstop = DEF_TABSTOP;
opt.tabexp = 'e'; opt.tabexp = 'e';
opt.killblank = -1; opt.killblank = -1;
for (idummy=0; idummy<ANZ_SIDES; ++idummy) for (idummy = 0; idummy < ANZ_SIDES; ++idummy) {
opt.padding[idummy] = -1; opt.padding[idummy] = -1;
}
yyin = stdin; yyin = stdin;
/* /*
* Intercept '--help' and '-?' cases first, as they are not supported by getopt() * Intercept '--help' and '-?' cases first, as they are not supported by getopt()
*/ */
if (argc >= 2 && argv[1] != NULL if (argc >= 2 && argv[1] != NULL
&& (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)) && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0)) {
{
usage_long(stdout); usage_long(stdout);
return 42; return 42;
} }
@ -465,14 +450,14 @@ static int process_commandline (int argc, char *argv[])
errfl = 1; errfl = 1;
break; break;
} }
if (errfl) if (errfl) {
break; break;
else } else {
++pdummy; ++pdummy;
} }
}
if (errfl) { if (errfl) {
fprintf (stderr, "%s: Illegal text format -- %s\n", fprintf(stderr, "%s: Illegal text format -- %s\n", PROJECT, optarg);
PROJECT, optarg);
return 1; return 1;
} }
break; break;
@ -491,8 +476,7 @@ static int process_commandline (int argc, char *argv[])
templine.len = strlen(opt.cld); templine.len = strlen(opt.cld);
templine.text = opt.cld; templine.text = opt.cld;
if (empty_line(&templine)) { if (empty_line(&templine)) {
fprintf (stderr, "%s: boxes may not consist entirely " fprintf(stderr, "%s: boxes may not consist entirely of whitespace\n", PROJECT);
"of whitespace\n", PROJECT);
return 1; return 1;
} }
} }
@ -518,8 +502,7 @@ static int process_commandline (int argc, char *argv[])
*/ */
f = fopen(optarg, "r"); f = fopen(optarg, "r");
if (f == NULL) { if (f == NULL) {
fprintf (stderr, "%s: Couldn\'t open config file \'%s\' " fprintf(stderr, "%s: Couldn\'t open config file \'%s\' for input.\n", PROJECT, optarg);
"for input.\n", PROJECT, optarg);
return 1; return 1;
} }
rc = is_dir(optarg); rc = is_dir(optarg);
@ -528,8 +511,7 @@ static int process_commandline (int argc, char *argv[])
return 1; return 1;
} }
else if (rc) { else if (rc) {
fprintf (stderr, "%s: Alleged config file '%s' is a " fprintf(stderr, "%s: Alleged config file '%s' is a directory\n", PROJECT, optarg);
"directory\n", PROJECT, optarg);
fclose(f); fclose(f);
return 1; return 1;
} }
@ -554,13 +536,13 @@ static int process_commandline (int argc, char *argv[])
* Indentation mode * Indentation mode
*/ */
optlen = strlen(optarg); optlen = strlen(optarg);
if (optlen <= 3 && !strncasecmp ("box", optarg, optlen)) if (optlen <= 3 && !strncasecmp("box", optarg, optlen)) {
opt.indentmode = 'b'; opt.indentmode = 'b';
else if (optlen <= 4 && !strncasecmp ("text", optarg, optlen)) } else if (optlen <= 4 && !strncasecmp("text", optarg, optlen)) {
opt.indentmode = 't'; opt.indentmode = 't';
else if (optlen <= 4 && !strncasecmp ("none", optarg, optlen)) } else if (optlen <= 4 && !strncasecmp("none", optarg, optlen)) {
opt.indentmode = 'n'; opt.indentmode = 'n';
else { } else {
fprintf(stderr, "%s: invalid indentation mode\n", PROJECT); fprintf(stderr, "%s: invalid indentation mode\n", PROJECT);
return 1; return 1;
} }
@ -571,11 +553,11 @@ static int process_commandline (int argc, char *argv[])
*/ */
case 'k': case 'k':
if (opt.killblank == -1) { if (opt.killblank == -1) {
if (strisyes (optarg)) if (strisyes(optarg)) {
opt.killblank = 1; opt.killblank = 1;
else if (strisno (optarg)) } else if (strisno(optarg)) {
opt.killblank = 0; opt.killblank = 0;
else { } else {
fprintf(stderr, "%s: -k: invalid parameter\n", PROJECT); fprintf(stderr, "%s: -k: invalid parameter\n", PROJECT);
return 1; return 1;
} }
@ -647,12 +629,12 @@ static int process_commandline (int argc, char *argv[])
errfl = 1; errfl = 1;
break; break;
} }
if (errfl) if (errfl) {
break; break;
} }
}
if (errfl) { if (errfl) {
fprintf (stderr, "%s: invalid padding specification - " fprintf(stderr, "%s: invalid padding specification - %s\n", PROJECT, optarg);
"%s\n", PROJECT, optarg);
return 1; return 1;
} }
break; break;
@ -676,12 +658,16 @@ static int process_commandline (int argc, char *argv[])
* Specify desired box target size * Specify desired box target size
*/ */
pdummy = strchr(optarg, 'x'); pdummy = strchr(optarg, 'x');
if (!pdummy) pdummy = strchr (optarg, 'X'); if (!pdummy) {
pdummy = strchr(optarg, 'X');
}
if (pdummy) { if (pdummy) {
*pdummy = '\0'; *pdummy = '\0';
} }
errno = 0; errno = 0;
if (optarg != pdummy) opt.reqwidth = strtol (optarg, NULL, 10); if (optarg != pdummy) {
opt.reqwidth = strtol(optarg, NULL, 10);
}
if (pdummy) { if (pdummy) {
opt.reqheight = strtol(pdummy + 1, NULL, 10); opt.reqheight = strtol(pdummy + 1, NULL, 10);
*pdummy = 'x'; *pdummy = 'x';
@ -742,7 +728,8 @@ static int process_commandline (int argc, char *argv[])
printf("%s version %s\n", PROJECT, VERSION); printf("%s version %s\n", PROJECT, VERSION);
return 42; return 42;
case ':': case '?': case ':':
case '?':
/* /*
* Missing argument or illegal option - do nothing else * Missing argument or illegal option - do nothing else
*/ */
@ -774,8 +761,7 @@ static int process_commandline (int argc, char *argv[])
} }
else if (argv[optind + 1] && argv[optind + 2]) { /* illegal third file */ else if (argv[optind + 1] && argv[optind + 2]) { /* illegal third file */
fprintf (stderr, "%s: illegal parameter -- %s\n", fprintf(stderr, "%s: illegal parameter -- %s\n", PROJECT, argv[optind + 2]);
PROJECT, argv[optind+2]);
usage_short(stderr); usage_short(stderr);
return 1; return 1;
} }
@ -787,8 +773,7 @@ static int process_commandline (int argc, char *argv[])
else { else {
opt.infile = fopen(argv[optind], "r"); opt.infile = fopen(argv[optind], "r");
if (opt.infile == NULL) { if (opt.infile == NULL) {
fprintf (stderr, "%s: Can\'t open input file -- %s\n", PROJECT, fprintf(stderr, "%s: Can\'t open input file -- %s\n", PROJECT, argv[optind]);
argv[optind]);
return 9; /* can't read infile */ return 9; /* can't read infile */
} }
} }
@ -803,8 +788,9 @@ static int process_commandline (int argc, char *argv[])
opt.outfile = fopen(argv[optind + 1], "w"); opt.outfile = fopen(argv[optind + 1], "w");
if (opt.outfile == NULL) { if (opt.outfile == NULL) {
perror(PROJECT); perror(PROJECT);
if (opt.infile != stdin) if (opt.infile != stdin) {
fclose(opt.infile); fclose(opt.infile);
}
return 10; return 10;
} }
} }
@ -815,30 +801,26 @@ static int process_commandline (int argc, char *argv[])
*/ */
if (opt.cld == NULL) { if (opt.cld == NULL) {
rc = get_config_file(); /* sets yyin and yyfilename */ rc = get_config_file(); /* sets yyin and yyfilename */
if (rc) /* may change working directory */ if (rc) { /* may change working directory */
return rc; return rc;
} }
}
#if defined(DEBUG) || 0 #if defined(DEBUG) || 0
fprintf (stderr, "Command line option settings (excerpt):\n"); fprintf (stderr, "Command line option settings (excerpt):\n");
fprintf (stderr, "- Padding: l:%d t:%d r:%d b:%d\n", opt.padding[BLEF], fprintf (stderr, "- Padding: l:%d t:%d r:%d b:%d\n", opt.padding[BLEF],
opt.padding[BTOP], opt.padding[BRIG], opt.padding[BBOT]); opt.padding[BTOP], opt.padding[BRIG], opt.padding[BBOT]);
fprintf (stderr, "- Requested box size: %ldx%ld\n", opt.reqwidth, fprintf (stderr, "- Requested box size: %ldx%ld\n", opt.reqwidth, opt.reqheight);
opt.reqheight);
fprintf (stderr, "- Tabstop distance: %d\n", opt.tabstop); fprintf (stderr, "- Tabstop distance: %d\n", opt.tabstop);
fprintf (stderr, "- Tab handling: \'%c\'\n", opt.tabexp); fprintf (stderr, "- Tab handling: \'%c\'\n", opt.tabexp);
fprintf (stderr, "- Alignment: horiz %c, vert %c\n", fprintf (stderr, "- Alignment: horiz %c, vert %c\n", opt.halign?opt.halign:'?', opt.valign?opt.valign:'?');
opt.halign?opt.halign:'?', opt.valign?opt.valign:'?'); fprintf (stderr, "- Indentmode: \'%c\'\n", opt.indentmode? opt.indentmode: '?');
fprintf (stderr, "- Indentmode: \'%c\'\n", fprintf (stderr, "- Line justification: \'%c\'\n", opt.justify? opt.justify: '?');
opt.indentmode? opt.indentmode: '?');
fprintf (stderr, "- Line justification: \'%c\'\n",
opt.justify? opt.justify: '?');
fprintf (stderr, "- Kill blank lines: %d\n", opt.killblank); fprintf (stderr, "- Kill blank lines: %d\n", opt.killblank);
fprintf (stderr, "- Remove box: %d\n", opt.r); fprintf (stderr, "- Remove box: %d\n", opt.r);
fprintf (stderr, "- Special handling for Web UI: %d\n", opt.q); fprintf (stderr, "- Special handling for Web UI: %d\n", opt.q);
fprintf (stderr, "- Mend box: %d\n", opt.mend); fprintf (stderr, "- Mend box: %d\n", opt.mend);
fprintf (stderr, "- Design Definition W shape: %s\n", fprintf (stderr, "- Design Definition W shape: %s\n", opt.cld? opt.cld: "n/a");
opt.cld? opt.cld: "n/a");
#endif #endif
return 0; return 0;
@ -888,31 +870,37 @@ static int build_design (design_t **adesigns, const char *cld)
dp->shape[W].width = strlen(cld); dp->shape[W].width = strlen(cld);
dp->shape[W].elastic = 1; dp->shape[W].elastic = 1;
rc = genshape(dp->shape[W].width, dp->shape[W].height, &(dp->shape[W].chars)); rc = genshape(dp->shape[W].width, dp->shape[W].height, &(dp->shape[W].chars));
if (rc) if (rc) {
return rc; return rc;
}
strcpy(dp->shape[W].chars[0], cld); strcpy(dp->shape[W].chars[0], cld);
for (i = 0; i < ANZ_SHAPES; ++i) { for (i = 0; i < ANZ_SHAPES; ++i) {
c = dp->shape + i; c = dp->shape + i;
if (i == NNW || i == NNE || i == WNW || i == ENE || i == W if (i == NNW || i == NNE || i == WNW || i == ENE || i == W
|| i == WSW || i == ESE || i == SSW || i == SSE) || i == WSW || i == ESE || i == SSW || i == SSE) {
continue; continue;
}
switch (i) { switch (i) {
case NW: case SW: case NW:
case SW:
c->width = dp->shape[W].width; c->width = dp->shape[W].width;
c->height = 1; c->height = 1;
c->elastic = 0; c->elastic = 0;
break; break;
case NE: case SE: case NE:
case SE:
c->width = 1; c->width = 1;
c->height = 1; c->height = 1;
c->elastic = 0; c->elastic = 0;
break; break;
case N: case S: case E: case N:
case S:
case E:
c->width = 1; c->width = 1;
c->height = 1; c->height = 1;
c->elastic = 1; c->elastic = 1;
@ -924,9 +912,10 @@ static int build_design (design_t **adesigns, const char *cld)
} }
rc = genshape(c->width, c->height, &(c->chars)); rc = genshape(c->width, c->height, &(c->chars));
if (rc) if (rc) {
return rc; return rc;
} }
}
dp->maxshapeheight = 1; dp->maxshapeheight = 1;
dp->minwidth = dp->shape[W].width + 2; dp->minwidth = dp->shape[W].width + 2;
@ -936,6 +925,7 @@ static int build_design (design_t **adesigns, const char *cld)
} }
static char *escape(const char *org, const int pLength) static char *escape(const char *org, const int pLength)
{ {
char *result = (char *) calloc(1, 2 * strlen(org) + 1); char *result = (char *) calloc(1, 2 * strlen(org) + 1);
@ -951,12 +941,15 @@ static char* escape (const char* org, const int pLength)
} }
static int style_sort(const void *p1, const void *p2) static int style_sort(const void *p1, const void *p2)
{ {
return strcasecmp((const char *) ((*((design_t **) p1))->name), return strcasecmp((const char *) ((*((design_t **) p1))->name),
(const char *) ((*((design_t **) p2))->name)); (const char *) ((*((design_t **) p2))->name));
} }
static int list_styles() static int list_styles()
/* /*
* Generate sorted listing of available box styles. * Generate sorted listing of available box styles.
@ -983,8 +976,9 @@ static int list_styles()
fprintf(opt.outfile, "Complete Design Information for \"%s\":\n", fprintf(opt.outfile, "Complete Design Information for \"%s\":\n",
d->name); d->name);
fprintf(opt.outfile, "-----------------------------------"); fprintf(opt.outfile, "-----------------------------------");
for (i=strlen(d->name); i>0; --i) for (i = strlen(d->name); i > 0; --i) {
fprintf(opt.outfile, "-"); fprintf(opt.outfile, "-");
}
fprintf(opt.outfile, "\n"); fprintf(opt.outfile, "\n");
fprintf(opt.outfile, "Author: %s\n", fprintf(opt.outfile, "Author: %s\n",
@ -1018,10 +1012,11 @@ static int list_styles()
fprintf(opt.outfile, "%d. (%s) \"%s\" WITH \"%s\"\n", i + 1, fprintf(opt.outfile, "%d. (%s) \"%s\" WITH \"%s\"\n", i + 1,
d->reprules[i].mode == 'g' ? "glob" : "once", d->reprules[i].mode == 'g' ? "glob" : "once",
d->reprules[i].search, d->reprules[i].repstr); d->reprules[i].search, d->reprules[i].repstr);
if (i < (int) d->anz_reprules - 1) if (i < (int) d->anz_reprules - 1) {
fprintf(opt.outfile, " "); fprintf(opt.outfile, " ");
} }
} }
}
else { else {
fprintf(opt.outfile, "none\n"); fprintf(opt.outfile, "none\n");
} }
@ -1031,10 +1026,11 @@ static int list_styles()
fprintf(opt.outfile, "%d. (%s) \"%s\" TO \"%s\"\n", i + 1, fprintf(opt.outfile, "%d. (%s) \"%s\" TO \"%s\"\n", i + 1,
d->revrules[i].mode == 'g' ? "glob" : "once", d->revrules[i].mode == 'g' ? "glob" : "once",
d->revrules[i].search, d->revrules[i].repstr); d->revrules[i].search, d->revrules[i].repstr);
if (i < (int) d->anz_revrules - 1) if (i < (int) d->anz_revrules - 1) {
fprintf(opt.outfile, " "); fprintf(opt.outfile, " ");
} }
} }
}
else { else {
fprintf(opt.outfile, "none\n"); fprintf(opt.outfile, "none\n");
} }
@ -1047,21 +1043,25 @@ static int list_styles()
|| d->padding[BBOT] || d->padding[BLEF]) { || d->padding[BBOT] || d->padding[BLEF]) {
if (d->padding[BLEF]) { if (d->padding[BLEF]) {
fprintf(opt.outfile, "left %d", d->padding[BLEF]); fprintf(opt.outfile, "left %d", d->padding[BLEF]);
if (d->padding[BTOP] || d->padding[BRIG] || d->padding[BBOT]) if (d->padding[BTOP] || d->padding[BRIG] || d->padding[BBOT]) {
fprintf(opt.outfile, ", "); fprintf(opt.outfile, ", ");
} }
}
if (d->padding[BTOP]) { if (d->padding[BTOP]) {
fprintf(opt.outfile, "top %d", d->padding[BTOP]); fprintf(opt.outfile, "top %d", d->padding[BTOP]);
if (d->padding[BRIG] || d->padding[BBOT]) if (d->padding[BRIG] || d->padding[BBOT]) {
fprintf(opt.outfile, ", "); fprintf(opt.outfile, ", ");
} }
}
if (d->padding[BRIG]) { if (d->padding[BRIG]) {
fprintf(opt.outfile, "right %d", d->padding[BRIG]); fprintf(opt.outfile, "right %d", d->padding[BRIG]);
if (d->padding[BBOT]) if (d->padding[BBOT]) {
fprintf(opt.outfile, ", "); fprintf(opt.outfile, ", ");
} }
if (d->padding[BBOT]) }
if (d->padding[BBOT]) {
fprintf(opt.outfile, "bottom %d", d->padding[BBOT]); fprintf(opt.outfile, "bottom %d", d->padding[BBOT]);
}
fprintf(opt.outfile, "\n"); fprintf(opt.outfile, "\n");
} }
else { else {
@ -1078,8 +1078,9 @@ static int list_styles()
fprintf(opt.outfile, "Elastic Shapes: "); fprintf(opt.outfile, "Elastic Shapes: ");
sstart = 0; sstart = 0;
for (i = 0; i < ANZ_SHAPES; ++i) { for (i = 0; i < ANZ_SHAPES; ++i) {
if (isempty(d->shape+i)) if (isempty(d->shape + i)) {
continue; continue;
}
if (d->shape[i].elastic) { if (d->shape[i].elastic) {
fprintf(opt.outfile, "%s%s", sstart ? ", " : "", shape_name[i]); fprintf(opt.outfile, "%s%s", sstart ? ", " : "", shape_name[i]);
sstart = 1; sstart = 1;
@ -1125,8 +1126,9 @@ static int list_styles()
return 1; return 1;
} }
for (i=0; i<anz_designs; ++i) for (i = 0; i < anz_designs; ++i) {
list[i] = &(designs[i]); list[i] = &(designs[i]);
}
qsort(list, design_idx + 1, sizeof(design_t *), style_sort); qsort(list, design_idx + 1, sizeof(design_t *), style_sort);
sprintf(buf, "%d", anz_designs); sprintf(buf, "%d", anz_designs);
@ -1136,8 +1138,9 @@ static int list_styles()
anz_designs, anz_designs == 1 ? "" : "s", yyfilename); anz_designs, anz_designs == 1 ? "" : "s", yyfilename);
fprintf(opt.outfile, "-----------------------%s", fprintf(opt.outfile, "-----------------------%s",
anz_designs == 1 ? "" : "-"); anz_designs == 1 ? "" : "-");
for (i=strlen(yyfilename)+strlen(buf); i>0; --i) for (i = strlen(yyfilename) + strlen(buf); i > 0; --i) {
fprintf(opt.outfile, "-"); fprintf(opt.outfile, "-");
}
fprintf(opt.outfile, "\n\n"); fprintf(opt.outfile, "\n\n");
} }
for (i = 0; i < anz_designs; ++i) { for (i = 0; i < anz_designs; ++i) {
@ -1236,8 +1239,9 @@ static int apply_substitutions (const int mode)
char buf[LINE_MAX_BYTES * 2]; char buf[LINE_MAX_BYTES * 2];
size_t buf_len; /* length of string in buf */ size_t buf_len; /* length of string in buf */
if (opt.design == NULL) if (opt.design == NULL) {
return 1; return 1;
}
if (mode == 0) { if (mode == 0) {
anz_rules = opt.design->anz_reprules; anz_rules = opt.design->anz_reprules;
@ -1261,7 +1265,9 @@ static int apply_substitutions (const int mode)
rules[j].prog = regcomp(rules[j].search); rules[j].prog = regcomp(rules[j].search);
} }
opt.design->current_rule = NULL; opt.design->current_rule = NULL;
if (errno) return 3; if (errno) {
return 3;
}
/* /*
* Apply regular expression substitutions to input lines * Apply regular expression substitutions to input lines
@ -1282,7 +1288,9 @@ static int apply_substitutions (const int mode)
#ifdef REGEXP_DEBUG #ifdef REGEXP_DEBUG
fprintf (stderr, "%d\n", buf_len); fprintf (stderr, "%d\n", buf_len);
#endif #endif
if (errno) return 1; if (errno) {
return 1;
}
BFREE (input.lines[k].text); BFREE (input.lines[k].text);
input.lines[k].text = (char *) strdup(buf); input.lines[k].text = (char *) strdup(buf);
@ -1293,12 +1301,12 @@ static int apply_substitutions (const int mode)
input.lines[k].len = buf_len; input.lines[k].len = buf_len;
if (input.lines[k].len > input.maxline) if (input.lines[k].len > input.maxline) {
input.maxline = input.lines[k].len; input.maxline = input.lines[k].len;
}
#ifdef REGEXP_DEBUG #ifdef REGEXP_DEBUG
fprintf (stderr, "input.lines[%d] == {%d, \"%s\"}\n", k, fprintf (stderr, "input.lines[%d] == {%d, \"%s\"}\n", k, input.lines[k].len, input.lines[k].text);
input.lines[k].len, input.lines[k].text);
#endif #endif
} }
opt.design->current_rule = NULL; opt.design->current_rule = NULL;
@ -1311,11 +1319,12 @@ static int apply_substitutions (const int mode)
if (opt.design->indentmode == 't') { if (opt.design->indentmode == 't') {
int rc; int rc;
rc = get_indent(input.lines, input.anz_lines); rc = get_indent(input.lines, input.anz_lines);
if (rc >= 0) if (rc >= 0) {
input.indent = (size_t) rc; input.indent = (size_t) rc;
else } else {
return 4; return 4;
} }
}
return 0; return 0;
} }
@ -1605,6 +1614,7 @@ static int read_all_input (const int use_stdin)
} }
/* _\|/_ /* _\|/_
(o o) (o o)
+----oOO-{_}-OOo------------------------------------------------------------+ +----oOO-{_}-OOo------------------------------------------------------------+
@ -1630,10 +1640,12 @@ int main (int argc, char *argv[])
fprintf (stderr, "Processing Command Line ...\n"); fprintf (stderr, "Processing Command Line ...\n");
#endif #endif
rc = process_commandline(argc, argv); rc = process_commandline(argc, argv);
if (rc == 42) if (rc == 42) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
if (rc) }
if (rc) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
/* /*
* Store system character encoding * Store system character encoding
@ -1652,13 +1664,15 @@ int main (int argc, char *argv[])
#endif #endif
if (opt.cld == NULL) { if (opt.cld == NULL) {
rc = yyparse(); rc = yyparse();
if (rc) if (rc) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
}
else { else {
rc = build_design(&designs, opt.cld); rc = build_design(&designs, opt.cld);
if (rc) if (rc) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
anz_designs = 1; anz_designs = 1;
} }
BFREE (opt.design); BFREE (opt.design);
@ -1677,30 +1691,38 @@ int main (int argc, char *argv[])
* Increase box width/height by width/height of empty sides in order * Increase box width/height by width/height of empty sides in order
* to match appearance of box with the user's expectations (if -s). * to match appearance of box with the user's expectations (if -s).
*/ */
if (opt.reqheight > (long) opt.design->minheight) if (opt.reqheight > (long) opt.design->minheight) {
opt.design->minheight = opt.reqheight; opt.design->minheight = opt.reqheight;
if (opt.reqwidth > (long) opt.design->minwidth) }
if (opt.reqwidth > (long) opt.design->minwidth) {
opt.design->minwidth = opt.reqwidth; opt.design->minwidth = opt.reqwidth;
}
if (opt.reqwidth) { if (opt.reqwidth) {
if (empty_side (opt.design->shape, BRIG)) if (empty_side(opt.design->shape, BRIG)) {
opt.design->minwidth += opt.design->shape[SE].width; opt.design->minwidth += opt.design->shape[SE].width;
if (empty_side (opt.design->shape, BLEF)) }
if (empty_side(opt.design->shape, BLEF)) {
opt.design->minwidth += opt.design->shape[NW].width; opt.design->minwidth += opt.design->shape[NW].width;
} }
}
if (opt.reqheight) { if (opt.reqheight) {
if (empty_side (opt.design->shape, BTOP)) if (empty_side(opt.design->shape, BTOP)) {
opt.design->minheight += opt.design->shape[NW].height; opt.design->minheight += opt.design->shape[NW].height;
if (empty_side (opt.design->shape, BBOT)) }
if (empty_side(opt.design->shape, BBOT)) {
opt.design->minheight += opt.design->shape[SE].height; opt.design->minheight += opt.design->shape[SE].height;
} }
if (opt.indentmode) }
if (opt.indentmode) {
opt.design->indentmode = opt.indentmode; opt.design->indentmode = opt.indentmode;
}
saved_designwidth = opt.design->minwidth; saved_designwidth = opt.design->minwidth;
saved_designheight = opt.design->minheight; saved_designheight = opt.design->minheight;
do { do {
if (opt.mend == 1) /* Mending a box works in two phases: */ if (opt.mend == 1) { /* Mending a box works in two phases: */
opt.r = 0; /* opt.mend == 2: remove box */ opt.r = 0; /* opt.mend == 2: remove box */
}
--opt.mend; /* opt.mend == 1: add it back */ --opt.mend; /* opt.mend == 1: add it back */
opt.design->minwidth = saved_designwidth; opt.design->minwidth = saved_designwidth;
opt.design->minheight = saved_designheight; opt.design->minheight = saved_designheight;
@ -1712,19 +1734,22 @@ int main (int argc, char *argv[])
fprintf (stderr, "Reading all input ...\n"); fprintf (stderr, "Reading all input ...\n");
#endif #endif
rc = read_all_input(opt.mend); rc = read_all_input(opt.mend);
if (rc) if (rc) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
if (input.anz_lines == 0) }
if (input.anz_lines == 0) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
}
/* /*
* Adjust box size to fit requested padding value * Adjust box size to fit requested padding value
* Command line-specified box size takes precedence over padding. * Command line-specified box size takes precedence over padding.
*/ */
for (i = 0; i < ANZ_SIDES; ++i) { for (i = 0; i < ANZ_SIDES; ++i) {
if (opt.padding[i] > -1) if (opt.padding[i] > -1) {
opt.design->padding[i] = opt.padding[i]; opt.design->padding[i] = opt.padding[i];
} }
}
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.anz_lines;
@ -1732,14 +1757,15 @@ int main (int argc, char *argv[])
if (pad > opt.design->minheight) { if (pad > opt.design->minheight) {
if (opt.reqheight) { if (opt.reqheight) {
for (i = 0; i < (int) (pad - opt.design->minheight); ++i) { for (i = 0; i < (int) (pad - opt.design->minheight); ++i) {
if (opt.design->padding[i%2?BBOT:BTOP]) if (opt.design->padding[i % 2 ? BBOT : BTOP]) {
opt.design->padding[i % 2 ? BBOT : BTOP] -= 1; opt.design->padding[i % 2 ? BBOT : BTOP] -= 1;
else if (opt.design->padding[i%2?BTOP:BBOT]) } else if (opt.design->padding[i % 2 ? BTOP : BBOT]) {
opt.design->padding[i % 2 ? BTOP : BBOT] -= 1; opt.design->padding[i % 2 ? BTOP : BBOT] -= 1;
else } else {
break; break;
} }
} }
}
else { else {
opt.design->minheight = pad; opt.design->minheight = pad;
} }
@ -1752,14 +1778,15 @@ int main (int argc, char *argv[])
if (pad > opt.design->minwidth) { if (pad > opt.design->minwidth) {
if (opt.reqwidth) { if (opt.reqwidth) {
for (i = 0; i < (int) (pad - opt.design->minwidth); ++i) { for (i = 0; i < (int) (pad - opt.design->minwidth); ++i) {
if (opt.design->padding[i%2?BRIG:BLEF]) if (opt.design->padding[i % 2 ? BRIG : BLEF]) {
opt.design->padding[i % 2 ? BRIG : BLEF] -= 1; opt.design->padding[i % 2 ? BRIG : BLEF] -= 1;
else if (opt.design->padding[i%2?BLEF:BRIG]) } else if (opt.design->padding[i % 2 ? BLEF : BRIG]) {
opt.design->padding[i % 2 ? BLEF : BRIG] -= 1; opt.design->padding[i % 2 ? BLEF : BRIG] -= 1;
else } else {
break; break;
} }
} }
}
else { else {
opt.design->minwidth = pad; opt.design->minwidth = pad;
} }
@ -1774,18 +1801,20 @@ int main (int argc, char *argv[])
fprintf (stderr, "Removing Box ...\n"); fprintf (stderr, "Removing Box ...\n");
#endif #endif
if (opt.killblank == -1) { if (opt.killblank == -1) {
if (empty_side (opt.design->shape, BTOP) if (empty_side(opt.design->shape, BTOP) && empty_side(opt.design->shape, BBOT)) {
&& empty_side (opt.design->shape, BBOT))
opt.killblank = 0; opt.killblank = 0;
else } else {
opt.killblank = 1; opt.killblank = 1;
} }
}
rc = remove_box(); rc = remove_box();
if (rc) if (rc) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
rc = apply_substitutions(1); rc = apply_substitutions(1);
if (rc) if (rc) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
output_input(opt.mend > 0); output_input(opt.mend > 0);
} }
@ -1804,8 +1833,9 @@ int main (int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
rc = generate_box(thebox); rc = generate_box(thebox);
if (rc) if (rc) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
output_box(thebox); output_box(thebox);
} }
} while (opt.mend > 0); } while (opt.mend > 0);