nxxd 1.2 → 1.4

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/nxxd +33 -25
  3. data/lib/nxxd/version.rb +2 -2
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99cd24eb4d74fb9a81fce360616a0a86f6dd0477fa78505a21a4208078462732
4
- data.tar.gz: a87372bd1c459e6e0b723850f428845002a91db0e15e3c822365b4819bbd2de1
3
+ metadata.gz: bbf9ab29dd62c0a7e1f4d08c59fdf54f0e0417b644a4322708a842d2c1f54599
4
+ data.tar.gz: '09993305785a0ef2fe95ceee5d32e0976ce4e96e10e8630d96339e91ad45f1c9'
5
5
  SHA512:
6
- metadata.gz: 1eb13f4df36abd0b7ed1fdff6536c5de1f2f89b93458480a0abd0d0d3c0e0905e59f83b43ddff532ea5c3e4d22eedc1b6683fc18b8026c88d4e1852735a60d59
7
- data.tar.gz: 05a66adf955aea5e81423caf432d98cee8b0df2f54674732ebec58b5f0eeea3943e2deda38edf61f176b929bdaf1be5080922eae7138b2d82cd7fe6827ebe987
6
+ metadata.gz: 58e8a9ba275d34d3f79422060d26b11a5e1d180f24f8c32854eff55607948c37548f063b18e97ffbb3b55665a2199a7a9c93c7348e2b55ef8829982c551e4bd5
7
+ data.tar.gz: 12d11bf3dc4304d1d8abcad03c58211458cb42d6a3eb312be24717cb339fc69d478a398518113986b9dcfca1a3e52471fd36403499919c9e3b9d159335499c81
data/bin/nxxd CHANGED
@@ -18,6 +18,7 @@ module Nxxd
18
18
  "r" => [ :reverse, true, "Reverse operation, pack"],
19
19
  "o" => [ :output, :NAME, "Output file (- = stdout)"],
20
20
  "output" => "o",
21
+ "n" => [ :noclobber, true, "Don't overwrite existing files"],
21
22
  "f" => [ :full, true, "Full output (no squeeze)"],
22
23
  "full" => "f",
23
24
  "a" => [ :full, false, "Abbreviate (squeeze duplicate lines)"],
@@ -47,37 +48,38 @@ module Nxxd
47
48
  attr_reader :opts, :args
48
49
 
49
50
  def initialize params
50
- @opts, @args = {}, []
51
+ @opts = {}
52
+ @args = []
51
53
  env = ENV[ OPT_ENV]
52
54
  if env then
53
- @params = env.split
54
- until @params.empty? do
55
- p = @params.shift
56
- case p
57
- when /^--/ then $'.empty? or set $'
58
- when /^-/ then set_short $'
59
- else set p
60
- end
61
- end
55
+ @params, @args = env.split, []
56
+ parse_params
57
+ @args.empty? or @args.clear
62
58
  end
63
59
  @params = params
60
+ parse_params
61
+ rescue StandardError
62
+ $stderr.puts $!
63
+ exit 1
64
+ ensure
65
+ @params = nil
66
+ end
67
+
68
+ private
69
+
70
+ def parse_params
64
71
  until @params.empty? do
65
72
  p = @params.shift
66
73
  case p
67
- when /^--/ then $'.empty? and break ; set $'
68
- when /^-/ then set_short $'
74
+ when /^--/ then if $'.empty? then break else set $' end
75
+ when /^-/ then if $'.empty? then @args.push p else set_short $' end
69
76
  else @args.push p
70
77
  end
71
78
  end
72
79
  @args.concat @params
73
- @params = nil
74
- rescue StandardError
75
- $stderr.puts $!
76
- exit 1
80
+ @params.clear
77
81
  end
78
82
 
79
- private
80
-
81
83
  def set_short cont
82
84
  @cont = cont
83
85
  until @cont.empty? do
@@ -131,7 +133,7 @@ module Nxxd
131
133
  _, arg, text = *defn
132
134
  type = type_repr arg if Symbol === arg
133
135
  end
134
- puts " %-10s %-10s %s" % [(opt_repr opt), type, text]
136
+ puts " %-16s %-10s %s" % [(opt_repr opt), type, text]
135
137
  }
136
138
  end
137
139
 
@@ -148,13 +150,11 @@ module Nxxd
148
150
  def initialize params
149
151
  o = Options.new params
150
152
  @opts, @args = o.opts, o.args
151
- @inputs = []
152
- @inputs.push @args.shift
153
- @output = (@opts.delete :output) || @args.pop
154
- @inputs.push @args.shift until @args.empty?
155
153
  end
156
154
 
157
155
  def run
156
+ @output = (@opts.delete :output) || last_arg_if_not_existing
157
+ @args.push nil if @args.empty?
158
158
  open_output do |o|
159
159
  if @opts.delete :reverse then
160
160
  open_inputs do |f|
@@ -189,9 +189,14 @@ module Nxxd
189
189
 
190
190
  private
191
191
 
192
+ def last_arg_if_not_existing
193
+ a = @args.last
194
+ @args.pop unless not a or a == "-" or File.exist? a
195
+ end
196
+
192
197
  def open_inputs
193
198
  plain = @opts.delete :plain
194
- @inputs.each do |i|
199
+ @args.each do |i|
195
200
  i = nil if i == "-"
196
201
  if i then
197
202
  @opts[ :input] = i unless plain or @opts[ :reverse]
@@ -208,9 +213,12 @@ module Nxxd
208
213
  end
209
214
 
210
215
  def open_output
216
+ nc = @opts.delete :noclobber
211
217
  o = @output unless @output == "-"
212
218
  if o then
213
- File.open o, "w" do |o| yield o end
219
+ mode = "w"
220
+ mode << "x" if nc
221
+ File.open o, mode do |f| yield f end
214
222
  else
215
223
  yield $stdout
216
224
  end
data/lib/nxxd/version.rb CHANGED
@@ -4,8 +4,8 @@
4
4
 
5
5
  module Nxxd
6
6
 
7
- VERSION = "1.2".freeze
8
- AUTHOR = "(C) 2025 Bertram Scharpf <software@bertram-scharpf.de>"
7
+ VERSION = "1.4".freeze
8
+ AUTHOR = "(C) 2026 Bertram Scharpf <software@bertram-scharpf.de>"
9
9
  LICENSE = "BSD-2-Clause+"
10
10
 
11
11
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nxxd
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-06 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: 'Yet another Xxd reimplementation.
13
13
 
@@ -45,7 +45,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
45
45
  version: '0'
46
46
  requirements:
47
47
  - Just Ruby
48
- rubygems_version: 3.6.3
48
+ rubygems_version: 3.7.1
49
49
  specification_version: 4
50
50
  summary: Hex Dump Tool
51
51
  test_files: []