Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (EternallyCurious, howardR), 646 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Command line: pass string arguments #479959
05/08/20 18:22
05/08/20 18:22
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline OP
Serious User
AndrewAMD  Offline OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
jcl,

I'd like the ability to pass up to four strings to zorro from the command line, much like the -i argument.

Example usage, where three strings are supplied:
zorro.exe -s "alpha beta" -s "gamma,delta" -s "epsilon_zeta"

Script side, there would be a global variable CommandStr[0] .. CommandStr[3], which would point to the same strings.

Re: Command line: pass string arguments [Re: AndrewAMD] #479972
05/10/20 17:21
05/10/20 17:21
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline OP
Serious User
AndrewAMD  Offline OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Thanks, it looks like this feature was just added!

Here's some sample code showing it at work. Here, I extract the string "alpha beta" from the command line:
Code
// Note: this only works if arbitrary input string is in double quotations.
// example commandline entry:
// zorro -u "alpha beta" -run commandline_string.c
// output: 'alpha beta'

// returns a temporary string with -u output, if it's in double quotations.
string get_u_output(){
	int len = strlen(report(3));
	string str = zalloc(len);
	strcpy(str,report(3));
	char* p = strstr(str,"-u \"");
	if(!p) return NULL;
	if(!strtok(p,"\"")) return NULL;
	return strtok(0,"\"");
}

int main(void){
	printf("\n\'%s\'",get_u_output());
}

Re: Command line: pass string arguments [Re: AndrewAMD] #479982
05/11/20 08:59
05/11/20 08:59
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
Yes, this was a coincidence, although it is not exactly the same feature that you wanted.

Re: Command line: pass string arguments [Re: AndrewAMD] #479996
05/11/20 23:08
05/11/20 23:08
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline OP
Serious User
AndrewAMD  Offline OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
It's okay, because either way, I'll need to parse it!

Re: Command line: pass string arguments [Re: AndrewAMD] #485017
01/09/22 16:16
01/09/22 16:16
Joined: Jan 2022
Posts: 1
A
AndreasTrader Offline
Guest
AndreasTrader  Offline
Guest
A

Joined: Jan 2022
Posts: 1
Thanks to @AndrewAMD for the code snippet. Very helpful!

In testing it, I noticed that the report(3) function is limited to 256 bytes. To increase the number of variables that can be passed and thus the reliability a 1K limit would be great like it is used for the TEMPstrings. Thanks.

Re: Command line: pass string arguments [Re: AndrewAMD] #485020
01/10/22 11:29
01/10/22 11:29
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline OP
Serious User
AndrewAMD  Offline OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
You can always use the Windows API directly. Try this:
Code
#include<default.c>
#include<windows.h>

LPSTR GetCommandLineA();
API(GetCommandLineA,Kernel32)

// returns a temporary string with -u output, if it's in double quotations.
string get_u_output(){
	int len = strlen(GetCommandLineA());
	string str = zalloc(len);
	strcpy(str,report(3));
	char* p = strstr(str,"-u \"");
	if(!p) return NULL;
	if(!strtok(p,"\"")) return NULL;
	return strtok(0,"\"");
}

void main(){
	printf("\n\"%s\"",GetCommandLineA());
	printf("\n\"%s\"",get_u_output());
	
	printf("\nDone.");
}

Re: Command line: pass string arguments [Re: AndrewAMD] #485021
01/10/22 12:55
01/10/22 12:55
Joined: Jul 2000
Posts: 27,978
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,978
Frankfurt
There is indeed a command line limit, but AFAIK it's 8k, not 256 bytes. It does not matter if you call report(3) or GetCommandLine.

Re: Command line: pass string arguments [Re: AndrewAMD] #485025
01/10/22 13:47
01/10/22 13:47
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline OP
Serious User
AndrewAMD  Offline OP
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
If you really did run out of room at the command line (8k?), you can always make use of environment variables via the windows API.
https://docs.microsoft.com/en-us/windows/win32/api/processenv/nf-processenv-getenvironmentvariablea


Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1