[srvx-commits] CVS: services/src helpfile.c,1.66,1.67
Brought to you by:
entrope
|
From: Entrope <en...@us...> - 2003-12-14 22:33:57
|
Update of /cvsroot/srvx/services/src
In directory sc8-pr-cvs1:/tmp/cvs-serv7092/src
Modified Files:
helpfile.c
Log Message:
fix a line continuation bug
Index: helpfile.c
===================================================================
RCS file: /cvsroot/srvx/services/src/helpfile.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -C2 -r1.66 -r1.67
*** helpfile.c 18 Oct 2003 15:52:21 -0000 1.66
--- helpfile.c 14 Dec 2003 22:33:54 -0000 1.67
***************
*** 157,160 ****
--- 157,161 ----
static struct string_buffer input;
unsigned int size, ipos, pos, length, chars_sent, use_color;
+ unsigned int expand_pos, expand_ipos, newline_ipos;
char line[MAX_LINE_SIZE];
***************
*** 204,209 ****
* that requires a very big intermediate buffer.
*/
! ipos = 0;
! pos = 0;
chars_sent = 0;
while (input.list[ipos]) {
--- 205,210 ----
* that requires a very big intermediate buffer.
*/
! expand_ipos = newline_ipos = ipos = 0;
! expand_pos = pos = 0;
chars_sent = 0;
while (input.list[ipos]) {
***************
*** 215,219 ****
}
! if (!input.list[ipos]) goto send_line;
if (input.list[ipos] == '\n') {
ipos++;
--- 216,221 ----
}
! if (!input.list[ipos])
! goto send_line;
if (input.list[ipos] == '\n') {
ipos++;
***************
*** 221,249 ****
}
if (pos == size) {
! char *terminal;
! line[size - 1] = 0;
! terminal = strrchr(line, ' ');
! if (terminal) {
! unsigned int backup = pos - (terminal - line);
! /* min_backup is where we started -- after the last $-expression */
! if (ipos < backup) {
! backup = ipos;
! terminal = line + pos - backup;
! }
! *terminal = 0;
! ipos -= backup;
! pos -= backup;
! } else {
! /* Send the entire word, even though it's bigger than
! * the requested maximum size. But stop at line size.
*/
! pos--;
! for (ch = input.list[--ipos];
! ch && (ch != ' ') && (pos < MAX_LINE_SIZE);
! ch = input.list[++ipos]) {
! line[pos++] = ch;
! }
}
! while (input.list[ipos] == ' ') ipos++;
goto send_line;
}
--- 223,250 ----
}
if (pos == size) {
! unsigned int new_ipos;
! /* Scan backwards for a space in the input, until we hit
! * either the last newline or the last variable expansion.
! * Print the line up to that point, and start from there.
! */
! for (new_ipos = ipos;
! (new_ipos > expand_ipos) && (new_ipos > newline_ipos);
! --new_ipos)
! if (input.list[new_ipos] == ' ')
! break;
! if (new_ipos == newline_ipos) {
! /* Single word was too big to fit on one line; skip
! * forward to its end and print it as a whole.
*/
! while ((input.list[new_ipos] != ' ')
! && (input.list[new_ipos] != '\n')
! && (input.list[new_ipos] != '$'))
! line[pos++] = input.list[new_ipos++];
! } else {
! pos -= ipos - new_ipos;
}
! ipos = new_ipos;
! while (input.list[ipos] == ' ')
! ipos++;
goto send_line;
}
***************
*** 293,297 ****
value = handle ? handle->handle : "Account";
break;
! #define SEND_LINE() do { line[pos] = 0; if (pos > 0) irc_send(src, dest, line); chars_sent += pos; pos = 0; } while (0)
/* Custom expansion handled by helpfile-specific function. */
case '{':
--- 294,298 ----
value = handle ? handle->handle : "Account";
break;
! #define SEND_LINE() do { line[pos] = 0; if (pos > 0) irc_send(src, dest, line); chars_sent += pos; pos = 0; newline_ipos = ipos; } while (0)
/* Custom expansion handled by helpfile-specific function. */
case '{':
***************
*** 345,349 ****
/* copy over spaces, until (possible) end of line */
while (*value == ' ') {
! if (pos < size-1) line[pos++] = *value;
value++;
}
--- 346,351 ----
/* copy over spaces, until (possible) end of line */
while (*value == ' ') {
! if (pos < size-1)
! line[pos++] = *value;
value++;
}
***************
*** 359,363 ****
value += length;
/* skip any trailing spaces */
! while (*value == ' ') value++;
}
}
--- 361,366 ----
value += length;
/* skip any trailing spaces */
! while (*value == ' ')
! value++;
}
}
***************
*** 370,377 ****
length = strlen(value);
memcpy(line + pos, value, length);
! if (free_value) free(free_value);
pos += length;
! if ((pos < size-1) && input.list[ipos]) continue;
send_line:
SEND_LINE();
#undef SEND_LINE
--- 373,387 ----
length = strlen(value);
memcpy(line + pos, value, length);
! if (free_value)
! free(free_value);
pos += length;
! if ((pos < size-1) && input.list[ipos]) {
! expand_pos = pos;
! expand_ipos = ipos;
! continue;
! }
send_line:
+ expand_pos = pos;
+ expand_ipos = ipos;
SEND_LINE();
#undef SEND_LINE
|