home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / busi / smiiutil.zip / TEXTVIEW.PF2 < prev    next >
Text File  |  1990-01-10  |  8KB  |  278 lines

  1. '*****************************************************************************
  2. '       FILENAME:   TEXTVIEW.PF2
  3. '
  4. '     Programmer:   Pierce D. Nunley
  5. '        Updated:   A.M.  1/05/90
  6. '
  7. '          Notes:   Written in PDL (Informix, SmartWare II, Ver. 1.01)
  8. '
  9. '    Description:   This a text viewer that I threw together.  Its only
  10. '                   use is within a Project when you want to allow the user
  11. '                   to view, but not edit, a file (e.g. help files, and
  12. '                   text file reports, etc).  I have not cleaned up the code,
  13. '                   and there are plenty of places to make modifications.
  14. '                   I recommend using this as a function in which it is fed
  15. '                   $filename (the filename to be read) and $title (the title
  16. '                   that appears on line 1 of the screen).  e.g. the call
  17. '                   would be "texview($filename,$title)"
  18. '
  19. '                   Play with it and enjoy.  If you use it, or any significant
  20. '                   part of it, for any commercial applications, I would
  21. '                   appreciate some reimbursement for my efforts.   This may
  22. '                   seem like easy code, but it took quite a long time to get
  23. '                   the bugs out.
  24. '
  25. '****************************************************************************
  26. ' Copyright Notice
  27. ' Copyright (c) January 1, 1989    Pierce Nunley Consulting
  28. ' 3921 Bell Ave.
  29. ' Kansas City, Missouri  64111
  30. '****************************************************************************
  31. public $text[3000], $limit, $line, $pos, $lastline, $q, $filename, $title
  32. public $goto, $searchtxt, $searchpos
  33. public $wrap, $tick
  34. public goto(0), search()
  35. public $path,$files,$select
  36. lock module $line
  37.  
  38. $searchtxt=null
  39. '---------------------------------------------------------------------------
  40.   'the following is just a way of getting a file name into $filename.  It
  41.   'puts all *.txt files in the current directory into a menu which they can
  42.   'be selected from.
  43.   $path = path(datapath)
  44.   $files = getfnames("*.txt",1)
  45.   screen clear box 4 9 21 71 12 1  'print a blue box with red border
  46.   screen print 21 11 14 1 " Path = "|$path|" "  'print the path on the box
  47.   if len($files) < 3 ' check for no project files in directory
  48.     beep
  49.     screen print 11 10 12 1 format "M60" "There are no ""*.txt"" files in this directory"
  50.     inchar
  51.     exit
  52.   end if
  53.   screen menu 5 10   20 70   15 1   1 15   1   $files $select
  54.   if $select = 0   'checks for ESC out of menu
  55.     exit 'quit project
  56.   end if
  57.   $filename = group($files,$select) 'convert the menu number to the file name
  58.   $title=upper($filename)
  59. '---------------------------------------------------------------------------
  60.  
  61.  
  62. screen clear box 1 1 scrheight 80 15 0
  63. screen clear box 2 1 scrheight-1 80 15 0 no-border
  64. screen print 1 39-(len($title)/2) 14 0 " "|$title|" "
  65. screen print scrheight 24 15 0 "F3=Find  F4=Goto  F8=Wrap/Unwrap"
  66. screen print scrheight/2 1 15 0 format "M80" "Reading """|upper($filename)|""" into Text Viewer"
  67.  
  68. $wrap="No Wrap"
  69. $limit=3000
  70.  
  71. '---------------------------------
  72. label readtext
  73. '---------------------------------
  74. fopen $filename as 1
  75. error on
  76. for $line = 1 to $limit
  77.  
  78.   if nextkey = keyvalue("Esc")  'allow an exit
  79.     stop
  80.   end if
  81.  
  82.   'the following is a ticker in case it takes a while to load a file
  83.   $tick= val(mid(str(fixed(now,7)),11))
  84.   if $tick < 1000/8
  85.     $tick="|"
  86.   elseif $tick < 2*(1000/8)
  87.     $tick="/"
  88.   elseif $tick < 3*(1000/8)
  89.     $tick="-"
  90.   elseif $tick < 4*(1000/8)
  91.     $tick= "\"
  92.   elseif $tick < 5*(1000/8)
  93.     $tick="|"
  94.   elseif $tick < 6*(1000/8)
  95.     $tick="/"
  96.   elseif $tick < 7*(1000/8)
  97.     $tick="-"
  98.   else
  99.     $tick= "\"
  100.   end if
  101.   screen print (scrheight/2)+1 1 15 0 format "M80" $tick
  102.  
  103.   'check memory and rediminsion if necessary.  truncate if necessary.
  104.   if memleft < 2500
  105.     beep
  106.     if $line < $limit-500
  107.       beep 2
  108.       $limit=$limit-500
  109.       redimension $text[$limit]
  110.       error off 'turn off beep for "filename already open"
  111.       fseek 1 0
  112.       jump readtext
  113.     else
  114.       exit for 'just display the lines that we have enough memory for
  115.     end if
  116.   end if
  117.  
  118.   fread 1 into $text[$line]
  119.  
  120.   if $wrap="Wrap"
  121.     while len($text[$line]) > 80
  122.       $line=$line+1
  123.       if $line>10000
  124.         exit while
  125.       end if
  126.       $text[$line]=mid($text[$line-1],81)
  127.     end while
  128.   end if
  129.  
  130.   if eof(1)=1
  131.     exit for
  132.   end if
  133.  
  134. end for
  135.  
  136. fclose 1
  137.  
  138. $lastline=$line-1
  139. if $lastline=0
  140.   beep 2
  141.   screen print scrheight/2 1 15 0 format "M80" "File contains no data, Hit any key to Exit."
  142.   inchar
  143.   exit
  144. end if
  145. $pos=1
  146.  
  147.  
  148. while 1 <> 2  'keep the loop going until 'exit' has been issued
  149.   for $line = 2 to scrheight-1
  150.     if len($text[$pos])<=80
  151.       screen print $line 1 15 0 format "L80" $text[$pos]
  152.       if $pos=$searchpos
  153.         screen print $line find($searchtxt,$text[$pos],0)+1 0 15 $searchtxt
  154.       end if
  155.     else
  156.       screen print $line 1 15 0 left($text[$pos],80)
  157.       if $pos=$searchpos
  158.         screen print $line find($searchtxt,$text[$pos],0)+1 0 15 $searchtxt
  159.       end if
  160.     end if
  161.     $pos=$pos+1
  162.  
  163.     if $pos>$lastline
  164.       $line=$line+1
  165.       while $line < scrheight
  166.         screen print $line 1 15 0 format "L80" ""
  167.         $line=$line+1
  168.       end while
  169.     end if
  170.   end for
  171.  
  172.   'the following line will print the % of file that has been scrolled
  173.   screen print scrheight 5 15 0 " "|str( round((($pos-1)/$lastline)*100,0) )|"%  "
  174.   screen print scrheight 70 15 0 format "M9" $wrap
  175.   '--------------------
  176.   label keyentry
  177.   '--------------------
  178.   key name inchar $q
  179.   case lower($q)
  180.   when "home"
  181.     $pos=1
  182.   when "end"
  183.     $pos=$lastline-(scrheight-3)
  184.   when "pgup"
  185.     $pos=$pos-(scrheight-2)*2
  186.   when "pgdn"
  187.     'no change
  188.   when "up"
  189.     $pos=$pos-(scrheight-1)
  190.   when "down"
  191.     $pos=$pos-(scrheight-3)
  192.   when "f4"
  193.     goto()
  194.   when "f3"
  195.     search()
  196.   when "esc"
  197.     exit while
  198.   when "f8"
  199.     if $wrap="Wrap"
  200.       $wrap="No Wrap"
  201.     else
  202.       $wrap="Wrap"
  203.     end if
  204.     jump readtext
  205.   otherwise
  206.     $pos=$pos-(scrheight-2)
  207.     jump keyentry 'use instead of continue while to avoid rewritting screen
  208.   end case
  209.  
  210.   if $pos<1
  211.     '$pos=$lastline+$pos                       'revolving text
  212.     $pos=1                                    'non-revolving text
  213. '  elseif $pos > $lastline                     'revolving text
  214.   elseif $pos > $lastline-(scrheight-3)       'non-revolving text
  215.     '$pos=$pos-$lastline                       'revolving text
  216.     if scrheight-2 >= $lastline               'non-revolving text
  217.       $pos=1                                  'non-revolving text
  218.     else                                      'non-revolving text
  219.       $pos=$lastline-(scrheight-3)            'non-revolving text
  220.     end if                                    'non-revolving text
  221.   end if
  222.  
  223. end while
  224.  
  225. '*******************************************************
  226. function goto()
  227. '*******************************************************
  228. screen clear box 10 20 13 60 15 1
  229. screen print 11 21 15 1 format "M39" "Enter Page Number (1-"|str ( int( ($lastline/(scrheight-2))+1 ) )|")"
  230. screen input 12 39 0 7 3 $goto mask "{#{#{#}}}"
  231.  
  232. if $goto=null
  233.  $pos=$pos-(scrheight-2)  'screen won't change
  234.  return
  235. end if
  236.  
  237. $goto=(val($goto)*(scrheight-2))-(scrheight-3)
  238. if $goto > $lastline
  239.   beep
  240.   screen clear box 10 20 13 60 15 1
  241.   screen print 11 21 15 1 format "M39" "Page Number Out of Range"
  242.   screen print 12 21 15 1 format "M39" "Press Any Key to Continue"
  243.   inchar
  244.   $pos=$pos-(scrheight-2)  'screen won't change
  245.   return
  246. end if
  247. $pos=$goto
  248. end function
  249.  
  250.  
  251. '*******************************************************
  252. function search()
  253. '*******************************************************
  254. screen clear box 10 20 13 60 15 1
  255. screen print 11 21 15 1 format "M39" "Enter Search Text to Find"
  256. screen input 12 25 0 7 30 $searchtxt $searchtxt
  257.  
  258. if $searchtxt=null
  259.  $pos=$pos-(scrheight-2)  'screen won't change
  260.  return
  261. end if
  262.  
  263. $line=$pos-(scrheight-2)
  264. error off
  265. for $pos = $line+1 to $lastline
  266.   clearerror
  267.   find($searchtxt,left($text[$pos],80),0)
  268.   if lerror <> 18
  269.     exit for
  270.   end if
  271. end for
  272. error on
  273. $searchpos=$pos
  274.  
  275. end function
  276.  
  277.  
  278.