1 /*
2  * src/gotime.h, part of Complete Goban (game program)
3  * Copyright (C) 1995 William Shubert.
4  * See "configure.h.in" for more copyright information.
5  */
6 
7 
8 #ifndef  _GOTIME_H_
9 #define  _GOTIME_H_  1
10 
11 #ifndef  _WMS_STR_H_
12 #include <wms/str.h>
13 #endif
14 
15 
16 /**********************************************************************
17  * Data types
18  **********************************************************************/
19 typedef enum  {
20   goTime_none, goTime_absolute, goTime_japanese, goTime_canadian,
21   goTime_ing
22 } GoTimeType;
23 
24 
25 typedef struct  {
26   GoTimeType  type;
27   int  main;
28   int  by;
29   int  aux;
30 } GoTime;
31 
32 
33 typedef struct  {
34   int  timeLeft, aux;
35   int  usLeft;
36   struct timeval startTime;
37 } GoTimer;
38 
39 
40 /**********************************************************************
41  * Functions
42  **********************************************************************/
43 void  goTime_str(int time, Str *out);
44 int  goTime_parseChars(const char *t, bool ignoreExtra, bool *err);
45 void  goTime_describeStr(const GoTime *time, Str *out);
46 void  goTime_parseDescribeChars(GoTime *time, const char *desc);
47 void  goTime_remainStr(const GoTime *time, const GoTimer *timer, Str *out);
48 
49 void  goTimer_init(GoTimer *timer, const GoTime *time);
50 
51 void  goTime_startTimer(const GoTime *time, GoTimer *timer);
52 /*
53  * goTime_checkTimer() and goTime_endTimer() return FALSE if you are out of
54  *   time.
55  */
56 bool  goTime_checkTimer(const GoTime *time, GoTimer *timer);
57 bool  goTime_endTimer(const GoTime *time, GoTimer *timer);
58 int  goTime_ingPenalty(const GoTime *time, const GoTimer *timer);
59 #define  goTime_out(tm, tmr)  (((tm)->type != goTime_none) &&  \
60 			       ((tmr)->timeLeft < 0))
61 #define goTime_low(tm, tmr, limit)					\
62   ((((tm)->type == goTime_absolute) && ((tmr)->timeLeft < limit)) ||	\
63    (((tm)->type == goTime_canadian) && ((tmr)->aux > 0) &&		\
64     ((tmr)->timeLeft < limit)) ||					\
65    (((tm)->type == goTime_japanese) && ((tmr)->timeLeft < limit)))
66 
67 #endif  /* _GOTIME_H_ */
68