X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=xgamelist.c;h=06ebf4a210c94156485bd1c27c1785dbdb2c7924;hb=3d0e4f38019f924c773592842adad7922531e421;hp=4f86718df7f02f3fa601f2ecb7f07d2d6dcdc8c1;hpb=fb6556cba3193316b2b383c7fc0e0cdd1c75e9fd;p=xboard.git diff --git a/xgamelist.c b/xgamelist.c index 4f86718..06ebf4a 100644 --- a/xgamelist.c +++ b/xgamelist.c @@ -95,7 +95,7 @@ void SetFocus P((Widget w, XtPointer data, XEvent *event, Boolean *b)); static Widget filterText; static char filterString[MSG_SIZ]; -static int listLength; +static int listLength, wins, losses, draws; char gameListTranslations[] = "(2): LoadSelectedProc(0) \n \ @@ -109,6 +109,8 @@ char gameListTranslations[] = char filterTranslations[] = "Return: SetFilterProc() \n"; +char *dummyList[] = { N_("no games matched your request"), NULL }; + typedef struct { Widget shell; Position x, y; @@ -169,7 +171,7 @@ GameListCreate(name, callback, client_data) XtCreateManagedWidget("viewport", viewportWidgetClass, form, args, j); j = 0; - XtSetArg(args[j], XtNlist, glc->strings); j++; +// XtSetArg(args[j], XtNlist, glc->strings); j++; XtSetArg(args[j], XtNdefaultColumns, 1); j++; XtSetArg(args[j], XtNforceColumns, True); j++; XtSetArg(args[j], XtNverticalList, True); j++; @@ -186,7 +188,7 @@ GameListCreate(name, callback, client_data) XtSetArg(args[j], XtNleft, XtChainLeft); j++; XtSetArg(args[j], XtNright, XtChainLeft); j++; b_load = - XtCreateManagedWidget(_("load"), commandWidgetClass, form, args, j); + XtCreateManagedWidget(_("thresholds"), commandWidgetClass, form, args, j); XtAddCallback(b_load, XtNcallback, callback, client_data); j = 0; @@ -197,9 +199,9 @@ GameListCreate(name, callback, client_data) XtSetArg(args[j], XtNleft, XtChainLeft); j++; XtSetArg(args[j], XtNright, XtChainLeft); j++; b_loadprev = - XtCreateManagedWidget(_("prev"), commandWidgetClass, form, args, j); + XtCreateManagedWidget(_("find position"), commandWidgetClass, form, args, j); XtAddCallback(b_loadprev, XtNcallback, callback, client_data); - +#if 1 j = 0; XtSetArg(args[j], XtNfromVert, viewport); j++; XtSetArg(args[j], XtNfromHoriz, b_loadprev); j++; @@ -210,7 +212,9 @@ GameListCreate(name, callback, client_data) b_loadnext = XtCreateManagedWidget(_("next"), commandWidgetClass, form, args, j); XtAddCallback(b_loadnext, XtNcallback, callback, client_data); - +#else + b_loadnext = b_loadprev; +#endif j = 0; XtSetArg(args[j], XtNfromVert, viewport); j++; XtSetArg(args[j], XtNfromHoriz, b_loadnext); j++; @@ -240,7 +244,7 @@ GameListCreate(name, callback, client_data) XtSetArg(args[j], XtNbottom, XtChainBottom); j++; XtSetArg(args[j], XtNleft, XtChainLeft); j++; XtSetArg(args[j], XtNright, XtChainRight); j++; - XtSetArg(args[j], XtNwidth, fw_width - 225 - squareSize); j++; + XtSetArg(args[j], XtNwidth, fw_width - 275 - squareSize); j++; XtSetArg(args[j], XtNstring, filterString); j++; XtSetArg(args[j], XtNdisplayCaret, False); j++; XtSetArg(args[j], XtNresizable, True); j++; @@ -321,25 +325,37 @@ GameListCreate(name, callback, client_data) } static int -GameListPrepare() +GameListPrepare(int byPos) { // [HGM] filter: put in separate routine, to make callable from call-back int nstrings; ListGame *lg; char **st, *line; + if(st = glc->strings) while(*st) free(*st++); nstrings = ((ListGame *) gameList.tailPred)->number; glc->strings = (char **) malloc((nstrings + 1) * sizeof(char *)); st = glc->strings; lg = (ListGame *) gameList.head; - listLength = 0; + listLength = wins = losses = draws = 0; while (nstrings--) { + int pos = -1; line = GameListLine(lg->number, &lg->gameInfo); - if(filterString[0] == NULLCHAR || SearchPattern( line, filterString ) ) { - *st++ = line; // [HGM] filter: make adding line conditional + if((filterString[0] == NULLCHAR || SearchPattern( line, filterString )) && (!byPos || (pos=GameContainsPosition(glc->fp, lg)) >= 0) ) { + if(listLength < 1500) *st++ = line; // [HGM] filter: make adding line conditional. *** X listboxes have severe size limit *** listLength++; + if( lg->gameInfo.result == WhiteWins ) wins++; else + if( lg->gameInfo.result == BlackWins ) losses++; else + if( lg->gameInfo.result == GameIsDrawn ) draws++; + } + if(lg->number % 2000 == 0) { + char buf[MSG_SIZ]; + snprintf(buf, MSG_SIZ, _("Scanning through games (%d)"), lg->number); + DisplayTitle(buf); } + lg->position = pos; lg = (ListGame *) lg->node.succ; } + DisplayTitle("XBoard"); *st = NULL; return listLength; } @@ -349,10 +365,17 @@ GameListReplace() { // filter: put in separate routine, to make callable from call-back Widget listwidg; + Arg arg; + char buf[MSG_SIZ],*p; listwidg = XtNameToWidget(glc->shell, "*form.viewport.list"); + XtSetArg(arg, XtNlist, listLength ? glc->strings : dummyList); // empty list displays message XawListChange(listwidg, glc->strings, 0, 0, True); + XtSetValues(listwidg, &arg, 1); XawListHighlight(listwidg, 0); + snprintf(buf, MSG_SIZ, "%s- %d/%d games (%d-%d-%d)", glc->filename, listLength, ((ListGame *) gameList.tailPred)->number, wins, losses, draws); + XtSetArg(arg, XtNtitle, buf); + XtSetValues(glc->shell, &arg, 1); } void @@ -376,6 +399,10 @@ GameListCallback(w, client_data, call_data) GameListPopDown(); return; } + if (strcmp(name, _("thresholds")) == 0) { + LoadOptionsProc(); + return; + } listwidg = XtNameToWidget(glc->shell, "*form.viewport.list"); rs = XawListShowCurrent(listwidg); if (strcmp(name, _("load")) == 0) { @@ -398,22 +425,27 @@ GameListCallback(w, client_data, call_data) return; } XawListHighlight(listwidg, index); - } else if (strcmp(name, _("apply")) == 0) { - String name; + } else if (strcmp(name, _("apply")) == 0 || + strcmp(name, _("find position")) == 0) { + String text; j = 0; - XtSetArg(args[j], XtNstring, &name); j++; + XtSetArg(args[j], XtNstring, &text); j++; XtGetValues(filterText, args, j); - safeStrCpy(filterString, name, sizeof(filterString)/sizeof(filterString[0])); + safeStrCpy(filterString, text, sizeof(filterString)/sizeof(filterString[0])); XawListHighlight(listwidg, 0); - if(GameListPrepare()) GameListReplace(); // crashes on empty list... + GameListPrepare(strcmp(name, _("find position")) == 0); GameListReplace(); return; } +#if 1 index = atoi(glc->strings[index])-1; // [HGM] filter: read true index from sequence nr of line if (cmailMsgLoaded) { CmailLoadGame(glc->fp, index + 1, glc->filename, True); } else { LoadGame(glc->fp, index + 1, glc->filename, True); } +#else + printf("This code should have been unreachable. Please report bug!\n"); +#endif } void @@ -430,15 +462,7 @@ GameListPopUp(fp, filename) glc->x = glc->y = -1; } - if (glc->strings != NULL) { - st = glc->strings; - while (*st) { - free(*st++); - } - free(glc->strings); - } - - GameListPrepare(); // [HGM] filter: code put in separate routine + GameListPrepare(False); // [HGM] filter: code put in separate routine glc->fp = fp; @@ -449,12 +473,12 @@ GameListPopUp(fp, filename) if (glc->shell == NULL) { glc->shell = GameListCreate(filename, GameListCallback, glc); } else { - GameListReplace(); // [HGM] filter: code put in separate routine j = 0; XtSetArg(args[j], XtNiconName, (XtArgVal) filename); j++; - XtSetArg(args[j], XtNtitle, (XtArgVal) filename); j++; +// XtSetArg(args[j], XtNtitle, (XtArgVal) filename); j++; XtSetValues(glc->shell, args, j); } + GameListReplace(); // [HGM] filter: code put in separate routine, and also called to set title XtPopup(glc->shell, XtGrabNone); glc->up = True; @@ -519,7 +543,7 @@ LoadSelectedProc(w, event, prms, nprms) XawListReturnStruct *rs; int index, direction = atoi(prms[0]); - if (glc == NULL) return; + if (glc == NULL || listLength == 0) return; listwidg = XtNameToWidget(glc->shell, "*form.viewport.list"); rs = XawListShowCurrent(listwidg); index = rs->list_index; @@ -554,7 +578,7 @@ SetFilterProc(w, event, prms, nprms) XtSetArg(args[j], XtNstring, &name); j++; XtGetValues(filterText, args, j); safeStrCpy(filterString, name, sizeof(filterString)/sizeof(filterString[0])); - if(GameListPrepare()) GameListReplace(); // crashes on empty list... + GameListPrepare(False); GameListReplace(); list = XtNameToWidget(glc->shell, "*form.viewport.list"); XawListHighlight(list, 0); j = 0; @@ -608,35 +632,35 @@ GameListIsUp() return glc && glc->up; } -int SaveGameListAsText(FILE *f) -{ - ListGame * lg = (ListGame *) gameList.head; - int nItem; - - if( !glc || ((ListGame *) gameList.tailPred)->number <= 0 ) { - DisplayError("Game list not loaded or empty", 0); - return False; - } - - /* Copy the list into the global memory block */ - if( f != NULL ) { +int SaveGameListAsText(FILE *f) +{ + ListGame * lg = (ListGame *) gameList.head; + int nItem; + + if( !glc || ((ListGame *) gameList.tailPred)->number <= 0 ) { + DisplayError("Game list not loaded or empty", 0); + return False; + } + + /* Copy the list into the global memory block */ + if( f != NULL ) { - lg = (ListGame *) gameList.head; - - for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){ - char * st = GameListLineFull(lg->number, &lg->gameInfo); + lg = (ListGame *) gameList.head; + + for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){ + char * st = GameListLineFull(lg->number, &lg->gameInfo); char *line = GameListLine(lg->number, &lg->gameInfo); if(filterString[0] == NULLCHAR || SearchPattern( line, filterString ) ) fprintf( f, "%s\n", st ); - free(st); free(line); - lg = (ListGame *) lg->node.succ; - } - + free(st); free(line); + lg = (ListGame *) lg->node.succ; + } + fclose(f); - return True; + return True; } - return False; -} + return False; +} //--------------------------------- Game-List options dialog ------------------------------------------ Widget gameListOptShell, listwidg;