Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!news.larc.nasa.gov!ames!haven!adm!smoke!brl.mil!moss From: moss@brl.mil (Gary S. Moss (VLD/VMB) ) Newsgroups: comp.windows.x Subject: Re: How do I get XtAppAddInput to work correctly Message-ID: <14801@smoke.brl.mil> Date: 9 Jan 91 21:30:13 GMT References: <1990Dec31.170612.7040@lta.com> <5184@trantor.harris-atd.com> Sender: news@smoke.brl.mil Reply-To: moss@brl.mil Organization: Ballistic Research Laboratory Lines: 64 In article <5184@trantor.harris-atd.com>, wdavis@x102c.harris-atd.com (davis william 26373) writes: |> |> I will remove the input for X if there is a way to know when the |> file has something more added to the end of what has already been |> read. Any ideas on this? The proper semantics of available data for input are clear when reading from a pipe or socket, but when reading from a file, it becomes something of a religious argument. I was fooled by the documentation also, so perhaps it should be tweaked. Anyway, I have combined the XtAppAddInput with code which checks for available input in the file. It is fairly simple so I have included it below; the application monitors a log file (like running a "tail -f" into an AsciiText widget. This doesn't solve the problem of your registered function being called in a tight loop so that your work proc doesn't get scheduled, but you could perhaps not use XtAppAddInput at all. Hope this helps, -Gary ... /* Register error log monitoring function. */ (void) XtAppAddInput( apcon, fileno(errorfp), XtInputReadMask, displayLogMsg, (XtPointer) errorfp ); /* Loop to handle events. */ XtAppMainLoop( apcon ); ... /* void displayLogMsg( XtPointer client_data, int *source, XtInputId *id ) Display the next line of the log file in the "errors" text widget. */ /*ARGSUSED*/ STATIC void displayLogMsg( client_data, source, id ) XtPointer client_data; int *source; XtInputId *id; { register int ct; long addr; /* save file offset of beginning of line */ FILE *fp = (FILE *) client_data; char buffer[MAXLOGLNLEN]; if( fp == NULL ) return; /* monitoring of log errors turned off */ addr = ftell( fp ); if( fgets( buffer, MAXLOGLNLEN, fp ) != NULL ) { register int len = strlen( buffer ); /* if( len <= 1 ) return; /* ignore blank lines */ if( buffer[len-1] != '\n' ) { /* A missing newline means that a write to the log is in progress, so we are done. */ (void) fseek( fp, addr, 0 ); /* beginning of line */ return; } sendToTextWidget( XtNameToWidget( toplevel, "main.errors" ), buffer ); } else clearerr( fp ); /* for 4.2 BSD or SUNs, need to clear EOF */ }