justify_format(), do_justify() - Various fixes for starting blank spaces, spaces after punctuation, & segfault with quoting strings (David Benbennick)
git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1103 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
46e3118e9d
commit
d4fa0d3904
12
ChangeLog
12
ChangeLog
|
@ -54,6 +54,9 @@ CVS code -
|
||||||
- nano.1:
|
- nano.1:
|
||||||
- Added Noconvert option to man page (DLR).
|
- Added Noconvert option to man page (DLR).
|
||||||
- nano.c:
|
- nano.c:
|
||||||
|
justify_format(), do_justify()
|
||||||
|
- Various fixes for starting blank spaces, spaces after
|
||||||
|
punctuation, & segfault with quoting strings (David Benbennick).
|
||||||
help_init()
|
help_init()
|
||||||
- Added message re: having multiple blank buffers (DLR).
|
- Added message re: having multiple blank buffers (DLR).
|
||||||
main()
|
main()
|
||||||
|
@ -71,14 +74,17 @@ CVS code -
|
||||||
bottombars(), onekey()
|
bottombars(), onekey()
|
||||||
- Make bottom list dynamic with screen size (Guus Sliepen & Chris).
|
- Make bottom list dynamic with screen size (Guus Sliepen & Chris).
|
||||||
- More cleanups w/width of shortcut.
|
- More cleanups w/width of shortcut.
|
||||||
- utils.c:
|
|
||||||
strstrwrapper()
|
|
||||||
- NANO_SMALL test was backwards (Ken Tyler).
|
|
||||||
- utils.c:
|
- utils.c:
|
||||||
strcasestr(),revstrcasestr()
|
strcasestr(),revstrcasestr()
|
||||||
- Renamed to stristr and revstristr since strcasestr has not
|
- Renamed to stristr and revstristr since strcasestr has not
|
||||||
been confirmed to be detected properly on various Linux
|
been confirmed to be detected properly on various Linux
|
||||||
systems.
|
systems.
|
||||||
|
strstrwrapper()
|
||||||
|
- NANO_SMALL test was backwards (Ken Tyler).
|
||||||
|
- winio.c:
|
||||||
|
strlenpt()
|
||||||
|
- Changed main function to strnlenpt() for new justify changes,
|
||||||
|
original function now just a stub.
|
||||||
- nanorc.sample
|
- nanorc.sample
|
||||||
- Mention unset in the sample nanorc.
|
- Mention unset in the sample nanorc.
|
||||||
- po/ca.po, po/es.po:
|
- po/ca.po, po/es.po:
|
||||||
|
|
55
nano.c
55
nano.c
|
@ -2201,8 +2201,8 @@ void justify_format(char *data)
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int len = strlen(data);
|
int len = strlen(data);
|
||||||
|
|
||||||
/* Skip first character regardless and leading whitespace. */
|
/* Skip leading whitespace. */
|
||||||
for (i = 1; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (!isspace((int) data[i]))
|
if (!isspace((int) data[i]))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2212,12 +2212,21 @@ void justify_format(char *data)
|
||||||
/* No double spaces allowed unless following a period. Tabs -> space. No double tabs. */
|
/* No double spaces allowed unless following a period. Tabs -> space. No double tabs. */
|
||||||
for (; i < len; i++) {
|
for (; i < len; i++) {
|
||||||
if (isspace((int) data[i]) && isspace((int) data[i - 1])
|
if (isspace((int) data[i]) && isspace((int) data[i - 1])
|
||||||
&& (data[i - 2] != '.')) {
|
&& (data[i - 2] != '.')
|
||||||
|
&& (data[i-2]!='!') && (data[i-2]!='?')) {
|
||||||
memmove(data + i, data + i + 1, len - i);
|
memmove(data + i, data + i + 1, len - i);
|
||||||
len--;
|
len--;
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* Skip trailing whitespace.
|
||||||
|
* i<=len iff there was a non-space in the line. In that case, we
|
||||||
|
* strip spaces from the end of the line. Note that "line" means the
|
||||||
|
* whole paragraph. */
|
||||||
|
if (i<=len) {
|
||||||
|
for(i=len-1; i>0 && isspace((int) data[i]); i--);
|
||||||
|
data[i+1] = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -2333,23 +2342,33 @@ int do_justify(void)
|
||||||
int len2 = 0;
|
int len2 = 0;
|
||||||
filestruct *tmpline = nmalloc(sizeof(filestruct));
|
filestruct *tmpline = nmalloc(sizeof(filestruct));
|
||||||
|
|
||||||
/* Start at fill , unless line isn't that long (but it
|
|
||||||
* appears at least fill long with tabs.
|
|
||||||
*/
|
|
||||||
if (slen > fill)
|
|
||||||
i = fill;
|
|
||||||
else
|
|
||||||
i = slen;
|
|
||||||
|
|
||||||
for (; i > 0; i--) {
|
/* The following code maybe could be better. In particular, can we
|
||||||
if (isspace((int) current->data[i]) &&
|
* merely increment instead of calling strnlenpt for each new character?
|
||||||
((strlenpt(current->data) - strlen(current->data + i))
|
* In fact, can we assume the only tabs are at the beginning of the line?
|
||||||
<= fill))
|
*/
|
||||||
break;
|
/* Note that we CAN break before the first word, since that is how
|
||||||
}
|
* pico does it. */
|
||||||
|
int last_space = -1; /* index of the last breakpoint */
|
||||||
|
int allowed_width;
|
||||||
|
|
||||||
if (!i)
|
i = qdepth * strlen(quotestr); /* the line starts with
|
||||||
break;
|
indentation, so we must skip it! */
|
||||||
|
allowed_width = fill - i; /* how wide can our lines be? */
|
||||||
|
|
||||||
|
for(; i<slen; i++) {
|
||||||
|
if (isspace((int) current->data[i])) last_space = i;
|
||||||
|
if (last_space!=-1 &&
|
||||||
|
strnlenpt(current->data,i) >= allowed_width) {
|
||||||
|
i = last_space;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/* Now data[i] is a space. We want to break at the LAST space in this
|
||||||
|
* group. Probably, the only possibility is two in a row, but let's be
|
||||||
|
* generic. Note that we actually replace this final space with \0. Is
|
||||||
|
* this okay? It seems to work fine. */
|
||||||
|
for(; i<slen-1 && isspace((int) current->data[i+1]); i++) ;
|
||||||
|
|
||||||
current->data[i] = '\0';
|
current->data[i] = '\0';
|
||||||
|
|
||||||
|
|
1
proto.h
1
proto.h
|
@ -99,6 +99,7 @@ int free_filestruct(filestruct * src);
|
||||||
int xplustabs(void);
|
int xplustabs(void);
|
||||||
int do_yesno(int all, int leavecursor, char *msg, ...);
|
int do_yesno(int all, int leavecursor, char *msg, ...);
|
||||||
int actual_x(filestruct * fileptr, int xplus);
|
int actual_x(filestruct * fileptr, int xplus);
|
||||||
|
int strnlenpt(char *buf, int size);
|
||||||
int strlenpt(char *buf);
|
int strlenpt(char *buf);
|
||||||
int statusq(int allowtabs, shortcut s[], char *def, char *msg, ...);
|
int statusq(int allowtabs, shortcut s[], char *def, char *msg, ...);
|
||||||
int write_file(char *name, int tmpfile, int append, int nonamechange);
|
int write_file(char *name, int tmpfile, int append, int nonamechange);
|
||||||
|
|
9
winio.c
9
winio.c
|
@ -134,14 +134,14 @@ int actual_x(filestruct * fileptr, int xplus)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* a strlen with tabs factored in, similar to xplustabs() */
|
/* a strlen with tabs factored in, similar to xplustabs() */
|
||||||
int strlenpt(char *buf)
|
int strnlenpt(char *buf, int size)
|
||||||
{
|
{
|
||||||
int i, tabs = 0;
|
int i, tabs = 0;
|
||||||
|
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
for (i = 0; buf[i] != 0; i++) {
|
for (i = 0; i < size; i++) {
|
||||||
tabs++;
|
tabs++;
|
||||||
|
|
||||||
if (buf[i] == NANO_CONTROL_I) {
|
if (buf[i] == NANO_CONTROL_I) {
|
||||||
|
@ -158,6 +158,11 @@ int strlenpt(char *buf)
|
||||||
return tabs;
|
return tabs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int strlenpt(char *buf)
|
||||||
|
{
|
||||||
|
return strnlenpt(buf, strlen(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* resets current_y, based on the position of current, and puts the cursor at
|
/* resets current_y, based on the position of current, and puts the cursor at
|
||||||
(current_y, current_x) */
|
(current_y, current_x) */
|
||||||
|
|
Loading…
Reference in New Issue