![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Examples
List of Checked Out FilesThe following is a standalone Apex Shell script which given views or configurations as arguments finds the files within them that are Checked_Out or privately Checked_Out
while ($#argv > 0) if ($1:e == cfg) then configuration cfg $1 foreach viewname (`cfg.view_names`) check_view $viewname end else check_view $1 endif shift end function check_view view v1 $1 if (`v1.fail`) return foreach name (`v1.object_names`) file obj $name set state = `obj.status` if ($state == Checked_Out || $state == Private) then echo `obj.name` endif end end_functionChanging the foreach body in the function to the following, finds files which are out of date with respect to the last Checked_In version.
file obj $name set vnum = `obj.version_number` set lvnum = `obj.latest_version_number` if ($vnum == $lvnum) continue if ($vnum+1 < $lvnum) then echo `obj.name` else set lstate = `obj.latest_status` if ($lstate == Checked_In || $lstate == Deleted) then echo `obj.name` endif endif
Show Directory TreeThe following script outputs a directory tree given a directory name as an argument.
This script is an example of simulated recursion using Apex Shell. Although function recursion is directly supported, Apex Shell objects always have global scope. The expand_directory function overcomes this limitation by changing the name of the file object at each level of recursion.
#! apex_shell # function expand_directory directory d$2 $1 local this local i foreach this (`d$2.directory_entries`) if ($this:t != "." && $this:t != ".." ) then for ( set i=0; $i < $2; @ i++) echo -n " " end file f$2 `d$2.name`/$this:t if ("`f$2.object_kind`" == "directory") then echo $this:t/ expand_directory `f$2.name` `expr $2 + 1` else echo $this:t endif f$2.destroy endif end d$2.destroy end_function expand_directory $1 1
Propagate SwitchesThe following is a standalone Apex Shell script which propagates switch values from a source view to target views.
The source can also be a configuration in which case the targets should be simple view names and it will be done for all views in the configuration to each of the targets.
The switches to propagate are specified with a command line option Only switches which occur in both the source view and the target view and which are different in the target view are changed.
function usage_message echo usage: propagate_switches '-switches "name1 ..."' \ source_view_or_config target_view1 ... end_function set noglob set vnames = () string_set switches_to_change -upper while ($#argv > 0) if ($1:e == cfg) then set cfgname = $1 else if ($1 == -switches) then if ($#argv >= 2) then foreach name ($2) switches_to_change.add $name end shift endif else if (! $?cfgname && ! $?source_viewname) then set source_viewname = `cpath $1` else set vnames = ($vnames $1) endif shift end if (! $?cfgname && ! $?source_viewname) then echo No source view or configuration given usage_message exit 1 endif if ($#vnames == 0) then echo No target view names given usage_message exit 1 endif if (`switches_to_change.cardinality` == 0) then echo No switch names to change given usage_message exit 1 endif if ($?cfgname) then configuration cfg $cfgname foreach viewname (`cfg.view_names`) process_target_views $viewname end else process_target_views $source_viewname endif #//////////// function process_target_views foreach vname ($vnames) if (`length $vname` == 0) continue switch (`char $vname 0`) case /: propagate_switches $1 $vname breaksw case .: propagate_switches $1 `cpath $vname` breaksw default: propagate_switches $1 `subsystem_name $1`/$vname breaksw endsw end end_function #//////////// function propagate_switches view v1 $1 if (`v1.fail`) then echo `v1.error` return endif view v2 $2 if (`v2.fail`) then echo `v2.error` return endif string_map differing_switches set map1 = `v1.switch_map` set map2 = `v2.switch_map` $map1.iterate while (! `$map1.done`) set switch_name = `$map1.current` if (`switches_to_change.contains $switch_name` && \ `$map2.is_bound $switch_name`) then set range1 = `$map1.get_range $switch_name` set range2 = `$map2.get_range $switch_name` if ($range1 != $range2) then if (`length $range1` > 0 && `char $range1 0` == -) then differing_switches.bind $switch_name " $range1"
else differing_switches.bind $switch_name "$range1" endif endif endif $map1.next end if (`differing_switches.cardinality` == 0) return set cmd = \ (apex set_switch -switch_context `v2.name` -output_filter progress) differing_switches.iterate while (! `differing_switches.done`) set sname = `differing_switches.current` set value = `differing_switches.get_range $sname` set cmd = ($cmd:q $sname "$value") differing_switches.next end $cmd:q end_function
List an Executable's Sources
function find_source # $1 = object file name local objname=$1 if ( $objname =~ *.[12].o ) then file obj $objname if ( "`obj.view_name`" != "" ) then local cand=`obj.element_name` if ( `substring $cand 0 21` == ".Rational/Compilation" ) then set cand=`obj.view_name`/`substring $cand 22 10000` if ( -r $cand:r.ada ) return $cand:r.ada endif endif endif if ( -r $objname:r.C ) return $objname:r.C if ( -r $objname:r.c ) return $objname:r.c # Give up! return $objname end_function
########### Main ################### set mainfile=$1 if ( ! ( $mainfile =~ *.2.ada ) ) set mainfile=$mainfile.2.ada file mf $mainfile string_set clist set tmp=`mf.code_file_name` if ( "$tmp" != "" ) then if ( -r ${tmp}_batch ) then foreach this (`cat ${tmp}_batch`) clist.add $this end endif if ( -r ${tmp:r:r}.c_objs.files ) then foreach this ( `cat ${tmp:r:r}.c_objs.files` ) if ( $this =~ *.a ) then if ( -r $this.closure ) then foreach that (`cat $this.closure`) clist.add $that end endif else clist.add $this endif end endif endif clist.iterate while ( ! `clist.done` ) local obj=`clist.current` echo `find_source $obj` clist.next end
Reduce Items to a Set of ViewsThe following is an example of a Menu_Item action written in Apex Shell which runs off of a directory window.
Given a set of selected items (or the current window's context) it reduces that set to the set of views named or implied and visits any Code_Rule files that those views have.
action showCodeRules options shell apex string_set views set names = $SELECTION if (`length $names` == 0) then set from_context set vname = `viewname $CONTEXT` if (`length $vname` > 0) then views.add $vname endif else foreach name ($names) set vname = `viewname $name` if (`length $vname` > 0) then views.add $vname endif end endif if (`views.cardinality` == 0) then echo No views selected return endif set count = 0 views.iterate while (! `views.done`) set crfile = `views.current`/Policy/Code_Rules.sw if (-e $crfile) then visit $crfile @ count++ endif views.next end if ($count == 0) then if ($?from_context) then echo No code rule file exists for this context else echo No code rule files exist for the selected items endif endif end_action
Sample Dialog BoxThe following is a dialog box done with Apex Shell.
%dialog cmvcSourceLines %prog build popup navigate objects*navigate objects*textEntry nav1 "" objects*list %prog nav1 dialog nav1 fileLocator `arg 1` "" "Source Lines - Objects" %prog init setw objects*list `arg 3 *` setw sourceLines true setw commentLines true setw blankLines true setw totalLines true focus OK %prog exec check `valw objects*list` file "You need to specify some objects." \ "The following are illegal:" set start = "<table,sort,>Object<left, >" set rest = "{<object><column>" set count = 0 set objects = (`valw objects*list`) if ($#objects == 1) then set summary else set summary = ,summary endif if (`valw sourceLines`) then set start = "${start}Source<right$summary, >" set rest = "$rest:q<object'source_lines><column>" @ count++ endif if (`valw commentLines`) then set start = "${start}Comment<right$summary, >" set rest = "$rest:q<object'comment_lines><column>" @ count++ endif if (`valw blankLines`) then set start = "${start}Blank<right$summary, >" set rest = "$rest:q<object'blank_lines><column>" @ count++ endif if (`valw totalLines`) then set start = "${start}Total<right$summary,>" set rest = "$rest:q<object'total_lines>" @ count++ endif if ($count == 0) then check "" "" "No option specified" "" endif set rest = "$rest:q}" apex report -format "$start$rest:q" $objects \ -expand_configs \ -output_filter errors \ -output_title source_lines \ -window_to_notify `alias_key\Q & %end_dialogThe following is the exec prog from the File > New > View dialog
%prog exec if (`valw name*value` == "") then dialog er message_dialog "" "" "You need to specify a view name." fail endif check `valw context*value` directory \ "You need to specify a subsystem." \ "The subsystem is illegal:" \ "You must specify only one subsystem." if (`valw in_dir`) then check `valw storage*value` directory \ "You need to specify a storage directory or click other option." \ "The storage directory is illegal:" \ "You must specify only one storage directory." endif set noglob set opts = () if (`valw visit`) set opts = ($opts -visit) if (`valw interface_only`) set opts = ($opts -interface) if (`valw model*value`) set opts = ($opts -model `valw model*value`) if (`valw in_dir`) then set opts = ($opts -storage `valw storage*value`) else if (`valw rci_directory`) \ set opts = ($opts -rci_target_directory `valw rci_directory`) if (`valw rci_machine`) \ set opts = ($opts -rci_compilation_platform `valw rci_machine`) if (`valw rci_hostOnly`) set opts = ($opts -rci_host_only) endif set access = (`valw access_category*menuValue`) set opts = ($opts -access_category $access[1]) set opts = ($opts -group `valw group*menuValue`) if (`valw view_kind*menuValue` == Working) then set cmd = create_working else set cmd = create_release endif set rest = (-output_title new_view -window_to_notify `alias_key`) set imps = `valw imports*value` if ($imps) then apex $cmd `valw name*value` $opts -import "$imps" $rest & else apex $cmd `valw name*value` $opts $rest & endifServer/Client Applications
This function is used in the examples below to connect to an Apex session. It creates and returns the name of a "connection" object.
function connect_to_session if (! $?APEX_MESSAGE_SERVER) then set info = `apex_display get_root_property \ APEX_MESSAGE_SERVER` else set info = "$APEX_MESSAGE_SERVER" endif if (`parm_count` > 0) then connection c1 "$1" "$info" else connection c1 "$info" endif if (`c1.fail`) then echo CONNECTION FAILED: `c1.error` exit 1 endif return c1 end_functionSending a message to the Message_Server
set cname = `connect_to_session` request req "" set_value req.append domain_value req.append "range value" req.send "$cname"Sending messages to the Text_Server and Directory Server
These examples are of sending messages to the Text_Server and Directory_Server at the request level. These examples could be done more simply with subcommands of Apex_Display.
set cname = `connect_to_session -persistent` request r1 Apex_Text_Server set_environment set arg = ENVVAR=value r1.append "`arg.length` $arg" r1.send "$cname" # the "perform" command is sent as a subcommand of the # top-level operation called editor_operation. The # parameters to perform are encoded in a string with # length preceded values. set op = select set arg = /tmp/foo set params = "`op.length` $op`cwd.length` \ $cwd`arg.length` $arg" request r2 Apex_Directory_Server editor_operation r2.append "" r2.append Directory r2.append_long `r2.integer_operation perform` r2.append "$params" r2.send "$cname"Shell script that runs as an Apex server
set cname = `connect_to_session` $cname.register My_Server_Name if (`$cname.fail`) then echo REGISTER FAILED: `$cname.error` exit 1 endif request req while (1) req.receive "$cname" if (`req.fail`) then echo RECEIVE FAILED: `req.error` exit 1 endif switch (`req.operation`) case shutdown: break case 10001: # ... breaksw endsw end $cname.closeShell script that runs as a general server waiting for requests
connection rconn -receive if (`rconn.fail`) then echo RECEIVE CONNECT: `rconn.error` exit 1 endif set value = `rconn.image` set ignore = `apex_display set_root_property SERVER_TEST "$value"` request r while (1) set newconn = `rconn.accept` if (`rconn.fail`) then echo ACCEPT FAILED: `rconn.error` exit 1 endif r.receive "$newconn" if (`r.fail`) then echo RECEIVE FAILED: `r.error` exit 1 endif if (`r.operation` == shutdown) then exit endif if (`r.operation` == get_environment) then set name = `r.get` r.make_empty r.append "`getenv $name`" r.send "$newconn" $newconn.destroy continue endif while (`r.more`) set line = `r.get` # ... end $newconn.destroy endShell script that sends requests to the above kind of server
set info = `apex_display get_root_property SERVER_TEST` connection sconn "$info" if (`sconn.fail`) then echo CONNECT FAILED: `sconn.error` exit 1 endif request req "" get_environment req.append APEX_HOME req.call sconn if (`req.fail`) then echo CALL FAILED: `req.error` exit 1 endif set value = `req.get` echo APEX_HOME = "$value" connection sconn "$info" req.make_empty req.set_operation 500 req.append line1 req.append "line2 data" req.send sconn if (`req.fail`) then echo SEND FAILED: `req.error` exit 1 endif
Rational Software Corporation http://www.rational.com support@rational.com techpubs@rational.com Copyright © 1993-2001, Rational Software Corporation. All rights reserved. |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |