Print this page
11506 smatch resync


   3  *
   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.
   8  *
   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.
  13  *
  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
  16  */
  17 
  18 #include "smatch.h"
  19 
  20 int list_has_string(struct string_list *str_list, const char *str)
  21 {
  22         char *tmp;

  23 
  24         if (!str)
  25                 return 0;
  26 
  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;
  35 }
  36 
  37 void insert_string(struct string_list **str_list, const char *_new)
  38 {
  39         char *new = (char *)_new;
  40         char *tmp;

  41 
  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(alloc_string(new), tmp);
  49                         return;
  50                 }
  51         } END_FOR_EACH_PTR(tmp);
  52         new = alloc_string(new);
  53         add_ptr_list(str_list, new);

  54 }
  55 
  56 struct string_list *clone_str_list(struct string_list *orig)
  57 {
  58         char *tmp;
  59         struct string_list *ret = NULL;
  60 
  61         FOR_EACH_PTR(orig, tmp) {
  62                 add_ptr_list(&ret, tmp);
  63         } END_FOR_EACH_PTR(tmp);
  64         return ret;
  65 }
  66 
  67 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two)
  68 {
  69         struct string_list *ret;
  70         char *tmp;
  71 
  72         ret = clone_str_list(one);
  73         FOR_EACH_PTR(two, tmp) {


   3  *
   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.
   8  *
   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.
  13  *
  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
  16  */
  17 
  18 #include "smatch.h"
  19 
  20 int list_has_string(struct string_list *str_list, const char *str)
  21 {
  22         char *tmp;
  23         int cmp;
  24 
  25         if (!str)
  26                 return 0;
  27 
  28         FOR_EACH_PTR(str_list, tmp) {
  29                 cmp = strcmp(tmp, str);
  30                 if (cmp < 0)
  31                         continue;
  32                 if (cmp == 0)
  33                         return 1;
  34                 return 0;
  35         } END_FOR_EACH_PTR(tmp);
  36         return 0;
  37 }
  38 
  39 int insert_string(struct string_list **str_list, const char *_new)
  40 {
  41         char *new = (char *)_new;
  42         char *tmp;
  43         int cmp;
  44 
  45         FOR_EACH_PTR(*str_list, tmp) {
  46                 cmp = strcmp(tmp, new);
  47                 if (cmp < 0)
  48                         continue;
  49                 else if (cmp == 0) {
  50                         return 0;
  51                 } else {
  52                         INSERT_CURRENT(alloc_string(new), tmp);
  53                         return 1;
  54                 }
  55         } END_FOR_EACH_PTR(tmp);
  56         new = alloc_string(new);
  57         add_ptr_list(str_list, new);
  58         return 1;
  59 }
  60 
  61 struct string_list *clone_str_list(struct string_list *orig)
  62 {
  63         char *tmp;
  64         struct string_list *ret = NULL;
  65 
  66         FOR_EACH_PTR(orig, tmp) {
  67                 add_ptr_list(&ret, tmp);
  68         } END_FOR_EACH_PTR(tmp);
  69         return ret;
  70 }
  71 
  72 struct string_list *combine_string_lists(struct string_list *one, struct string_list *two)
  73 {
  74         struct string_list *ret;
  75         char *tmp;
  76 
  77         ret = clone_str_list(one);
  78         FOR_EACH_PTR(two, tmp) {