/* to simulate the XEDIT count command, even the annoying 'No' instead of 0 Syntax: count /string_to_be_counted/ target Author: Scott Mattes, I-Net, Inc. (error handling and change on exit criterion introduced by Franz-Josef Wirtz, fw@ecotopia.oche.de) This is in the public domain. set rexxout file 3000; trace i */ parse arg '/'text'/'target need_help = 0 if (length( strip( text)) = 0) then need_help = 1 if (length( strip( target)) = 0) then need_help = 1 if (need_help = 1) then do 'set msgmode on' 'emsg Wrong number of arguments' 'msg Syntax: count /string_to_be_counted/ target' exit end target_check = valid_target( target) if (target_check = 'ERROR') then do 'emsg specified target is not valid' exit end parse value target_check with first how_many . last = first + how_many if (first > last) then do locate_cmd = 'locate -/'text'/' /* to tof */ direction_flag = -1 first_step = 'down' end else do locate_cmd = 'locate /'text'/' /* to eof */ direction_flag = 1 first_step = 'up' end found = 0 'extract /msgmode/' 'set msgmode off' /* move off current line to include this line */ first_step /* now iterate until error/not found or past last target line */ do forever locate_cmd if (rc <> 0) then leave if (direction_flag * (last - line.1()) < 0) then leave found = found + 1 end 'set msgmode' msgmode.1 'locate :'first if (found = 0) then found = 'No' 'emsg' found 'occurances.'