]>
Commit | Line | Data |
---|---|---|
e8b212b8 | 1 | # Copyright (C) 2003,2004 Free Software Foundation, Inc. |
2 | # Contributed by Kelley Cook, June 2004. | |
3 | # Original code from Neil Booth, May 2003. | |
4 | # | |
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 | |
8 | # later version. | |
9 | # | |
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. | |
14 | # | |
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. | |
18 | ||
19 | # This Awk script reads in the option records generated from | |
20 | # opt-gather.awk, combines the flags of duplicat options and generates a | |
21 | # C file. | |
22 | # | |
23 | # This program uses functions from opt-functions.awk | |
24 | # | |
25 | # Usage: awk -f opt-functions.awk -f optc-gen.awk \ | |
26 | # [-v header_name=header.h] < inputfile > options.c | |
27 | ||
28 | BEGIN { | |
29 | n_opts = 0 | |
30 | n_langs = 0 | |
31 | quote = "\042" | |
32 | comma = "," | |
33 | FS=SUBSEP | |
34 | # Default the name of header created from opth-gen.awk to options.h | |
35 | if (header_name == "") header_name="options.h" | |
36 | } | |
37 | ||
38 | # Collect the text and flags of each option into an array | |
39 | { | |
40 | if ($1 == "Language") { | |
41 | langs[n_langs] = $2 | |
42 | n_langs++; | |
43 | } | |
44 | else { | |
a9341855 | 45 | name = opt_args("Mask", $1) |
46 | if (name == "") { | |
47 | opts[n_opts] = $1 | |
48 | flags[n_opts] = $2 | |
49 | help[n_opts] = $3 | |
50 | n_opts++; | |
51 | } | |
e8b212b8 | 52 | } |
53 | } | |
54 | ||
55 | # Dump that array of options into a C file. | |
56 | END { | |
57 | print "/* This file is auto-generated by opts.sh. */" | |
58 | print "" | |
59 | print "#include <intl.h>" | |
60 | print "#include " quote header_name quote | |
61 | print "#include " quote "opts.h" quote | |
62 | print "" | |
63 | ||
64 | for (i = 0; i < n_opts; i++) { | |
65 | name = var_name(flags[i]); | |
66 | if (name == "") | |
67 | continue; | |
68 | ||
a150399d | 69 | if (flag_set_p("VarExists", flags[i])) |
e8b212b8 | 70 | continue; |
71 | ||
a150399d | 72 | init = opt_args("Init", flags[i]) |
73 | if (init != "") | |
74 | init = " = " init; | |
c5e839cb | 75 | else if (name in var_seen) |
76 | continue; | |
a150399d | 77 | |
78 | printf ("/* Set by -%s.\n %s */\nint %s%s;\n\n", | |
e8b212b8 | 79 | opts[i], help[i], name,init) |
c5e839cb | 80 | |
81 | var_seen[name] = 1; | |
a150399d | 82 | } |
e8b212b8 | 83 | |
84 | ||
85 | print "const char * const lang_names[] =\n{" | |
86 | for (i = 0; i < n_langs; i++) { | |
87 | macros[i] = "CL_" langs[i] | |
88 | gsub( "[^A-Za-z0-9_]", "X", macros[i] ) | |
89 | s = substr(" ", length (macros[i])) | |
90 | print " " quote langs[i] quote "," | |
91 | } | |
92 | ||
93 | print " 0\n};\n" | |
94 | print "const unsigned int cl_options_count = N_OPTS;\n" | |
95 | ||
96 | print "const struct cl_option cl_options[] =\n{" | |
97 | ||
98 | for (i = 0; i < n_opts; i++) | |
99 | back_chain[i] = "N_OPTS"; | |
100 | ||
101 | for (i = 0; i < n_opts; i++) { | |
102 | # Combine the flags of identical switches. Switches | |
103 | # appear many times if they are handled by many front | |
104 | # ends, for example. | |
105 | while( i + 1 != n_opts && opts[i] == opts[i + 1] ) { | |
106 | flags[i + 1] = flags[i] " " flags[i + 1]; | |
107 | i++; | |
108 | } | |
109 | ||
110 | len = length (opts[i]); | |
111 | enum = "OPT_" opts[i] | |
112 | if (opts[i] == "finline-limit=") | |
113 | enum = enum "eq" | |
114 | gsub ("[^A-Za-z0-9]", "_", enum) | |
115 | ||
116 | # If this switch takes joined arguments, back-chain all | |
117 | # subsequent switches to it for which it is a prefix. If | |
118 | # a later switch S is a longer prefix of a switch T, T | |
119 | # will be back-chained to S in a later iteration of this | |
120 | # for() loop, which is what we want. | |
a150399d | 121 | if (flag_set_p("Joined.*", flags[i])) { |
e8b212b8 | 122 | for (j = i + 1; j < n_opts; j++) { |
123 | if (substr (opts[j], 1, len) != opts[i]) | |
124 | break; | |
125 | back_chain[j] = enum; | |
126 | } | |
127 | } | |
128 | ||
129 | s = substr(" ", length (opts[i])) | |
130 | if (i + 1 == n_opts) | |
131 | comma = "" | |
132 | ||
133 | if (help[i] == "") | |
134 | hlp = "0" | |
135 | else | |
b1fcce27 | 136 | hlp = quote help[i] quote; |
e8b212b8 | 137 | |
138 | printf(" { %c-%s%c,\n %s,\n %s, %u, %s, %s, %s }%s\n", | |
139 | quote, opts[i], quote, hlp, back_chain[i], len, | |
140 | switch_flags(flags[i]), | |
141 | var_ref(flags[i]), var_set(flags[i]), comma) | |
142 | } | |
143 | ||
144 | print "};" | |
145 | } |