gram@uctcs.uucp (Graham Wheeler) (09/28/90)
Yet another Athena widgets problem! I have written an editor using the text widget, and am now trying to compile the file in the text widget buffer. I could always save this file and compile from the disk copy, but I would like to rather use the in-memory copy. I have written the following routine as a sort of `getchar' to read characters. My compiler expects null bytes at the end of a file, so the compiler stops immediately, as I seem to only get null bytes. The text widget is called EdWinWidget, while its asciiSrc widget is called EdSrcWidget. static char TxtBuf[81]; /* Buffer for read text */ static XawTextBlock TxtBlk; /* Block structure for Xaw read */ static int pos, /* Position in TxtBuf */ XtPos, /* Position in file */ avail; /* Count of chars available in TxtBuf */ int Ed_NextChar() { if (avail==0) /* Time to read... */ { pos = 0; /* Reset buffer position */ avail = XawTextSourceRead(EdSrcWidget, XtPos, TxtBlk, 80); #ifdef DEBUG printf("XawTextSourceRead (from %d) got %d chars\n", XtPos, avail); printf("TxtBlk.ptr = %X, TxtBuf = %X\n", TxtBlk.ptr, TxtBuf); printf("Contents of TxtBuf is (%s)\n", TxtBuf); printf("First four bytes are %d, %d, %d, %d\n", TxtBuf[0], TxtBuf[1], TxtBuf[2], TxtBuf[3]); #endif XtPos += avail; /* Update file position */ } if (avail==0) return '\0'; /* EOF */ else { avail--; return TxtBuf[pos++]; } } /* `Compile' command widget button event handler */ static void Compile(w,client_data,call_data) Widget w; XtPointer client_data, call_data; { linenum = pos = XtPos = avail = 0; TxtBlk.firstPos = 0; TxtBlk.length = 80; TxtBlk.ptr = TxtBuf; TxtBlk.format = FMT8BIT; #ifdef DEBUG puts("Compiling..."); #endif run_compiler(); } The output (on stdout) that I get if DEBUG is defined is: Compiling... XawTextSourceRead (from 0) got 80 chars TextBlk.ptr = 19460, TxtBuf = 19460 Contents of TxtBuf is () First four bytes are 0, 0, 0, 0 This is when I have a file loaded which certainly does NOT begin with four null bytes. If I use the EdWinWidget instead of the EdSrcWidget in the call to XawTextSourceRead, I get a response identical except the second line says `.. got 0 chars'. So the EdSrcWidget seems to be the right one. But I just cannot get any sensible text returned. Any ideas, anyone? I suspect that it is because I am confusing TextSrc and asciiSrc widgets. If this is the case, is there a way of reading the text in an asciiSrc widget when the type is XawAsciiFile? On the other hand, AsciiSrc is a subclass of TextSrc, so it should have all the functionality of a TextSrc, shouldn't it? Am I just stupid? P.S. - I haven't had any responses to my earlier problem about XawAsciiSourceChanged returning TRUE even after querying the string resource and, in fact, changing it to load a new file. I would still very much appreciate help on that problem as well. WELL I HAVE TO GO NOW BYE!! COWABUNGA!!! Graham Wheeler | "Don't bother me,
gram@uctcs.uucp (Graham Wheeler) (09/28/90)
Sorry, my signature got lost on the last posting. This is just to correct that. Graham Wheeler | "Don't bother me, Data Network Architectures Lab| I'm reading a `Crisis'!" Dept. of Computer Science | Internet: <gram.uctcs@f4.n494.z5.fidonet.org> University of Cape Town | BANG: <...uunet!ddsw1!olsa99!uctcs!gram>