mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-20 01:37:52 +02:00
Bugfix: Mixed up SW and NE in padding calculation (tricky, that one)
Added indent mode command line option for grammar overrides Moved empty_side() to shape.c after small change in signature Added text-in-block justification (j) to alignment option (-a)
This commit is contained in:
parent
93763e64ec
commit
e9f3b88ef9
115
src/boxes.c
115
src/boxes.c
@ -3,7 +3,7 @@
|
|||||||
* Date created: March 18, 1999 (Thursday, 15:09h)
|
* Date created: March 18, 1999 (Thursday, 15:09h)
|
||||||
* Author: Thomas Jensen
|
* Author: Thomas Jensen
|
||||||
* tsjensen@stud.informatik.uni-erlangen.de
|
* tsjensen@stud.informatik.uni-erlangen.de
|
||||||
* Version: $Id: boxes.c,v 1.19 1999/06/23 12:31:26 tsjensen Exp tsjensen $
|
* Version: $Id: boxes.c,v 1.20 1999/06/23 19:17:27 tsjensen Exp tsjensen $
|
||||||
* Language: ANSI C
|
* Language: ANSI C
|
||||||
* Platforms: sunos5/sparc, for now
|
* Platforms: sunos5/sparc, for now
|
||||||
* World Wide Web: http://home.pages.de/~jensen/boxes/
|
* World Wide Web: http://home.pages.de/~jensen/boxes/
|
||||||
@ -34,6 +34,17 @@
|
|||||||
* Revision History:
|
* Revision History:
|
||||||
*
|
*
|
||||||
* $Log: boxes.c,v $
|
* $Log: boxes.c,v $
|
||||||
|
* Revision 1.20 1999/06/23 19:17:27 tsjensen
|
||||||
|
* Removed snprintf() and vsnprintf() prototypes (why were they in anyway?)
|
||||||
|
* along with stdarg.h include
|
||||||
|
* Exported input global data and empty_side() function
|
||||||
|
* Declared non-exported functions static
|
||||||
|
* Moved horiz_precalc(), vert_precalc(), horiz_assemble(), vert_assemble(),
|
||||||
|
* horiz_generate(), vert_generate(), generate_box() and output_box() to a
|
||||||
|
* new file generate.c
|
||||||
|
* Moved best_match(), hmm(), detect_horiz(), detect_design(), remove_box()
|
||||||
|
* and output_input() to a new file remove.c
|
||||||
|
*
|
||||||
* Revision 1.19 1999/06/23 12:31:26 tsjensen
|
* Revision 1.19 1999/06/23 12:31:26 tsjensen
|
||||||
* Improvements on design detection (could still be better though)
|
* Improvements on design detection (could still be better though)
|
||||||
* Moved iscorner(), on_side(), isempty(), shapecmp(), both_on_side(),
|
* Moved iscorner(), on_side(), isempty(), shapecmp(), both_on_side(),
|
||||||
@ -145,7 +156,7 @@ extern int optind, opterr, optopt; /* for getopt() */
|
|||||||
|
|
||||||
|
|
||||||
static const char rcsid_boxes_c[] =
|
static const char rcsid_boxes_c[] =
|
||||||
"$Id: boxes.c,v 1.19 1999/06/23 12:31:26 tsjensen Exp tsjensen $";
|
"$Id: boxes.c,v 1.20 1999/06/23 19:17:27 tsjensen Exp tsjensen $";
|
||||||
|
|
||||||
|
|
||||||
/* _\|/_
|
/* _\|/_
|
||||||
@ -188,6 +199,7 @@ static void usage (FILE *st)
|
|||||||
fprintf (st, " -d name select box design\n");
|
fprintf (st, " -d name select box design\n");
|
||||||
fprintf (st, " -f file use only file as configuration file\n");
|
fprintf (st, " -f file use only file as configuration file\n");
|
||||||
fprintf (st, " -h print usage information\n");
|
fprintf (st, " -h print usage information\n");
|
||||||
|
fprintf (st, " -i mode indentation mode\n");
|
||||||
fprintf (st, " -l list available box designs w/ samples\n");
|
fprintf (st, " -l list available box designs w/ samples\n");
|
||||||
fprintf (st, " -p fmt padding [default: design-dependent]\n");
|
fprintf (st, " -p fmt padding [default: design-dependent]\n");
|
||||||
fprintf (st, " -r remove box from input\n");
|
fprintf (st, " -r remove box from input\n");
|
||||||
@ -218,6 +230,7 @@ static int process_commandline (int argc, char *argv[])
|
|||||||
char c;
|
char c;
|
||||||
int errfl = 0; /* true on error */
|
int errfl = 0; /* true on error */
|
||||||
int outfile_existed = 0; /* true if we overwrite a file */
|
int outfile_existed = 0; /* true if we overwrite a file */
|
||||||
|
size_t optlen;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set default values
|
* Set default values
|
||||||
@ -233,8 +246,11 @@ static int process_commandline (int argc, char *argv[])
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Parse Command Line
|
||||||
|
*/
|
||||||
do {
|
do {
|
||||||
oc = getopt (argc, argv, "a:d:f:hlp:rs:t:v");
|
oc = getopt (argc, argv, "a:d:f:hi:lp:rs:t:v");
|
||||||
|
|
||||||
switch (oc) {
|
switch (oc) {
|
||||||
|
|
||||||
@ -268,6 +284,15 @@ static int process_commandline (int argc, char *argv[])
|
|||||||
default: errfl = 1; break;
|
default: errfl = 1; break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case 'j':
|
||||||
|
case 'J':
|
||||||
|
switch (pdummy[1]) {
|
||||||
|
case 'l': case 'L': opt.justify = 'l'; break;
|
||||||
|
case 'c': case 'C': opt.justify = 'c'; break;
|
||||||
|
case 'r': case 'R': opt.justify = 'r'; break;
|
||||||
|
default: errfl = 1; break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
errfl = 1;
|
errfl = 1;
|
||||||
break;
|
break;
|
||||||
@ -325,6 +350,23 @@ static int process_commandline (int argc, char *argv[])
|
|||||||
usage (stdout);
|
usage (stdout);
|
||||||
return 42;
|
return 42;
|
||||||
|
|
||||||
|
case 'i':
|
||||||
|
/*
|
||||||
|
* Indentation mode
|
||||||
|
*/
|
||||||
|
optlen = strlen (optarg);
|
||||||
|
if (optlen <= 3 && !strncasecmp ("box", optarg, optlen))
|
||||||
|
opt.indentmode = 'b';
|
||||||
|
else if (optlen <= 4 && !strncasecmp ("text", optarg, optlen))
|
||||||
|
opt.indentmode = 't';
|
||||||
|
else if (optlen <= 4 && !strncasecmp ("none", optarg, optlen))
|
||||||
|
opt.indentmode = 'n';
|
||||||
|
else {
|
||||||
|
fprintf (stderr, "%s: invalid indentation mode\n", PROJECT);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 'l':
|
case 'l':
|
||||||
/*
|
/*
|
||||||
* List available box styles
|
* List available box styles
|
||||||
@ -334,7 +376,7 @@ static int process_commandline (int argc, char *argv[])
|
|||||||
|
|
||||||
case 'p':
|
case 'p':
|
||||||
/*
|
/*
|
||||||
* Padding. format is ([ahvbtrl]n)+
|
* Padding. format is ([ahvtrbl]n)+
|
||||||
*/
|
*/
|
||||||
errfl = 0;
|
errfl = 0;
|
||||||
pdummy = optarg;
|
pdummy = optarg;
|
||||||
@ -587,6 +629,10 @@ static int process_commandline (int argc, char *argv[])
|
|||||||
fprintf (stderr, "- Tabstop distance: %d\n", opt.tabstop);
|
fprintf (stderr, "- Tabstop distance: %d\n", opt.tabstop);
|
||||||
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, "- Line justification: \'%c\'\n",
|
||||||
|
opt.justify? opt.justify: '?');
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -914,44 +960,6 @@ static design_t *select_design (design_t *darr, char *sel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int empty_side (design_t *d, const int aside)
|
|
||||||
/*
|
|
||||||
* Return true if the shapes on the given side consist entirely out of
|
|
||||||
* spaces - and spaces only, tabs are considered non-empty.
|
|
||||||
*
|
|
||||||
* d pointer to design to check
|
|
||||||
* aside the box side (one of BTOP etc.)
|
|
||||||
*
|
|
||||||
* RETURNS: == 0 side is not empty
|
|
||||||
* != 0 side is empty
|
|
||||||
*
|
|
||||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
size_t j;
|
|
||||||
sentry_t *cs;
|
|
||||||
char *p;
|
|
||||||
|
|
||||||
for (i=0; i<SHAPES_PER_SIDE; ++i) {
|
|
||||||
cs = d->shape + sides[aside][i];
|
|
||||||
if (isempty(cs))
|
|
||||||
continue;
|
|
||||||
for (j=0; j<cs->height; ++j) {
|
|
||||||
p = cs->chars[j];
|
|
||||||
while (*p && *p == ' ')
|
|
||||||
++p;
|
|
||||||
if (*p)
|
|
||||||
return 0; /* side is not empty */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 1; /* side is empty */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* _\|/_
|
/* _\|/_
|
||||||
(o o)
|
(o o)
|
||||||
+----oOO-{_}-OOo------------------------------------------------------------+
|
+----oOO-{_}-OOo------------------------------------------------------------+
|
||||||
@ -1032,6 +1040,16 @@ int main (int argc, char *argv[])
|
|||||||
exit (rc);
|
exit (rc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Adjust box size and indentmode to command line specification
|
||||||
|
*/
|
||||||
|
if (opt.reqheight > (long) opt.design->minheight)
|
||||||
|
opt.design->minheight = opt.reqheight;
|
||||||
|
if (opt.reqwidth > (long) opt.design->minwidth)
|
||||||
|
opt.design->minwidth = opt.reqwidth;
|
||||||
|
if (opt.indentmode)
|
||||||
|
opt.design->indentmode = opt.indentmode;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Read input lines
|
* Read input lines
|
||||||
*/
|
*/
|
||||||
@ -1039,18 +1057,11 @@ int main (int argc, char *argv[])
|
|||||||
fprintf (stderr, "Reading all input ...\n");
|
fprintf (stderr, "Reading all input ...\n");
|
||||||
#endif
|
#endif
|
||||||
rc = read_all_input();
|
rc = read_all_input();
|
||||||
if (rc) exit (EXIT_FAILURE);
|
if (rc)
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
if (input.anz_lines == 0)
|
if (input.anz_lines == 0)
|
||||||
exit (EXIT_SUCCESS);
|
exit (EXIT_SUCCESS);
|
||||||
|
|
||||||
/*
|
|
||||||
* Adjust box size to command line specification
|
|
||||||
*/
|
|
||||||
if (opt.reqheight > (long) opt.design->minheight)
|
|
||||||
opt.design->minheight = opt.reqheight;
|
|
||||||
if (opt.reqwidth > (long) opt.design->minwidth)
|
|
||||||
opt.design->minwidth = opt.reqwidth;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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.
|
||||||
@ -1082,7 +1093,7 @@ int main (int argc, char *argv[])
|
|||||||
pad = opt.design->padding[BLEF] + opt.design->padding[BRIG];
|
pad = opt.design->padding[BLEF] + opt.design->padding[BRIG];
|
||||||
if (pad > 0) {
|
if (pad > 0) {
|
||||||
pad += input.maxline;
|
pad += input.maxline;
|
||||||
pad += opt.design->shape[NW].width + opt.design->shape[SW].width;
|
pad += opt.design->shape[NW].width + opt.design->shape[NE].width;
|
||||||
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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user