Updated Spanish translation
[anjuta-git-plugin.git] / plugins / valgrind / vgrulepattern.c
blob71f95b3ae39b54156e0f64f9b729278a5a913ff5
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3 * Authors: Jeffrey Stedfast <fejj@ximian.com>
5 * Copyright 2003 Ximian, Inc. (www.ximian.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
28 #include <string.h>
29 #include <sys/types.h>
30 #include <regex.h>
32 #include "vgrulepattern.h"
34 struct _VgRulePattern {
35 GPtrArray *patterns;
36 vgrule_t type;
37 char *syscall;
41 VgRulePattern *
42 vg_rule_pattern_new (VgRule *rule)
44 VgRulePattern *pat;
45 VgCaller *c;
47 pat = g_new (VgRulePattern, 1);
48 pat->patterns = g_ptr_array_new ();
49 pat->type = rule->type;
50 pat->syscall = g_strdup (rule->syscall);
52 c = rule->callers;
53 while (c != NULL) {
54 regex_t *regex;
56 regex = g_new (regex_t, 1);
58 if (regcomp (regex, c->name, REG_EXTENDED | REG_NOSUB) != 0) {
59 g_free (regex);
60 break;
63 g_ptr_array_add (pat->patterns, regex);
65 c = c->next;
68 return pat;
72 void
73 vg_rule_pattern_free (VgRulePattern *pat)
75 int i;
77 if (pat == NULL)
78 return;
80 for (i = 0; i < pat->patterns->len; i++) {
81 regex_t *regex = pat->patterns->pdata[i];
83 regfree (regex);
84 g_free (regex);
87 g_ptr_array_free (pat->patterns, TRUE);
88 g_free (pat->syscall);
89 g_free (pat);
93 gboolean
94 vg_rule_pattern_matches (VgRulePattern *pat, VgError *err)
96 VgErrorStack *s = err->summary->frames;
97 vgrule_t type;
98 int i;
100 if (s == NULL)
101 return FALSE;
103 if (!vg_rule_type_from_report (err->summary->report, &type, NULL) || type != pat->type)
104 return FALSE;
106 if (pat->type == VG_RULE_PARAM) {
107 const char *syscall;
108 int n;
110 syscall = err->summary->report + 14;
111 n = strcspn (syscall, " ");
113 if (n != strlen (pat->syscall) || strncmp (pat->syscall, syscall, n) != 0)
114 return FALSE;
117 for (i = 0; s != NULL && i < pat->patterns->len; i++) {
118 regex_t *regex = pat->patterns->pdata[i];
119 const char *str;
121 if (s->symbol) {
122 str = s->symbol;
123 } else if (s->type == VG_STACK_OBJECT) {
124 str = s->info.object;
125 } else {
126 return FALSE;
129 if (regexec (regex, str, 0, NULL, 0) != 0)
130 return FALSE;
132 s = s->next;
135 if (i == pat->patterns->len)
136 return TRUE;
138 return FALSE;