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 # If FLAGS contains a "NAME(...argument...)" flag, return the value
22 # of the argument. Return the empty string otherwise.
23 function opt_args
(name
, flags
)
26 if (flags !~
" " name
"\\(")
28 sub(".* " name
"\\(", "", flags
)
29 sub("\\).*", "", flags
)
34 # Return the Nth comma-separated element of S. Return the empty string
35 # if S does not contain N elements.
36 function nth_arg
(n
, s
)
41 sub("[^,]*, *", "", s
)
47 # Return a bitmask of CL_* values for option flags FLAGS.
48 function switch_flags
(flags
)
52 for (j =
0; j
< n_langs
; j
++) {
53 regex =
" " langs
[j
] " "
54 gsub ( "\\+", "\\+", regex
)
56 result = result
" | " macros
[j
]
58 if (flags ~
" Common ") result = result
" | CL_COMMON"
59 if (flags ~
" Target ") result = result
" | CL_TARGET"
60 if (flags ~
" Joined ") result = result
" | CL_JOINED"
61 if (flags ~
" JoinedOrMissing ") \
62 result = result
" | CL_JOINED | CL_MISSING_OK"
63 if (flags ~
" Separate ") result = result
" | CL_SEPARATE"
64 if (flags ~
" RejectNegative ") result = result
" | CL_REJECT_NEGATIVE"
65 if (flags ~
" UInteger ") result = result
" | CL_UINTEGER"
66 if (flags ~
" Undocumented ") result = result
" | CL_UNDOCUMENTED"
67 if (flags ~
" Report ") result = result
" | CL_REPORT"
68 sub( "^0 \\| ", "", result
)
72 # If FLAGS includes a Var flag, return the name of the variable it specifies.
73 # Return the empty string otherwise.
74 function var_name
(flags
)
76 return nth_arg
(0, opt_args
("Var", flags
))
79 # Given that an option has flags FLAGS, return an initializer for the
80 # "var_cond" and "var_value" fields of its cl_options[] entry.
81 function var_set
(flags
)
83 s = nth_arg
(1, opt_args
("Var", flags
))
85 return "CLVC_EQUAL, " s
86 s = opt_args
("Mask", flags
);
88 return "CLVC_BIT_SET, MASK_" s
89 s = nth_arg
(0, opt_args
("InverseMask", flags
));
91 return "CLVC_BIT_CLEAR, MASK_" s
92 return "CLVC_BOOLEAN, 0"
95 # Given that an option has flags FLAGS, return an initializer for the
96 # "flag_var" field of its cl_options[] entry.
97 function var_ref
(flags
)
99 name = var_name
(flags
)
102 if (opt_args
("Mask", flags
) != "")
103 return "&target_flags"
104 if (opt_args
("InverseMask", flags
) != "")
105 return "&target_flags"