synced with r24573
[mplayer/glamo.git] / libass / ass_utils.c
blob3be71b8f31a10b2250d21d8b20275bfd1a45123a
1 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
2 // vim:ts=8:sw=8:noet:ai:
3 /*
4 Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "config.h"
23 #include <stdlib.h>
24 #include <inttypes.h>
26 #include "mputils.h"
27 #include "ass_utils.h"
29 int mystrtoi(char** p, int base, int* res)
31 char* start = *p;
32 *res = strtol(*p, p, base);
33 if (*p != start) return 1;
34 else return 0;
37 int mystrtou32(char** p, int base, uint32_t* res)
39 char* start = *p;
40 *res = strtoll(*p, p, base);
41 if (*p != start) return 1;
42 else return 0;
45 int mystrtod(char** p, double* res)
47 char* start = *p;
48 *res = strtod(*p, p);
49 if (*p != start) return 1;
50 else return 0;
53 int strtocolor(char** q, uint32_t* res)
55 uint32_t color = 0;
56 int result;
57 char* p = *q;
59 if (*p == '&') ++p;
60 else mp_msg(MSGT_ASS, MSGL_DBG2, "suspicious color format: \"%s\"\n", p);
62 if (*p == 'H' || *p == 'h') {
63 ++p;
64 result = mystrtou32(&p, 16, &color);
65 } else {
66 result = mystrtou32(&p, 0, &color);
70 unsigned char* tmp = (unsigned char*)(&color);
71 unsigned char b;
72 b = tmp[0]; tmp[0] = tmp[3]; tmp[3] = b;
73 b = tmp[1]; tmp[1] = tmp[2]; tmp[2] = b;
75 if (*p == '&') ++p;
76 *q = p;
78 *res = color;
79 return result;