ANN: LibWrapper 0.1

Andre Garzia soapdog at mac.com
Sat Jun 12 00:41:10 EDT 2004


Hi Folks,

I am announcing libWrapper a simple and stupid idea on  quick'n'dirty 
gui wrapper for command line tools. I'll explain the theory behind it, 
give some cool examples and tell the download url. Let's assume that a 
trivial command line tool is usually used by invoking it's executable 
file with parameters. What the library does is assemble this line for 
you, it does not execute the line, there's only one function, and this 
function will return a string with the line. You execute it on your own 
okay?

It's all based on custom properties. First important custom property is 
cShellCommand, this you set on the card serving as wrapper. It's the 
executable file to be launched, like in the psWrapper is cShellCommand 
= /bin/ps. Now, let's understand about the innerworkings here (it's 
silly...). Function will loop thru all controls in the card, each 
control should resolve/evaluate to a parameter. The loop is based on 
the index, so first controls will be checked first, they are accessed 
by name, so no duplicate naming allowed. Controls with cIgnore set to 
true are skipped.

Field controls: They will be skipped if there's no content in them. if 
they have a cParameter property, this parameter will be used, and a 
simple string replacing routine will swap %CONTENTS% placeholder with 
the actual field contents. Example the grep pipe wrapper in the ps 
Wrapper, it's a field, the last field, so it's the last to be checked, 
it's cParameter is [| grep "%CONTENTS%" ] without the brackets, this 
way it will be appended last, the field contents will be inserted in 
%CONTENTS% and we'll have a piping wrapper!!!! It's a ps wrapper that's 
able to pipe to grep without any code at all!!!!

Buttons: buttons should set their cParamTrue and cParamFalse to the 
desired parameters. Checkbox and Radio buttons are evaluate based on 
their hilites, true look for cParamTrue, false look for cParamFalse. 
Get the picture? for example there's a check box in the ps wrapper 
called "Show all users?" cParamTrue = -a  cParamFalse does not exist 
for we need no option not to show everyone. If button style is menu, 
then it will look for cParameter prop, and append it to the command 
line, use your own code to set the correct parameter when the user 
clicks the menu, look into the /bin/defaults wrapper for an example.

Tips: always set the cIgnore of your "Run!" button...

LibWrapper is: A mainstack with only one function called wrapIt. You 
invoke it with two parameters: stack and card. It returns the assembled 
string. Ex: get wrapIt("psWrapper",1)
Two example substacks, one is a MacOS X Wrapper for the /bin/defaults 
utility! (beware not to write crap to your defaults!) and the other is 
a /bin/ps wrapper for unix-like systems.

This code is free! I collect postcard if anyone care! :D

You can fetch libwrapper.rev at http://public.soapdog.org or you can 
run it from http://www.soapdog.org/rev/libwrapper.rev

There are some strange things in the loop, some parameters are 
evaluated twice...  it's a bug with my code, a silly one, i'll fix it 
soon, but you can use it anyway! usually commandline tools to not argue 
with duplicate equal parameters....

If anyone patch, improves or create any wrapper, please send them to 
me!!!

This email text is bigger than the code... he he he.... simple code, 
complex ideas!

Andre Alves Garzia: "Wrap the Developer!"




More information about the use-livecode mailing list