magic_pragma 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,4 @@
1
+ ## 0.0.1 (August 11, 2011)
2
+
3
+ forked from magic_encoding 0.0.2 (August 3, 2010)
4
+
data/LICENCE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Manuel Ryan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,37 @@
1
+ = Magic pragma
2
+
3
+ Magic Pragma is a little tool that allows you to quickly
4
+ add or modify the "#pragma once" that indicate header file
5
+ should only be included once, which is a common task for C++
6
+ programmers, for an entire directory structure.
7
+
8
+ (Manuel Ryan)[https://github.com/m-ryan] originally wrote the (magic_encoding)[https://github.com/m-ryan/magic_encoding]
9
+ to get rid of "invalid multibyte char (US-ASCII)" error of ruby.
10
+ I thought, hey! This little tool should also be useful to C++ programmers like me!
11
+ So I forked it, changed it, used it on my C++ projects. Hope you don't mind Ryan :)
12
+
13
+ == Installation
14
+
15
+ gem install magic_pragma
16
+
17
+ == Usage
18
+
19
+ you can call the tool from the console with default parameters like so
20
+
21
+ magic_pragma
22
+
23
+ this will prepend every ".h" and ".hpp" file in the working directory (recursively) with the following line :
24
+
25
+ #pragma once
26
+
27
+ Notes :
28
+ - existing #pragma once are replaced
29
+ - the rest of the file remains unchanged
30
+
31
+ you can pass options to the tool to specify the desired pragma (other than 'once') and the path where you want the tool to run, for example :
32
+
33
+ magic_encoding auto_inline /path/to/cpp/project
34
+
35
+ Thanks goes to Manuel Ryan for the original work.
36
+
37
+
data/bin/magic_pragma ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Easily add "#pragma once" to multiple ".h" and ".hpp" header files
4
+
5
+ require 'magic_pragma'
6
+
7
+ AddMagicComment.process(ARGV)
@@ -0,0 +1,54 @@
1
+ # Easily add "#pragma once" to multiple ".h" and ".hpp" header files
2
+
3
+ module AddMagicComment
4
+
5
+ # Options :
6
+ # 1 : Encoding
7
+ # 2 : Path
8
+ # TODO : check that the pragma specified is a valid pragma
9
+ def self.process(options)
10
+
11
+ # defaults
12
+ pragma = options[0] || "once"
13
+ directory = options[1] || Dir.pwd
14
+
15
+ prefix = "#pragma #{pragma}\n"
16
+
17
+ # TODO : add options for recursivity (and application of the script to a single file)
18
+ rbfiles = File.join(directory ,"**", "*.{h,hpp}")
19
+ Dir.glob(rbfiles).each do |filename|
20
+ file = File.new(filename, "r+")
21
+
22
+ lines = file.readlines
23
+
24
+ # remove current pragma once(s)
25
+ while lines[0] && (
26
+ lines[0].starts_with?("#pragma #{pragma}") ||
27
+ lines[0].strip == ""
28
+ )
29
+ lines.shift
30
+ end
31
+
32
+ # set new pragma once
33
+ lines.insert(0,prefix)
34
+
35
+ file.pos = 0
36
+ file.puts(lines.join)
37
+ file.close
38
+ end
39
+ print "\"#pragma once\" set for #{Dir.glob(rbfiles).count} header files\n"
40
+ end
41
+
42
+ end
43
+
44
+ class String
45
+
46
+ def starts_with?(s)
47
+ self[0..s.length-1] == s
48
+ end
49
+
50
+ end
51
+
52
+
53
+
54
+
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: magic_pragma
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - P.S.V.R
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-08-11 00:00:00 +08:00
18
+ default_executable: magic_pragma
19
+ dependencies: []
20
+
21
+ description:
22
+ email:
23
+ - pmq2001@gmail.com
24
+ executables:
25
+ - magic_pragma
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - bin/magic_pragma
32
+ - lib/magic_pragma.rb
33
+ - README.rdoc
34
+ - CHANGELOG
35
+ - LICENCE
36
+ has_rdoc: true
37
+ homepage: http://github.com/pmq20/magic_pragma
38
+ licenses: []
39
+
40
+ post_install_message:
41
+ rdoc_options: []
42
+
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 1
60
+ - 3
61
+ - 6
62
+ version: 1.3.6
63
+ requirements: []
64
+
65
+ rubyforge_project:
66
+ rubygems_version: 1.3.7
67
+ signing_key:
68
+ specification_version: 3
69
+ summary: Easily add "#pragma once" to multiple ".h" and ".hpp" header files
70
+ test_files: []
71
+