#../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
#

  mRowColumn rc topLevel

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

    mPushButton Quit rc activateCallback quit

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

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

  form f topLevel

    asciiText 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
     textReplace 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

