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, ...]
29 BEGIN{ RS=""; FS="\n" }
30 # Ignore comments and blank lines
31 /^[ \t]*(;|$)/ { next }
32 /^[^ \t]/ { gsub ("\n", "\034", $0); print }
33 ' | LANG=C ${SORT} | ${AWK} '
34 function switch_flags (langs, flags)
37 gsub( " ", ":", langs)
39 if (langs ~ ":C:") flags = flags " | CL_C"
40 if (langs ~ ":ObjC:") flags = flags " | CL_OBJC"
41 if (langs ~ ":C\\+\\+:") flags = flags " | CL_CXX"
42 if (langs ~ ":ObjC\\+\\+:") flags = flags " | CL_OBJCXX"
43 if (langs ~ ":Joined") flags = flags " | CL_JOINED"
44 if (langs ~ ":Separate") flags = flags " | CL_SEPARATE"
45 sub( "^0 \\| ", "", flags )
50 c_file = "'${C_FILE}'"
51 h_file = "'${H_FILE}'"
53 print "/* This file is auto-generated by opts.sh. */\n" > h_file
54 print "/* This file is auto-generated by opts.sh. */\n" > c_file
55 print "struct cl_option\n{" >> h_file
56 print " const char *opt_text;" >> h_file
57 print " unsigned char opt_len;" >> h_file
58 print " unsigned char flags;" >> h_file
59 print "};\n" >> h_file
60 print "enum opt_code\n{" >> h_file
61 print "static const struct cl_option cl_options[] =\n{" >> c_file
66 gsub ( "[^A-Za-z0-9]", "_", opt)
67 s = substr (" ", length (opt))
69 printf (" %s,%s/* -%s */\n", enum, s, $1 ) >> h_file
70 printf (" { \"%s\", %u, %s },\n", $1, \
71 length ($1), switch_flags($2)) >> c_file
75 print " N_OPTS\n};" >> h_file