I was wondering how arguments are passed to programs, i know it can be done because whenever i use HLA i do it, ie HLA myprogram.hla, i always figured that myprogram.hla would mess up the exectution path of the main program, but obviously it doesn't, anybody can give me some examples on how this works


Thanks
Posted on 2003-11-30 13:53:11 by WhiteDwarf
I'm not sure I understand you.
Do you want to write an HLA program that uses commandline arguments?
Posted on 2003-11-30 14:53:59 by Odyssey
yea for example


Say if you had a program named caps.exe , and it capitilizes all characters in a string, and it gets the string from the command prompt as an argument, it's similar to when you assemble with HLA, you type C:/HLA myprogram.hla , "myprogram.hla" is the argument it accepts and the program uses that to know which one to assemble so

C:/caps.exe This is the string to capitilize


caps.exe would execute and load "This is the string to capitilize" into a string variable and do something like


mov(theString,ebx);
mov(0,ecx);
Looper:
cmp(ecx, str.len(theString);
jae LoopedThruAll:
mov([ebx+ecx],al);
sub(32,al);
mov(al,s)
stdout.put(s);
inc(ecx);
jmp Looper;
LoopedThruAll:


I'm sure this is possible (Programmers note* I need type coercion on the "cmp(ecx,str.len(theString);" i believe, just trying to give an example
Posted on 2003-11-30 16:08:50 by WhiteDwarf
You can use the functions in the args module. The arg.c function accepts no parameters and returns in eax the number of commandline paramters passed to your program. You can then use the arg.v() function to extract indivdual commandline paramters. Here's an example:

 

program cmdline;

#include ("stdlib.hhf")

begin cmdline;


// Count commandline paramters

arg.c();

stdout.put( "Number of parameters = ", eax , nl );


mov( eax, edx );

for( mov( 0, ecx ); ecx < edx; inc ( ecx )) do

// Extract ecxth parameter
// Function returns a string

arg.v( ecx );
stdout.puts ( eax );
stdout.newln();

// Free String when we're
// done with it

strfree( eax );


endfor;



end cmdline;
Posted on 2003-11-30 16:30:45 by Odyssey
Ooo thanks man, how bout this



program cmdline;

#include ("stdlib.hhf")
static
theString: string;


begin cmdline;

arg.cmdLn();
mov( eax, theString );
str.delete(theString,0,9);
fileio.openNew(theString);

end cmdline;


Doesn't seem to work
Posted on 2003-11-30 17:51:30 by WhiteDwarf
What doesn't work? Is the file not being created? I think using the arg.v function is the better way to get the individual command line parameters. I think you want to get the first commandline argument. You can do this easily using:

 


arg.v( 1 );
mov( eax , theString );

...
strfree ( theString );


I think I didn't explain the example I posted earlier. :grin: Anyway it first counts the number of commandline parameters passed to the program and prints each of them.
Posted on 2003-11-30 18:26:55 by Odyssey
Yea sorry bout that i was using my other code example to help a friend he wanted to load a parameter as a string into the program so i used that method.....


This seemed to like to work in C but HLA doesn't like it
program cmdline; 


#include ("stdlib.hhf")
static
theString: string;


begin cmdline;

arg.v(1);
mov( eax, theString );
if(fileio.open(theString, fileio.rw)== NULL) then
fileio.openNew(theString);
endif;

end cmdline;





How long have u been programming in HLA odyssey? you seem really good
Thanks
Posted on 2003-12-01 00:58:35 by WhiteDwarf
The fileio.open function returns the handle to the file if it exists and raises an exception if it doesn't so to do what you want you'll have to handle the ex.FileOpenFailure exception. Here an example:

 

program cmdline;

#include ("stdlib.hhf")

static
theString: string;


begin cmdline;

arg.v(1);
mov( eax, theString );

try

fileio.open( theString, fileio.rw );

exception ( ex.FileOpenFailure );

fileio.openNew ( theString );

endtry;

fileio.close ( eax );

end cmdline;


I started really learning asm about a year ago around the same time I joined this forum and I began to read aoa32 and I learned a bit about HLA in the process :grin: . I'm still not finished reading it yet. It's a huge book and I'm at volume 3 :grin: If I didn't hang around these forums so much I would get more time to read it :grin:
Posted on 2003-12-01 04:20:16 by Odyssey