mirror of
https://github.com/ascii-boxes/boxes.git
synced 2024-12-13 18:30:39 +01:00
Don't adjust indentation after removing a box unless something was
removed on the west side East Padding made dynamic, i.e. dependant on the east side size
This commit is contained in:
parent
498bd9c12a
commit
02b697659e
36
src/boxes.c
36
src/boxes.c
@ -3,7 +3,7 @@
|
||||
* Date created: March 18, 1999 (Thursday, 15:09h)
|
||||
* Author: Thomas Jensen
|
||||
* tsjensen@stud.informatik.uni-erlangen.de
|
||||
* Version: $Id: boxes.c,v 1.10 1999/06/03 18:54:05 tsjensen Exp tsjensen $
|
||||
* Version: $Id: boxes.c,v 1.11 1999/06/03 19:24:14 tsjensen Exp tsjensen $
|
||||
* Language: ANSI C
|
||||
* Platforms: sunos5/sparc, for now
|
||||
* World Wide Web: http://home.pages.de/~jensen/boxes/
|
||||
@ -18,6 +18,9 @@
|
||||
* Revision History:
|
||||
*
|
||||
* $Log: boxes.c,v $
|
||||
* Revision 1.11 1999/06/03 19:24:14 tsjensen
|
||||
* a few fixes related to box removal (as expected)
|
||||
*
|
||||
* Revision 1.10 1999/06/03 18:54:05 tsjensen
|
||||
* lots of fixes
|
||||
* Added remove box functionality, which remains to be tested
|
||||
@ -83,19 +86,12 @@ extern int optind, opterr, optopt; /* for getopt() */
|
||||
|
||||
|
||||
static const char rcsid_boxes_c[] =
|
||||
"$Id: boxes.c,v 1.10 1999/06/03 18:54:05 tsjensen Exp tsjensen $";
|
||||
"$Id: boxes.c,v 1.11 1999/06/03 19:24:14 tsjensen Exp tsjensen $";
|
||||
|
||||
extern FILE *yyin; /* lex input file */
|
||||
|
||||
|
||||
|
||||
/* Number of spaces appended to all input lines prior to removing a box.
|
||||
* A greater number takes more space and time, but enables the correct
|
||||
* removal of boxes whose east sides consist of lots of spaces (the given
|
||||
* value).
|
||||
*/
|
||||
#define EAST_PADDING 20
|
||||
|
||||
/* max. allowed tab stop distance
|
||||
*/
|
||||
#define MAX_TABSTOP 16
|
||||
@ -1956,7 +1952,7 @@ static int output_box (const sentry_t *thebox)
|
||||
thebox[BRIG].chars[j]);
|
||||
}
|
||||
|
||||
obuf_len = strlen (obuf); /* TODO Can't we compute this?! */
|
||||
obuf_len = strlen (obuf);
|
||||
|
||||
if (obuf_len > LINE_MAX) {
|
||||
size_t newlen = LINE_MAX;
|
||||
@ -2495,6 +2491,7 @@ int remove_box()
|
||||
size_t boxend = 0; /* index of 1st line trailing the box */
|
||||
int m; /* true if a match was found */
|
||||
size_t j; /* loop counter */
|
||||
int did_something = 0; /* true if there was something to remove */
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf (stderr, "remove_box()\n");
|
||||
@ -2512,8 +2509,12 @@ int remove_box()
|
||||
|
||||
/*
|
||||
* Add trailing spaces to input lines (needed for recognition)
|
||||
* Also append a number of spaces to all input lines. A greater number
|
||||
* takes more space and time, but enables the correct removal of boxes
|
||||
* whose east sides consist of lots of spaces (the given value). So we
|
||||
* add a number of spaces equal to the east side width.
|
||||
*/
|
||||
input.maxline += EAST_PADDING;
|
||||
input.maxline += opt.design->shape[NE].width;
|
||||
for (j=0; j<input.anz_lines; ++j) {
|
||||
input.lines[j].text = (char *)
|
||||
realloc (input.lines[j].text, input.maxline+1);
|
||||
@ -2572,7 +2573,6 @@ int remove_box()
|
||||
for (j=textstart; j<textend; ++j) {
|
||||
char *ws, *we, *es, *ee; /* west start & end, east start&end */
|
||||
char *p;
|
||||
int c;
|
||||
|
||||
m = best_match (input.lines+j, &ws, &we, &es, &ee);
|
||||
if (m < 0)
|
||||
@ -2595,6 +2595,7 @@ int remove_box()
|
||||
es&&ee? (ee-input.lines[j].text-(es-input.lines[j].text)):0);
|
||||
#endif
|
||||
if (ws && we) {
|
||||
did_something = 1;
|
||||
for (p=ws; p<we; ++p)
|
||||
*p = ' ';
|
||||
}
|
||||
@ -2603,6 +2604,16 @@ int remove_box()
|
||||
*p = ' ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Remove as many spaces from the left side of the line as the west side
|
||||
* of the box was wide. Don't do it if we never removed anything from the
|
||||
* west side. Don't harm the line's text if there aren't enough spaces.
|
||||
*/
|
||||
if (did_something) {
|
||||
for (j=textstart; j<textend; ++j) {
|
||||
int c;
|
||||
for (c=0; c<(int)opt.design->shape[NW].width; ++c) {
|
||||
if (input.lines[j].text[c] != ' ')
|
||||
break;
|
||||
@ -2610,6 +2621,7 @@ int remove_box()
|
||||
memmove (input.lines[j].text, input.lines[j].text + c,
|
||||
input.lines[j].len - c);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Phase 4: Remove box top and body lines from input
|
||||
|
Loading…
Reference in New Issue
Block a user