1 | #include "muscle.h" |
---|
2 | #include <stdio.h> |
---|
3 | |
---|
4 | const char *SecsToStr(unsigned long Secs) |
---|
5 | { |
---|
6 | static char Str[24]; // potential buffer overflow (warned by gcc 7.5.0) |
---|
7 | long hh, mm, ss; |
---|
8 | |
---|
9 | hh = Secs/(60*60); |
---|
10 | mm = (Secs/60)%60; |
---|
11 | ss = Secs%60; |
---|
12 | |
---|
13 | sprintf(Str, "%02ld:%02ld:%02ld", hh, mm, ss); |
---|
14 | return Str; |
---|
15 | } |
---|
16 | |
---|
17 | const char *BoolToStr(bool b) |
---|
18 | { |
---|
19 | return b ? "True" : "False"; |
---|
20 | } |
---|
21 | |
---|
22 | const char *ScoreToStr(SCORE Score) |
---|
23 | { |
---|
24 | if (MINUS_INFINITY >= Score) |
---|
25 | return " *"; |
---|
26 | // Hack to use "circular" buffer so when called multiple |
---|
27 | // times in a printf-like argument list it works OK. |
---|
28 | const int iBufferCount = 16; |
---|
29 | const int iBufferLength = 16; |
---|
30 | static char szStr[iBufferCount*iBufferLength]; |
---|
31 | static int iBufferIndex = 0; |
---|
32 | iBufferIndex = (iBufferIndex + 1)%iBufferCount; |
---|
33 | char *pStr = szStr + iBufferIndex*iBufferLength; |
---|
34 | sprintf(pStr, "%8g", Score); |
---|
35 | return pStr; |
---|
36 | } |
---|
37 | |
---|
38 | // Left-justified version of ScoreToStr |
---|
39 | const char *ScoreToStrL(SCORE Score) |
---|
40 | { |
---|
41 | if (MINUS_INFINITY >= Score) |
---|
42 | return "*"; |
---|
43 | // Hack to use "circular" buffer so when called multiple |
---|
44 | // times in a printf-like argument list it works OK. |
---|
45 | const int iBufferCount = 16; |
---|
46 | const int iBufferLength = 16; |
---|
47 | static char szStr[iBufferCount*iBufferLength]; |
---|
48 | static int iBufferIndex = 0; |
---|
49 | iBufferIndex = (iBufferIndex + 1)%iBufferCount; |
---|
50 | char *pStr = szStr + iBufferIndex*iBufferLength; |
---|
51 | sprintf(pStr, "%.3g", Score); |
---|
52 | return pStr; |
---|
53 | } |
---|
54 | |
---|
55 | const char *WeightToStr(WEIGHT w) |
---|
56 | { |
---|
57 | return ScoreToStr(w); |
---|
58 | } |
---|