hsss 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/hsss +24 -0
- data/hsss.gemspec +46 -0
- data/lib/hsss/version.rb +3 -0
- data/lib/hsss.rb +119 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e18cdde9d547acb2420ff5683d4f45efc4594049
|
4
|
+
data.tar.gz: 234f8ff81da11391c1ed79ef8b2f8ec721e07078
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1df99a643094b33149a334346c2ce427cef4ef42f2fca1de45dd603211b9f20acc0aac431770b056e3bcfec6a4b71a61b7c696deb1176ba3622438fc5e2a64d8
|
7
|
+
data.tar.gz: 1fe5bb54fe45e6037552d0642ef5cbff15ee6c07032c7f06428b3f25261d359916fab87e11ace41f8e8f96e4ac18f7ff07a1d8641474c6c29fc27640426f0ab8
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
In the spirit of inclusiveness, cooperation and community, this gem is
|
2
|
+
distributed with the strictly enforced CYHTFYW Code of Conduct. Failure to
|
3
|
+
comply with this code may result in punitive action and angry bees.
|
4
|
+
|
5
|
+
CYHTFYW Code of Conduct:
|
6
|
+
1. Conduct yourself however the fuck you want.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Authored in 2016 by Leo Ponomarev
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Hsss
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/hsss`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'hsss'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install hsss
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/hsss.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hsss"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/hsss
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'hsss'
|
3
|
+
require "optparse"
|
4
|
+
opt={}
|
5
|
+
|
6
|
+
arg=OptionParser.new do |opts|
|
7
|
+
opts.on("--struct [#{Hsss::DEFAULT_STRUCT_NAME}]", "C struct name"){|v| opt[:struct_name]= v}
|
8
|
+
opts.on("--scripts [#{Hsss::DEFAULT_SCRIPTS_NAME}]", "Scripts variable"){|v| opt[:scripts_name]=v}
|
9
|
+
opts.on("--hashes [#{Hsss::DEFAULT_HASHES_NAME}]", "Hashes variable"){|v| opt[:hashes_name]=v}
|
10
|
+
opts.on("--names [#{Hsss::DEFAULT_NAMES_NAME}]", "Script names variable"){|v| opt[:names_name]=v}
|
11
|
+
opts.on("--no-parse", "Skip using luac to check script syntax"){opt[:no_luac]=true}
|
12
|
+
opts.on("--prefix PREFIX", "Prefix default names with this"){|v| opt[:prefix]=v}
|
13
|
+
end
|
14
|
+
arg.banner=<<EOS
|
15
|
+
Hash-Safe Script Splinterer, a Lua Script and hash embedder into C source.
|
16
|
+
Good for putting Redis Lua scripts in your C headers.
|
17
|
+
Usage: hsss [options] files
|
18
|
+
EOS
|
19
|
+
|
20
|
+
rest = arg.parse!
|
21
|
+
|
22
|
+
hsss = Hsss::Hsss.new(rest, opt)
|
23
|
+
|
24
|
+
puts hsss.to_s
|
data/hsss.gemspec
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hsss/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hsss"
|
8
|
+
spec.version = Hsss::VERSION
|
9
|
+
spec.authors = ["Leo P."]
|
10
|
+
spec.email = ["junk@slact.net"]
|
11
|
+
|
12
|
+
spec.summary = %q{Hash-Safe Script Splinter}
|
13
|
+
spec.description = %q{Transforms Lua files into structs of C-strings and associated headers. Great for embedding Redis Lua scripts.}
|
14
|
+
spec.homepage = "https://github.com/slact/hsss"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
dependencies = [
|
31
|
+
#[:runtime, ""],
|
32
|
+
[:development, "bundler"],
|
33
|
+
[:development, "rake"],
|
34
|
+
[:development, "pry"],
|
35
|
+
[:development, "pry-debundle"]
|
36
|
+
]
|
37
|
+
|
38
|
+
dependencies.each do |type, name, version|
|
39
|
+
if spec.respond_to?("add_#{type}_dependency")
|
40
|
+
spec.send("add_#{type}_dependency", name, version)
|
41
|
+
else
|
42
|
+
spec.add_dependency(name, version)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
data/lib/hsss/version.rb
ADDED
data/lib/hsss.rb
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
require "hsss/version"
|
2
|
+
require 'digest/sha1'
|
3
|
+
|
4
|
+
module Hsss
|
5
|
+
DEFAULT_STRUCT_NAME="redis_lua_script_t"
|
6
|
+
DEFAULT_HASHES_NAME="redis_lua_hashes"
|
7
|
+
DEFAULT_NAMES_NAME="redis_lua_script_names"
|
8
|
+
DEFAULT_SCRIPTS_NAME="redis_lua_scripts"
|
9
|
+
|
10
|
+
class Hsss
|
11
|
+
EXT="lua"
|
12
|
+
|
13
|
+
attr_accessor :struct_name, :hashes_struct, :names_struct, :scripts_struct
|
14
|
+
def initialize(files, opt={})
|
15
|
+
@scripts={}
|
16
|
+
|
17
|
+
{ struct_name: DEFAULT_STRUCT_NAME,
|
18
|
+
hashes_struct: DEFAULT_HASHES_NAME,
|
19
|
+
names_struct: DEFAULT_NAMES_NAME,
|
20
|
+
scripts_struct: DEFAULT_SCRIPTS_NAME }.each do |var, default|
|
21
|
+
send "#{var}=", opt[var] || default
|
22
|
+
end
|
23
|
+
|
24
|
+
if opt[:prefix]
|
25
|
+
[:struct_name, :hashes_struct, :names_struct, :scripts_struct].each do |var|
|
26
|
+
send "#{var}=", "#{opt[:prefix]}#{send var}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
(Array === files ? files : [ files ]).each do |f|
|
31
|
+
begin
|
32
|
+
file_contents = IO.read f
|
33
|
+
if opt[:no_luac] or check_script(f)
|
34
|
+
@scripts[File.basename(f, ".#{EXT}") .to_sym]=file_contents
|
35
|
+
end
|
36
|
+
rescue Errno::ENOENT => e
|
37
|
+
STDERR.puts "Failed to open file #{f}"
|
38
|
+
@failed = true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
@cout= <<-EOS.gsub(/^ {8}/, '')
|
43
|
+
//don't edit this please, it was auto-generated
|
44
|
+
|
45
|
+
typedef struct {
|
46
|
+
%s
|
47
|
+
} #{struct_name};
|
48
|
+
|
49
|
+
static #{struct_name} #{hashes_struct} = {
|
50
|
+
%s
|
51
|
+
};
|
52
|
+
|
53
|
+
#define REDIS_LUA_HASH_LENGTH %i
|
54
|
+
|
55
|
+
static #{struct_name} #{names_struct} = {
|
56
|
+
%s
|
57
|
+
};
|
58
|
+
|
59
|
+
static #{struct_name} #{scripts_struct} = {
|
60
|
+
%s
|
61
|
+
};
|
62
|
+
EOS
|
63
|
+
|
64
|
+
@struct=[]
|
65
|
+
@name_table=[]
|
66
|
+
@script_table=[]
|
67
|
+
@hashed_table=[]
|
68
|
+
|
69
|
+
@scripts.sort_by {|k,v| k}.each do |v|
|
70
|
+
name=v.first
|
71
|
+
script=v.last
|
72
|
+
|
73
|
+
@name_table << " \"#{name}\","
|
74
|
+
|
75
|
+
str=[]
|
76
|
+
for l in script.lines do
|
77
|
+
cmt=l.match /^--(.*)/
|
78
|
+
break unless cmt
|
79
|
+
str << " //#{cmt[1]}"
|
80
|
+
end
|
81
|
+
str << " char *#{name};\n"
|
82
|
+
@struct << str.join("\n")
|
83
|
+
|
84
|
+
@script_table << " //#{name}\n#{cquote(script)}"
|
85
|
+
|
86
|
+
@hashed_table << " \"#{Digest::SHA1.hexdigest script}\""
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
def check_script(path)
|
92
|
+
system "luac -p #{path}"
|
93
|
+
end
|
94
|
+
|
95
|
+
def cquote(str)
|
96
|
+
out=[]
|
97
|
+
str.each_line do |l|
|
98
|
+
l.sub! "\n", "\\n"
|
99
|
+
l.gsub! '"', '\"'
|
100
|
+
l.gsub! /^(.*)$/, " \"\\1\""
|
101
|
+
out << l
|
102
|
+
end
|
103
|
+
out.join "\n"
|
104
|
+
end
|
105
|
+
|
106
|
+
def to_s
|
107
|
+
if @scripts.count > 0
|
108
|
+
out=sprintf @cout, @struct.join("\n"), @hashed_table.join(",\n"), Digest::SHA1.hexdigest("foo").length, @name_table.join("\n"), @script_table.join(",\n\n")
|
109
|
+
else
|
110
|
+
out="//nothing here\n"
|
111
|
+
end
|
112
|
+
out
|
113
|
+
end
|
114
|
+
|
115
|
+
def failed?
|
116
|
+
@failed
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hsss
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Leo P.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry-debundle
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Transforms Lua files into structs of C-strings and associated headers.
|
70
|
+
Great for embedding Redis Lua scripts.
|
71
|
+
email:
|
72
|
+
- junk@slact.net
|
73
|
+
executables:
|
74
|
+
- hsss
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- CODE_OF_CONDUCT.md
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/console
|
85
|
+
- bin/setup
|
86
|
+
- exe/hsss
|
87
|
+
- hsss.gemspec
|
88
|
+
- lib/hsss.rb
|
89
|
+
- lib/hsss/version.rb
|
90
|
+
homepage: https://github.com/slact/hsss
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata:
|
94
|
+
allowed_push_host: https://rubygems.org
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.5.1
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Hash-Safe Script Splinter
|
115
|
+
test_files: []
|