Moderators: hgm, Andres Valverde
As I brought up in the email, this is a bit more complicated than it seems. Xboard has standard X Windows options such as "geometry" that are parsed automatically by the X library calls. I believe that it also looks at the ~/.Xdefaults file for these options. So I'm not sure of the best way to do it. Really, the "geometry" option is useless because it screws up the board, but options like "display" have a useful purpose (I can start Xboard matches remotely via SSH by directing the window output to my monitor at home, whereas otherwise it wouldn't find a display). I'm not sure of the best way to handle this. I think perhaps instead of converting the ParseArgs() routine, we keep it, but we make a portable framework for the command line options that are automatically converted into the native format before they are sent to the library calls, similar to the proposed menu idea. It means that Xboard users still wouldn't get an xboard.ini, but we've been able to do without it for a while.H.G.Muller wrote:* move all processing of command-line options to the back-end, so they automatically benefit xboard.
This one is pretty important, but I don't think it would be too hard. I haven't looked much at the window system, but perhaps the portable data structure could look like this:* Separate the display sizing code from main() in xboard.c, so that it can be called from any place in the code, so that it becomes possible to re-size and re-format the display while running (rather than just at start-up). This is already essential for switching between crazyhouse and other variants in ICS mode (where the ICS commands such changes), but will become essential in local mode as well, in order for the board-size and variant menu to work.
* Collect all routines that display menus in either front-end, and try to collapse them into a single, universal table-driven menu-handling routine, plus data-tables that have to be passed to that routine. (I know very little about event-driven programming with windows, basically WinBoard is the only program using menus that I have ever seen the source of, but it looks like there are zillions of routines in there that all do almost exactly the same, except for a tiny change of the text they print and the routine they call when the button next to that text is pressed...) If we would convert the WinBoard menu handling this way, most of it could go to the back-end, and all menus would be automatically avalable in xboard as well. This would save us the task of xplicitly designing and adding xboard menus.
typedef struct{
char *menu_name;
char *menu_parent;
Boolean *argument;
FuncPointer action;
} MenuEntry;
I'd want to convert as much as this as possible into back end functions. Ideally, we would make front end functions such as CreateWindow, AddText, and I suppose some drawing functions. So that way, if done properly, new functions added, wouldn't require _any_ extra code to work in either port. This is a little ambitious, but it can happen slowly...* Fix the display of the crazyhouse holdings, which currently does not indicate the number of pieces of a given type that is held in xboard. (In WinBoard there is a display bug in Flip View there, btw.)
* Alter the piece drag animator to handle stacking of pieces in the holdings in a more natural way.
* Make the loading of piece bitmaps (slightly) variant dependent, in order for Shogi to work. Fix potential other problems in Shogi (promotions?).
* Fix xboard such that it no longer pops-up a promotion menu on illegal moves.
* Implement cliking on the clocks in the mouse interrupt handler as a way to adjust the time.
* Move some of the clock-display routines to the back-end, and allow the "flag fell" info to be displayed there in xboard.
* design a better format for the piece bitmaps/pixmaps. The current format is horrendously space wasting. The pixmaps are effectively duplicated now, and us 1 byte per pixel for storage, even where 1 bit would suffice (for the black pieces). Not to talk about the compression factor that could be acieved with run-length coding on such simple bitmaps.
* Implement some equivalent to the font-based rendering in xboard. I would also be satisfied with an external tool that would produce bitmaps from a scalable template (like a true-type font), so that it becomes trivial to create a directory with pixmaps that can be loaded during runtime. Provided WinBoard then acquires the ability to load thes bitmaps at run time too.
* Add the WinBoard_x auxilary windows for engine output and eval graph to xboard. (And move history? Or is that already there?)
* Implement the WinBoard_x backTexture feature into the drawng routines of xboard.
* Implement the -allWhite and -flipBlack options in the piece dawing routine of xboard.
* Convert and add the Japanes Shogi pixmaps to xboard.
Zach Wegner wrote:As I brought up in the email, this is a bit more complicated than it seems. Xboard has standard X Windows options such as "geometry" that are parsed automatically by the X library calls. I believe that it also looks at the ~/.Xdefaults file for these options.H.G.Muller wrote:* move all processing of command-line options to the back-end, so they automatically benefit xboard.
I'm really not sure, as I don't too much about the X internals. I could research it though.H.G.Muller wrote:I am not sure I understand the difficulty. Surely there must be a way to request options that were not processed and recognized by the X-library calls to the user application. Or, if this is not possible, pre-process the arguments before invoking the X-library calls, copying them to a string.
It works differently. Xboard has a big list of command line options, and the actions to take, and passes it to XtAppInitialize, which parses all the command line both against standard X options and the supplied ones. I looked a little closer though, and it shouldn't be too hard: XtAppInitialize modifies argc and argv so that any unrecognized options can be parsed separately. So either we pass a NULL pointer for the custom options, or a pointer to an empty set. The man page for XtAppInitialize is very terse and doesn't go into much detail about this. But I guess it should be easier than I thought. I think the ParseArgs from Winboard should be broken up just to pull the strings apart, and then they should be passed into the back end, so that xboard doesn't have to merge all the strings together, only to merge them back. In fact, that probably wouldn't work anyways: if an argument is given on the command line, like this: xboard -fcp gnuchess -fd "/home/chess and stuff/engines and other stuff/gnuchess", then the shell automatically takes care of the quotes and gives the path as just one string, without the quotes included. The back end wouldn't know which arguments were which once they were merged together.How does this .Xdefaults stuff work? Is it something the command shell reads, and prepends to the user-supplied options before passing the lot in the exec call to the new core image? Or is it something the startup code of the new program does, after it has woken up with its memory initialized with the arguments passed through exec? Just reading .Xdefaults, and slipping the lines read there into the argument list, before giving the user control?
In the worst case we can add all X windows argumets to the list of xboard arguments, as dummies, to make sure they are ignored. But I would be surprised if that was necessary.
Zach Wegner wrote:It works differently. Xboard has a big list of command line options, and the actions to take, and passes it to XtAppInitialize, which parses all the command line both against standard X options and the supplied ones. I looked a little closer though, and it shouldn't be too hard: XtAppInitialize modifies argc and argv so that any unrecognized options can be parsed separately. So either we pass a NULL pointer for the custom options, or a pointer to an empty set. The man page for XtAppInitialize is very terse and doesn't go into much detail about this. But I guess it should be easier than I thought. I think the ParseArgs from Winboard should be broken up just to pull the strings apart, and then they should be passed into the back end, so that xboard doesn't have to merge all the strings together, only to merge them back.
ArgGet(void **p)
{
int *ip = (int **) p; char c;
if((*ip >> 8) >= argc) return EOF; // no more arguments
c = argv[(*ip)>>8][(*ip)&255]; // next char of current arg
if(c != 0) { (*ip)++; retiurn(c); }
*ip = (*ip | 255) + 1; // skip to first char of next arg
return(' ');
}
I think we should try to avoid that kind of code as much as possible.H.G.Muller wrote:I had something much simpler in mind. Move ParseArgs and associated stuff to the back-end. Just provide a third type of GetFunc for it (next to FileGet() to read from a file and StringGet() to read the next string character): ArgGet(). This would be defined in the front-end. In winboard.c it would be an identical copy of StringGet (which was moved to the back-end).
But in xboard, it would be a function that returns the next character from the current arguument, or, if that runs out, it returns a space, and sets the 'pointer' with which it is called to the first character of the next argument. The pointer would be a kind of two-dimensional pointer, the high-order byte would code for the argument number, and the low-orderr byte for the character. So basically:
- Code: Select all
ArgGet(void **p)
{
int *ip = (int **) p; char c;
if((*ip >> 8) >= argc) return EOF; // no more arguments
c = argv[(*ip)>>8][(*ip)&255]; // next char of current arg
if(c != 0) { (*ip)++; retiurn(c); }
*ip = (*ip | 255) + 1; // skip to first char of next arg
return(' ');
}
Only hack is that argc and argv have to be globally available.
char *c;
c = getstr(cl);
if (c == NULL) break;
if (*c == ';') {
/* Comment to end of line */
continue;
} else if (*c == '/' || *c == '-') {
/* Switch */
for (ad = argDescriptors; ad->argName != NULL; ad++)
if (strcmp(ad->argName, c + 1) == 0) break;
if (ad->argName == NULL)
ExitArgError("Unrecognized argument", c);
} else if (*c == '@') {
/* Indirection file */
ad = argDescriptorIndirection;
} else {
/* Positional argument */
/* What the hell does this do?? It just grabs straight from the array of valid command line options, which means that the user must supply every command line option in the order in winboard.c... very strange... */
ad = &argDescriptors[posarg++];
strcpy(argName, ad->argName);
}
....
char buffer[123], *c, ch;
do
ch = get(cl);
while (ch == ' ' || ch == '\n' || ch == '\t');
if (ch == NULLCHAR) return NULL;
if (ch == ';') {
/* Comment to end of line */
c = buffer;
do {
*c = ch;
ch = get(cl);
} while (ch != '\n' && ch != NULLCHAR);
*c = NULLCHAR;
return buffer;
} else if (ch == '/' || ch == '-') {
/* Switch */
c = buffer;
while (ch != ' ' && ch != '=' && ch != ':' && ch != NULLCHAR &&
ch != '\n' && ch != '\t') {
*c++ = ch;
ch = get(cl);
}
*q = NULLCHAR;
} else if (ch == '@') {
/* Indirection file */
buffer[0] = '@';
buffer[1] = NULLCHAR;
return buffer;
} else {
/* Positional argument */
buffer[0] = NULLCHAR;
return buffer;
}
...
-tc
1
int Escapes() { return TRUE; } // in xboard.c
int Escapes() { return FALSE; } // in winboard.c
No, it takes a full string, with quotes or whatever, and breaks it up into chunks. I'm not sure exactly what you are referring to, but the code I put up doesn't require any fudging around with the arguments.H.G.Muller wrote:That pre-parsing only involves removal of quotes of string arguments, not? I guess that makes the ArgGet a little bit more complicated: when it wants to return the first character of the next argument, it should scan the argument for spaces, and slip in a quote.
I think xboard users can live without those escapes in their filenames. But the treatment of backslashes works the same way. I put in an argument to an argDescriptor which specifies what type of argument it is, and filenames don't use escapes.I guess there is a subtlety here concerning the treatment of the backslash: with single or double quoting WinBoard accepts this as an escape character, but not if the argument type is filename.
Is there any harm in forbidding escapes like \n, \r and \t in file names used by xboard? Seems to me you have to be pretty malicious to use those in file names. Of course we could let the back-end ask to the front-end if it should treat the \ as an escape character in filenames, or not. That might be the simplest solution:
- Code: Select all
int Escapes() { return TRUE; } // in xboard.c
int Escapes() { return FALSE; } // in winboard.c
Certainly a very interesting idea. There hasn't really been much work on the front/back end separation yet, so now would certainly be a good time to decide.Eric Mullins wrote:I'm interested in this project, and can assist some. Is there any interest in migrating the frontend to Qt or similar framework?
Zach Wegner wrote:I don't really know anything about Qt. GTK is also a reasonable alternative (makes pretty nice looking applications, including Firefox). GTK has the advantage of being in C, as well as being GPL. On first glance it looks easier to integrate into the x/winboard code.
Whatever the case, I think a portable GUI framework would be a great idea.
Return to WinBoard development and bugfixing
Users browsing this forum: No registered users and 18 guests