Skip to content
Snippets Groups Projects
Commit ddf6c810 authored by deuce's avatar deuce
Browse files

More fixin' for the last commit... we need to fall-through from a soft CR

into the wrapping bits since we've added a space.
parent cb4f5970
No related branches found
No related tags found
No related merge requests found
......@@ -274,6 +274,40 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
case '\r':
crcount++;
break;
case '\x1f': /* Delete... meaningless... strip. */
break;
case '\b': /* Backspace... handle if possible, but don't go crazy. */
if(l>0) {
if(l>1 && linebuf[l-2]=='\x01') {
if(linebuf[l-1]=='\x01') {
ocol--;
icol--;
}
l-=2;
}
else {
l--;
ocol--;
icol--;
}
}
break;
case '\t': /* TAB */
linebuf[l++]=inbuf[i];
/* Can't ever wrap on whitespace remember. */
icol++;
ocol++;
while(ocol%8)
ocol++;
while(icol%8)
icol++;
break;
case '\x01': /* CTRL-A */
linebuf[l++]=inbuf[i++];
if(inbuf[i]!='\x01') {
linebuf[l++]=inbuf[i];
break;
}
case '\n':
if(handle_quotes && (quote_count=get_prefix(inbuf+i+1, &prefix_bytes, &prefix_len, len*2+2))!=0) {
/* Move the input pointer offset to the last char of the prefix */
......@@ -285,6 +319,7 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size);
l=0;
ocol=1;
continue;
}
/* If there's a new prefix, it is a hardcr */
else if(compare_prefix(prefix, old_prefix_bytes, inbuf+i+1-prefix_bytes, prefix_bytes)!=0) {
......@@ -308,6 +343,8 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
l=prefix_bytes;
ocol=prefix_len+1;
old_prefix_bytes=prefix_bytes;
icol=prefix_len+1;
continue;
}
else if(isspace((unsigned char)inbuf[i+1])) { /* Next line starts with whitespace. This is a "hard" CR. */
linebuf[l++]='\r';
......@@ -315,6 +352,8 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
outbuf_append(&outbuf, &outp, linebuf, l, &outbuf_size);
l=prefix_bytes;
ocol=prefix_len+1;
icol=prefix_len+1;
continue;
}
else {
if(icol < oldlen) { /* If this line is overly long, It's impossible for the next word to fit */
......@@ -328,6 +367,8 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
memcpy(linebuf,prefix,prefix_bytes);
l=prefix_bytes;
ocol=prefix_len+1;
icol=prefix_len+1;
continue;
}
else { /* Not a hard CR... add space if needed */
if(l<1 || !isspace((unsigned char)linebuf[l-1])) {
......@@ -343,47 +384,14 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
}
}
}
icol=prefix_len+1;
break;
case '\x1f': /* Delete... meaningless... strip. */
break;
case '\b': /* Backspace... handle if possible, but don't go crazy. */
if(l>0) {
if(l>1 && linebuf[l-2]=='\x01') {
if(linebuf[l-1]=='\x01') {
ocol--;
icol--;
}
l-=2;
}
else {
l--;
ocol--;
icol--;
}
}
break;
case '\t': /* TAB */
linebuf[l++]=inbuf[i];
/* Can't ever wrap on whitespace remember. */
icol++;
ocol++;
while(ocol%8)
/* Fall-through soft CRs for wrapping! */
default:
if (inbuf[i] != '\n') {
linebuf[l++]=inbuf[i];
ocol++;
while(icol%8)
icol++;
break;
case '\x01': /* CTRL-A */
linebuf[l++]=inbuf[i++];
if(inbuf[i]!='\x01') {
linebuf[l++]=inbuf[i];
break;
}
default:
linebuf[l++]=inbuf[i];
ocol++;
icol++;
if(ocol>len && inbuf[i+1] && !isspace((unsigned char)inbuf[i+1])) { /* Need to wrap here */
if(ocol>len && inbuf[i+1] && !isspace(inbuf[i+1])) { /* Need to wrap here */
/* Find the start of the last word */
k=l; /* Original next char */
l--; /* Move back to the last char */
......@@ -394,7 +402,7 @@ char* wordwrap(char* inbuf, int len, int oldlen, BOOL handle_quotes)
* If it's longer than len, there's no point in trying
* to make it fit, so we can just chop it.
*/
next_len=(ocol-1)-(l+1) + get_word_len(inbuf, i+1);
next_len=(k-(l==0?0:(l+1))) + get_word_len(inbuf, i+1);
if(next_len > len) { /* Won't be able to wrap... may as well chop. */
l=k;
while(l>1 && linebuf[l-2]=='\x01' && linebuf[l-1]!='\x01')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment