Running executables with spaces on xboard

Discussions about the WinBoard protocol. Here you can also report bugs and request new features.

Moderators: hgm, Andres Valverde

Running executables with spaces on xboard

Postby Pradu » 10 Aug 2008, 20:28

I'm trying to get PSWBTM to work with xboard but I ran into a problem. I don't know how to run executables with spaces for xboard. For Winboard, something like this would work:
Code: Select all
xboard -fd "/home/pradu/Desktop/Buzz" -fcp '"./Buz 2" -log'

But this doesn't work for xboard. Is there any way to launch executables with spaces for xboard?
User avatar
Pradu
 
Posts: 343
Joined: 12 Jan 2005, 19:17
Location: Chandler, Arizona, USA

Re: Running executables with spaces on xboard

Postby H.G.Muller » 10 Aug 2008, 21:30

When you call xboard, you probably use exec() to call it. Arguments in exec() are passed in a structured way, as an array of strings. So it would be obvious to xboard that "./Buzz 2" is a single argument, because it is in a single string.

I don't think that you need to do the actual quoting. That is shell input syntax in Linux, to indicate that the string within the quote is a single argument. But the shell takes that information, strips the quotes off, and passes the stuff within quotes as a single argument to exec.

This might be the problem: that you pass quoted arguments, and that xboard chokes on them,
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Running executables with spaces on xboard

Postby H.G.Muller » 10 Aug 2008, 21:45

Sorry, I see now your question is more subtle than that. You have quotes within quotes.

I looked at the xboard code, and the answer is: NOT POSSIBLE. The code in xboard to startup the engine child is very simpleminded: it takes the string passed as -fcp, scans it for spaces, and cuts it at every space into a separate argument. It does not scan for quotes or escapes or anything.

Is this a problem? It is still not too late to try to make it slightly more smart. E.g. delete single quotes, and not cut at speces in between those. But I's rather not., as I cannot test it, and it seems bug-prone. So I'd rather live with the fact that spaces in file names are not allowed. I thought that Linux people would be smart enough to not use such filenames...
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Running executables with spaces on xboard

Postby H.G.Muller » 10 Aug 2008, 22:07

OK, if you can compile xboard yourself, you can try to make the following modification in the routine StartChildProcess() in xboard.c:

Code: Select all
    for (;;) {
#if 1
   while(*p == ' ') p++; // skip leading spaces
        if(*p == '"') {
            argv[i++] = ++p;
            p = strchr(p, '"');
   } else if(*p == '\'') {
            argv[i++] = ++p;
            p = strchr(p, '\'');
   } else {
       argv[i++] = p;
       p = strchr(p, ' ');
   }
#else
   argv[i++] = p;
   p = strchr(p, ' ');
#endif
   if (p == NULL) break;
   *p++ = NULLCHAR;
    }

This would treat single and double quoting in the engine command line, and let it protect anything. If you make it #if 0, you have the original code.
User avatar
H.G.Muller
 
Posts: 3453
Joined: 16 Nov 2005, 12:02
Location: Diemen, NL

Re: Running executables with spaces on xboard

Postby Zach Wegner » 11 Aug 2008, 00:27

I patched this too on SVN.
User avatar
Zach Wegner
 
Posts: 182
Joined: 26 Sep 2004, 22:02
Location: Austin, Texas, USA


Return to WinBoard development and bugfixing

Who is online

Users browsing this forum: No registered users and 29 guests