IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Reasonable way of checking wildcards using REXX


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Wed Sep 07, 2016 8:43 pm
Reply with quote

My post has been deleted from wrong forum by moderators.

Here is slightly updated copy FYI.

My version is using REXX as REXX, neither as COBOL, nor as C/C++, nor anything else.
For nails, a hammer is the best tool, while for screws a screwdriver is more suitable. For bolts the best tool is a wrench. Not vice versa; do not mix them!

Code:
/* REXX */                                                         
Test:                                                               
                                                                   
Wild = 'A?C*3'                                                     
Str = 'ABC123'                                                     
Say "$WildStr( '"Str"', '"Wild"' ) ==>" $WildStr( Str, Wild )       
                                                                   
Wild = 'A?C*3??5*'                                                 
Str = 'ABC---3xx5yyyyy'                                             
Say "$WildStr( '"Str"', '"Wild"' ) ==>" $WildStr( Str, Wild )       
                                                                   
Wild = '*A?C*3??5*'                                                 
Str = 'zzzzzzABC---3xx5yyyyy'                                       
Say "$WildStr( '"Str"', '"Wild"' ) ==>" $WildStr( Str, Wild )       
                                                                   
Wild = 'A?C*3??5*'                                                 
Str = 'ABC---3xxxx5yyyyy'                                           
Say "$WildStr( '"Str"', '"Wild"' ) ==>" $WildStr( Str, Wild )       
                                                                   
return                                                                 
/**********************************************************************/
$WildStr: /* verify String against complex StrMask */ procedure         
/* Call:                                                               
      If $WildStr( MemberName, '*AB*C???0*1*' ) Then ...               
      If $WildStr( MemberName, '*AB*C%%%0*1*', , '%' ) Then ...         
      If $WildStr( MemberName, '*AB~C???0~1~', '~' ) Then ...           
*/                                                                     
                                                                       
Parse Arg String, StrMask, StrChar, WildChar                           
If StrChar = '' Then StrChar = '*'                                     
Else                 StrChar = Left( StrChar, 1 )                       
                                                                       
If WildChar = '' Then WildChar = '?'                                   
Else                  WildChar = Left( WildChar, 1 )                   
                                                                       
Do While StrMask > ''                                                   
   Parse var StrMask,   /* split by the first '*' */                   
      PreWild (StrChar) StrMask                                         
   If PreWild > '' Then Do /* check left from '*' as simple wildcard */
      LeftStr = Left( String, Length(PreWild) ) /* same size fragment */
      If ¬ $WildEq( LeftStr, PreWild, WildChar ) Then                   
         Return 0                                                       
   End                                                                 
   If StrMask = '' Then /* whole string verified successfully */       
      Return 1                                                         
                                                                       
   /* try to match the '*' found as next part */                       
   Do i = (Length(PreWild) + 1) To Length(String)                       
      /* skip left characters one by one; verify the rest recursively */
      RestStr = Substr( String, i )                                     
      If $WildStr( RestStr, StrMask, StrChar, WildChar ) Then           
         Return 1                                                       
   End i                                                               
End                                                                     
                                                                       
Return 0                                                               
/**********************************************************************/
$WildEQ: /* verify String against simple WildMask */ procedure         
/* Call:                                                               
      If $WildEQ( MemberName, 'ABC???01' ) Then ...                     
      If $WildEQ( MemberName, 'ABC%%%01', '%' ) Then ...               
*/                                                                     
Parse Arg String, WildMask, WildChar                                   
                                                                       
If WildChar = '' Then WildChar = '?'                                   
Else                  WildChar = Left( WildChar, 1 )                   
                                                                       
LowMask = Translate( WildMask, '00'x, WildChar )                       
HiMask  = Translate( WildMask, 'FF'x, WildChar )                       
                                                                       
LowString = BitOr( LowMask, String, ' ' )                               
HiString = BitAnd( HiMask,  String, ' ' )                               
                                                                       
Return (LowString == HiString)                                         
/**********************************************************************/
Back to top
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Wed Sep 07, 2016 11:15 pm
Reply with quote

Thanks for posting it back!
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Fri Sep 09, 2016 9:43 pm
Reply with quote

Three types of wildcard handler:
1) If $WildDSN(...) - to verify specific zOS DSNAME syntax rules, with '**', '*', and '%' masks
2) If $WildCard(...) - to verify complex string wildcard with '*', and '?' masks
3) If $WildWord(...) - to verify simple words with '?' masks only

Code:
/* REXX */
WILDCARD_Test:

Wild = 'A?C*3'
Str = 'ABC123'
Say "$WildCard( '"Str"', '"Wild"' ) ==>" $WildCard( Str, Wild )

Wild = 'A?C*3??5*'
Str = 'ABC---3xx5yyyyy'
Say "$WildCard( '"Str"', '"Wild"' ) ==>" $WildCard( Str, Wild )

Wild = '*A?C*3??5*'
Str = 'zzzzzzABC---3xx5yyyyy'
Say "$WildCard( '"Str"', '"Wild"' ) ==>" $WildCard( Str, Wild )

Wild = 'A?C*3??5*'
Str = 'ABC---3xxxx5yyyyy'
Say "$WildCard( '"Str"', '"Wild"' ) ==>" $WildCard( Str, Wild )

Wild = 'SYS%.**.PROC*'
Str = 'SYS1.PROCLIB'
Say "$WildDSN( '"Str"', '"Wild"' ) ==>" $WildDSN( Str, Wild )

Wild = 'SYS%.**.PROC*'
Str = 'SYS2.PROCLIB'
Say "$WildDSN( '"Str"', '"Wild"' ) ==>" $WildDSN( Str, Wild )

Wild = 'SYS%.**.PROC*'
Str = 'SYS2.PROCFILE'
Say "$WildDSN( '"Str"', '"Wild"' ) ==>" $WildDSN( Str, Wild )

Wild = 'SYS%.**.PROC*'
Str = 'SYS2.SPECIAL.PROCFILE'
Say "$WildDSN( '"Str"', '"Wild"' ) ==>" $WildDSN( Str, Wild )

Wild = 'SYS%.**.*LIB'
Str = 'SYS1.PROCLIB'
Say "$WildDSN( '"Str"', '"Wild"' ) ==>" $WildDSN( Str, Wild )

Wild = 'SYS%.**.*LIB'
Str = 'SYS1.1ROCLIB'
Say "$WildDSN( '"Str"', '"Wild"' ) ==>" $WildDSN( Str, Wild )

Wild = 'SYS%.**.PROC*'
Str = 'SYS2.PR!CLIB'
Say "$WildDSN( '"Str"', '"Wild"' ) ==>" $WildDSN( Str, Wild )

Wild = 'SYS%.**.PROC*'
Str = 'SYS2.PROCFILEXXX'
Say "$WildDSN( '"Str"', '"Wild"' ) ==>" $WildDSN( Str, Wild )

Wild = 'SYS%.**.PROC*'
Str = 'SYS2.SPECIALLONG.PROCFILE'
Say "$WildDSN( '"Str"', '"Wild"' ) ==>" $WildDSN( Str, Wild )

return
/**********************************************************************/
$WildDSN: /* verify DSNAME against complex StrMask */ procedure
/* Call:
      If $WildDSN( DSNAME, 'SYSXXX.A*.B%C.*.TASK*.**.PROCLIB' ) Then ...
*/

Parse Arg DSNAME, DSNMask

If Length(DSNAME) > 44,
 | Length(DSNAME) < 1 Then
   Return 0

Do While DSNMask > ''

   Parse var DSNAME  PreDSN '.' .
   If ¬ $IsDSNPart( PreDSN ) Then /* bad part of DSNAME found */
      Return 0

   Parse var DSNMask  PreQual '.' DSNMask

   If PreQual = '**' Then Do /* handle DSN part of any size */
      Do While PreDSN > ''
         If $WildDSN( DSNAME, DSNMask ) Then
            Return 1
         Else
            Parse var DSNAME  PreDSN '.' DSNAME
      End
   End
   Else If $WildCard( PreDSN, PreQual, '*', '%' ) Then Do
      Parse var DSNAME  . '.' DSNAME  /* skip good part */

      If DSNAME = '' Then
         Return (DSNMask = '')
   End
   Else
      Return 0               /* non-matching part detected */

End /* DSNMask > '' */

Return 0
/**********************************************************************/
$WildCard: /* verify String against complex StrMask */ procedure
/* Call:
      If $WildCard( MemberName, '*AB*C???0*1*' ) Then ...
      If $WildCard( MemberName, '*AB*C%%%0*1*', , '%' ) Then ...
      If $WildCard( MemberName, '~AB~C???0~1~', '~' ) Then ...
*/

Parse Arg String, StrMask, StrChar, WildChar
If StrChar = '' Then StrChar = '*'
Else                 StrChar = Left( StrChar, 1 )

If WildChar = '' Then WildChar = '?'
Else                  WildChar = Left( WildChar, 1 )

Do While StrMask > ''
   Parse var StrMask,   /* split by the first '*' */
      PreWild (StrChar) StrMask
   If PreWild > '' Then Do /* check left from '*' as simple wildcard */
      LeftStr = Left( String, Length(PreWild) ) /* same size fragment */
      If ¬ $WildWord( LeftStr, PreWild, WildChar ) Then
         Return 0
   End
   If StrMask = '' Then /* whole string verified successfully */
      Return 1

   /* try to match the '*' found as next part */
   Do i = (Length(PreWild) + 1) To Length(String)
      /* skip left characters one by one; verify the rest recursively */
      RestStr = Substr( String, i )
      If $WildCard( RestStr, StrMask, StrChar, WildChar ) Then
         Return 1
   End i
End

Return 0
/**********************************************************************/
$WildWord: /* verify String against simple WildMask */ procedure
/* Call:
      If $WildWord( MemberName, 'ABC???01' ) Then ...
      If $WildWord( MemberName, 'ABC%%%01', '%' ) Then ...
*/
Parse Arg String, WildMask, WildChar

If WildChar = '' Then WildChar = '?'
Else                  WildChar = Left( WildChar, 1 )

LowMask = Translate( WildMask, '00'x, WildChar )
HiMask  = Translate( WildMask, 'FF'x, WildChar )

LowString = BitOr( LowMask, String, ' ' )
HiString = BitAnd( HiMask,  String, ' ' )

Return (LowString == HiString)
/**********************************************************************/
$IsDSNPart: /* verify single DSN qualifier */ procedure
/* Call:
      If $IsDSNPart( String ) Then ...
*/
Parse Arg String .
StrSize = Length(String)
LeftChar = Left( String, 1 )

Return (StrSize > 0 & StrSize <= 8) ,
     & 0 = Verify( LeftChar, '@#$ABCDEFGHIJKLMNOPQRSTUVWXYZ' ) ,
     & 0 = Verify( String, '@#$ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' )
/**********************************************************************/

Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Thu Sep 15, 2016 7:42 pm
Reply with quote

BTW, if REXTOOLS is available in your environment then everything can be simplified with REXXTOOLS function(s), like this:
Code:
Examples:
1. say match( 'abc*', 'abcdef' ) /* '1' */
2. say match( 'abc*', 'abc' ) /* '1' */
3. say match( 'abc???', 'abcdef' ) /* '1' */
4. say match( 'abc???', 'abcd' ) /* '0' */
5. say match( '*xyz', 'xyz' ) /* '1' */
6. say match( '\*abc', 'abc' ) /* '0' */
7. say match( '\*abc', '*abc' ) /* '1' */ 

RTFM icon_exclaim.gif
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1788
Location: Bloomington, IL

PostPosted: Thu Sep 15, 2016 8:22 pm
Reply with quote

REXXTOOLS from Open Software?
Back to top
View user's profile Send private message
sergeyken

Senior Member


Joined: 29 Apr 2008
Posts: 2023
Location: USA

PostPosted: Thu Sep 15, 2016 9:39 pm
Reply with quote

Yes

REXXTOOLS/MVS(TM)

Open Software Technologies, Inc.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Compile Several JCL JOB Through one r... CLIST & REXX 4
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
No new posts run rexx code with jcl CLIST & REXX 15
Search our Forums:

Back to Top