math: use correct type
[smatch.git] / smatch_string_list.c
blob6ff5cf7a871b2ef1f2ab3291afc2450d95a66416
1 /*
2 * Copyright (C) 2013 Oracle.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 #include "smatch.h"
20 int list_has_string(struct string_list *str_list, char *str)
22 char *tmp;
24 FOR_EACH_PTR(str_list, tmp) {
25 if (strcmp(tmp, str) < 0)
26 continue;
27 if (strcmp(tmp, str) == 0)
28 return 1;
29 return 0;
30 } END_FOR_EACH_PTR(tmp);
31 return 0;
34 void insert_string(struct string_list **str_list, char *new)
36 char *tmp;
38 FOR_EACH_PTR(*str_list, tmp) {
39 if (strcmp(tmp, new) < 0)
40 continue;
41 else if (strcmp(tmp, new) == 0) {
42 return;
43 } else {
44 INSERT_CURRENT(new, tmp);
45 return;
47 } END_FOR_EACH_PTR(tmp);
48 add_ptr_list(str_list, new);
51 struct string_list *clone_str_list(struct string_list *orig)
53 char *tmp;
54 struct string_list *ret = NULL;
56 FOR_EACH_PTR(orig, tmp) {
57 add_ptr_list(&ret, tmp);
58 } END_FOR_EACH_PTR(tmp);
59 return ret;
62 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two)
64 struct string_list *ret;
65 char *tmp;
67 ret = clone_str_list(one);
68 FOR_EACH_PTR(two, tmp) {
69 insert_string(&ret, tmp);
70 } END_FOR_EACH_PTR(tmp);
71 return ret;