quick 'n easy batch complex ?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

quick 'n easy batch complex ?

#1 Post by Ed Dyreen » 03 Feb 2016 13:33

Essentially we all want the same thing, we want to be able to design programs quickly without too much effort and we want to do it in batch.

From when I first started using batch I've always been saving tricks and optimizing functions.

When we write a function we don't just want it to return the result.
We want it to return the result correctly, whether the function was called with delayed expansion enabled or disabled.
So to prevent repetitive code I wrote a function that would inspect the original environment's delayed state and then adjust the variables accordingly and push them over endlocal.

So at a certain point in time I had written about 300 functions.
And many functions would delegate to other functions which involved many calls and large sections of code would have to be plowed through to find the correct label.

This became unworkable, I thought about saving each function in it's own separate file, but I never did.
I knew it was possible to save primitive tasks in a variable, how to execute it, and that it is much faster to execute a variable ( there is no call ).
Variables that can be called like functions are called macros.

A big breakthrough was when I figured out a way to pass arguments to this variable and have it be able to change it's behavior depending on the arguments.
I now had something similar to a function but inside a variable.

I started converting all functions that were called very often and would fit within 8191 bytes.

These macros all needed to be loaded, and I did not want to force the caller to use a specific delayed state.
When I write a macro I often want to delegate to other functions and thus need to swith delayed expansion.
So now I needed to push the entire variable over endlocal back to the caller's environment.

This process is so cpu intensive that at a certain point it would take minutes to load and push everything over endlocal.
This became unworkable, the need raised to selectively load the function I actually was going to use.
Rewriting it like this saved me some time but still it was all too slow.

I decided to dump all these variables from the memory to files.
One folder for files that were prepared to be loaded with delayed expansion disabled and one folder for enabled.

I then wrote a batch file that if it was called would not set the delayed state but figure out the caller's delayed state to figure out which dumps to call.

I then decided to organize these functions and am currently working out the concept.

So this could become the start of some batch program:

Code: Select all

echo off &set "@include=call %%~dp0\doskit\includer.CMD"
( %@include% %= load the includer =% )

( %@include_% "thread\singleton_" )
( %@include_% "function\*" )
( %@include_% "system\*" )


:main
:: (
   ( %while_% singleton_ )

   ( %necho_% The program has been serialized. )
:: )
( %exit_% §e )
Some classes require more classes to be loaded but this is handled internally by includer.CMD.

To get a list of available commands or help on a specific command you can use the interactive help by opening a cmd prompt where the library is and type: 'man'.
This help may in the future also be available and provided as html pages.

I can choose to build the project which replaces the includes with the code all into a single file.


You like the idea, the concept ?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: quick 'n easy batch complex ?

#2 Post by Squashman » 03 Feb 2016 14:19

Ed Dyreen wrote:Essentially we all want the same thing, we want to be able to design programs quickly without too much effort and we want to do it in batch.

From when I first started using batch I've always been saving tricks and optimizing functions.

When we write a function we don't just want it to return the result.
We want it to return the result correctly, whether the function was called with delayed expansion enabled or disabled.

You are preaching to the choir Ed! :lol:

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: quick 'n easy batch complex ?

#3 Post by Ed Dyreen » 03 Feb 2016 15:23

I take some question we see a lot here on the forum and solve it in this thread using the library, maybe that will raise some interest. But not today, still freaking and tweaking.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: quick 'n easy batch complex ?

#4 Post by foxidrive » 04 Feb 2016 00:33

It's an interesting idea. :thumbsup:

npocmaka_
Posts: 516
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: quick 'n easy batch complex ?

#5 Post by npocmaka_ » 04 Feb 2016 03:32

You are trying to put some kind of semi-OOP in the batch scripting?
This even looks like a different language (I suppose you can call it batch++).


How did you implemented a singleton?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: quick 'n easy batch complex ?

#6 Post by Ed Dyreen » 04 Feb 2016 10:27

npocmaka_ wrote:You are trying to put some kind of semi-OOP in the batch scripting?
This even looks like a different language (I suppose you can call it batch++).


How did you implemented a singleton?
That's a bit off topic but to answer it, singleton tries to create a file based mutex.

Singleton accepts an optional argument that sets the name for the mutex.
If this arguments is not provided the filename of the caller's script will be used.

Code: Select all

Allow only a single instance of this script to run simultaneously.

use: ( %singleton_% process,$script.file )
ret: void
err: 0 for succes, 97 for instance already running
You know how to build a file based mutex ? You can find the topic here at dostips or just ask if you need it.

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: quick 'n easy batch complex ?

#7 Post by Squashman » 04 Feb 2016 14:56

Some days I wish good old Billy boy himself would stop here at our humble forums and see some of the amazing stuff you guys pull of with his baby.

Post Reply