home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 5
/
ctrom5b.zip
/
ctrom5b
/
DOS
/
TEKST
/
AURORA2
/
SCAN2.AML
< prev
next >
Wrap
Text File
|
1995-04-28
|
5KB
|
151 lines
/* ------------------------------------------------------------------ */
/* Macro: SCAN2.AML */
/* Written by: nuText Systems */
/* */
/* Description: This macro can be used as an alternative to the File */
/* Scan command. Unlike like the File Scan command, */
/* this macro lists all occurrences of the search */
/* string in each file scanned. */
/* */
/* Each occurrence of the scan search string is */
/* displayed in a popup menu similar to the menu used */
/* in the Find Occurrences command. Selecting a line */
/* from the menu opens the file containing the */
/* occurrence of the string and positions the cursor */
/* appropriately. Selecting the first line in the */
/* menu allows you to edit all scanned occurrences in */
/* a separate file. */
/* */
/* Usage: Select this macro from the Macro List (on the Macro */
/* menu), or run it from the macro picklist <shift f12> */
/* ------------------------------------------------------------------ */
include bootpath "define.aml"
// disable 'onloading' in EXT.AML while this macro is running
function onloading
end
// get scan multi-string from the user
scanstring = if _PromptStyle == 'd' then
scandlg
else
ask "[string/files/iwx] Scan" "_scan"
end
if not scanstring then
return
end
// add the scan string to _scan history buffer
addhistory "_scan" scanstring
var search_string
var filespec
var options
// parse the scan multi-string
n = splitstr '' scanstring
ref search_string ref filespec ref options
if n < 3 then
options = _SearchOpt
if n < 2 then
filespec = '.'
end
end
if not search_string then
return
end
options = options + '*'
// fully qualify the filespec
dirname = qualify filespec (getbufname)
if not dir? dirname then
display
say dirname + " is not a directory" 'b'
return
end
// create the buffer to hold occurrences
buffer = createbuf
ovltext "≡≡≡≡≡≡ Select this line to edit occurrences ≡≡≡≡≡≡"
// load the directory into dirbuffer
dirbuffer = loadbuf dirname
if not dirbuffer then
return
end
// sort the directory buffer
sendobject "fmgr" "fsort" 'n'
// do for all files in the directory buffer
notify = "onscanning"
repeat
file = sendobject "fmgr" "getffile"
// load each file in the directory
if loadbuf file then
lines = getlines buffer
name = getname file
// use 'onscanning' to display the scan progress window
send notify name
// find all occurrences of the search string in the file
while find search_string options do
addline name + ' (' + getrow + "): " + gettext '' '' buffer
col MAX_COL
end
// remove the file from memory
destroybuf
// notify 'onscanning' if any occurrences were found
if lines < (getlines buffer) then
send notify name 1
end
end
until not down
// remove the scan progress window
send notify
// destroy the directory buffer
destroybuf
// display occurrences
if (getlines buffer) > 1 then
bname = getbufname
line = popup buffer
"Occurrences of '" + search_string + "' in "
+ dirname + " - " + ((getlines buffer) - 1) +
" lines" getvidcols - 11 getvidrows - 8
if line then
// edit the occurrences
if line [1] == '≡' then
delline 1 1 buffer
setbufname (qualify "TEMP.TXT" bname) buffer
openbuf buffer
// position the cursor to the selected occurrence in the file
else
destroybuf buffer
p = pos ' ' line
name = line [1 : p - 1]
line = line [p + 2 : TO_END]
linenumber = line [1 : (pos ')' line 'r') - 1]
open (qualify name dirname)
bufferflag '-m'
gotopos 1 linenumber
onfound (find search_string options + '*')
end
end
else
destroybuf buffer
display
say "'" + scanstring + "' not found" 'b'
end