File: typetostr.cpp

package info (click to toggle)
muscle 3.52-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,196 kB
  • ctags: 1,763
  • sloc: cpp: 21,335; xml: 185; makefile: 104
file content (58 lines) | stat: -rw-r--r-- 1,439 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "muscle.h"
#include <stdio.h>

const char *SecsToStr(unsigned long Secs)
	{
	static char Str[16];
	long hh, mm, ss;

	hh = Secs/(60*60);
	mm = (Secs/60)%60;
	ss = Secs%60;

	sprintf(Str, "%02d:%02d:%02d", hh, mm, ss);
	return Str;
	}

const char *BoolToStr(bool b)
	{
	return b ? "True" : "False";
	}

const char *ScoreToStr(SCORE Score)
	{
	if (MINUS_INFINITY >= Score)
		return "       *";
// Hack to use "circular" buffer so when called multiple
// times in a printf-like argument list it works OK.
	const int iBufferCount = 16;
	const int iBufferLength = 16;
	static char szStr[iBufferCount*iBufferLength];
	static int iBufferIndex = 0;
	iBufferIndex = (iBufferIndex + 1)%iBufferCount;
	char *pStr = szStr + iBufferIndex*iBufferLength;
	sprintf(pStr, "%8g", Score);
	return pStr;
	}

// Left-justified version of ScoreToStr
const char *ScoreToStrL(SCORE Score)
	{
	if (MINUS_INFINITY >= Score)
		return "*";
// Hack to use "circular" buffer so when called multiple
// times in a printf-like argument list it works OK.
	const int iBufferCount = 16;
	const int iBufferLength = 16;
	static char szStr[iBufferCount*iBufferLength];
	static int iBufferIndex = 0;
	iBufferIndex = (iBufferIndex + 1)%iBufferCount;
	char *pStr = szStr + iBufferIndex*iBufferLength;
	sprintf(pStr, "%.3g", Score);
	return pStr;
	}

const char *WeightToStr(WEIGHT w)
	{
	return ScoreToStr(w);
	}