Commit cf1d812c authored by Chris Allegretta's avatar Chris Allegretta
Browse files

- nano.c:do_justify() - More fixes for indented justify (David Benbennick)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1137 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
No related merge requests found
Showing with 11 additions and 15 deletions
+11 -15
...@@ -11,6 +11,8 @@ CVS code - ...@@ -11,6 +11,8 @@ CVS code -
read_file() read_file()
- Abort if we read a file of 0 lines (num_lines == 0), fixes BUG #70. - Abort if we read a file of 0 lines (num_lines == 0), fixes BUG #70.
- nano.c: - nano.c:
do_justify()
- More fixes for indented justify (David Benbennick).
help_init() help_init()
- Capitalize Meta altkeys. - Capitalize Meta altkeys.
- Various fixes and string changes. - Various fixes and string changes.
......
...@@ -2282,10 +2282,9 @@ int do_justify(void) ...@@ -2282,10 +2282,9 @@ int do_justify(void)
totsize += slen; totsize += slen;
if ((strlenpt(current->data) > (fill)) if ((strlenpt(current->data) > (fill))
&& !no_spaces(current->data)) { && !no_spaces(current->data + qdepth)) {
do { do {
int i = 0, j = 0; int i = 0, j = 0;
int len2 = 0;
filestruct *tmpline = nmalloc(sizeof(filestruct)); filestruct *tmpline = nmalloc(sizeof(filestruct));
...@@ -2296,16 +2295,12 @@ int do_justify(void) ...@@ -2296,16 +2295,12 @@ int do_justify(void)
/* Note that we CAN break before the first word, since that is how /* Note that we CAN break before the first word, since that is how
* pico does it. */ * pico does it. */
int last_space = -1; /* index of the last breakpoint */ int last_space = -1; /* index of the last breakpoint */
int allowed_width;
i = qdepth * strlen(quotestr); /* the line starts with for(i=qdepth; i<slen; i++) {
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 (isspace((int) current->data[i])) last_space = i;
if (last_space!=-1 && if (last_space!=-1 &&
strnlenpt(current->data,i) >= allowed_width) { /* ARGH! We must look at the length of the first i+1 characters. */
strnlenpt(current->data,i+1) > fill) {
i = last_space; i = last_space;
break; break;
} }
...@@ -2318,15 +2313,15 @@ int do_justify(void) ...@@ -2318,15 +2313,15 @@ int do_justify(void)
current->data[i] = '\0'; current->data[i] = '\0';
len2 = strlen(current->data + i + 1); slen -= i + 1 - qdepth; /* note i > qdepth */
tmpline->data = charalloc(len2 + 1 + qdepth); tmpline->data = charalloc(slen + 1);
for (j = 0; j < qdepth; j += strlen(quotestr)) for (j = 0; j < qdepth; j += strlen(quotestr))
strcpy(&tmpline->data[j], quotestr); strcpy(&tmpline->data[j], quotestr);
/* Skip the white space in current. */ /* Skip the white space in current. */
memcpy(&tmpline->data[j], current->data + i + 1, len2); memcpy(&tmpline->data[qdepth], current->data + i + 1, slen-qdepth);
tmpline->data[len2 + qdepth] = '\0'; tmpline->data[slen] = '\0';
current->data = nrealloc(current->data, i + 1); current->data = nrealloc(current->data, i + 1);
...@@ -2337,10 +2332,9 @@ int do_justify(void) ...@@ -2337,10 +2332,9 @@ int do_justify(void)
current->next = tmpline; current->next = tmpline;
current = tmpline; current = tmpline;
slen -= i + 1;
current_y++; current_y++;
} while ((strlenpt(current->data) > (fill)) } while ((strlenpt(current->data) > (fill))
&& !no_spaces(current->data)); && !no_spaces(current->data + qdepth));
} }
tmpbot = current; tmpbot = current;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment