3 # Copyright (C) 2003 Free Software Foundation, Inc.
4 # Contributed by Neil Booth, May 2003.
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation; either version 2, or (at your option) any
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 # Usage: opts.sh outfile.c outfile.h file1.opt [file2.opt, ...]
22 # Always operate in the C locale.
26 export LANG LANGUAGE LC_ALL
28 # Set AWK if environment has not already set it.
31 SORT=sort # Could be /bin/sort or /usr/bin/sort
37 BEGIN{ RS=""; FS="\n" }
38 # Ignore comments and blank lines
39 /^[ \t]*(;|$)/ { next }
40 /^[^ \t]/ { gsub ("\n", "\034", $0); print }
41 ' | ${SORT} | ${AWK} '
42 function switch_flags (langs, flags)
45 gsub( " ", ":", langs)
47 if (langs ~ ":C:") flags = flags " | CL_C"
48 if (langs ~ ":ObjC:") flags = flags " | CL_OBJC"
49 if (langs ~ ":C\\+\\+:") flags = flags " | CL_CXX"
50 if (langs ~ ":ObjC\\+\\+:") flags = flags " | CL_OBJCXX"
51 if (langs ~ ":Joined:") flags = flags " | CL_JOINED"
52 if (langs ~ ":Separate:") flags = flags " | CL_SEPARATE"
53 if (langs ~ ":RejectNegative:") flags = flags " | CL_REJECT_NEGATIVE"
54 sub( "^0 \\| ", "", flags )
59 c_file = "'${C_FILE}'"
60 h_file = "'${H_FILE}'"
62 print "/* This file is auto-generated by opts.sh. */\n" > h_file
63 print "/* This file is auto-generated by opts.sh. */\n" > c_file
64 print "struct cl_option\n{" >> h_file
65 print " const char *opt_text;" >> h_file
66 print " unsigned char opt_len;" >> h_file
67 print " unsigned char flags;" >> h_file
68 print "};\n" >> h_file
69 print "enum opt_code\n{" >> h_file
70 print "static const struct cl_option cl_options[] =\n{" >> c_file
75 gsub ( "[^A-Za-z0-9]", "_", opt)
76 s = substr (" ", length (opt))
78 printf (" %s,%s/* -%s */\n", enum, s, $1 ) >> h_file
79 printf (" { \"%s\", %u, %s },\n", $1, \
80 length ($1), switch_flags($2)) >> c_file
84 print " N_OPTS\n};" >> h_file