HTStyle 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2871a16e2a864e261412002b8ae3ffe076351e79
4
+ data.tar.gz: d07e3e8c06bae751a56b184a9983c696f88afebf
5
+ SHA512:
6
+ metadata.gz: c4abd742c0aa36d5ec30d295095c7bd286571d35c4dcfe3b53e24adb61ab122a87dedd0318f23f2932901be176a1300318477e13fd05324f6738aa193aef7904
7
+ data.tar.gz: 6c4a01767d4c7f6b1fbaa35d5b9b745785897f3e77f6b4584148310df4be02e6cbcb3bea7f68651347e2e4e12101f7f57b849acc15b72acc7c650509c519f1ac
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/.rubocop.yml ADDED
@@ -0,0 +1,22 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-07-07 08:41:58 +0000 using RuboCop version 0.32.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 1
9
+ # Cop supports --auto-correct.
10
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
11
+ Style/StringLiterals:
12
+ Enabled: false
13
+
14
+ Style/GlobalVars:
15
+ Exclude:
16
+ - 'spec/*'
17
+ Metrics/AbcSize:
18
+ Max: 17
19
+
20
+ AllCops:
21
+ Exclude:
22
+ - '*.gemspec'
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gem 'rubocop'
3
+ gem 'rspec'
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ Copyright (c) 2015,
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24
+
data/README.md ADDED
@@ -0,0 +1,14 @@
1
+ ##HTStyle
2
+ Now that everyone looks up to Hack Team, you probably want to implement their coding style.
3
+
4
+ This application can re-indent you rexisting codebase to match the awesome style.
5
+
6
+ ###Usage
7
+
8
+ ./htstyle < input.c > output.c
9
+
10
+ ###Example Output
11
+
12
+ [See our tests output for an example of HT Style](https://github.com/technion/htstyle/blob/master/spec/example_output.c).
13
+
14
+ ![Build Status](https://travis-ci.org/technion/htstyle.svg)
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new do |task|
6
+ task.rspec_opts = ['--color', '--format', 'doc']
7
+ end
8
+
9
+ RuboCop::RakeTask.new
10
+
11
+ task default: [:spec, :rubocop]
data/bin/htstyle.rb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift(File.dirname(File.realpath(__FILE__)) + '/../lib')
3
+
4
+ require 'htstyle'
5
+ HTStyle.indenter
data/htstyle.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "HTStyle"
7
+ spec.version = HTStyle::VERSION
8
+ spec.authors = ["Joshua Small"]
9
+ spec.email = ["technion@lolware.net"]
10
+ spec.summary = %q{Implements Hack Team code style}
11
+ spec.description = %q{Implements Hack Team code style}
12
+ spec.homepage = "https://github.com/technion/htstyle"
13
+ spec.license = "BSD"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.6"
21
+ spec.add_development_dependency "rake"
22
+ end
23
+
data/lib/htstyle.rb ADDED
@@ -0,0 +1,16 @@
1
+ # Main re-indent module for HTStyle. See https://github.com/technion/htstyle
2
+ module HTStyle
3
+ module_function
4
+
5
+ def indenter(handle = STDIN)
6
+ accum = 0
7
+ handle.each_line do |line|
8
+ line.lstrip!
9
+ accum += 4 if line.chomp[-1] == '{'
10
+ accum -= 4 if line.chomp[-1] == '}'
11
+ white = 80 - line.length - accum
12
+ white = 0 if white < 0
13
+ puts " " * white + line
14
+ end
15
+ end
16
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,4 @@
1
+ # Main re-indent module for HTStyle. See https://github.com/technion/htstyle
2
+ module HTStyle
3
+ VERSION = "0.1"
4
+ end
@@ -0,0 +1,74 @@
1
+ /* Example socket code - find a free port
2
+ * technion@lolware.net
3
+ * 10/2/2015
4
+ * Example only - not production tested
5
+ */
6
+ #include <stdio.h>
7
+ #include <sys/socket.h>
8
+ #include <arpa/inet.h>
9
+ #include <string.h>
10
+ #ifndef S_SPLINT_S
11
+ #include <unistd.h>
12
+ #endif
13
+ #include <stdlib.h>
14
+ #include <errno.h>
15
+
16
+ #define STARTPORT 8081 /* Start port range to check for a free port */
17
+ #define ENDPOINT 8090
18
+
19
+ static uint16_t bind_open_port(int sock);
20
+
21
+ int main()
22
+ {
23
+ int sock;
24
+ uint16_t port;
25
+
26
+ /* Generic socket creation, ipv4, TCP */
27
+ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
28
+ if (sock < 0) {
29
+ perror("Failed to create socket");
30
+ exit(EXIT_FAILURE);
31
+ }
32
+
33
+ port = bind_open_port(sock);
34
+ printf("Successfully bound to socket %d\n", port);
35
+ (void)close(sock);
36
+
37
+ return 0;
38
+ }
39
+
40
+ /* Cycles from STARTPORT to ENDPORT, looking for a port that is
41
+ * available for bind().
42
+ * int sock: Valid socket
43
+ * Returns: port number, or 0 for error
44
+ */
45
+
46
+ static uint16_t bind_open_port(int sock)
47
+ {
48
+ struct sockaddr_in servAddr;
49
+ uint16_t port;
50
+
51
+ for(port = STARTPORT; port <= ENDPOINT; port++) {
52
+ memset(&servAddr, 0, sizeof(servAddr));
53
+ servAddr.sin_family = AF_INET;
54
+ servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
55
+ servAddr.sin_port = htons(port);
56
+ if (bind(sock, (struct sockaddr *) &servAddr,
57
+ (socklen_t)sizeof(servAddr)) == 0) {
58
+ /* Successful bind */
59
+ return port;
60
+ }
61
+ /* Error condition on bind() */
62
+ if(errno == EADDRINUSE) {
63
+ /* This is the "port in use" error, try for another port */
64
+ printf("Port %d is in use\n", port);
65
+ continue;
66
+ }
67
+ /* Reaching here indicates a different error */
68
+ perror("Failed to bind");
69
+ }
70
+ printf("Unable to find a valid port");
71
+ return 0;
72
+
73
+ }
74
+
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'htstyle'
4
+ require 'version'
5
+
6
+ describe HTStyle do
7
+ it 'reads the example input' do
8
+ $infile = File.read "spec/sockdem.c"
9
+ end
10
+ it 'reads the example output' do
11
+ $outfile = File.read "spec/example_output.c"
12
+ end
13
+ it 'has a version number' do
14
+ defined? HTStyle.VERSION
15
+ end
16
+ it 'gets the right output' do
17
+ expect { HTStyle.indenter($infile) }.to output($outfile).to_stdout
18
+ end
19
+ end
data/spec/sockdem.c ADDED
@@ -0,0 +1,74 @@
1
+ /* Example socket code - find a free port
2
+ * technion@lolware.net
3
+ * 10/2/2015
4
+ * Example only - not production tested
5
+ */
6
+ #include <stdio.h>
7
+ #include <sys/socket.h>
8
+ #include <arpa/inet.h>
9
+ #include <string.h>
10
+ #ifndef S_SPLINT_S
11
+ #include <unistd.h>
12
+ #endif
13
+ #include <stdlib.h>
14
+ #include <errno.h>
15
+
16
+ #define STARTPORT 8081 /* Start port range to check for a free port */
17
+ #define ENDPOINT 8090
18
+
19
+ static uint16_t bind_open_port(int sock);
20
+
21
+ int main()
22
+ {
23
+ int sock;
24
+ uint16_t port;
25
+
26
+ /* Generic socket creation, ipv4, TCP */
27
+ sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
28
+ if (sock < 0) {
29
+ perror("Failed to create socket");
30
+ exit(EXIT_FAILURE);
31
+ }
32
+
33
+ port = bind_open_port(sock);
34
+ printf("Successfully bound to socket %d\n", port);
35
+ (void)close(sock);
36
+
37
+ return 0;
38
+ }
39
+
40
+ /* Cycles from STARTPORT to ENDPORT, looking for a port that is
41
+ * available for bind().
42
+ * int sock: Valid socket
43
+ * Returns: port number, or 0 for error
44
+ */
45
+
46
+ static uint16_t bind_open_port(int sock)
47
+ {
48
+ struct sockaddr_in servAddr;
49
+ uint16_t port;
50
+
51
+ for(port = STARTPORT; port <= ENDPOINT; port++) {
52
+ memset(&servAddr, 0, sizeof(servAddr));
53
+ servAddr.sin_family = AF_INET;
54
+ servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
55
+ servAddr.sin_port = htons(port);
56
+ if (bind(sock, (struct sockaddr *) &servAddr,
57
+ (socklen_t)sizeof(servAddr)) == 0) {
58
+ /* Successful bind */
59
+ return port;
60
+ }
61
+ /* Error condition on bind() */
62
+ if(errno == EADDRINUSE) {
63
+ /* This is the "port in use" error, try for another port */
64
+ printf("Port %d is in use\n", port);
65
+ continue;
66
+ }
67
+ /* Reaching here indicates a different error */
68
+ perror("Failed to bind");
69
+ }
70
+ printf("Unable to find a valid port");
71
+ return 0;
72
+
73
+ }
74
+
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: HTStyle
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Joshua Small
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-08 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: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ description: Implements Hack Team code style
42
+ email:
43
+ - technion@lolware.net
44
+ executables:
45
+ - htstyle.rb
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rubocop.yml"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - bin/htstyle.rb
57
+ - htstyle.gemspec
58
+ - lib/htstyle.rb
59
+ - lib/version.rb
60
+ - spec/example_output.c
61
+ - spec/htstyle_spec.rb
62
+ - spec/sockdem.c
63
+ homepage: https://github.com/technion/htstyle
64
+ licenses:
65
+ - BSD
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Implements Hack Team code style
87
+ test_files:
88
+ - spec/example_output.c
89
+ - spec/htstyle_spec.rb
90
+ - spec/sockdem.c