Debian Codegraph @

easel/devkit/c2optlist

raw
1 #! /usr/bin/perl
2
3
4 # c2optlist <main .c file>
5 #
6 # From one of our "standardized" main C files containing an
7 # ESL_OPTIONS block, print a table listing each option.
8 # Only the first block in the file is parsed, if multiple
9 # ones exist.
10 #
11 # Crosscomparisons with man2optlist and sqc2optlist allow verification
12 # that the options in a main .c file are documented in a .man page
13 # and tested in a .sqc unit test file.
14 #
15 # Options are looked for following a line
16 # static ESL_OPTIONS ...
17 # until a bare
18 # }
19 # is found on a line by itself.
20 #
21 # SRE, Tue Sep 15 10:04:30 2009 [Janelia]
22 # SVN $Id$
23 #
24
25
26 while (<>)
27 {
28 if (/^static ESL_OPTIONS/) { $in_optionblock = 1; next; }
29
30 if ($in_optionblock)
31 {
32 if (/^\s*{\s*"(-\S)",\s*([^,]+),/) { $option = $1; $arg = $2; } # short option
33 elsif (/^\s*{\s*"(--\S+)",\s*([^,]+),/) { $option = $1; $arg = $2; } # long option
34 elsif (/^\s*$/) { next; } # blank line
35 elsif (/^\s*\/\*/) { next; } # comment line
36 elsif (/^#if/) { next; } # allow conditional compilation of options
37 elsif (/^#end/) { next; } # allow conditional compilation of options
38 elsif (/^\s*{\s*0,\s*0,\s*0,/) { last; } # empty vector: end of options
39 else { die "unrecognized option line:\n$_"; }
40
41 if ($arg eq "eslARG_NONE") { $optarg = "-"; }
42 elsif ($arg eq "eslARG_INT") { $optarg = "<n>"; }
43 elsif ($arg eq "eslARG_REAL") { $optarg = "<x>"; }
44 elsif ($arg eq "eslARG_CHAR") { $optarg = "<c>"; }
45 elsif ($arg eq "eslARG_STRING") { $optarg = "<s>"; }
46 elsif ($arg eq "eslARG_INFILE") { $optarg = "<f>"; }
47 elsif ($arg eq "eslARG_OUTFILE") { $optarg = "<f>"; }
48 else { die "unrecognized option argument $arg on line:\n$_"; }
49
50 printf ("%-20s %s\n", $option, $optarg);
51 }
52
53 if (/^};/) { die "Reached end of option structure without seeing empty 0,0,0,... vector"; }
54 }
55
56
57
58