From 66a4d3394a1b23ab654e3fb6027ad9b5b2bd461c Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Tue, 5 Oct 2010 21:14:08 +0200 Subject: [PATCH] Allow -timeIncrement to be a float The increment can now be fractional seconds. The printing in ParseTimeControl() and SendTimeControl() is done with %g format, so that for integer increment there is backward compatibility with the old level command. --- args.h | 5 +++-- backend.c | 17 ++++++++++++----- backend.h | 2 +- common.h | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/args.h b/args.h index 00126f9..b101ef4 100644 --- a/args.h +++ b/args.h @@ -217,8 +217,8 @@ ArgDescriptor argDescriptors[] = { { "td", ArgFloat, (void *) &appData.timeDelay, FALSE, INVALID }, { "timeControl", ArgString, (void *) &appData.timeControl, TRUE, (ArgIniType) TIME_CONTROL }, { "tc", ArgString, (void *) &appData.timeControl, FALSE, INVALID }, - { "timeIncrement", ArgInt, (void *) &appData.timeIncrement, TRUE, (ArgIniType) TIME_INCREMENT }, - { "inc", ArgInt, (void *) &appData.timeIncrement, FALSE, INVALID }, + { "timeIncrement", ArgFloat, (void *) &appData.timeIncrement, TRUE, INVALID }, + { "inc", ArgFloat, (void *) &appData.timeIncrement, FALSE, INVALID }, { "internetChessServerMode", ArgBoolean, (void *) &appData.icsActive, FALSE, INVALID }, { "ics", ArgTrue, (void *) &appData.icsActive, FALSE, (ArgIniType) FALSE }, { "xics", ArgFalse, (void *) &appData.icsActive, FALSE, INVALID }, @@ -1158,6 +1158,7 @@ InitAppData(char *lpCmdLine) // float: casting to int is not harmless, so default cannot be contained in table appData.timeDelay = TIME_DELAY; + appData.timeIncrement = TIME_INCREMENT; // some complex, platform-dependent stuff that could not be handled from table SetDefaultTextAttribs(); diff --git a/backend.c b/backend.c index eed8bff..471a065 100644 --- a/backend.c +++ b/backend.c @@ -1027,6 +1027,13 @@ int NextSessionFromString( char ** str, int *moves, long * tc, long *inc, int *i if(**str == '!') type = *(*str)++; // Bronstein TC if(result = NextIntegerFromString( str, &temp2)) return -1; *inc = temp2 * 1000; + if(**str == '.') { // read fraction of increment + char *start = ++(*str); + if(result = NextIntegerFromString( str, &temp2)) return -1; + temp2 *= 1000; + while(start++ < *str) temp2 /= 10; + *inc += temp2; + } } else *inc = 0; *moves = 0; *tc = temp * 1000; *incType = type; return 0; @@ -1069,7 +1076,7 @@ int GetTimeQuota(int movenr, int lastUsed, char *tcString) int ParseTimeControl(tc, ti, mps) char *tc; - int ti; + float ti; int mps; { long tc1; @@ -1084,9 +1091,9 @@ ParseTimeControl(tc, ti, mps) if(ti > 0) { if(mps) - snprintf(buf, MSG_SIZ, ":%d/%s+%d", mps, mytc, ti); + snprintf(buf, MSG_SIZ, ":%d/%s+%g", mps, mytc, ti); else - snprintf(buf, MSG_SIZ, ":%s+%d", mytc, ti); + snprintf(buf, MSG_SIZ, ":%s+%g", mytc, ti); } else { if(mps) snprintf(buf, MSG_SIZ, ":%d/%s", mps, mytc); @@ -13539,9 +13546,9 @@ SendTimeControl(cps, mps, tc, inc, sd, st) /* Note old gnuchess bug -- minutes:seconds used to not work. Fixed in later versions, but still avoid :seconds when seconds is 0. */ - snprintf(buf, MSG_SIZ, "level %d %ld %d\n", mps, tc/60000, inc/1000); + snprintf(buf, MSG_SIZ, "level %d %ld %g\n", mps, tc/60000, inc/1000); } else { - snprintf(buf, MSG_SIZ, "level %d %ld:%02d %d\n", mps, tc/60000, + snprintf(buf, MSG_SIZ, "level %d %ld:%02d %g\n", mps, tc/60000, seconds, inc/1000); } } diff --git a/backend.h b/backend.h index 79478aa..7b39f88 100644 --- a/backend.h +++ b/backend.h @@ -189,7 +189,7 @@ void AdjustClock P((Boolean which, int dir)); void DisplayBothClocks P((void)); void EditPositionMenuEvent P((ChessSquare selection, int x, int y)); void DropMenuEvent P((ChessSquare selection, int x, int y)); -int ParseTimeControl P((char *tc, int ti, int mps)); +int ParseTimeControl P((char *tc, float ti, int mps)); void EscapeExpand(char *p, char *q); void ProcessICSInitScript P((FILE * f)); void EditCommentEvent P((void)); diff --git a/common.h b/common.h index 64e4ece..077c979 100644 --- a/common.h +++ b/common.h @@ -385,7 +385,7 @@ typedef struct { int premoveHighlightColor; #endif int movesPerSession; - int timeIncrement; + float timeIncrement; char *initString; char *secondInitString; char *firstComputerString; -- 1.7.0.4