/* Start tin in its own window with newsserver name in title bar */
If  RxFuncQuery('SysLoadFuncs') Then Do
    call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'       
    call SysLoadFuncs                                                 
End /* Do */

parse arg cmdline
tinexe = SysSearchPath('PATH', 'tin.exe')
If tinexe = '' Then tinexe = SysSearchPath('PATH', 'rtin.exe')
If tinexe = '' Then Do; say 'Cannot find TIN.EXE or RTIN.EXE in your PATH.'; exit; end
If pos('RTIN', translate(tinexe)) > 0 Then rtin = true
tab = '09'x
If pos('large', cmdline) > 0 Then Do
   columns = '120'
   rows = '43'
   cmdline = delword(cmdline, wordpos('large', cmdline), 1)
End /* Do */
Else Do
   columns = '96'
   rows = '34'
End /* Do */
homedir = value('HOME',,'OS2ENVIRONMENT')
tinhome = value('TIN_HOME',,'OS2ENVIRONMENT')
server = value('NNTPSERVER',,'OS2ENVIRONMENT')
tinopts = value('TINOPTS',,'OS2ENVIRONMENT')
If (pos('r',tinopts) = 0 & rtin \= true) Then tinopts = '-r' tinopts
If length(tinhome) > 0 Then homedir = tinhome

curdir = directory()
call directory homedir
call SysFileTree '1*.tmp','old_tmpfiles','FO'
Do i = 1 to old_tmpfiles.0
   call SysFileDelete old_tmpfiles.i
End /* Do */

If pos('-g', cmdline) > 0 Then Do
   newsrctable = homedir'/.tin/newsrctable'
   parse var cmdline . '-g' snick .
   call stream newsrctable, 'c', 'open read'
   Do until ( pos(snick, fline) > 0 | lines(newsrctable) = 0 )
      fline = linein(newsrctable)
   End /* Do */
   call stream newsrctable, 'c', 'close'
   If pos(snick, fline) > 0 Then parse var fline server (tab) .
   server = strip(server)
End /* Do */

/* say 'Running' tinexe tinopts cmdline 'with window size' columns'x'rows'.' */
n=setlocal()
call value 'TERM', 'mono', 'OS2ENVIRONMENT'
call value 'COLUMNS', columns, 'OS2ENVIRONMENT'
call value 'LINES', rows, 'OS2ENVIRONMENT'
'@start "tin - 'server'" /f/max/c mode' columns','rows '^&^&' tinexe tinopts cmdline
n=endlocal
call directory curdir
'pwd'

