Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!athena.mit.edu!bjaspan From: bjaspan@athena.mit.edu (Barr3y Jaspan) Newsgroups: comp.windows.x Subject: Re: Athena asciiStringWidget questions Message-ID: <15485@bloom-beacon.MIT.EDU> Date: 29 Oct 89 01:21:39 GMT References: <8909252128.AA28066@mbunix.mitre.org> <8910262127.AA20276@expo.lcs.mit.edu> Sender: daemon@bloom-beacon.MIT.EDU Reply-To: bjaspan@athena.mit.edu (Barr3y Jaspan) Organization: Massachusetts Institute of Technology Lines: 72 I have written a function that takes a text widget and a string and appends the string to the widget, deleting text from the beginning if necessary. I wrote it a little while ago and haven't used it lately, so it might have undergone bit rot, but it worked when I used it. (It does some less-than-brilliant things in case of error.. you probably will want to fix that.) Barr3y Jaspan, bjaspan@athena.mit.edu MIT Project Athena ----- snip snip ----- /* * AppendString.c -- appends a string to the end of a text widget. It * assumes the widget is in the proper state to accept input in this manner * (ie: it does no error checking.) * * Written by Barry Jaspan (bjaspan@ATHENA.MIT.EDU) */ #include #include #include #include void AppendString(w, value, maxlen) Widget w; caddr_t value; int maxlen; { XtTextBlock text; static XtTextPosition last=0; unsigned long length; int retval; length = (unsigned long) strlen((char *) value); if (length == 0) { printf("Length of %s = %ld\n",(char *) value, length); XBell( XtDisplay(w), 0 ); return; } /* If this text puts us over the buffer len, just delete enough */ /* text from the front to compensate. Not an ideal algorithm. */ if ((last+length)>maxlen) { text.ptr = ""; text.firstPos = 0; text.length = 0; text.format = FMT8BIT; XtTextReplace(w,(XtTextPosition)0,(XtTextPosition)length,&text); last -= length; XtTextSetInsertionPoint(w, (XtTextPosition) last); XtTextSetLastPos(w, (XtTextPosition) last); } text.ptr = (char *) value; text.firstPos = 0; text.length = length; text.format = FMT8BIT; if ((retval=XtTextReplace(w, last, last, &text))!=0) { XBell(XtDisplay(w), 0); printf("TextReplace returned %d\n",retval); } else { XtTextSetInsertionPoint(w, last + text.length); last += (XtTextPosition) length; } } Barry Jaspan Project Athena ``Watchmaker'' SIPB (Student Information Processing Board) Member OLC Volunteer