Updated email and web addresses in comment header etc.

Applied patch by Elmar Loos that adds -m option for mending a box
Changed a few more things to make the box mending patch work in
connection with all the other boxes options
This commit is contained in:
Thomas Jensen 2006-07-12 05:49:50 +00:00
parent 9eaecc9b3e
commit f8df42aa6a

View File

@ -1,12 +1,11 @@
/*
* File: boxes.c
* Date created: March 18, 1999 (Thursday, 15:09h)
* Author: Copyright (C) 1999 Thomas Jensen
* tsjensen@stud.informatik.uni-erlangen.de
* Version: $Id: boxes.c,v 1.35 2000/03/21 14:26:31 tsjensen Exp tsjensen $
* Author: Copyright (C) 1999 Thomas Jensen <boxes@thomasjensen.com>
* Version: $Id: boxes.c,v 1.36 2000-04-01 10:27:17-08 tsjensen Exp tsjensen $
* Language: ANSI C
* Platforms: sunos5/sparc, for now
* World Wide Web: http://home.pages.de/~jensen/boxes/
* World Wide Web: http://boxes.thomasjensen.com/
* Purpose: Filter to draw boxes around input text (and remove it).
* Intended for use with vim(1).
*
@ -48,6 +47,9 @@
* Revision History:
*
* $Log: boxes.c,v $
* Revision 1.36 2000-04-01 10:27:17-08 tsjensen
* Added -c option (simple comment definition)
*
* Revision 1.35 2000/03/21 14:26:31 tsjensen
* Minor change to make boxes compile on DEC/OSF, too (S_ISDIR)
*
@ -246,7 +248,7 @@ extern int optind, opterr, optopt; /* for getopt() */
static const char rcsid_boxes_c[] =
"$Id: boxes.c,v 1.35 2000/03/21 14:26:31 tsjensen Exp tsjensen $";
"$Id: boxes.c,v 1.36 2000-04-01 10:27:17-08 tsjensen Exp tsjensen $";
@ -295,6 +297,7 @@ static void usage (FILE *st)
fprintf (st, " -i mode indentation mode [default: box]\n");
fprintf (st, " -k bool kill leading/trailing blank lines on removal or not\n");
fprintf (st, " -l list available box designs w/ samples\n");
fprintf (st, " -m mend box, i.e. remove it and redraw it afterwards\n");
fprintf (st, " -p fmt padding [default: none]\n");
fprintf (st, " -r remove box from input\n");
fprintf (st, " -s wxh specify box size (width w and/or height h)\n");
@ -526,7 +529,7 @@ static int process_commandline (int argc, char *argv[])
* Parse Command Line
*/
do {
oc = getopt (argc, argv, "a:c:d:f:hi:k:lp:rs:t:v");
oc = getopt (argc, argv, "a:c:d:f:hi:k:lmp:rs:t:v");
switch (oc) {
@ -666,8 +669,8 @@ static int process_commandline (int argc, char *argv[])
* Display usage information and terminate
*/
printf ("%s - draws any kind of box around your text (and removes it)\n", PROJECT);
printf (" (c) Thomas Jensen <tsjensen@stud.informatik.uni-erlangen.de>\n");
printf (" Web page: http://home.pages.de/~jensen/%s/\n", PROJECT);
printf (" (c) Thomas Jensen <boxes@thomasjensen.com>\n");
printf (" Web page: http://boxes.thomasjensen.com/\n");
usage (stdout);
return 42;
@ -709,6 +712,14 @@ static int process_commandline (int argc, char *argv[])
opt.l = 1;
break;
case 'm':
/*
* Mend box: remove, then redraw
*/
opt.mend = 2;
opt.r = 1;
break;
case 'p':
/*
* Padding. format is ([ahvtrbl]n)+
@ -905,7 +916,7 @@ static int process_commandline (int argc, char *argv[])
#if defined(DEBUG) || 0
fprintf (stderr, "Command line option settings (excerpt):\n");
fprintf (stderr, "- Padding: l%d o%d r%d u%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]);
fprintf (stderr, "- Requested box size: %ldx%ld\n", opt.reqwidth,
opt.reqheight);
@ -917,6 +928,8 @@ static int process_commandline (int argc, char *argv[])
fprintf (stderr, "- Line justification: \'%c\'\n",
opt.justify? opt.justify: '?');
fprintf (stderr, "- Kill blank lines: %d\n", opt.killblank);
fprintf (stderr, "- Remove box: %d\n", opt.r);
fprintf (stderr, "- Mend box: %d\n", opt.mend);
fprintf (stderr, "- Design Definition W shape: %s\n",
opt.cld? opt.cld: "n/a");
#endif
@ -1389,13 +1402,16 @@ static int apply_substitutions (const int mode)
static int read_all_input()
static int read_all_input (const int use_stdin)
/*
* Read entire input from stdin and store it in 'input' array.
* Read entire input (possibly from stdin) and store it in 'input' array.
*
* Tabs are expanded.
* Might allocate slightly more memory than it needs. Trade-off for speed.
*
* use_stdin: flag indicating whether to read from stdin (use_stdin != 0)
* or use the data currently present in input (use_stdin == 0).
*
* RETURNS: != 0 on error (out of memory)
* == 0 on success
*
@ -1410,10 +1426,12 @@ static int read_all_input()
size_t i;
int rc;
input.anz_lines = 0;
input.indent = LINE_MAX;
input.maxline = 0;
if (use_stdin) {
input.anz_lines = 0;
/*
* Start reading
*/
@ -1474,6 +1492,16 @@ static int read_all_input()
BFREE (input.lines);
return 1;
}
}
else {
/* recalculate input statistics for redrawing the mended box */
for (i=0; i<input.anz_lines; ++i) {
input.lines[i].len = strlen (input.lines[i].text);
if (input.lines[i].len > input.maxline)
input.maxline = input.lines[i].len;
}
}
/*
* Exit if there was no input at all
@ -1540,6 +1568,8 @@ int main (int argc, char *argv[])
int rc; /* general return code */
size_t pad;
int i;
int saved_designwidth; /* opt.design->minwith backup, used for mending */
int saved_designheight; /* opt.design->minheight backup, used for mending */
#ifdef DEBUG
fprintf (stderr, "BOXES STARTING ...\n");
@ -1549,7 +1579,7 @@ int main (int argc, char *argv[])
* Process command line options
*/
#ifdef DEBUG
fprintf (stderr, "Processing Comand Line ...\n");
fprintf (stderr, "Processing Command Line ...\n");
#endif
rc = process_commandline (argc, argv);
if (rc == 42)
@ -1608,6 +1638,15 @@ int main (int argc, char *argv[])
}
if (opt.indentmode)
opt.design->indentmode = opt.indentmode;
saved_designwidth = opt.design->minwidth;
saved_designheight = opt.design->minheight;
do {
if (opt.mend == 1) /* Mending a box works in two phases: */
opt.r = 0; /* opt.mend == 2: remove box */
--opt.mend; /* opt.mend == 1: add it back */
opt.design->minwidth = saved_designwidth;
opt.design->minheight = saved_designheight;
/*
* Read input lines
@ -1615,7 +1654,7 @@ int main (int argc, char *argv[])
#ifdef DEBUG
fprintf (stderr, "Reading all input ...\n");
#endif
rc = read_all_input();
rc = read_all_input (opt.mend);
if (rc)
exit (EXIT_FAILURE);
if (input.anz_lines == 0)
@ -1690,7 +1729,7 @@ int main (int argc, char *argv[])
rc = apply_substitutions (1);
if (rc)
exit (EXIT_FAILURE);
output_input();
output_input (opt.mend > 0);
}
else {
@ -1712,6 +1751,7 @@ int main (int argc, char *argv[])
exit (EXIT_FAILURE);
output_box (thebox);
}
} while (opt.mend > 0);
return EXIT_SUCCESS;
}