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