18937
|
1 #include "config.h"
|
|
2
|
|
3 #include <stdlib.h>
|
|
4 #include <stdint.h>
|
|
5 #include <sys/time.h>
|
|
6 #include <time.h>
|
|
7
|
|
8 #include "mp_msg.h"
|
|
9 #include "ass_utils.h"
|
|
10
|
|
11 int mystrtoi(char** p, int base, int* res)
|
|
12 {
|
|
13 char* start = *p;
|
|
14 *res = strtol(*p, p, base);
|
|
15 if (*p != start) return 1;
|
|
16 else return 0;
|
|
17 }
|
|
18
|
|
19 int mystrtou32(char** p, int base, uint32_t* res)
|
|
20 {
|
|
21 char* start = *p;
|
|
22 *res = strtoll(*p, p, base);
|
|
23 if (*p != start) return 1;
|
|
24 else return 0;
|
|
25 }
|
|
26
|
|
27 int mystrtod(char** p, double* res)
|
|
28 {
|
|
29 char* start = *p;
|
|
30 *res = strtod(*p, p);
|
|
31 if (*p != start) return 1;
|
|
32 else return 0;
|
|
33 }
|
|
34
|
|
35 int strtocolor(char** q, uint32_t* res)
|
|
36 {
|
|
37 uint32_t color = 0;
|
|
38 int result;
|
|
39 char* p = *q;
|
|
40
|
|
41 if (*p == '&') ++p;
|
19003
|
42 else mp_msg(MSGT_GLOBAL, MSGL_DBG2, "suspicious color format: \"%s\"\n", p);
|
18937
|
43
|
19003
|
44 if (*p == 'H' || *p == 'h') {
|
18937
|
45 ++p;
|
|
46 result = mystrtou32(&p, 16, &color);
|
|
47 } else {
|
19003
|
48 result = mystrtou32(&p, 0, &color);
|
18937
|
49 }
|
|
50
|
|
51 {
|
|
52 unsigned char* tmp = (unsigned char*)(&color);
|
|
53 unsigned char b;
|
|
54 b = tmp[0]; tmp[0] = tmp[3]; tmp[3] = b;
|
|
55 b = tmp[1]; tmp[1] = tmp[2]; tmp[2] = b;
|
|
56 }
|
|
57 if (*p == '&') ++p;
|
|
58 *q = p;
|
|
59
|
|
60 *res = color;
|
|
61 return result;
|
|
62 }
|
|
63
|