mirror of
https://github.com/QB64Official/qb64.git
synced 2024-07-03 10:01:21 +00:00
Add support for COMMAND$(n) returning the nth command line parameter, 1 through
to _COMMANDCOUNT, with 0 being the name of the program. This revision will not build, since internal/source/ has references to the old COMMAND$ call.
This commit is contained in:
parent
859a046cfb
commit
bc7fa3539e
|
@ -17950,13 +17950,30 @@ double func_sqr(double value){
|
|||
|
||||
|
||||
qbs *func_command_str=NULL;
|
||||
qbs *func_command(){
|
||||
char **func_command_array = NULL;
|
||||
int32 func_command_count = 0;
|
||||
|
||||
qbs *func_command(int32 index, int32 passed){
|
||||
static qbs *tqbs;
|
||||
tqbs=qbs_new(func_command_str->len,1);
|
||||
memcpy(tqbs->chr,func_command_str->chr,func_command_str->len);
|
||||
if (passed) { //Get specific parameter
|
||||
//If out of bounds or error getting cmdline args (on Android, perhaps), return empty string.
|
||||
if (index >= func_command_count || index < 0 || func_command_array==NULL) {tqbs = qbs_new(0, 1); return tqbs;}
|
||||
int len = strlen(func_command_array[index]);
|
||||
//Create new temp qbs and copy data into it.
|
||||
tqbs=qbs_new(len, 1);
|
||||
memcpy(tqbs->chr, func_command_array[index], len);
|
||||
}
|
||||
else { //Legacy support; return whole commandline
|
||||
tqbs=qbs_new(func_command_str->len,1);
|
||||
memcpy(tqbs->chr,func_command_str->chr,func_command_str->len);
|
||||
}
|
||||
return tqbs;
|
||||
}
|
||||
|
||||
int32 func__commandcount(){
|
||||
return func_command_count - 1;
|
||||
}
|
||||
|
||||
int32 shell_call_in_progress=0;
|
||||
|
||||
#ifdef QB64_WINDOWS
|
||||
|
@ -29399,6 +29416,8 @@ qbs_set(startDir,func__cwd());
|
|||
|
||||
#ifdef QB64_ANDROID
|
||||
func_command_str=qbs_new(0,0);
|
||||
func_command_array = NULL;
|
||||
func_command_count = 0;
|
||||
#else
|
||||
i=argc;
|
||||
if (i>1){
|
||||
|
@ -29419,6 +29438,9 @@ qbs_set(startDir,func__cwd());
|
|||
}else{
|
||||
func_command_str=qbs_new(0,0);
|
||||
}
|
||||
|
||||
func_command_count = argc;
|
||||
func_command_array = argv;
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -513,7 +513,8 @@ extern int32 func__sndplaying(int32 handle);
|
|||
extern void sub__sndclose(int32 handle);
|
||||
extern void sub__sndplayfile(qbs *filename,int32 sync,double volume,int32 passed);
|
||||
extern void sub__sndplaycopy(int32 handle,double volume,int32 passed);
|
||||
extern qbs *func_command();
|
||||
extern qbs *func_command(int32 index,int32 passed);
|
||||
extern int32 func__commandcount();
|
||||
extern void sub_kill(qbs *str);
|
||||
extern void sub_name(qbs *oldname,qbs *newname);
|
||||
extern void sub_chdir(qbs *str);
|
||||
|
@ -1044,11 +1045,11 @@ void chain_input(){
|
|||
//check if command$ contains a tmp chain directive
|
||||
int32 FF;
|
||||
|
||||
if ((func_command())->len>= 32 ){
|
||||
if (qbs_equal(qbs_right(func_command(), 4 ),qbs_new_txt_len(".tmp",4))){
|
||||
if (qbs_equal(func_mid(func_command(),(func_command())->len- 31 , 25 ,1),qbs_new_txt_len("(unique-tag:=/@*$+-)chain",25))){
|
||||
if ((func_command(0, 0))->len>= 32 ){
|
||||
if (qbs_equal(qbs_right(func_command(0, 0), 4 ),qbs_new_txt_len(".tmp",4))){
|
||||
if (qbs_equal(func_mid(func_command(0, 0),(func_command(0, 0))->len- 31 , 25 ,1),qbs_new_txt_len("(unique-tag:=/@*$+-)chain",25))){
|
||||
FF=func_freefile();
|
||||
sub_open(func_mid(func_command(),(func_command())->len- 11 , 12 ,1), 2 ,NULL,NULL,FF,NULL,0);
|
||||
sub_open(func_mid(func_command(0, 0),(func_command(0, 0))->len- 11 , 12 ,1), 2 ,NULL,NULL,FF,NULL,0);
|
||||
|
||||
static int32 int32val,int32val2;
|
||||
static int64 int64val,int64val2;
|
||||
|
@ -1077,7 +1078,7 @@ sub_get(FF,NULL,byte_element((uint64)&int32val,4),0);
|
|||
|
||||
sub_close(FF,1);
|
||||
|
||||
sub_kill(func_mid(func_command(),(func_command())->len- 11 , 12 ,1));
|
||||
sub_kill(func_mid(func_command(0, 0),(func_command(0, 0))->len- 11 , 12 ,1));
|
||||
|
||||
chdir((char*)chdir_data);
|
||||
|
||||
|
|
|
@ -1466,11 +1466,21 @@ id.n = "COMMAND"
|
|||
id.musthave = "$"
|
||||
id.subfunc = 1
|
||||
id.callname = "func_command"
|
||||
id.args = 0
|
||||
id.args = 1
|
||||
id.arg = MKL$(LONGTYPE - ISPOINTER)
|
||||
id.ret = STRINGTYPE - ISPOINTER
|
||||
id.specialformat = "[?]"
|
||||
id.NoCloud = 1
|
||||
regid
|
||||
|
||||
clearid
|
||||
id.n = "_COMMANDCOUNT"
|
||||
id.subfunc = 1
|
||||
id.callname = "func__commandcount"
|
||||
id.ret = LONGTYPE - ISPOINTER
|
||||
regid
|
||||
|
||||
|
||||
'QB64 AUDIO
|
||||
|
||||
clearid
|
||||
|
|
Loading…
Reference in a new issue