Small inaccuracy in COMMAND$(0) for DOS
-
- Posts: 42
- Joined: Mar 05, 2013 5:37
Small inaccuracy in COMMAND$(0) for DOS
Function COMMAND$(0) returns name of the executable file in the Linux style, but not DOS, that is, with forward slashes, not backward.
If name of the executable file is "C:\FREBASIC\EXAMPLE.EXE", COMMAND$(0) will return "c:/frebasic/example.exe"
If name of the executable file is "C:\FREBASIC\EXAMPLE.EXE", COMMAND$(0) will return "c:/frebasic/example.exe"
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Small inaccuracy in COMMAND$(0) for DOS
Weird.. I tested exepath() and curdir(), and they seem to use backslashes as expected, so it looks like it's just command(0).
The following patch probably fixes it, but I don't have a DOS build setup so I can't test:
The following patch probably fixes it, but I don't have a DOS build setup so I can't test:
Code: Select all
diff --git a/src/rtlib/sys_cmd.c b/src/rtlib/sys_cmd.c
index e2a0282..f5bef20 100644
--- a/src/rtlib/sys_cmd.c
+++ b/src/rtlib/sys_cmd.c
@@ -39,11 +39,25 @@ FBCALL FBSTRING *fb_Command ( int arg )
if( arg >= __fb_ctx.argc )
return &__fb_ctx.null_desc;
- dst = fb_hStrAllocTemp( NULL, strlen( __fb_ctx.argv[arg] ) );
+ len = strlen( __fb_ctx.argv[arg] );
+ dst = fb_hStrAllocTemp( NULL, len );
if( dst == NULL )
return &__fb_ctx.null_desc;
strcpy( dst->data, __fb_ctx.argv[arg] );
+#ifdef HOST_DOS
+ if( arg == 0 )
+ {
+ /* DOS gives us COMMAND(0) with '/' path separators -
+ * change them to the more DOS-like '\'. */
+ for( i = 0; i < len; ++i )
+ {
+ if( dst->data[i] == '/' )
+ dst->data[i] == '\\';
+ }
+ }
+#endif
+
return dst;
}
-
- Posts: 42
- Joined: Mar 05, 2013 5:37
Re: Small inaccuracy in COMMAND$(0) for DOS
It's very silly, but I could not apply the patch to the file.
When l try to make this, an utility "patch" fails with the following error message:
(Patch is indented 4 spaces.)
patching file sys_cmd.c
patch unexpectedly ends in middle of line
Hunk #1 FAILED at 39.
1 out of 1 hunk FAILED -- saving rejects to file sys_cmd.new.rej
Could you lay out somewhere already patched file?
When l try to make this, an utility "patch" fails with the following error message:
(Patch is indented 4 spaces.)
patching file sys_cmd.c
patch unexpectedly ends in middle of line
Hunk #1 FAILED at 39.
1 out of 1 hunk FAILED -- saving rejects to file sys_cmd.new.rej
Could you lay out somewhere already patched file?
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Small inaccuracy in COMMAND$(0) for DOS
It's probably complaining about whitespace. Try grabbing the original version by Quoting my post and copying from there.
Otherwise it's an easy patch to apply manually. (Again, Quote the post for the original whitespacing.)(A link to the original can be found here:
http://sf.net/p/fbc/code/ci/0.24.0/tree ... /sys_cmd.c)
Otherwise it's an easy patch to apply manually. (Again, Quote the post for the original whitespacing.)
Code: Select all
/* command$ */
#include "fb.h"
/*:::::*/
FBCALL FBSTRING *fb_Command ( int arg )
{
FBSTRING *dst;
int i, len;
/* return all arguments? */
if( arg < 0 )
{
/* no args? */
if( __fb_ctx.argc <= 1 )
return &__fb_ctx.null_desc;
/* concatenate all args but 0 */
len = 0;
for( i = 1; i < __fb_ctx.argc; i++ )
len += strlen( __fb_ctx.argv[i] );
dst = fb_hStrAllocTemp( NULL, len + __fb_ctx.argc-2 );
if( dst == NULL )
return &__fb_ctx.null_desc;
dst->data[0] = '\0';
for( i = 1; i < __fb_ctx.argc; i++ )
{
strcat( dst->data, __fb_ctx.argv[i] );
if( i != __fb_ctx.argc-1 )
strcat( dst->data, " " );
}
return dst;
}
/* return just one argument */
if( arg >= __fb_ctx.argc )
return &__fb_ctx.null_desc;
len = strlen( __fb_ctx.argv[arg] );
dst = fb_hStrAllocTemp( NULL, len ); if( dst == NULL )
return &__fb_ctx.null_desc;
strcpy( dst->data, __fb_ctx.argv[arg] );
#ifdef HOST_DOS
if( arg == 0 )
{
/* DOS gives us COMMAND(0) with '/' path separators -
* change them to the more DOS-like '\'. */
for( i = 0; i < len; ++i )
{
if( dst->data[i] == '/' )
dst->data[i] == '\\';
}
}
#endif
return dst;
}
http://sf.net/p/fbc/code/ci/0.24.0/tree ... /sys_cmd.c)
-
- Posts: 42
- Joined: Mar 05, 2013 5:37
Re: Small inaccuracy in COMMAND$(0) for DOS
It's very strange, but the patch has not changed anything.
Function still returns the result in the Linux style with incorrect slashes.
Function still returns the result in the Linux style with incorrect slashes.
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Small inaccuracy in COMMAND$(0) for DOS
Oh sorry, Equals Fail.
Try changing '==' to '=' in "dest->data == '\\';"
Try changing '==' to '=' in "dest->data == '\\';"
-
- Posts: 42
- Joined: Mar 05, 2013 5:37
Re: Small inaccuracy in COMMAND$(0) for DOS
Now all works well. Thank you.
Can you apply this patch to the file on Sourceforge?
And I would like to write about another little bug that was noticed by me in function EXEPATH$.
This error occurs when the executable file is in the root directory.
Path, which returned by the function EXEPATH$, does not contain the final backslash.
If name of the executable file is "C:\EXAMPLE.EXE", EXEPATH$ will return "c:", but not "C:\".
Can you apply this patch to the file on Sourceforge?
And I would like to write about another little bug that was noticed by me in function EXEPATH$.
This error occurs when the executable file is in the root directory.
Path, which returned by the function EXEPATH$, does not contain the final backslash.
If name of the executable file is "C:\EXAMPLE.EXE", EXEPATH$ will return "c:", but not "C:\".
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Small inaccuracy in COMMAND$(0) for DOS
I've made the fix for Command(0).
I've also made the change so that the Exepath() return value in Windows/DOS will keep the slash after the drive letter, and Unix/Linux/... will keep the slash if it's all there is.
Exepath() on DOS explicitly capitalises the drive letter though, so if you're getting "c:" and not "C:", I have no idea why that would be. Either way, it should return "C:\" (or at least "c:\") in the next release.
I've also made the change so that the Exepath() return value in Windows/DOS will keep the slash after the drive letter, and Unix/Linux/... will keep the slash if it's all there is.
Exepath() on DOS explicitly capitalises the drive letter though, so if you're getting "c:" and not "C:", I have no idea why that would be. Either way, it should return "C:\" (or at least "c:\") in the next release.
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Small inaccuracy in COMMAND$(0) for DOS
By the way, I had a minor problem fixing the Win32 ExePath - on compiling, I realised the isalpha() function/macro seems to be available in the included headers in DOS but not in Win32.
Anyway, I don't have a DOS build environment set up, so would you mind testing this new file?
http://sf.net/p/fbc/code/ci/master/tree ... texepath.c
The only net change is the if() block at the end of the code.
Anyway, I don't have a DOS build environment set up, so would you mind testing this new file?
http://sf.net/p/fbc/code/ci/master/tree ... texepath.c
The only net change is the if() block at the end of the code.
-
- Posts: 42
- Joined: Mar 05, 2013 5:37
Re: Small inaccuracy in COMMAND$(0) for DOS
Everything work well. At least I think so.
Here are a few examples.
The only thing I want to note that the drive letter is converted to uppercase for EXEPATH$ only, but not for COMMAND$(0). It looks quite unlogical.
Here are a few examples.
Code: Select all
C:\FREBASIC\examples\ADVINTER>CMNDTEST.EXE
COMMAND$(0)=c:\frebasic\examples\advinter\cmndtest.exe
EXEPATH=C:\frebasic\examples\advinter
D:\>CMNDTEST.EXE
COMMAND$(0)=d:\cmndtest.exe
EXEPATH=D:\
C:\FREBASIC\examples>CMNDTEST.EXE
COMMAND$(0)=c:\frebasic\examples\cmndtest.exe
EXEPATH=C:\frebasic\examples
C:\>CMNDTEST.EXE
COMMAND$(0)=c:\cmndtest.exe
EXEPATH=C:\
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Small inaccuracy in COMMAND$(0) for DOS
Ok, I'll look into that. How about curdir()?
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Small inaccuracy in COMMAND$(0) for DOS
OK, if you could test the code here:
http://sf.net/p/fbc/code/ci/master/tree ... s_getcwd.c
What does curdir() do?
http://sf.net/p/fbc/code/ci/master/tree ... s_getcwd.c
What does curdir() do?
-
- Posts: 42
- Joined: Mar 05, 2013 5:37
Re: Small inaccuracy in COMMAND$(0) for DOS
Everything looks good except strangeness with the register of a drive letter.
Code: Select all
C:\FREBASIC\examples\ADVINTER>CMNDTEST.EXE
COMMAND$(0)=c:\frebasic\examples\advinter\cmndtest.exe
EXEPATH$=C:\frebasic\examples\advinter
CURDIR$=c:\frebasic\examples\advinter
D:\>CMNDTEST.EXE
COMMAND$(0)=d:\cmndtest.exe
EXEPATH$=D:\
CURDIR$=d:\
C:\GRAVIS>CMNDTEST.EXE
COMMAND$(0)=c:\gravis\cmndtest.exe
EXEPATH$=C:\gravis
CURDIR$=c:\gravis
C:\>CMNDTEST.EXE
COMMAND$(0)=c:\cmndtest.exe
EXEPATH$=C:\
CURDIR$=c:\
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Small inaccuracy in COMMAND$(0) for DOS
Sorry, I messed up the URL before. The Command() fix can be found at http://sf.net/p/fbc/code/ci/master/tree ... _cmd.c#l52 - please test the fix there.
When you say "strangeness", do you just mean some functions are always returning a lower-case drive letter, or is there something stranger that I'm missing?
Either way, I'll have a look into Curdir(), now you've confirmed the problem exists there.
When you say "strangeness", do you just mean some functions are always returning a lower-case drive letter, or is there something stranger that I'm missing?
Either way, I'll have a look into Curdir(), now you've confirmed the problem exists there.
-
- Posts: 42
- Joined: Mar 05, 2013 5:37
Re: Small inaccuracy in COMMAND$(0) for DOS
There is an error during compilation.
Code: Select all
src/rtlib/sys_cmd.c: In function 'fb_Command':
src/rtlib/sys_cmd.c:53:14: error: invalid operands to binary == (have 'FBSTRING'
and 'int')
compilation terminated due to -Wfatal-errors.
make.exe: *** [src/rtlib/dos-obj/sys_cmd.o] Error 1