1 /*
2 * drivers/amlogic/amports/config_parser.c
3 *
4 * Copyright (C) 2015 Amlogic, Inc. All rights reserved.
5 *
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.
10 *
11 * This program is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * more details.
15 *
16 */
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/errno.h>
21
22 #include "config_parser.h"
23 /*
24 *sample config:
25 *configs: width:1920;height:1080;
26 *need:width
27 *ok: return 0;
28 **val = value;
29 */
get_config_int(const char * configs,const char * need,int * val)30 int get_config_int(const char *configs, const char *need, int *val)
31 {
32 const char *str;
33 int ret;
34 int lval = 0;
35 *val = 0;
36
37 if (!configs || !need)
38 return -1;
39 str = strstr(configs, need);
40 if (str != NULL) {
41 if (str > configs && str[-1] != ';') {
42 /*
43 * if not the first config val.
44 * make sure before is ';'
45 * to recognize:
46 * ;crop_width:100
47 * ;width:100
48 */
49 return -2;
50 }
51 str += strlen(need);
52 if (str[0] != ':' || str[1] == '\0')
53 return -3;
54 ret = sscanf(str, ":%d", &lval);
55 if (ret == 1) {
56 *val = lval;
57 return 0;
58 }
59 }
60
61 return -4;
62 }
63 EXPORT_SYMBOL(get_config_int);
64
65