#../wafe --f
# a program to test various approaches to use addInput/removeInput
# Gustaf Neumann                      Thu Oct 21 02:14:43 GMT 1993
set testfile ttt

if ![file readable $testfile] {
    puts stderr "*** This program produces output when data is appended to '$testfile'"
    puts stderr "*** File '$testfile' is not readable, aborting."
    quit
}

mergeResources topLevel *background gray85

if ![lsearch [split $PACKAGES { }] MOTIF*] {
#
#  we are running under OSF/Motif
#

  XmRowColumn rc topLevel

    XmScrolledText text rc \
       columns 80 \
       rows 24 \
       editable false \
       editMode MULTI_LINE_EDIT \
       autoShowCursorPosition true \
       scrollHorizontal false \
       cursorPositionVisible true

    XmPushButton Quit rc activateCallback quit

  proc displayBuffer {buffer} {
    set cursorPosition [gV text cursorPosition]
    XmTextInsert text $cursorPosition $buffer
    sV text cursorPosition [incr cursorPosition [string length $buffer]]
    XmTextShowPosition text $cursorPosition
  }

} else {
#
#  no OSF/Motif, must be Athena
#

  Form f topLevel

    Text text f \
        width 800 \
        height 300 \
        editType edit \
        scrollVertical whenNeeded

    Command Quit f fromVert text callback quit

  proc displayBuffer {buffer} {
     set cursorPosition [gV text insertPosition]
     set text(firstPos) 0
     set text(length)   [set length [string length $buffer]]
     set text(ptr)      $buffer
     XawTextReplace text $cursorPosition $cursorPosition text
     sV text insertPosition [incr cursorPosition $length]
  }

}
realize


proc checkData {file} {
  set inputId [addInput [fileno $file r] read buffer {
    displayBuffer $buffer
    set buffer {}
  }]
  addTimeOut 0 "removeInput $inputId"
  addTimeOut 100 "checkData $file"
}

set f [open ttt r]
#mightBeBusy $f
#checkRememberData $f
checkData $f

