hsss 0.1.14 → 0.1.19

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 (5) hide show
  1. checksums.yaml +5 -5
  2. data/exe/hsss +3 -0
  3. data/lib/hsss.rb +69 -26
  4. data/lib/hsss/version.rb +1 -1
  5. metadata +6 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c63fa9e158201da35d648e6a03ed4ca5b471387d
4
- data.tar.gz: 6cadb149d7b7ba5089bc3b93364a90c53025272a
2
+ SHA256:
3
+ metadata.gz: 96bbfca29172fb609c9de7699b81e89c02e0b7539e63a5632f963e2202940031
4
+ data.tar.gz: 210afcafd9fd2829ae7cc1865150acd329a175d9b9afc1506dd81d3bd10c9778
5
5
  SHA512:
6
- metadata.gz: f1ceb56c5b93b08394ee2436345e3745b23d534a5a1b1612e4afae5c2268744394540fd30ec87ff516bf0f7b535e447172dbd92fd2f4b52274e02a2be0a5f537
7
- data.tar.gz: 2682f818c6ab443bcb1720ed67a4a931b2c8a1455641937f7e7ad2b6ab271f22ff2c9df490fa7e7856564d154d089be9aa8dd167109bb5058b7943645a5e92f1
6
+ metadata.gz: 1bcda4beaed9ffdd7f9d2e254da451dade55bed7861e6691029d987e0df6e4d469e74091649dbdb3aab77dfb05885c965f03131d7e26174148ecb03ef23aeaf9
7
+ data.tar.gz: 2530fcf8cfcf4b7a5bff064097f16da2de02fc0db0ea32ba7c7270424b3adfa42854c7d4e561acd137aa79ef4fa0961e702cc67b71f51dc857891ff52758ee78
data/exe/hsss CHANGED
@@ -18,6 +18,9 @@ arg=OptionParser.new do |opts|
18
18
  opts.on("--no-each", "Omit the iterator macro"){opt[:skip_each]=true}
19
19
  opts.on("--no-parse", "Skip using luac to check script syntax"){opt[:no_luac]=true}
20
20
  opts.on("--no-static", "Don't make variables static (file-scoped)"){opt[:no_static]=true}
21
+ opts.on("--header-only", "just the header"){opt[:header_only]=true}
22
+ opts.on("--header-guard", "header guard string"){|v|opt[:header_guard]=v}
23
+ opts.on("--data-only", "just the data"){opt[:data_only]=true}
21
24
  opts.on("--prefix [#{Hsss::DEFAULT_PREFIX}]", "Prefix default names with this"){|v| opt[:prefix]=v}
22
25
  end
23
26
  arg.banner=<<EOS
@@ -16,11 +16,11 @@ module Hsss
16
16
  attr_accessor :struct_name, :hashes_struct, :names_struct, :scripts_struct, :count_name, :iter_macro_name, :row_struct_name
17
17
 
18
18
  def cased_prefix(prefix, name)
19
- if name && prefix
19
+ if name
20
20
  if name.upcase == name and name.downcase != name
21
- name = "#{prefix.upcase}#{name}"
21
+ name = "#{(prefix || DEFAULT_PREFIX).upcase}#{name}"
22
22
  else
23
- name = "#{prefix}#{name}"
23
+ name = "#{(prefix || DEFAULT_PREFIX)}#{name}"
24
24
  end
25
25
  end
26
26
  name
@@ -39,9 +39,12 @@ module Hsss
39
39
  names.each do |var, default|
40
40
  send "#{var}=", opt[var]!=false ? opt[var] || cased_prefix(opt[:prefix], default) : false
41
41
  end
42
-
42
+ @static=opt[:no_static] ? "" : "static "
43
+ @header_only = opt[:header_only]
44
+ @data_only = opt[:data_only]
43
45
  @include_count = !opt[:skip_count]
44
46
  @include_iter_macro = !opt[:skip_each]
47
+ @header_guard = opt[:header_guard]
45
48
  @include_hash = !!hashes_struct
46
49
 
47
50
  (Array === files ? files : [ files ]).each do |f|
@@ -122,7 +125,7 @@ module Hsss
122
125
 
123
126
  EOS
124
127
  @struct_fmt= <<-EOS.gsub(/^ {8}/, '')
125
- #{opt[:no_static] ? "" : "static "}#{struct_name} %s = {
128
+ #{@static}#{struct_name} %s = {
126
129
  %s
127
130
  };
128
131
 
@@ -139,28 +142,41 @@ module Hsss
139
142
 
140
143
  def to_s
141
144
  out = ""
145
+ if @header_only
142
146
  out << sprintf(@head, @struct.join("\n"))
143
- if @scripts.count > 0
144
- out << sprintf(@struct_fmt, hashes_struct, @hashed_table.map{|v|" \"#{v}\""}.join(",\n")) if hashes_struct
145
- out << sprintf(@struct_fmt, names_struct, @name_table.map{|v|" \"#{v}\","}.join("\n")) if names_struct
146
- out << sprintf(@struct_fmt, scripts_struct, @script_table.join(",\n\n")) if scripts_struct
147
+ out << "#{@static}#{struct_name} #{hashes_struct};\n" if hashes_struct
148
+ out << "#{@static}#{struct_name} #{names_struct};\n" if names_struct
149
+ out << "#{@static}#{struct_name} #{scripts_struct};\n" if scripts_struct
150
+ out << "const int #{@count_name};\n" if @include_count
151
+ out << iter_macro
147
152
  else
148
- out << "//no scrpts\n"
153
+ out = ""
154
+ out << sprintf(@head, @struct.join("\n")) unless @data_only
155
+ if @scripts.count > 0
156
+ out << sprintf(@struct_fmt, hashes_struct, @hashed_table.map{|v|" \"#{v}\""}.join(",\n")) if hashes_struct
157
+ out << sprintf(@struct_fmt, names_struct, @name_table.map{|v|" \"#{v}\","}.join("\n")) if names_struct
158
+ out << sprintf(@struct_fmt, scripts_struct, @script_table.join(",\n\n")) if scripts_struct
159
+ else
160
+ out << "//no scrpts\n"
161
+ end
162
+ out << "const int #{@count_name}=#{@scripts.count};\n" if @include_count
163
+ out << iter_macro
149
164
  end
150
165
 
151
- out << "const int #{@count_name}=#{@scripts.count};\n" if @include_count
152
-
166
+ out
167
+ end
168
+
169
+ def iter_macro
153
170
  if @include_iter_macro
154
171
  macro = []
155
172
  macro << "#define #{iter_macro_name}(script_src, script_name, script_hash) \\"
156
173
  macro << "for((script_src)=(char **)&#{scripts_struct}, (script_hash)=(char **)&#{hashes_struct}, (script_name)=(char **)&#{names_struct}; (script_src) < (char **)(&#{scripts_struct} + 1); (script_src)++, (script_hash)++, (script_name)++) "
157
- out << macro.join("\n")
174
+ macro.join("\n")
175
+ else
176
+ ""
158
177
  end
159
-
160
- out
161
178
  end
162
179
 
163
-
164
180
  end
165
181
 
166
182
 
@@ -170,7 +186,7 @@ module Hsss
170
186
 
171
187
  def initialize(files, opt={})
172
188
  super
173
- @cout= <<-EOS.gsub(/^ {8}/, '')
189
+ @headf= <<-EOS.gsub(/^ {8}/, '')
174
190
  // don't edit this please, it was auto-generated by hsss
175
191
  // https://github.com/slact/hsss
176
192
 
@@ -182,8 +198,11 @@ module Hsss
182
198
  typedef struct {
183
199
  %s
184
200
  } #{struct_name};
201
+ EOS
202
+ @cout= <<-EOS.gsub(/^ {8}/, '')
203
+ #{@headf}
185
204
 
186
- #{opt[:no_static] ? "" : "static "}#{struct_name} #{scripts_struct} = {
205
+ #{@static}#{struct_name} #{scripts_struct} = {
187
206
  %s
188
207
  };
189
208
 
@@ -198,26 +217,50 @@ module Hsss
198
217
  cquote(script, " ")
199
218
  end
200
219
  def to_s
220
+ out = ""
221
+
201
222
  if @scripts.count > 0
202
223
  scrapts=[]
203
224
  for i in 0...@scripts.count do
204
225
  scrapts<< " {\"#{@name_table[i]}\", #{@include_hash ? "\"#{@hashed_table[i]}\"," : ""}\n#{@script_table[i]}}"
205
226
  end
206
- out=sprintf @cout, @struct.join("\n"), scrapts.join(",\n\n")
207
227
  else
208
- out="//nothing here\n"
228
+ scripties = nil
209
229
  end
210
-
211
- out << "const int #{@count_name}=#{@scripts.count};\n" if @include_count
212
-
230
+ if @header_only
231
+ if @header_guard
232
+ out << "#ifndef #{@header_guard}\n"
233
+ out << "#define #{@header_guard}\n"
234
+ end
235
+ out << sprintf(@headf, @struct.join("\n"))
236
+ out << "#{@static}#{struct_name} #{scripts_struct};\n"
237
+ out << "const int #{@count_name};\n" if @include_count
238
+ out << iter_macro
239
+ if @header_guard
240
+ out << "#endif //#{@header_guard}\n"
241
+ end
242
+ elsif @data_only
243
+ out << "#{@static}#{struct_name} #{scripts_struct} = {\n"
244
+ out << "#{scrapts.join(",\n\n")}\n"
245
+ out << "};\n"
246
+ out << "const int #{@count_name}=#{@scripts.count};\n" if @include_count
247
+ else
248
+ out << sprintf(@cout, (@struct || []).join("\n"), (scrapts || []).join(",\n\n"))
249
+ out << "const int #{@count_name}=#{@scripts.count};\n" if @include_count
250
+ out << iter_macro
251
+ end
252
+ out
253
+ end
254
+
255
+ def iter_macro
213
256
  if @include_iter_macro
214
257
  macro = []
215
258
  macro << "#define #{iter_macro_name}(script) \\"
216
259
  macro << "for((script)=(#{row_struct_name} *)&#{scripts_struct}; (script) < (#{row_struct_name} *)(&#{scripts_struct} + 1); (script)++) "
217
- out << macro.join("\n")
260
+ macro.join("\n")
261
+ else
262
+ ""
218
263
  end
219
-
220
- out
221
264
  end
222
265
 
223
266
  def failed?
@@ -1,3 +1,3 @@
1
1
  module Hsss
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.19"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hsss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leo P.
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-19 00:00:00.000000000 Z
11
+ date: 2020-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -78,7 +78,7 @@ licenses:
78
78
  - MIT
79
79
  metadata:
80
80
  allowed_push_host: https://rubygems.org
81
- post_install_message:
81
+ post_install_message:
82
82
  rdoc_options: []
83
83
  require_paths:
84
84
  - lib
@@ -93,9 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  requirements: []
96
- rubyforge_project:
97
- rubygems_version: 2.6.11
98
- signing_key:
96
+ rubygems_version: 3.1.3
97
+ signing_key:
99
98
  specification_version: 4
100
99
  summary: Hash-Safe Script Splinterer
101
100
  test_files: []