[comp.windows.x] Change to lib/Xaw/StringSrc.c

kwh@sei.cmu.edu (Kurt Hoyt) (05/07/88)

I needed the string source for the Text widget not to beep at me when it ran
out of space in the buffer handed to it. So, with inspiration from xedit, I
modified StringReplaceText in lib/Xaw/StringSrc.c to reallocate the string
when it becomes full. I add space 1K at a time. THESE ARE NOT APPROVED
CHANGES! I made them because I need them. Now, if I can only get wordBreak
to insert line feeds into the source string and not just in the sink...

Share and enjoy:

*** StringSrc.c.orig	Fri May  6 14:19:39 1988
--- StringSrc.c	Fri May  6 15:54:31 1988
***************
*** 117,122
  {
      StringSourcePtr data;
      int     i, length, delta;
  
      data = (StringSourcePtr) src->data;
      switch (src->edit_mode) {

--- 117,123 -----
  {
      StringSourcePtr data;
      int     i, length, delta;
+     char    *newstr;
  
      data = (StringSourcePtr) src->data;
      switch (src->edit_mode) {
***************
*** 132,139
  	    return (EditError);
      }
      length = endPos - startPos;
!     if ((data->length - length + text->length) > data->maxLength)
!         return (EditError);
  
      delta = text->length - length;
      if (delta < 0)		/* insert shorter than delete, text getting

--- 133,160 -----
  	    return (EditError);
      }
      length = endPos - startPos;
! 
! /*----------------------------------------------------------------*
!  * Fixed to expand the string as necessary instead of generating  *
!  * an error.                                                      *
!  *                                                                *
!  * Kurt Hoyt <kwh@sei.cmu.edu> 6 May 1988                         *
!  *                                                                *
!  * Original code:                                                 *
!  *  if ((data->length - length + text->length) > data->maxLength) *
!  *      return (EditError);                                       *
!  *----------------------------------------------------------------*/
! 
! #define CHUNK 1024
!     if ((data->length - length + text->length) > data->maxLength) {
!         while ((data->length - length + text->length) > data->maxLength) {
!             data->maxLength += CHUNK;
!             newstr = XtMalloc (data->maxLength);
!             bcopy (data->str, newstr, data->length);
!             XtFree (data->str);
!             data->str = newstr;
! 	}
!     }
  
      delta = text->length - length;
      if (delta < 0)		/* insert shorter than delete, text getting

-- 
Kurt Hoyt, Software Engineering Institute -- kwh@sei.cmu.edu
"From previous research with rendering systems we have learned that a good
dose of gratuitous partial differential equations is needed to meet the
paper quota for impressive formulas." SIGGRAPH '87 Proceedings, p. 73