# A more script showing use of sopen and sread commands.
if (!$?argv) then exit
if ($argc < 2) then
  secho "smore <file> ..."
  exit
endif
shift 1 argv

foreach file $argv
  if ($?flag) then
    secho -n "%i -- NEXT FILE ($file) -- %I "
    input -c ch
    if ($ch =~ "[xXqQ\e]") then exit
    secho -n "\e[H\e[2J"
  endif
  if (!(-e $file)) then
    secho "smore: no such file '${file}'."
    continue
  endif
  sopen xx $file READ
  if ($status) then
    secho "smore: error opening '${file}'."
    continue
  endif
  nset line = 0;
  while (1)
    sread xx -l l
    if ($?EOF || $status) then
      sclose xx
      if ($?EOF) then unset EOF
      set flag
      break
    endif
    secho -e "$l"
    if (++$line == 23) then
      secho -n "%i MORE %I "
      input -c ch
      secho -n "\r\e[2K"
      if ($ch =~ "[xXqQ\e]") then
        sclose xx
        set flag
        break
      endif
      nset line = 0
      if ($ch == '\n' || $ch == '\r') then nset line = 22
    endif
  wend
endfor
exit
