Daily bump.
[official-gcc.git] / fixincludes / fixtests.c
blob44ef97253f524778634bf5bdb7ceb418c8435aad
2 /*
4 Test to see if a particular fix should be applied to a header file.
6 Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
8 = = = = = = = = = = = = = = = = = = = = = = = = =
10 NOTE TO DEVELOPERS
12 The routines you write here must work closely with fixincl.c.
14 Here are the rules:
16 1. Every test procedure name must be suffixed with "_test".
17 These routines will be referenced from inclhack.def, sans the suffix.
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.
22 3. Put your test name into the FIX_TEST_TABLE
24 4. Do not write anything to stdout. It may be closed.
26 5. Write to stderr only in the event of a reportable error
27 In such an event, call "exit(1)".
29 = = = = = = = = = = = = = = = = = = = = = = = = =
31 This file is part of GCC.
33 GCC is free software; you can redistribute it and/or modify
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.
38 GCC is distributed in the hope that it will be useful,
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.
43 You should have received a copy of the GNU General Public License
44 along with GCC; see the file COPYING. If not, write to
45 the Free Software Foundation, 59 Temple Place - Suite 330,
46 Boston, MA 02111-1307, USA. */
48 #include "fixlib.h"
50 #define _ENV_(v,m,n,t) extern tCC* v;
51 ENV_TABLE
52 #undef _ENV_
54 typedef apply_fix_p_t t_test_proc ( tCC* file, tCC* text );
56 typedef struct {
57 tCC* test_name;
58 t_test_proc* test_proc;
59 } test_entry_t;
61 #define FIX_TEST_TABLE \
62 _FT_( "machine_name", machine_name_test ) \
63 _FT_( "stdc_0_in_system_headers", stdc_0_in_system_headers_test )
65 #define TEST_FOR_FIX_PROC_HEAD( test ) \
66 static apply_fix_p_t test ( tCC* fname ATTRIBUTE_UNUSED, \
67 tCC* text ATTRIBUTE_UNUSED )
69 TEST_FOR_FIX_PROC_HEAD( machine_name_test )
71 regex_t *label_re, *name_re;
72 regmatch_t match[2];
73 tCC *base, *limit;
74 IGNORE_ARG(fname);
76 if (!mn_get_regexps (&label_re, &name_re, "machine_name_test"))
77 return SKIP_FIX;
79 for (base = text;
80 xregexec (label_re, base, 2, match, 0) == 0;
81 base = limit)
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;
89 limit++;
90 limit = strchr (limit, '\n');
91 if (!limit)
92 return SKIP_FIX;
94 while (limit[-1] == '\\');
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.
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. */
105 if (xregexec (name_re, base, 1, match, REG_NOTBOL))
106 return SKIP_FIX; /* No match in file - no fix needed */
108 /* Match; is it on the line? */
109 if (match[0].rm_eo <= limit - base)
110 return APPLY_FIX; /* Yup */
112 /* Otherwise, keep looking... */
114 return SKIP_FIX;
118 TEST_FOR_FIX_PROC_HEAD( stdc_0_in_system_headers_test )
120 #ifdef STDC_0_IN_SYSTEM_HEADERS
121 return (pz_machine == NULL) ? APPLY_FIX : SKIP_FIX;
122 #else
123 return APPLY_FIX;
124 #endif
128 /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
130 test for fix selector
132 THIS IS THE ONLY EXPORTED ROUTINE
135 apply_fix_p_t
136 run_test( tCC* tname, tCC* fname, tCC* text )
138 #define _FT_(n,p) { n, p },
139 static test_entry_t test_table[] = { FIX_TEST_TABLE { NULL, NULL }};
140 #undef _FT_
141 #define TEST_TABLE_CT (ARRAY_SIZE (test_table)-1)
143 int ct = TEST_TABLE_CT;
144 test_entry_t* pte = test_table;
148 if (strcmp( pte->test_name, tname ) == 0)
149 return (*pte->test_proc)( fname, text );
150 pte++;
151 } while (--ct > 0);
152 fprintf( stderr, "fixincludes error: the `%s' fix test is unknown\n",
153 tname );
154 exit( 3 );