home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 25
/
CD_ASCQ_25_1095.iso
/
dos
/
tools
/
auror21a
/
countlin.aml
< prev
next >
Wrap
Text File
|
1995-08-31
|
5KB
|
154 lines
/* ------------------------------------------------------------------ */
/* Macro: COUNTLIN.AML */
/* Written by: nuText Systems */
/* */
/* Description: This macro counts the total number of lines and */
/* blank lines in files matching a user-specified */
/* filespec, and displays them in a popup menu. */
/* This macro can be useful for counting the total */
/* lines of source code in a directory or filespec. */
/* */
/* Usage: Select this macro from the Macro List (on the Macro */
/* menu), or run it from the macro picklist <shift f12> */
/* Select the first line of the popup menu to edit the */
/* contents of the menu. */
/* ------------------------------------------------------------------ */
// compile time macros and function definitions
include bootpath "define.aml"
// disable 'onloading' in EXT.AML while this macro is running
function onloading
end
// function to show progress while counting lines
function oncounting (filespec file status)
// create the progress window
if not window? 'count' then
createwindow 'count'
setwinobj
setframe ">b"
setcolor border_color color white on gray
setcolor text_color color black on gray
settitle "Counting lines in '" + filespec + "'" 'c'
setborder "1i"
setshadow 2 1
// center the window
width = 70
height = 16
ox = (getvidcols - width) / 2
oy = (getvidrows - height) / 2
sizewindow ox oy ox + width oy + height "ad"
// write header line
writestr "Total lines Blank lines" (color black on gray) (getcoord 'x1') - 25
// display line count for each file
elseif file then
writeline
writestr file
writestr status (color black on gray) (getcoord 'x1') - 21
else
destroywindow
end
display
end
// get filespec to count
filespec = ask "Enter filespec where lines should be counted"
// <esc> was pressed
if not filespec then
return
end
// <enter> was pressed
if filespec == ' ' then
filespec = "*.*"
end
filespec = qualify filespec (getbufname)
// initialize total lines and blank lines to zero
totallines = 0
totalblank = 0
// create a buffer to hold the results and initialize the first line
resultbuf = createbuf
ovltext "≡≡≡≡≡≡ Select this line to edit line counts ≡≡≡≡≡≡"
// get a directory listing
if (loadbuf filespec '' '' 'h') and getlinelen then
// sort by name
sendobject "fmgr" "fsort" 'n'
// create progress window
oncounting filespec
// count lines for all files in the directory
repeat
file = sendobject "fmgr" "getffile"
if loadbuf file then
lines = getlines
totallines = totallines + lines
blanklines = find "^ *$" "x*a"
totalblank = totalblank + blanklines
status = (pad (thousands lines) 7) +
(pad (thousands blanklines) 14)
oncounting filespec file status
addline (pad file 52 'l') + status '' '' resultbuf
destroybuf
end
until not down
// destroy the directory
destroybuf
// destroy the progress window
oncounting
currbuf resultbuf
if getlines > 1 then
// insert line count totals into the result buffer
insline '' '' 1
insline "Total lines: " + (thousands totallines) '' 2
insline "Total non-blank lines: " +
(thousands totallines - totalblank) '' 3
insline "Blank lines: " +
(totalblank * 100) / totallines + '%' '' 4
insline '' '' 5
insline "File" + (copystr " " 44) + "Total lines Blank lines" '' 6
insline "----" + (copystr " " 44) + "----------- -----------" '' 7
// display the results in a popup menu
file = popup resultbuf "Line counts for '" + filespec + "'" 74
if file then
// edit linecounts
if file [1] == '≡' then
delline 1 1 resultbuf
setbufname (qualify "LINES.TXT" (getbufname (getwinbuf))) resultbuf
openbuf resultbuf
// open the selected file
elseif file [2] == ':' then
open file [1 : (pos ' ' file) - 1]
end
end
end
else
destroybuf resultbuf
display
say filespec + " not found" 'b'
end