Commit | Line | Data |
---|---|---|
959f3c4c JH |
1 | ?RCS: $Id: cpp_stuff.U,v 3.0.1.1 1994/10/29 16:08:24 ram Exp $ |
2 | ?RCS: | |
3 | ?RCS: Copyright (c) 1991-1993, Raphael Manfredi | |
4 | ?RCS: | |
5 | ?RCS: You may redistribute only under the terms of the Artistic Licence, | |
6 | ?RCS: as specified in the README file that comes with the distribution. | |
7 | ?RCS: You may reuse parts of this distribution only within the terms of | |
8 | ?RCS: that same Artistic Licence; a copy of which may be found at the root | |
9 | ?RCS: of the source tree for dist 3.0. | |
10 | ?RCS: | |
11 | ?RCS: $Log: cpp_stuff.U,v $ | |
12 | ?RCS: Revision 3.0.1.1 1994/10/29 16:08:24 ram | |
13 | ?RCS: patch36: now uses cppstdin instead of plain cpp for consistency (ADO) | |
14 | ?RCS: patch36: remove temporary files when done | |
15 | ?RCS: | |
16 | ?RCS: Revision 3.0 1993/08/18 12:05:36 ram | |
17 | ?RCS: Baseline for dist 3.0 netwide release. | |
18 | ?RCS: | |
19 | ?MAKE:cpp_stuff: cat contains cppstdin cppflags cppminus rm | |
20 | ?MAKE: -pick add $@ %< | |
21 | ?S:cpp_stuff: | |
5eccb696 | 22 | ?S: This variable contains an identification of the concatenation mechanism |
959f3c4c JH |
23 | ?S: used by the C preprocessor. |
24 | ?S:. | |
25 | ?C:CAT2: | |
5eccb696 | 26 | ?C: This macro concatenates 2 tokens together. |
959f3c4c JH |
27 | ?C:. |
28 | ?C:CAT3: | |
5eccb696 | 29 | ?C: This macro concatenates 3 tokens together. |
959f3c4c JH |
30 | ?C:. |
31 | ?C:CAT4: | |
5eccb696 | 32 | ?C: This macro concatenates 4 tokens together. |
959f3c4c JH |
33 | ?C:. |
34 | ?C:CAT5: | |
5eccb696 | 35 | ?C: This macro concatenates 5 tokens together. |
959f3c4c JH |
36 | ?C:. |
37 | ?C:STRINGIFY: | |
38 | ?C: This macro surrounds its token with double quotes. | |
39 | ?C:. | |
40 | ?C:SCAT2: | |
5eccb696 | 41 | ?C: This macro concatenates 2 tokens together and stringifies the result. |
959f3c4c JH |
42 | ?C: It might not exist, so #ifdef it in your code! |
43 | ?C:. | |
44 | ?C:SCAT3: | |
5eccb696 | 45 | ?C: This macro concatenates 3 tokens together and stringifies the result. |
959f3c4c JH |
46 | ?C: It might not exist, so #ifdef it in your code! |
47 | ?C:. | |
48 | ?C:SCAT4: | |
5eccb696 | 49 | ?C: This macro concatenates 4 tokens together and stringifies the result. |
959f3c4c JH |
50 | ?C: It might not exist, so #ifdef it in your code! |
51 | ?C:. | |
52 | ?C:SCAT5: | |
5eccb696 | 53 | ?C: This macro concatenates 5 tokens together and stringifies the result. |
959f3c4c JH |
54 | ?C: It might not exist, so #ifdef it in your code! |
55 | ?C:. | |
56 | ?X: Dist pl70 included the following, but AIX's xlc compiler | |
57 | ?X: (which is ANSI-ish and has cpp_stuff == 42)) rejects | |
58 | ?X: The SQuoTe/EQuoTe stuff because the string literals are on | |
59 | ?X: separate lines. Sigh. | |
60 | ?X: Andy Dougherty 24 Feb 1998 | |
61 | ?X: ?H:?%<:#if $cpp_stuff == 1 | |
62 | ?X: ?H:?CAT2:#define CAT2(a,b)a/**/b | |
63 | ?X: ?H:?CAT3:#define CAT3(a,b,c)a/**/b/**/c | |
64 | ?X: ?H:?CAT4:#define CAT4(a,b,c,d)a/**/b/**/c/**/d | |
65 | ?X: ?H:?CAT5:#define CAT5(a,b,c,d,e)a/**/b/**/c/**/d/**/e | |
66 | ?X: ?H:?STRINGIFY:#define STRINGIFY(a)"a" | |
67 | ?X: ?H:?%<:#define SQuoTe(a)"a | |
68 | ?X: ?H:?%<:#define EQuoTe(a)a" | |
69 | ?X: ?H:?SCAT2:#define SCAT2(a,b)EQuoTe(SQuoTe(a)b) | |
70 | ?X: ?H:?SCAT3:#define SCAT3(a,b,c)EQuoTe(SQuoTe(a)b/**/c) | |
71 | ?X: ?H:?SCAT4:#define SCAT4(a,b,c,d)EQuoTe(SQuoTe(a)b/**/c/**/d) | |
72 | ?X: ?H:?SCAT5:#define SCAT5(a,b,c,d,e)EQuoTe(SQuoTe(a)b/**/c/**/d/**/e) | |
73 | ?X: ?H:?%<:#endif | |
74 | ?H:?%<:#if $cpp_stuff == 1 | |
fd1a35d0 JH |
75 | ?H:?CAT2:#define CAT2(a,b) a/**/b |
76 | ?H:?CAT3:#define CAT3(a,b,c) a/**/b/**/c | |
77 | ?H:?CAT4:#define CAT4(a,b,c,d) a/**/b/**/c/**/d | |
78 | ?H:?CAT5:#define CAT5(a,b,c,d,e) a/**/b/**/c/**/d/**/e | |
79 | ?H:?STRINGIFY:#define STRINGIFY(a) "a" | |
959f3c4c JH |
80 | ?H:?%<: /* If you can get stringification with catify, tell me how! */ |
81 | ?H:?%<:#endif | |
82 | ?H:?%<:#if $cpp_stuff == 42 | |
fd1a35d0 JH |
83 | ?H:?%<:#define PeRl_CaTiFy(a, b) a ## b |
84 | ?H:?%<:#define PeRl_StGiFy(a) #a | |
2b1f2868 JH |
85 | ?H:?%<:/* the additional level of indirection enables these macros to be |
86 | ?H:?%<: * used as arguments to other macros. See K&R 2nd ed., page 231. */ | |
fd1a35d0 JH |
87 | ?H:?CAT2:#define CAT2(a,b) PeRl_CaTiFy(a,b) |
88 | ?H:?CAT3:#define CAT3(a,b,c) CAT2(PeRl_CaTiFy(a,b),c) | |
89 | ?H:?CAT4:#define CAT4(a,b,c,d) CAT2(CAT3(a,b,c),d) | |
90 | ?H:?CAT5:#define CAT5(a,b,c,d,e) CAT2(CAT4(a,b,c,d),e) | |
91 | ?H:?%<:#define StGiFy(a) PeRl_StGiFy(a) | |
92 | ?H:?STRINGIFY:#define STRINGIFY(a) PeRl_StGiFy(a) | |
93 | ?H:?SCAT2:#define SCAT2(a,b) PeRl_StGiFy(a) PeRl_StGiFy(b) | |
94 | ?H:?SCAT3:#define SCAT3(a,b,c) PeRl_StGiFy(a) PeRl_StGiFy(b) PeRl_StGiFy(c) | |
95 | ?H:?SCAT4:#define SCAT4(a,b,c,d) PeRl_StGiFy(a) PeRl_StGiFy(b) PeRl_StGiFy(c) PeRl_StGiFy(d) | |
96 | ?H:?SCAT5:#define SCAT5(a,b,c,d,e) PeRl_StGiFy(a) PeRl_StGiFy(b) PeRl_StGiFy(c) PeRl_StGiFy(d) PeRl_StGiFy(e) | |
959f3c4c JH |
97 | ?H:?%<:#endif |
98 | ?H:?%<:#if $cpp_stuff != 1 && $cpp_stuff != 42 | |
5eccb696 | 99 | ?H:?%<:# include "Bletch: How does this C preprocessor concatenate tokens?" |
959f3c4c JH |
100 | ?H:?%<:#endif |
101 | ?H:. | |
102 | ?W:%<:CAT2 CAT3 CAT4 CAT5 STRINGIFY SCAT2 SCAT3 SCAT4 SCAT5 | |
103 | ?LINT:known StGiFy | |
fd1a35d0 JH |
104 | ?LINT:known PeRl_CaTiFy |
105 | ?LINT:known PeRl_StGiFy | |
5eccb696 | 106 | : how do we concatenate cpp tokens here? |
959f3c4c | 107 | echo " " |
5eccb696 | 108 | echo "Checking to see how your cpp does stuff like concatenate tokens..." >&4 |
959f3c4c JH |
109 | $cat >cpp_stuff.c <<'EOCP' |
110 | #define RCAT(a,b)a/**/b | |
111 | #define ACAT(a,b)a ## b | |
112 | RCAT(Rei,ser) | |
113 | ACAT(Cir,cus) | |
114 | EOCP | |
115 | $cppstdin $cppflags $cppminus <cpp_stuff.c >cpp_stuff.out 2>&1 | |
116 | if $contains 'Circus' cpp_stuff.out >/dev/null 2>&1; then | |
117 | echo "Oh! Smells like ANSI's been here." >&4 | |
118 | echo "We can catify or stringify, separately or together!" | |
119 | cpp_stuff=42 | |
120 | elif $contains 'Reiser' cpp_stuff.out >/dev/null 2>&1; then | |
121 | echo "Ah, yes! The good old days!" >&4 | |
122 | echo "However, in the good old days we don't know how to stringify and" | |
123 | echo "catify at the same time." | |
124 | cpp_stuff=1 | |
125 | else | |
126 | $cat >&4 <<EOM | |
5eccb696 JH |
127 | Hmm, I don't seem to be able to concatenate tokens with your cpp. |
128 | You're going to have to edit the values of CAT[2-5] in config.h... | |
959f3c4c JH |
129 | EOM |
130 | ?X: It would be nice to have configure remind us at the end that some manual | |
131 | ?X: intervention is needed -- FIXME | |
132 | cpp_stuff="/* Help! How do we handle cpp_stuff? */*/" | |
133 | fi | |
134 | $rm -f cpp_stuff.* | |
135 |