Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Reasonable way of checking wildcards using REXX

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
sergeyken

New User


Joined: 29 Apr 2008
Posts: 37
Location: Maryland

PostPosted: Wed Sep 07, 2016 8:43 pm    Post subject: Reasonable way of checking wildcards using REXX
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: 268
Location: Room: TREE(3). Hilbert's Hotel

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

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

New User


Joined: 29 Apr 2008
Posts: 37
Location: Maryland

PostPosted: Fri Sep 09, 2016 9:43 pm    Post subject: Adding wildcard analyzer for DSNAME
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

New User


Joined: 29 Apr 2008
Posts: 37
Location: Maryland

PostPosted: Thu Sep 15, 2016 7:42 pm    Post subject: REXXTOOLS
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: 1738
Location: Bloomington, IL

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

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

New User


Joined: 29 Apr 2008
Posts: 37
Location: Maryland

PostPosted: Thu Sep 15, 2016 9:39 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 6 Fri Nov 18, 2016 1:48 pm
This topic is locked: you cannot edit posts or make replies. Rexx to create GDG by scanning JJ result krish.deepu CLIST & REXX 5 Tue Oct 25, 2016 5:32 pm
No new posts Replace repeated JCL with looping REXX prino CLIST & REXX 3 Thu Oct 13, 2016 5:30 am
This topic is locked: you cannot edit posts or make replies. Need to code a Rexx PGM sundaram.naveen CLIST & REXX 18 Thu Oct 06, 2016 6:45 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us