Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – planix.SVN – Blame – /os/branches/planix-v0/sys/src/libventi/parsescore.c – Rev 2

Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include <u.h>
2
#include <libc.h>
3
#include <venti.h>
4
 
5
int
6
vtparsescore(char *s, char **prefix, uchar score[VtScoreSize])
7
{
8
	int i, c;
9
	char *buf, *colon;
10
 
11
	if((colon = strchr(s, ':')) != nil)
12
		buf = colon+1;
13
	else
14
		buf = s;
15
 
16
	if(strlen(buf) != 2*VtScoreSize)
17
		return -1;
18
 
19
	memset(score, 0, VtScoreSize);
20
	for(i=0; i<2*VtScoreSize; i++){
21
		if(buf[i] >= '0' && buf[i] <= '9')
22
			c = buf[i] - '0';
23
		else if(buf[i] >= 'a' && buf[i] <= 'z')
24
			c = buf[i] - 'a' + 10;
25
		else if(buf[i] >= 'A' && buf[i] <= 'Z')
26
			c = buf[i] - 'A' + 10;
27
		else
28
			return -1;
29
 
30
		if((i & 1) == 0)
31
			c <<= 4;
32
		score[i>>1] |= c;
33
	}
34
	if(colon){
35
		*colon = 0;
36
		if(prefix)
37
			*prefix = s;
38
	}else{
39
		if(prefix)
40
			*prefix = nil;
41
	}
42
	return 0;
43
}