mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-08-20 11:12:02 +02:00
Bugfix: For non-empty left box sides, spaces belonging to "empty" shape
lines were not properly removed in some cases
This commit is contained in:
228
src/remove.c
228
src/remove.c
@@ -4,7 +4,7 @@
|
|||||||
* Date created: June 23, 1999 (Wednesday, 20:59h)
|
* Date created: June 23, 1999 (Wednesday, 20:59h)
|
||||||
* Author: Copyright (C) 1999 Thomas Jensen
|
* Author: Copyright (C) 1999 Thomas Jensen
|
||||||
* tsjensen@stud.informatik.uni-erlangen.de
|
* tsjensen@stud.informatik.uni-erlangen.de
|
||||||
* Version: $Id: remove.c,v 1.4 1999/08/21 16:03:31 tsjensen Exp tsjensen $
|
* Version: $Id: remove.c,v 1.5 1999/11/07 17:46:26 tsjensen Exp tsjensen $
|
||||||
* Language: ANSI C
|
* Language: ANSI C
|
||||||
* World Wide Web: http://home.pages.de/~jensen/boxes/
|
* World Wide Web: http://home.pages.de/~jensen/boxes/
|
||||||
* Purpose: Box removal, i.e. the deletion of boxes
|
* Purpose: Box removal, i.e. the deletion of boxes
|
||||||
@@ -25,6 +25,11 @@
|
|||||||
* Revision History:
|
* Revision History:
|
||||||
*
|
*
|
||||||
* $Log: remove.c,v $
|
* $Log: remove.c,v $
|
||||||
|
* Revision 1.5 1999/11/07 17:46:26 tsjensen
|
||||||
|
* Bugfix: Horizontal box parts were not correctly detected if the west box
|
||||||
|
* side was empty (reported: Tobias Buchal)
|
||||||
|
* Bugfix: boxes could hang in detect_horiz() due to goeast/west confusion
|
||||||
|
*
|
||||||
* Revision 1.4 1999/08/21 16:03:31 tsjensen
|
* Revision 1.4 1999/08/21 16:03:31 tsjensen
|
||||||
* Bugfix: When matching vertical side shape lines, ignore empty shape lines
|
* Bugfix: When matching vertical side shape lines, ignore empty shape lines
|
||||||
*
|
*
|
||||||
@@ -53,7 +58,8 @@
|
|||||||
#include "remove.h"
|
#include "remove.h"
|
||||||
|
|
||||||
static const char rcsid_remove_c[] =
|
static const char rcsid_remove_c[] =
|
||||||
"$Id: remove.c,v 1.4 1999/08/21 16:03:31 tsjensen Exp tsjensen $";
|
"$Id: remove.c,v 1.5 1999/11/07 17:46:26 tsjensen Exp tsjensen $";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -101,137 +107,141 @@ static int best_match (const line_t *line,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find match for WEST side (TODO: nicht wenn BLEF leer)
|
* Find match for WEST side
|
||||||
*/
|
*/
|
||||||
quality = 0;
|
if (!empty_side (opt.design->shape, BLEF)) {
|
||||||
cs = opt.design->shape + WNW;
|
quality = 0;
|
||||||
for (j=0,k=0,w=3; j<numw; ++j,++k) {
|
cs = opt.design->shape + WNW;
|
||||||
if (k == cs->height) {
|
for (j=0,k=0,w=3; j<numw; ++j,++k) {
|
||||||
k = 0;
|
if (k == cs->height) {
|
||||||
cs = opt.design->shape + west_side[--w];
|
k = 0;
|
||||||
}
|
cs = opt.design->shape + west_side[--w];
|
||||||
|
}
|
||||||
|
|
||||||
chkline.text = cs->chars[k];
|
chkline.text = cs->chars[k];
|
||||||
chkline.len = cs->width;
|
chkline.len = cs->width;
|
||||||
if (empty_line (&chkline))
|
if (empty_line (&chkline) && !(quality==0 && j==numw-1))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
s = (char *) strdup (cs->chars[k]);
|
s = (char *) strdup (cs->chars[k]);
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
perror (PROJECT);
|
perror (PROJECT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cq = cs->width;
|
cq = cs->width;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
p = strstr (line->text, s);
|
p = strstr (line->text, s);
|
||||||
if (p) {
|
if (p) {
|
||||||
q = p-1;
|
q = p-1;
|
||||||
while (q >= line->text) {
|
while (q >= line->text) {
|
||||||
if (*q-- != ' ') {
|
if (*q-- != ' ') {
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!p && cq) {
|
||||||
|
if (*s == ' ')
|
||||||
|
memmove (s, s+1, cq--);
|
||||||
|
else if (s[cq-1] == ' ')
|
||||||
|
s[--cq] = '\0';
|
||||||
|
else {
|
||||||
|
cq = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p)
|
} while (cq && !p);
|
||||||
break;
|
|
||||||
}
|
if (cq == 0) {
|
||||||
if (!p && cq) {
|
BFREE (s);
|
||||||
if (*s == ' ')
|
continue;
|
||||||
memmove (s, s+1, cq--);
|
}
|
||||||
else if (s[cq-1] == ' ')
|
|
||||||
s[--cq] = '\0';
|
/*
|
||||||
else {
|
* If the current match is the best yet, adjust result values
|
||||||
cq = 0;
|
*/
|
||||||
break;
|
if (cq > quality) {
|
||||||
}
|
quality = cq;
|
||||||
}
|
*ws = p;
|
||||||
} while (cq && !p);
|
*we = p + cq;
|
||||||
|
}
|
||||||
|
|
||||||
if (cq == 0) {
|
|
||||||
BFREE (s);
|
BFREE (s);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* If the current match is the best yet, adjust result values
|
|
||||||
*/
|
|
||||||
if (cq > quality) {
|
|
||||||
quality = cq;
|
|
||||||
*ws = p;
|
|
||||||
*we = p + cq;
|
|
||||||
}
|
|
||||||
|
|
||||||
BFREE (s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find match for EAST side
|
* Find match for EAST side
|
||||||
*/
|
*/
|
||||||
quality = 0;
|
if (!empty_side (opt.design->shape, BRIG)) {
|
||||||
cs = opt.design->shape + ENE;
|
quality = 0;
|
||||||
for (j=0,k=0,w=1; j<nume; ++j,++k) {
|
cs = opt.design->shape + ENE;
|
||||||
if (k == cs->height) {
|
for (j=0,k=0,w=1; j<nume; ++j,++k) {
|
||||||
k = 0;
|
if (k == cs->height) {
|
||||||
cs = opt.design->shape + east_side[++w];
|
k = 0;
|
||||||
}
|
cs = opt.design->shape + east_side[++w];
|
||||||
#ifdef DEBUG
|
}
|
||||||
fprintf (stderr, "\nj %d, k %d, w %d, cs->chars[k] = \"%s\"\n",
|
#ifdef DEBUG
|
||||||
j, k, w, cs->chars[k]?cs->chars[k]:"(null)");
|
fprintf (stderr, "\nj %d, k %d, w %d, cs->chars[k] = \"%s\"\n",
|
||||||
#endif
|
j, k, w, cs->chars[k]?cs->chars[k]:"(null)");
|
||||||
|
#endif
|
||||||
|
|
||||||
chkline.text = cs->chars[k];
|
chkline.text = cs->chars[k];
|
||||||
chkline.len = cs->width;
|
chkline.len = cs->width;
|
||||||
if (empty_line (&chkline))
|
if (empty_line (&chkline))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
s = (char *) strdup (cs->chars[k]);
|
s = (char *) strdup (cs->chars[k]);
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
perror (PROJECT);
|
perror (PROJECT);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
cq = cs->width;
|
cq = cs->width;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
p = my_strnrstr (line->text, s, cq, 0);
|
p = my_strnrstr (line->text, s, cq, 0);
|
||||||
if (p) {
|
if (p) {
|
||||||
q = p + cq;
|
q = p + cq;
|
||||||
while (*q) {
|
while (*q) {
|
||||||
if (*q++ != ' ') {
|
if (*q++ != ' ') {
|
||||||
p = NULL;
|
p = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (p)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!p && cq) {
|
||||||
|
if (*s == ' ')
|
||||||
|
memmove (s, s+1, cq--);
|
||||||
|
else if (s[cq-1] == ' ')
|
||||||
|
s[--cq] = '\0';
|
||||||
|
else {
|
||||||
|
cq = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p)
|
} while (cq && !p);
|
||||||
break;
|
|
||||||
}
|
if (cq == 0) {
|
||||||
if (!p && cq) {
|
BFREE (s);
|
||||||
if (*s == ' ')
|
continue;
|
||||||
memmove (s, s+1, cq--);
|
}
|
||||||
else if (s[cq-1] == ' ')
|
|
||||||
s[--cq] = '\0';
|
/*
|
||||||
else {
|
* If the current match is the best yet, adjust result values
|
||||||
cq = 0;
|
*/
|
||||||
break;
|
if (cq > quality) {
|
||||||
}
|
quality = cq;
|
||||||
}
|
*es = p;
|
||||||
} while (cq && !p);
|
*ee = p + cq;
|
||||||
|
}
|
||||||
|
|
||||||
if (cq == 0) {
|
|
||||||
BFREE (s);
|
BFREE (s);
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* If the current match is the best yet, adjust result values
|
|
||||||
*/
|
|
||||||
if (cq > quality) {
|
|
||||||
quality = cq;
|
|
||||||
*es = p;
|
|
||||||
*ee = p + cq;
|
|
||||||
}
|
|
||||||
|
|
||||||
BFREE (s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return *ws || *es ? 1:0;
|
return *ws || *es ? 1:0;
|
||||||
|
Reference in New Issue
Block a user