1 # Copyright (C) 2003,2004 Free Software Foundation, Inc.
2 # Contributed by Kelley Cook, June 2004.
3 # Original code from Neil Booth, May 2003.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2, or (at your option) any
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 # Some common subroutines for use by opt[ch]-gen.awk.
21 # Return nonzero if FLAGS contains a flag matching REGEX.
22 function flag_set_p
(regex
, flags
)
24 return (" " flags
" ") ~
(" " regex
" ")
27 # Return STRING if FLAGS contains a flag matching regexp REGEX,
28 # otherwise return the empty string.
29 function test_flag
(regex
, flags
, string
)
31 if (flag_set_p
(regex
, flags
))
36 # If FLAGS contains a "NAME(...argument...)" flag, return the value
37 # of the argument. Return the empty string otherwise.
38 function opt_args
(name
, flags
)
41 if (flags !~
" " name
"\\(")
43 sub(".* " name
"\\(", "", flags
)
44 sub("\\).*", "", flags
)
49 # Return the Nth comma-separated element of S. Return the empty string
50 # if S does not contain N elements.
51 function nth_arg
(n
, s
)
56 sub("[^,]*, *", "", s
)
62 # Return a bitmask of CL_* values for option flags FLAGS.
63 function switch_flags
(flags
)
66 for (j =
0; j
< n_langs
; j
++) {
68 gsub ( "\\+", "\\+", regex
)
69 result = result test_flag
(regex
, flags
, " | " macros
[j
])
72 test_flag
("Common", flags
, " | CL_COMMON") \
73 test_flag
("Target", flags
, " | CL_TARGET") \
74 test_flag
("Joined", flags
, " | CL_JOINED") \
75 test_flag
("JoinedOrMissing", flags
, " | CL_JOINED | CL_MISSING_OK") \
76 test_flag
("Separate", flags
, " | CL_SEPARATE") \
77 test_flag
("RejectNegative", flags
, " | CL_REJECT_NEGATIVE") \
78 test_flag
("UInteger", flags
, " | CL_UINTEGER") \
79 test_flag
("Undocumented", flags
, " | CL_UNDOCUMENTED") \
80 test_flag
("Report", flags
, " | CL_REPORT")
81 sub( "^0 \\| ", "", result
)
85 # If FLAGS includes a Var flag, return the name of the variable it specifies.
86 # Return the empty string otherwise.
87 function var_name
(flags
)
89 return nth_arg
(0, opt_args
("Var", flags
))
92 # Given that an option has flags FLAGS, return an initializer for the
93 # "var_cond" and "var_value" fields of its cl_options[] entry.
94 function var_set
(flags
)
96 s = nth_arg
(1, opt_args
("Var", flags
))
98 return "CLVC_EQUAL, " s
99 s = opt_args
("Mask", flags
);
101 return "CLVC_BIT_SET, MASK_" s
102 s = nth_arg
(0, opt_args
("InverseMask", flags
));
104 return "CLVC_BIT_CLEAR, MASK_" s
105 return "CLVC_BOOLEAN, 0"
108 # Given that an option has flags FLAGS, return an initializer for the
109 # "flag_var" field of its cl_options[] entry.
110 function var_ref
(flags
)
112 name = var_name
(flags
)
115 if (opt_args
("Mask", flags
) != "")
116 return "&target_flags"
117 if (opt_args
("InverseMask", flags
) != "")
118 return "&target_flags"