home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
p2demo21.exe
/
PEL
/
MACROS.PEL
< prev
next >
Wrap
Text File
|
1995-03-31
|
12KB
|
485 lines
# $Header: P:\source\wmacros\macros.pev 1.32 31 Mar 1995 15:41:32 NOBLE $
##############################################################################
#
# Compuware Corporation
# 31440 Northwestern Highway
# Farmington Hills, Michigan 48334-2564
#
# This source code listing contains information that is
# proprietary to Compuware Corporation and may not be copied
# duplicated, translated, transmitted, stored, retrieved
# or in any manner or by any method conveyed or disclosed
# to a third party or parties without express written
# permission from Compuware Corporation.
#
#
##############################################################################
#### $Workfile: macros.pel $: Support for Playback/Record and Macros
# reserved global variables
global recording = -1
global recordString = ""
global playingback = 0
## record and playback
global currentRecordString = ""
local pausedRecordString = ""
local recordingPaused = 0
function pause_recording()
{
if ( !recording && recordingPaused )
{
record()
recordingPaused = 0
recording = 1
}
else if ( recording == 1 )
{
pausedRecordString = pausedRecordString record()
recordingPaused = 1
recording = 0
}
}
function record_macro()
{
local str
if ( playingback )
return
if ( recordingPaused )
{
message( "Keystroke macro defined." )
recordingPaused = 0
str = ""
}
else
str = record_key()
currentRecordString = pausedRecordString str
pausedRecordString = ""
}
function playback_macro()
{
playingback = 1
if ( recordingPaused )
message( "Playback while recording." )
else
{
if ( currentRecordString )
playback( currentRecordString )
else
playback()
}
playingback = 0
}
function load_key_file(append, fn)
{
local fid
local ch
if (!fn)
fn = prompt_history( "RECORD", "Keystroke macro file: ", "", 1, 1, "load_key_file_prompt")
if ( fn )
{
if ( (fid = fopen( fn, 0 )) > 0 )
{
if (!append)
currentRecordString = ""
while ( (ch = fgetc(fid)) >= 0 )
{
currentRecordString = currentRecordString chr( ch )
}
fclose( fid )
}
else
notify( "Unable to open: " fn )
}
}
function write_key_file(fn)
{
local fid
if ( currentRecordString )
{
if (!fn)
fn = prompt_history( "RECORD", "Save keystrokes as: ", "", 1, 1, "write_key_file_prompt")
if ( fn )
{
if ( (fid = fopen( fn, 1 )) > 0 )
{
fprintf( fid, currentRecordString )
fclose( fid )
}
else
notify( "Unable to open: " fn )
}
}
else
notify( "No keystroke macro to save." )
}
global function record_key()
{
if (playingback)
return
if( recording > 0 )
message("Keystroke macro defined.")
else
{
if (recording != -1)
{
if (tolower(confirm("Overwrite existing keystroke macro [yn]? ",
"YyNn")) != "y")
{
return
}
}
message("Defining keystroke macro.")
recording = 0
}
recording = !recording
return record()
}
## functions supporting invoke_function:
local instr
local inpos
global extended_quotes = FALSE # when true, Allows args that have characters
# before a quote (such as C'string').
# Get a backslash escape sequence from instr at inpos.
# Return the single character string.
#
local function getescape()
{
local acc, i, ch
ch = substr(instr,inpos,1)
inpos++
if (ch >= "0" && ch <= "7")
{
# Octal escape sequence.
acc = ch + 0
for (i=0; i<3; i++)
{
ch = substr(instr,inpos,1)
if (ch >= "0" && ch <= "7")
{
inpos++
acc = acc * 8 + ch
}
}
return( chr(acc) )
}
else if (ch == "x")
{
# Hex escape sequence.
for (i=0; i<2; i++)
{
ch = toupper( substr(instr,inpos+i,1) )
if ( !((ch >= "0" && ch <= "9") || (ch >= "A" && ch <= "F")))
break
}
ch = chr( 0 + ("0x" substr(instr,inpos,i)) )
inpos += i
return(ch)
}
else if ((i = index("btfnr\\",ch)))
return( substr("\b\t\f\n\r\\",i,1) )
else
return(ch)
}
# Break the string into arguments and return an array of the arguments,
# where arg[1] is the first argument, arg[2] the second, etc.
# Allow spaces in quoted arguments.
#
# 11/09/93 - MLW did it : Extened quote_args to allow either double (") or
# single (') quotes to be used. The other quote
# char can be embedded in the string.
# (I.E. 'This "is" ok!')
#
local function quote_args(lp)
{
local i, j, ch, outbuf, quote
local fun_args
local fun_argc = 0
instr = lp
inpos = 1
while (1)
{
ch = substr(instr,inpos,1)
if ( !ch )
break
else if ( index(" \t",ch) )
{
inpos++
continue
}
else if ( ch == "\"" || ch == "'")
{
inpos++
outbuf = ""
quote = ch
while (1)
{
ch = substr(instr,inpos++,1)
if ( ch == "" )
error("improperly quoted string: %s", instr)
else if ( ch == quote )
break
else if (ch == "\\")
outbuf = outbuf getescape()
else
outbuf = outbuf ch
}
fun_args[ ++fun_argc ] = outbuf
}
else
{
if ((i = cindex(substr(instr,inpos)," \t")))
{
if (extended_quotes)
{
outbuf = substr(instr,inpos,i-1)
if ((j = cindex(outbuf, "\"'")))
{
outbuf = substr(outbuf, 1, j)
inpos += j
quote = substr(instr,inpos-1,1)
while (1)
{
ch = substr(instr,inpos++,1)
if ( ch == "" )
error("improperly quoted string: %s", instr)
else
{
outbuf = outbuf ch
if ( ch == quote )
break
}
}
}
else
inpos += i
fun_args[++fun_argc] = outbuf
}
else
{
fun_args[++fun_argc] = substr(instr,inpos,i-1)
inpos += i
}
}
else
{
fun_args[++fun_argc] = substr(instr,inpos)
break
}
#outbuf = ""
#do {
# outbuf = outbuf ch
# ch = substr(instr,inpos++,1)
#} while (ch && ch != " " && ch != "\t")
}
}
return( fun_args )
}
# This is like function_id but allows quoted arguments in both
# function calls and variable assignments.
# Backslash sequences and spaces are processed in the quoted strings.
#
# 11/09/93 - MLW did it : See quote_args()
#
global function quoted_function_id(mac)
{
local args
if ( match( mac, /^[^\"=]+[ \t]*=[ \t]*\"/ ))
{
# It is an assignment of a quoted string to a variable,
# for example: var = "this and that"
args = quote_args( substr(mac,RLENGTH) )
# Concatenate the "var =" part with the first quoted argument.
# Trim spaces between the "=" and the quoted string
# so that the argument does not begin with extraneous spaces.
return function_id( trim(substr(mac,1,RLENGTH-1)) args[1] )
}
else if (cindex(mac,"\"'") && match(mac, /[ \t]/))
{
# It is a function call with quoted arguments.
args = quote_args( substr(mac,RSTART+1) )
return function_id( substr(mac,1,RSTART-1), args )
}
else
{
# No arguments.
return function_id( mac )
}
}
global function display_array( val, name )
{
local typo
local i, v
local dhArray
local width = 30
# check argument type
if ( typeof( val ) != "array" )
return
if ( name )
name = name " - "
# create a dialog box for the list
dhArray = create_selection_dialog( name "Array Contents", width )
set_dialog_item( dhArray, DI_OK, DAC_HIDE)
# insert the array contents
for ( i in val )
{
v = val[i]
typo = typeof( v )
if ( 0 + v )
v = sprintf( "%-12s (hex 0x%08X)", v, v )
if( typo == "string" )
v = sprintf( "%-12s: \"%s\"", i, v )
else if ( typo == "int" )
v = sprintf( "%-12s: %s", i, v )
else
v = sprintf( "%-12s: %s, type: %s", i, v, typo )
set_dialog_item( dhArray, IDL_LIST, DAC_ADD_ITEM, v )
}
begin_dialog(dhArray)
delete_dialog(dhArray)
# clear the message line
message( "" )
}
global function invoke_function( mac )
{
local typo, val, fid
if( !mac )
mac = ltrim( prompt_history("XMACRO","Command: ","", 1, 1, "command" ) );
if (mac)
{
add_prompt_history("XMACRO", mac)
message( "" )
if ( tolower( mac ) ~ /^help[ \t]/)
{
mac = ltrim( trim( tolower( substr( mac, 5 ) )))
if (mac)
display_help_item( mac )
else
gui_help_index()
}
else if ( (mac ~ /^dos[ \t]/) || (mac ~ /^system[ \t]/) )
{
# special handling for "dos" and related commands:
sub( /^dos[ \t]+/, "", mac )
sub( /^system[ \t]+/, "", mac )
sub( /[ \t]+$/, "", mac )
if( match( mac, /^".*"$/ ))
{
# remove outer-most quotes, if any:
mac = substr( mac, 2, length( mac ) - 2 )
}
else if( match( mac, /^'.*'$/ ))
{
# remove outer-most quotes, if any:
mac = substr( mac, 2, length( mac ) - 2 )
}
if(( val = system( mac )))
warning( "Command exited with %d", val )
}
else if (mac ~ /^filter[ \t]/ )
{
# special handling for "filter":
sub( /^filter[ \t]+/, "", mac )
if( match( mac, /^".*"$/ ))
{
# remove outer-most quotes, if any:
mac = substr( mac, 2, length( mac ) - 2 )
}
else if( match( mac, /^'.*'$/ ))
{
# remove outer-most quotes, if any:
mac = substr( mac, 2, length( mac ) - 2 )
}
filter( mac )
}
else if ( substr(mac,1,1) == "?" )
{
# special handling for variable inquiry:
mac = ltrim(substr(mac,2))
if( mac )
{
fid = quoted_function_id(mac)
if ( fid )
{
val = execute_function( fid )
display_update()
typo = typeof( val )
if ( typo == "array" )
{
display_array( val )
return
}
else if( 0 + val )
val = sprintf( "%s (hex 0x%08X)", val, val )
else if( typo == "string" )
val = "\"" val "\""
notify( "%s == %s, type: %s", mac, val, typo )
}
else
warning( "\"" mac "\" is invalid" )
}
}
else
{
# normal F10 commands:
if ((fid = quoted_function_id(mac)))
execute_function( fid )
else
warning( "\"%s\" is invalid", mac )
}
}
}