Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch.nt    |    Fun with Windows NT batch files    |    68,980 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 67,754 of 68,980    |
|    John Stockton to REGLARXP.BAT    |
|    Extending the Batch Language, using Batc    |
|    21 Aug 21 04:40:48    |
   
   From: dr.j.r.stockton@gmail.com   
      
   Looking at the Subject lines of recent posts I see that several authors want   
   to do something which is impossible, lengthy, or tedious in pure Batch, but   
   can easily be done in other languages.   
      
   Last year, when Batch needed to use a Regular Expression, I wrote in Batch a   
   RegExp Caller which used JScript (it could probably have used VBScript) and a   
   corresponding Callee. Perhaps I posted them here.   
      
   I expect that they could be improved and that the Caller could be generalised.   
      
      
   @REM REGLARXP.BAT (c) J R Stockton 2020-06-18+ - Batch RegExp replace   
   @REM Arguments are : SRC Rex Mod Sub DST   
   @if "%1"=="/?" echo REGLARXP.BAT arguments are : SRC Rex Mod Sub DST   
   @if "%1"=="/?" echo REGLARXP.BAT has as yet no more Help :-( & goto EOF   
   @if x%5==x echo REGLARXP.BAT must have five arguments & goto EOF   
   @echo REGLARXP.BAT says arguments are `%1` `%2` `%3` `%4` `%5`   
   @echo REGLARXP.BAT says value of %1 = `%Z1%`   
   @echo REGLARXP.BAT says value of %5 = `%Z2%`   
   @echo REGLARXP.BAT next calls REGLARXP.JS, redirecting to a new file   
   @echo %temp%\$RHUBARB.BAT,   
   @echo which will immediately be executed and deleted   
      
    @call CSCRIPT //nologo REGLARXP.JS %* > %temp%\$RHUBARB.BAT &    
   temp%\$RHUBARB.BAT & del %temp%\$RHUBARB.BAT   
      
   @echo REGLARXP.BAT says value of %1 = `%Z1%`   
   @echo REGLARXP.BAT says value of %5 = `%Z2%`   
   @REM which seems to be correct.   
   :EOF   
      
      
   // REGLARXP.JS (c) J R Stockton 2020-05-30+ - Engine for REGLARXP.BAT   
   // Arguments are : SRC Rex Mod Sub DST ; writes to Standard Output   
      
   WScript.Echo("\t@REM REGLARXP.JS has started")   
      
   WScript.Echo("\t@REM REGLARXP.JS aside : test .replace : " +   
    "*NO*".replace(/NO/, "YES"))   
      
   function Q(S) { return "`" + S + "`" }   
      
   var WshShell = new ActiveXObject("WScript.Shell")   
   var objEnv = WshShell.Environment("Process") // was Process   
      
   var Args = WScript.Arguments, ArgCt = Args.Unnamed.count   
      
   WScript.Echo("\t@REM REGLARXP.JS argument count : " + ArgCt +   
    " - must be 5")   
      
   if (ArgCt == 5) {   
      
    var SRC = Args(0), Src = objEnv(SRC)   
    var Reg = Args(1), Mod = Args(2), Sub = Args(3)   
    var DST = Args(4), Dst = objEnv(DST)   
    WScript.Echo("\t@REM REGLARXP.JS got Args(0) : " +   
    Q(SRC) + " = " + Q(Src))   
    WScript.Echo("\t@REM REGLARXP.JS got Args(1) : " +   
    Q(Reg))   
    WScript.Echo("\t@REM REGLARXP.JS got Args(2) : " +   
    Q(Mod))   
    WScript.Echo("\t@REM REGLARXP.JS got Args(3) : " +   
    Q(Sub))   
    WScript.Echo("\t@REM REGLARXP.JS got Args(4) : " +   
    Q(DST) + " = " + Q(objEnv(DST)))   
      
    var RXP = new RegExp(Reg, Mod)   
    WScript.Echo("\t@REM REGLARXP.JS RXP is " + Q(RXP) +   
    " Sub is " + Q(Sub))   
    var Out = Src.replace(RXP, Sub) // Does the work   
      
    WScript.Echo("\t@REM REGLARXP.JS ran Src.replace ; result : " +   
    Q(Out))   
      
    WScript.Echo("\t@REM REGLARXP.JS current value " +   
    Q(DST) + " = " + Q(objEnv(DST)))   
      
    WScript.Echo("\t@REM REGLARXP.JS next write crucial batch file line")   
    WScript.Echo(" @SET " + DST + "=" + Out + "& @REM * Crucial *")   
    // The above statement is ESSENTIAL ; write nothing twixt Out, & !   
      
    }   
      
   WScript.Echo("\t@REM REGLARXP.JS finishing")   
      
   // One could use regular file output to write $RHUBARB.BAT;   
   // there may be a direct way to write to a variable in the   
   // caller's environment.   
      
   // End REGLARXP.JS   
      
      
   --   
    (c) John Stockton, near London, UK. Using Google Groups. |   
    Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca