Fix GameListHighlight WB
[xboard.git] / winboard / wgamelist.c
index 17e78f1..196c837 100644 (file)
@@ -437,14 +437,22 @@ VOID GameListPopDown(void)
 VOID GameListHighlight(int index)\r
 {\r
   char buf[MSG_SIZ];\r
-  int i, res = 0;\r
+  int i, j, k, n, res = 0;\r
   if (gameListDialog == NULL) return;\r
-  for(i=0; res != LB_ERR; i++) {\r
+  for(i=64; ; i+=i) {\r
         res = SendDlgItemMessage( gameListDialog, OPT_GameListText, LB_GETTEXT, i, (LPARAM)buf );\r
-        if(index <= atoi( buf )) break;\r
+        if(res == LB_ERR || index < atoi( buf )) break;\r
   }\r
-  SendDlgItemMessage(gameListDialog, OPT_GameListText,\r
-    LB_SETCURSEL, i, 0);\r
+  j = i/2;\r
+  while(i-j > 1) {\r
+        n = (i + j) >> 1;\r
+        res = SendDlgItemMessage( gameListDialog, OPT_GameListText, LB_GETTEXT, n, (LPARAM)buf );\r
+        if(res == LB_ERR || index < (k = atoi( buf ))) i = n; else {\r
+            j = n;\r
+            if(index == k) break;\r
+        }\r
+  }\r
+  SendDlgItemMessage(gameListDialog, OPT_GameListText, LB_SETCURSEL, j, 0);\r
 }\r
 \r
 \r