]>
Commit | Line | Data |
---|---|---|
5abc1f74 BK |
1 | |
2 | /* | |
3 | ||
4 | Test to see if a particular fix should be applied to a header file. | |
5 | ||
3852e8af | 6 | Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. |
5abc1f74 BK |
7 | |
8 | = = = = = = = = = = = = = = = = = = = = = = = = = | |
9 | ||
10 | NOTE TO DEVELOPERS | |
11 | ||
b7976767 | 12 | The routines you write here must work closely with fixincl.c. |
5abc1f74 BK |
13 | |
14 | Here are the rules: | |
15 | ||
16 | 1. Every test procedure name must be suffixed with "_test". | |
17 | These routines will be referenced from inclhack.def, sans the suffix. | |
18 | ||
19 | 2. Use the "TEST_FOR_FIX_PROC_HEAD()" macro _with_ the "_test" suffix | |
20 | (I cannot use the ## magic from ANSI C) for defining your entry point. | |
21 | ||
22 | 3. Put your test name into the FIX_TEST_TABLE | |
23 | ||
24 | 4. Do not write anything to stdout. It may be closed. | |
25 | ||
26 | 5. Write to stderr only in the event of a reportable error | |
27 | In such an event, call "exit(1)". | |
28 | ||
29 | = = = = = = = = = = = = = = = = = = = = = = = = = | |
30 | ||
6e6a1681 | 31 | This file is part of GCC. |
5abc1f74 | 32 | |
6e6a1681 | 33 | GCC is free software; you can redistribute it and/or modify |
5abc1f74 BK |
34 | it under the terms of the GNU General Public License as published by |
35 | the Free Software Foundation; either version 2, or (at your option) | |
36 | any later version. | |
37 | ||
6e6a1681 | 38 | GCC is distributed in the hope that it will be useful, |
5abc1f74 BK |
39 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
40 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
41 | GNU General Public License for more details. | |
42 | ||
43 | You should have received a copy of the GNU General Public License | |
6e6a1681 | 44 | along with GCC; see the file COPYING. If not, write to |
5abc1f74 BK |
45 | the Free Software Foundation, 59 Temple Place - Suite 330, |
46 | Boston, MA 02111-1307, USA. */ | |
47 | ||
48 | #include "fixlib.h" | |
49 | ||
7b78a14a BK |
50 | #define _ENV_(v,m,n,t) extern tCC* v; |
51 | ENV_TABLE | |
52 | #undef _ENV_ | |
53 | ||
3af556f7 BK |
54 | typedef apply_fix_p_t t_test_proc PARAMS(( tCC* file, tCC* text )); |
55 | ||
5abc1f74 | 56 | typedef struct { |
3af556f7 BK |
57 | tCC* test_name; |
58 | t_test_proc* test_proc; | |
5abc1f74 BK |
59 | } test_entry_t; |
60 | ||
1c99d804 RH |
61 | #define FIX_TEST_TABLE \ |
62 | _FT_( "machine_name", machine_name_test ) \ | |
a26c3bb5 | 63 | _FT_( "stdc_0_in_system_headers", stdc_0_in_system_headers_test ) |
5abc1f74 | 64 | |
1c99d804 RH |
65 | #define TEST_FOR_FIX_PROC_HEAD( test ) \ |
66 | static apply_fix_p_t test PARAMS(( tCC* file, tCC* text )); \ | |
67 | static apply_fix_p_t test ( fname, text ) \ | |
68 | tCC* fname ATTRIBUTE_UNUSED; \ | |
69 | tCC* text ATTRIBUTE_UNUSED; | |
5abc1f74 | 70 | |
8f9ca912 | 71 | |
52c207e2 ZW |
72 | TEST_FOR_FIX_PROC_HEAD( machine_name_test ) |
73 | { | |
bff0dc38 BK |
74 | #ifndef MN_NAME_PAT |
75 | return SKIP_FIX; | |
76 | #else | |
52c207e2 ZW |
77 | regex_t *label_re, *name_re; |
78 | regmatch_t match[2]; | |
79 | tCC *base, *limit; | |
2629a114 | 80 | IGNORE_ARG(fname); |
52c207e2 | 81 | |
bff0dc38 | 82 | mn_get_regexps(&label_re, &name_re, "machine_name_test"); |
52c207e2 ZW |
83 | |
84 | for (base = text; | |
ab747408 | 85 | xregexec (label_re, base, 2, match, 0) == 0; |
52c207e2 ZW |
86 | base = limit) |
87 | { | |
88 | base += match[0].rm_eo; | |
89 | /* We're looking at an #if or #ifdef. Scan forward for the | |
90 | next non-escaped newline. */ | |
91 | limit = base; | |
92 | do | |
93 | { | |
94 | limit++; | |
95 | limit = strchr (limit, '\n'); | |
96 | if (!limit) | |
97 | return SKIP_FIX; | |
98 | } | |
99 | while (limit[-1] == '\\'); | |
100 | ||
101 | /* If the 'name_pat' matches in between base and limit, we have | |
102 | a bogon. It is not worth the hassle of excluding comments, | |
103 | because comments on #if/#ifdef/#ifndef lines are rare, | |
104 | and strings on such lines are illegal. | |
105 | ||
106 | REG_NOTBOL means 'base' is not at the beginning of a line, which | |
107 | shouldn't matter since the name_re has no ^ anchor, but let's | |
108 | be accurate anyway. */ | |
109 | ||
ab747408 | 110 | if (xregexec (name_re, base, 1, match, REG_NOTBOL)) |
52c207e2 ZW |
111 | return SKIP_FIX; /* No match in file - no fix needed */ |
112 | ||
113 | /* Match; is it on the line? */ | |
cef40e9f | 114 | if (match[0].rm_eo <= limit - base) |
52c207e2 ZW |
115 | return APPLY_FIX; /* Yup */ |
116 | ||
117 | /* Otherwise, keep looking... */ | |
118 | } | |
119 | return SKIP_FIX; | |
bff0dc38 | 120 | #endif |
52c207e2 ZW |
121 | } |
122 | ||
5c0d5b94 | 123 | |
a26c3bb5 RO |
124 | TEST_FOR_FIX_PROC_HEAD( stdc_0_in_system_headers_test ) |
125 | { | |
126 | #ifdef STDC_0_IN_SYSTEM_HEADERS | |
89e50a58 | 127 | return (pz_machine == NULL) ? APPLY_FIX : SKIP_FIX; |
a26c3bb5 RO |
128 | #else |
129 | return APPLY_FIX; | |
130 | #endif | |
131 | } | |
132 | ||
133 | ||
5abc1f74 BK |
134 | /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = |
135 | ||
136 | test for fix selector | |
137 | ||
138 | THIS IS THE ONLY EXPORTED ROUTINE | |
139 | ||
140 | */ | |
141 | apply_fix_p_t | |
142 | run_test( tname, fname, text ) | |
87ad679b BK |
143 | tCC* tname; |
144 | tCC* fname; | |
145 | tCC* text; | |
5abc1f74 | 146 | { |
99d525c9 | 147 | #define _FT_(n,p) { n, p }, |
5abc1f74 | 148 | static test_entry_t test_table[] = { FIX_TEST_TABLE { NULL, NULL }}; |
99d525c9 | 149 | #undef _FT_ |
b6a1cbae | 150 | #define TEST_TABLE_CT (ARRAY_SIZE (test_table)-1) |
5abc1f74 BK |
151 | |
152 | int ct = TEST_TABLE_CT; | |
153 | test_entry_t* pte = test_table; | |
154 | ||
155 | do | |
156 | { | |
157 | if (strcmp( pte->test_name, tname ) == 0) | |
158 | return (*pte->test_proc)( fname, text ); | |
8f9ca912 | 159 | pte++; |
5abc1f74 BK |
160 | } while (--ct > 0); |
161 | fprintf( stderr, "fixincludes error: the `%s' fix test is unknown\n", | |
162 | tname ); | |
163 | exit( 3 ); | |
164 | } |