Added GNU GPL disclaimer

Added -k option (kill leading/trailing blank lines on removal yes/no)
Bugfix: REPLACE and indentation conflict. Now applying regexp substitutions
only after indentation was already handled.
This commit is contained in:
Thomas Jensen 1999-07-20 18:45:29 +00:00
parent f73ceddb71
commit 0d0c2325b7

View File

@ -1,39 +1,56 @@
/* /*
* File: boxes.c * File: boxes.c
* Date created: March 18, 1999 (Thursday, 15:09h) * Date created: March 18, 1999 (Thursday, 15:09h)
* Author: Thomas Jensen * Author: Copyright (C) 1999 Thomas Jensen
* tsjensen@stud.informatik.uni-erlangen.de * tsjensen@stud.informatik.uni-erlangen.de
* Version: $Id: boxes.c,v 1.24 1999/06/30 12:37:25 tsjensen Exp tsjensen $ * Version: $Id: boxes.c,v 1.25 1999/07/12 18:16:36 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/
* Purpose: Filter to draw boxes around input text (and remove it). * Purpose: Filter to draw boxes around input text (and remove it).
* Intended for use with vim(1). * Intended for use with vim(1).
* *
* Remarks: - This version is leaking a small bit of memory. The sizes * Remarks: o This program is free software; you can redistribute it
* of the leaks do not depend on the number of lines * and/or modify it under the terms of the GNU General Public
* processed, so the leaks don't matter as long as this * License as published by the Free Software Foundation; either
* program is executed as a single process. * version 2 of the License, or (at your option) any later
* - The decision to number box shapes in clockwise order was * version.
* a major design mistake. Treatment of box parts of the * o This program is distributed in the hope that it will be
* same alignment (N-S and E-W) is usually combined in one * useful, but WITHOUT ANY WARRANTY; without even the implied
* function, which must now deal with the numbering being * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* reversed all the time. This is nasty, but changing the * PURPOSE. See the GNU General Public License for more details.
* shape order would pretty much mean a total rewrite of * o You should have received a copy of the GNU General Public
* the code, so we'll have to live with it. :-( * License along with this program; if not, write to the Free
* - All shapes defined in a box design must be used in any * Software Foundation, Inc., 59 Temple Place, Suite 330,
* box of that design at least once. In other words, there * Boston, MA 02111-1307 USA
* must not be a shape which is defined in the config file *
* but cannot be found in an actual box of that design. * - This version is leaking a small bit of memory. The sizes of
* This sort of limits how small your boxes can get. * the leaks do not depend on the number of lines processed, so
* However, in practice it is not a problem, because boxes * the leaks don't matter as long as this program is executed as
* which must be small usually consist of small shapes * a single process.
* which can be packed pretty tightly anyway. And again, * - The decision to number box shapes in clockwise order was a
* changing this would pretty much mean a total rewrite. * 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. This is nasty, but changing the shape order would
* pretty much mean a total rewrite of the code, so we'll have
* to live with it. :-(
* - 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.
* And again, changing this would pretty much mean a total
* rewrite.
* *
* Revision History: * Revision History:
* *
* $Log: boxes.c,v $ * $Log: boxes.c,v $
* Revision 1.25 1999/07/12 18:16:36 tsjensen
* Added include "config.h" to top of file
*
* Revision 1.24 1999/06/30 12:37:25 tsjensen * Revision 1.24 1999/06/30 12:37:25 tsjensen
* Added [lcr] "shorthand" to -a option * Added [lcr] "shorthand" to -a option
* *
@ -176,7 +193,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.24 1999/06/30 12:37:25 tsjensen Exp tsjensen $"; "$Id: boxes.c,v 1.25 1999/07/12 18:16:36 tsjensen Exp tsjensen $";
/* _\|/_ /* _\|/_
@ -220,6 +237,7 @@ static void usage (FILE *st)
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, " -i mode indentation mode\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, " -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");
@ -257,15 +275,16 @@ static int process_commandline (int argc, char *argv[])
*/ */
memset (&opt, 0, sizeof(opt_t)); memset (&opt, 0, sizeof(opt_t));
opt.tabstop = DEF_TABSTOP; opt.tabstop = DEF_TABSTOP;
yyin = stdin; 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;
/* /*
* Parse Command Line * Parse Command Line
*/ */
do { do {
oc = getopt (argc, argv, "a:d:f:hi:lp:rs:t:v"); oc = getopt (argc, argv, "a:d:f:hi:k:lp:rs:t:v");
switch (oc) { switch (oc) {
@ -397,6 +416,20 @@ static int process_commandline (int argc, char *argv[])
} }
break; break;
/*
* Kill blank lines or not [default: design-dependent]
*/
case 'k':
if (strisyes (optarg))
opt.killblank = 1;
else if (strisno (optarg))
opt.killblank = 0;
else {
fprintf (stderr, "%s: -k: invalid parameter\n", PROJECT);
return 1;
}
break;
case 'l': case 'l':
/* /*
* List available box styles * List available box styles
@ -650,7 +683,7 @@ static int process_commandline (int argc, char *argv[])
} }
} }
#ifdef DEBUG #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 o%d r%d u%d\n", opt.padding[BLEF], fprintf (stderr, "- Padding: l%d o%d r%d u%d\n", opt.padding[BLEF],
opt.padding[BTOP], opt.padding[BRIG], opt.padding[BBOT]); opt.padding[BTOP], opt.padding[BRIG], opt.padding[BBOT]);
@ -663,6 +696,7 @@ static int process_commandline (int argc, char *argv[])
opt.indentmode? opt.indentmode: '?'); opt.indentmode? opt.indentmode: '?');
fprintf (stderr, "- Line justification: \'%c\'\n", fprintf (stderr, "- Line justification: \'%c\'\n",
opt.justify? opt.justify: '?'); opt.justify? opt.justify: '?');
fprintf (stderr, "- Kill blank lines: %d\n", opt.killblank);
#endif #endif
return 0; return 0;
@ -907,14 +941,6 @@ static int read_all_input()
return 0; return 0;
} }
/*
* Apply regular expression substitutions
*/
if (opt.r == 0) {
if (apply_substitutions(0) != 0)
return 1;
}
/* /*
* Remove indentation, unless we want to preserve it (when removing * Remove indentation, unless we want to preserve it (when removing
* 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)
@ -935,6 +961,14 @@ static int read_all_input()
input.indent = 0; /* seems like blank lines only */ input.indent = 0; /* seems like blank lines only */
} }
/*
* Apply regular expression substitutions
*/
if (opt.r == 0) {
if (apply_substitutions(0) != 0)
return 1;
}
#if 0 #if 0
/* /*
* Debugging Code: Display contents of input structure * Debugging Code: Display contents of input structure
@ -1077,6 +1111,13 @@ int main (int argc, char *argv[])
#ifdef DEBUG #ifdef DEBUG
fprintf (stderr, "Removing Box ...\n"); fprintf (stderr, "Removing Box ...\n");
#endif #endif
if (opt.killblank == -1) {
if (empty_side (opt.design->shape, BTOP)
&& empty_side (opt.design->shape, BBOT))
opt.killblank = 0;
else
opt.killblank = 1;
}
rc = remove_box(); rc = remove_box();
if (rc) if (rc)
exit (EXIT_FAILURE); exit (EXIT_FAILURE);