modification_hooks: handle PARAM_SET earlier
[smatch.git] / smatch_string_list.c
blob1f3cf0d4a7ea702cea05ade0905e28f4b0c1d22f
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, const char *str)
22 char *tmp;
24 if (!str)
25 return 0;
27 FOR_EACH_PTR(str_list, tmp) {
28 if (strcmp(tmp, str) < 0)
29 continue;
30 if (strcmp(tmp, str) == 0)
31 return 1;
32 return 0;
33 } END_FOR_EACH_PTR(tmp);
34 return 0;
37 void insert_string(struct string_list **str_list, const char *_new)
39 char *new = (char *)_new;
40 char *tmp;
42 FOR_EACH_PTR(*str_list, tmp) {
43 if (strcmp(tmp, new) < 0)
44 continue;
45 else if (strcmp(tmp, new) == 0) {
46 return;
47 } else {
48 INSERT_CURRENT(new, tmp);
49 return;
51 } END_FOR_EACH_PTR(tmp);
52 add_ptr_list(str_list, new);
55 struct string_list *clone_str_list(struct string_list *orig)
57 char *tmp;
58 struct string_list *ret = NULL;
60 FOR_EACH_PTR(orig, tmp) {
61 add_ptr_list(&ret, tmp);
62 } END_FOR_EACH_PTR(tmp);
63 return ret;
66 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two)
68 struct string_list *ret;
69 char *tmp;
71 ret = clone_str_list(one);
72 FOR_EACH_PTR(two, tmp) {
73 insert_string(&ret, tmp);
74 } END_FOR_EACH_PTR(tmp);
75 return ret;