optgen 0.4 → 0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/optgen +62 -4
- metadata +2 -2
data/bin/optgen
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
2
|
|
|
3
3
|
#
|
|
4
|
-
# Copyright 2015-
|
|
4
|
+
# Copyright 2015-2018 Jyri J. Virkki <jyri@virkki.com>
|
|
5
5
|
#
|
|
6
6
|
# This file is part of optgen.
|
|
7
7
|
#
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
# along with optgen. If not, see <http://www.gnu.org/licenses/>.
|
|
20
20
|
#
|
|
21
21
|
|
|
22
|
-
$VERSION = '0.
|
|
22
|
+
$VERSION = '0.5'
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
#-----------------------------------------------------------------------------
|
|
@@ -135,6 +135,9 @@ class Command
|
|
|
135
135
|
# name of the command as given in the config file
|
|
136
136
|
attr_reader :name
|
|
137
137
|
|
|
138
|
+
# true if this is a hidden command
|
|
139
|
+
attr_reader :hidden
|
|
140
|
+
|
|
138
141
|
# human readable description as given in the config file
|
|
139
142
|
attr_reader :description
|
|
140
143
|
|
|
@@ -153,6 +156,10 @@ class Command
|
|
|
153
156
|
@description = $2.strip if ($2)
|
|
154
157
|
@options = Array.new()
|
|
155
158
|
@longest_option = 0
|
|
159
|
+
if (@name[0..1] == "H:")
|
|
160
|
+
@hidden = true
|
|
161
|
+
@name = @name[2..-1]
|
|
162
|
+
end
|
|
156
163
|
end
|
|
157
164
|
|
|
158
165
|
#---------------------------------------------------------------------------
|
|
@@ -194,7 +201,8 @@ class OptGen
|
|
|
194
201
|
line.chomp!
|
|
195
202
|
line.strip!
|
|
196
203
|
next if (line == "")
|
|
197
|
-
# depending on the ruby version, char from string may return
|
|
204
|
+
# depending on the ruby version, char from string may return
|
|
205
|
+
# a char or an int... sigh...
|
|
198
206
|
next if (line[0] == '#' || line[0] == 35)
|
|
199
207
|
|
|
200
208
|
if (line[0] == '[' || line[0] == 91)
|
|
@@ -315,6 +323,22 @@ ENDHEADER
|
|
|
315
323
|
o.puts "#include <stdlib.h>"
|
|
316
324
|
o.puts
|
|
317
325
|
|
|
326
|
+
# Print info about which option letters are not taken
|
|
327
|
+
alphanum = ('a'..'z').to_a + ('A'..'Z').to_a + ('0'..'9').to_a
|
|
328
|
+
o.puts "//"
|
|
329
|
+
o.puts "// The following short options are NOT yet taken:"
|
|
330
|
+
o.print "// "
|
|
331
|
+
alphanum.each { |c|
|
|
332
|
+
if (@allargs[c])
|
|
333
|
+
o.print "."
|
|
334
|
+
else
|
|
335
|
+
o.print "#{c}"
|
|
336
|
+
end
|
|
337
|
+
}
|
|
338
|
+
o.puts
|
|
339
|
+
o.puts "//"
|
|
340
|
+
o.puts
|
|
341
|
+
|
|
318
342
|
# Define constants OPT_* for each known option
|
|
319
343
|
n = 0
|
|
320
344
|
o.puts "#define COUNT_OPTIONS #{@options.size}"
|
|
@@ -423,6 +447,21 @@ ENDHEADER
|
|
|
423
447
|
o.puts 'char opt_char(char * str, char def);'
|
|
424
448
|
o.puts
|
|
425
449
|
|
|
450
|
+
o.puts '/**'
|
|
451
|
+
o.puts ' * Convenience function to string value of an option'
|
|
452
|
+
o.puts ' *'
|
|
453
|
+
o.puts ' * Parameters:'
|
|
454
|
+
o.puts ' * str - A value from options array'
|
|
455
|
+
o.puts ' * def - Default value if none given'
|
|
456
|
+
o.puts ' *'
|
|
457
|
+
o.puts ' * Return:'
|
|
458
|
+
o.puts ' *'
|
|
459
|
+
o.puts ' * Value of option as char *. If NULL, returns default def.'
|
|
460
|
+
o.puts ' *'
|
|
461
|
+
o.puts ' */'
|
|
462
|
+
o.puts 'char * opt_string(char * str, char * def);'
|
|
463
|
+
o.puts
|
|
464
|
+
|
|
426
465
|
o.puts '/**'
|
|
427
466
|
o.puts ' * Show help based on command and option descriptions.'
|
|
428
467
|
o.puts ' *'
|
|
@@ -457,7 +496,11 @@ ENDHEADER
|
|
|
457
496
|
o.puts
|
|
458
497
|
o.puts '// LCOV_EXCL_START'
|
|
459
498
|
o.puts
|
|
460
|
-
o.
|
|
499
|
+
o.print 'char * numstring[] = { '
|
|
500
|
+
1.upto(50) {|n|
|
|
501
|
+
o.print "\"#{n}\","
|
|
502
|
+
}
|
|
503
|
+
o.puts ' "X" };'
|
|
461
504
|
o.puts
|
|
462
505
|
|
|
463
506
|
# Define the options allowed by each command
|
|
@@ -575,6 +618,10 @@ ENDHEADER
|
|
|
575
618
|
o.puts " options[#{n}] = numstring[0];"
|
|
576
619
|
o.puts ' } else {'
|
|
577
620
|
o.puts " options[#{n}] = numstring[atoi(options[#{n}])];"
|
|
621
|
+
o.puts " if (!strcmp(options[#{n}], \"X\")) {"
|
|
622
|
+
o.puts " printf(\"error: option %s repeated too many times!\\n\", argv[pos]);"
|
|
623
|
+
o.puts ' exit(1);'
|
|
624
|
+
o.puts ' }'
|
|
578
625
|
o.puts ' }'
|
|
579
626
|
o.puts ' pos++;'
|
|
580
627
|
end
|
|
@@ -653,11 +700,22 @@ ENDHEADER
|
|
|
653
700
|
o.puts '}'
|
|
654
701
|
o.puts
|
|
655
702
|
|
|
703
|
+
o.puts 'char * opt_string(char * str, char * def)'
|
|
704
|
+
o.puts '{'
|
|
705
|
+
o.puts ' if (str == NULL) {'
|
|
706
|
+
o.puts ' return def;'
|
|
707
|
+
o.puts ' } else {'
|
|
708
|
+
o.puts ' return str;'
|
|
709
|
+
o.puts ' }'
|
|
710
|
+
o.puts '}'
|
|
711
|
+
o.puts
|
|
712
|
+
|
|
656
713
|
o.puts 'void opt_show_help()'
|
|
657
714
|
o.puts '{'
|
|
658
715
|
|
|
659
716
|
@commands.each { |command|
|
|
660
717
|
next if (command.name == "GLOBAL")
|
|
718
|
+
next if (command.hidden)
|
|
661
719
|
|
|
662
720
|
line = command.name
|
|
663
721
|
line = line + " " * (2 + @longest_command - command.name.length)
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: optgen
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '0.
|
|
4
|
+
version: '0.5'
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2018-02-13 00:00:00.000000000 Z
|
|
13
13
|
dependencies: []
|
|
14
14
|
description: Generate C code to parse command line options
|
|
15
15
|
email: jyri@virkki.com
|