From: Yann Dirson Date: Sat, 9 Nov 2013 16:54:11 +0000 (+0100) Subject: Refactor needlessly-complicated Raw_SelectLevel. X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=d382a9f843aa61ef352ce199823788f96d4912c3;p=gnushogi.git Refactor needlessly-complicated Raw_SelectLevel. --- diff --git a/gnushogi/commondsp.c b/gnushogi/commondsp.c index 40bfd22..422dab6 100644 --- a/gnushogi/commondsp.c +++ b/gnushogi/commondsp.c @@ -1744,10 +1744,13 @@ InputCommand(char *command) { ListGame(); } - else if ((strcmp(s, "level") == 0) - || (strcmp(s, "clock") == 0)) + else if (strcmp(s, "level") == 0) { - dsp->SelectLevel(sx); + dsp->SelectLevel(sx + strlen("level")); + } + else if (strcmp(s, "clock") == 0) + { + dsp->SelectLevel(sx + strlen("clock")); } else if (strcmp(s, "hash") == 0) { diff --git a/gnushogi/rawdsp.c b/gnushogi/rawdsp.c index fa121b0..8a6ec66 100644 --- a/gnushogi/rawdsp.c +++ b/gnushogi/rawdsp.c @@ -698,28 +698,16 @@ Raw_GiveHint(void) void Raw_SelectLevel(char *sx) { + char T[NO_SQUARES + 1], *p; - char T[NO_SQUARES + 1], *p, *q; + strncpy(T, sx, NO_SQUARES); + T[NO_SQUARES] = '\0'; - if ((p = strstr(sx, "level")) != NULL) - p += strlen("level"); - else if ((p = strstr(sx, "clock")) != NULL) - p += strlen("clock"); - - strcat(sx, "XX"); - q = T; - *q = '\0'; - - for (; *p != 'X'; *q++ = *p++); - - *q = '\0'; - - /* line empty ask for input */ + /* if line empty, ask for input */ if (!T[0]) { fputs("Enter #moves #minutes: ", stdout); fgets(T, NO_SQUARES + 1, stdin); - strcat(T, "XX"); } /* skip blackspace */ @@ -729,6 +717,7 @@ Raw_SelectLevel(char *sx) if (*p == 'f') { /* its a fischer clock game */ + char *q; p++; TCminutes = (short)strtol(p, &q, 10); TCadd = (short)strtol(q, NULL, 10) *100; @@ -738,6 +727,7 @@ Raw_SelectLevel(char *sx) else { /* regular game */ + char *q; TCadd = 0; TCmoves = (short)strtol(p, &q, 10); TCminutes = (short)strtol(q, &q, 10);