xref: /openbsd/gnu/usr.bin/perl/t/lib/h2ph.h (revision 5486feef)
1 /*
2  * Test header file for h2ph
3  *
4  * Try to test as many constructs as possible
5  * For example, the multi-line comment :)
6  */
7 
8 /* And here's a single line comment :) */
9 
10 /* Test #define with no indenting, over multiple lines */
11 #define SQUARE(x) \
12 ((x)*(x))
13 
14 /* Test #ifndef and parameter interpretation*/
15 #ifndef ERROR
16 #define ERROR(x) fprintf(stderr, "%s\n", x[2][3][0])
17 #endif /* ERROR */
18 
19 /* check for correct order of definitions vs. conditionals */
20 #ifdef NOT_DEFINED_HERE()
21     /* handle indented directives */
22     #error "NOT_DEFINED_HERE should not be defined at this point!"
23 #endif
24 
25 /* function-like macro with no parameters, outside of any conditional */
26 #define NOT_DEFINED_HERE() 42
27 
28 #ifndef _H2PH_H_
29 #define _H2PH_H_
30 
31 /* #ident - doesn't really do anything, but I think it always gets included anyway */
32 #ident "$Revision h2ph.h,v 1.0 98/05/04 20:42:14 billy $"
33 
34 /* Test #undef */
35 #undef MAX
36 #define MAX(a,b) ((a) > (b) ? (a) : (b))
37 
38 /* Test #undef'ining an existing constant function */
39 #define NOTTRUE 0
40 #undef NOTTRUE
41 
42 /* Test #ifdef */
43 #ifdef __SOME_UNIMPORTANT_PROPERTY
44 #define MIN(a,b) ((a) < (b) ? (a) : (b))
45 #endif /* __SOME_UNIMPORTANT_PROPERTY */
46 
47 /*
48  * Test #if, #elif, #else, #endif, #warn and #error, and '!'
49  * Also test whitespace between the '#' and the command
50  */
51 #if !(defined __SOMETHING_MORE_IMPORTANT)
52 #    warn Be careful...
53 #elif !(defined __SOMETHING_REALLY_REALLY_IMPORTANT)
54 #    error "Nup, can't go on" /* ' /* stupid font-lock-mode */
55 #else /* defined __SOMETHING_MORE_IMPORTANT && defined __SOMETHING_REALLY_REALLY_IMPORTANT */
56 #    define EVERYTHING_IS_OK
57 #endif
58 
59 /* Test && and || */
60 #undef WHATEVER
61 #if (!((defined __SOMETHING_TRIVIAL && defined __SOMETHING_LESS_SO)) \
62      || defined __SOMETHING_OVERPOWERING)
63 #    define WHATEVER 6
64 #elif !(defined __SOMETHING_TRIVIAL) /* defined __SOMETHING_LESS_SO */
65 #    define WHATEVER 7
66 #elif !(defined __SOMETHING_LESS_SO) /* defined __SOMETHING_TRIVIAL */
67 #    define WHATEVER 8
68 #else /* defined __SOMETHING_TRIVIAL && defined __SOMETHING_LESS_SO */
69 #    define WHATEVER 1000
70 #endif
71 
72 /* Test passing through the alien constructs (perlbug #34493) */
73 #ifdef __LANGUAGE_PASCAL__
74 function Tru64_Pascal(n: Integer): Integer;
75 #endif
76 
77 /*
78  * Test #include, #import and #include_next
79  * #include_next is difficult to test, it really depends on the actual
80  *  circumstances - for example, '#include_next <limits.h>' on a Linux system
81  *  with 'use lib qw(/opt/perl5/lib/site_perl/i586-linux/linux);' or whatever
82  *  your equivalent is...
83  */
84 #if 0
85 #include <sys/socket.h>
86 #import "sys/ioctl.h"
87 #include_next <sys/fcntl.h>
88 #endif
89 
90 /* typedefs should be ignored */
91 typedef struct a_struct {
92   int typedefs_should;
93   char be_ignored;
94   long as_well;
95 } a_typedef;
96 
97 /*
98  * however, typedefs of enums and just plain enums should end up being treated
99  * like a bunch of #defines...
100  */
101 
102 typedef enum _days_of_week { sun, mon, tue, wed, thu, fri, sat, Sun=0, Mon,
103                              Tue, Wed, Thu, Fri, Sat } days_of_week;
104 
105 /*
106  * Some moderate flexing of tri-graph pre substitution.
107  */
108 ??=ifndef _SOMETHING_TRIGRAPHIC
109 ??=define _SOMETHING_TRIGRAPHIC
110 ??= define SOMETHING_ELSE_TRIGRAPHIC_0 "??!"          /* | ??!|  || */
111  ??=define SOMETHING_ELSE_TRIGRAPHIC_1 "??'"          /* | ??'|  ^| */
112 ??= define SOMETHING_ELSE_TRIGRAPHIC_2 "??("          /* | ??(|  [| */
113  ??= define SOMETHING_ELSE_TRIGRAPHIC_3 "??)"         /* | ??)|  ]| */
114 ??=define SOMETHING_ELSE_TRIGRAPHIC_4  "??-0"         /* | ??-|  ~| */
115         ??= define SOMETHING_ELSE_TRIGRAPHIC_5 "??/ " /* | ??/|  \| */
116 ??= define SOMETHING_ELSE_TRIGRAPHIC_6 "??<"          /* | ??<|  {| */
117 ??=define SOMETHING_ELSE_TRIGRAPHIC_7  "??="          /* | ??=|  #| */
118 ??= define SOMETHING_ELSE_TRIGRAPHIC_8 "??>"          /* | ??>|  }| */
119         ??=endif
120 
121 // test C++-style comment
122 
123 #if 1
124 typdef struct empty_struct {
125 } // trailing C++-style comment should not force continuation
126 #endif
127 
128 /* comments (that look like string) inside enums... */
129 
130 enum {
131    /* foo;
132      can't
133    */
134  };
135 
136 enum flimflam {
137   flim,
138    /* foo;
139      can't
140    */
141   flam
142  } flamflim;
143 
blli_in_use(struct atm_blli blli)144 static __inline__ int blli_in_use(struct atm_blli blli)
145 {
146   return blli.l2_proto || blli.l3_proto;
147 }
148 
149 /* Handle multi-line quoted strings: */
150 __asm__ __volatile__("
151     this
152     produces
153     no
154     output
155 ");
156 
157 #define multiline "multiline
158 string"
159 
160 #endif /* _H2PH_H_ */
161