home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Media Share 9
/
MEDIASHARE_09.ISO
/
dbase
/
new194.zip
/
LISTFILE.PRG
< prev
next >
Wrap
Text File
|
1993-02-05
|
10KB
|
266 lines
*-------------------------------------------------------------------------------
*-- Program...: LISTFILE.PRG
*-- Programmer: Kenneth J. Mayer (CIS: 71333,1030)
*-- Date......: 01/25/1993
*-- Notes.....: This program/set of routines is designed to display an ASCII
*-- file of up to 1,178 lines, and 254 characters per line
*-- on the screen. It allows scrolling (up,down,left,right),
*-- and a few hot-keys as well:
*-- <Home> = the beginning/first character of the line
*-- <End> = the right side of a line
*-- <Ctrl><Home> = the top of the file
*-- <Ctrl><End> = the bottom of the file
*-- <PgUp>/<PgDn> = page up/down one screen at a time
*-- Usage.....: DO ListFile WITH <cFileName>,<nRow>[,<nMaxLines>[,<nTab>[,;
*-- <cColor>]]]
*-- Example...: do listfile with "ListFile.PRG",5,18,3,"rg+/g"
*-- Parameters: cFileName = name of file to list -- include extension and
*-- path if necessary
*-- nRow = starting row on screen (top of "window")
*-- nMaxLines = optional -- number of lines to display at one
*-- time -- if left off, routine will use as manu
*-- lines as possible from nRow to bottom of screen.
*-- nTab = optional -- number of spaces to use for tab
*-- characters at the beginning of a line. Ignores
*-- tabs after the first non-tab character in a line
*-- for speed's sake.
*-- cColor = optional -- provide color description for window,
*-- format: Foreground/Background. For example, to
*-- display the file in a window that has yellow text
*-- on a green background, the parameter would be:
*-- "rg+/g"
*-------------------------------------------------------------------------------
parameters cFileName,nRow,nMaxLines,nTab,cColor
private cWindow,cCursor,nDisplay,nBottom,nLastLine,x,nCount,nKey,;
nFirstLine,nCurrPos
save screen to sListFile && save screen description
cWindow = window() && store name of any "current" window on screen
cCursor = set("CURSOR") && save current cursor state
set cursor off && turn it off ...
activate screen && activate screen so we can display on TOP
&& of anything there.
if pCount() > 4
cColor = "COLOR "+cColor
else
cColor = ""
endif
if type("NMAXLINES") = "L" .or. isblank(nMaxLines)
&& determine # of lines to display on screen ...
*-- find bottom of screen, and then subtract nRow from that ...
if set("DISPLAY") # "MONO"
nDisplay = val(right(set("DISPLAY"),2))
else
nDisplay = 24
endif
if set("STATUS") = "ON" && if status line is on, we have two less
&& lines to work with
nDisplay = nDisplay - 4
endif
nMaxLines = nDisplay - nRow
endif
*-- bottom row of window is based on nMaxLines
nBottom = nRow + nMaxLines
if type("NTAB") = "L" && set default ... notice that if it's 0, that's
&& not undefined
nTab = 5
endif
*-- display a message for user to let them know we haven't just
*-- disappeared ...
@10,27 to 12,51 double color rg+/gb
@11,28 say "Reading/Processing File" color rg+/gb
*-- get it
nLastLine = TextLine(cFileName) && obtain line number of last line of file
x = AAppend(cFileName,"aFileList") && put file into array
*-- deal with tabs here
if nTab # 0
nCount = 1
do while nCount < nLastLine
do while chr(9) $ aFileList[nCount] && loop while current character is a tab
aFileList[nCount] = ;
stuff(aFileList[nCount],at(chr(9),aFileList[nCount]),1,space(nTab))
enddo
nCount = nCount + 1
enddo
endif
*-- loop and pad each array element with spaces to 254 characters
nCount = 1
do while nCount < nLastLine
aFileList[nCount] = aFileList[nCount]+space(254-len(aFileList[nCount]))
nCount = nCount + 1
enddo
*-- remove message
restore screen from sListFile
*-- define window
define window wListFile from nRow,0 to nBottom,79 none &cColor.
activate window wListFile
*-- now that we're here, let's go ...
nKey = 0 && initialize to something we're not looking for
nFirstLine = 1 && First line to display out of list ...
nCurrPos = 1 && current position in string
*-- here's the actual loop ...
do while nKey # 27 && must press <Esc> to exit
*-- display loop
nCounter = 0
do while nCounter < nMaxLines
@nCounter,0 say substr(aFileList[nFirstLine+nCounter],nCurrPos,80)
nCounter = nCounter + 1
enddo
*-- get keypress
nKey = inkey(0) && wait for a keypress
*-- if keypress is one of the following, do something with it ...
do case
case nKey = 5 && up arrow = up one row
if nFirstLine > 1
nFirstLine = nFirstLine - 1
endif
case nKey = 24 && down arrow = down one row
if nFirstLine+nMaxLines < nLastLine
nFirstLine = nFirstLine + 1
endif
case nKey = 3 && <PgDn> = down one screen
if nFirstLine+nMaxLines < nLastLine - nMaxLines
nFirstLine = nFirstLine + nMaxLines
else
nFirstLine = nLastLine - nMaxLines
endif
case nKey = 18 && <PgDn> = up one screen
if nFirstLine - nMaxLines > 1
nFirstLine = nFirstLine - nMaxLines
else
nFirstLine = 1
endif
case nKey = 23 && <Ctrl><End> = End of File
nFirstLine = nLastLine - nMaxLines
case nKey = 29 && <Ctrl><Home> = Beginning of File
nFirstLine = 1
case nKey = 19 && <Left> = Back up one character
if nCurrPos > 1
nCurrPos = nCurrPos - 1
endif
case nKey = 4 && <Right> = Go RIGHT one character
if nCurrPos < 174 && 254-80 (width of string - screen width
nCurrPos = nCurrPos + 1
endif
case nKey = 2 && <End> = end of line
nCurrPos = 174 && show last character(s) on right side of text
case nKey = 26 && <Home> = beginning of line
nCurrPos = 1
endcase
enddo
*-- if here, we <Esc>aped out of the loop
deactivate window wListFile
release window wListFile
restore screen from sListFile
release screen sListFile
if .not. isblank(cWindow)
activate window &cWindow
endif
release aFileList
set cursor &cCursor
RETURN
*-- EoP: ListFile
FUNCTION AAppend
*-------------------------------------------------------------------------------
*-- Programmer..: Adam L. Menkes (Borland Technical Support)
*-- Date........: 04/xx/1992
*-- Notes.......: Appends a text file into an array. This routine is limited to
*-- text files of 1,170 lines, and 254 characters per line.
*-- The text file must be an ASCII Txt formatted file. Taken from
*-- Technotes, April, 1992.
*-- Written for.: dBASE IV, 1.5
*-- Rev. History: None
*-- Calls.......: TextLine() Function in LOWLEVEL.PRG
*-- Called by...: Any
*-- Usage.......: AAppend(<cFileName>,<aArrayName>)
*-- Example.....: ?AAppend("CONFIG.DB","aConfig")
*-- Returns.....: .T.
*-- Parameters..: cFileName = Name of DOS Text file to read into array
*-- aArrayName = Name of array to create. If it already exists,
*-- this array will be destroyed and overwritten.
*-------------------------------------------------------------------------------
parameters cFileName, aArrayName
private aTArray, nLines, nX, nHandle
*-- assign array name to a temp variable name ...
aTArray = aArrayName
*-- if it exists, get rid of it, and then re-define it
release &aTArray
public &aTArray
nLines = TextLine(cFileName) && get number of lines
declare &aTArray[min(nLines,1170)]
*-- get file handle
nHandle = fopen(cFileName)
*-- store the file into the array
nX = 1
do while nX <= nLines
store fgets(nHandle,254) to &aTArray[nX]
nX = nX + 1
enddo
*-- close the file
nHandle = fClose(nHandle)
RETURN .T.
*-- EoF: AAppend()
FUNCTION TextLine
*-------------------------------------------------------------------------------
*-- Programmer..: Adam L. Menkes (Borland Technical Support)
*-- Date........: 04/xx/1992
*-- Notes.......: Returns the number of lines of text in an ASCII Text File
*-- Taken from TechNotes, April, 1992
*-- Written for.: dBASE IV, 1.5
*-- Rev. History: None
*-- Calls.......: None
*-- Called by...: Any
*-- Usage.......: TextLine(<cTextFile>)
*-- Example.....: ?TextLine("CONFIG.DB")
*-- Returns.....: Number of lines
*-- Parameters..: cTextFile = name of file
*-------------------------------------------------------------------------------
parameter cTextFile
private nLines, nHandle, cTemp, nClose
nLines = 0
if file(cTextFile) && if it exists ...
nHandle = fopen(cTextFile,"R")
do while .not. feof(nHandle)
cTemp = fgets(nHandle,254)
nLines = nLines + 1
enddo
nClose = fclose(nHandle)
endif
RETURN nLines
*-- EoF: TextLine()
*-------------------------------------------------------------------------------
*-- End of Program: LISTFILE.PRG
*-------------------------------------------------------------------------------