jls-grok 0.1.2840 → 0.1.3068
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/Makefile +2 -2
- data/ext/extconf.rb +1 -1
- data/ext/mkmf.log +3 -63
- data/ext/ruby_grok.c +43 -1
- data/ext/ruby_grok.o +0 -0
- data/ext/ruby_grokdiscover.o +0 -0
- data/ext/ruby_grokmatch.o +0 -0
- data/lib/grok.rb +3 -0
- data/lib/pile.rb +43 -0
- data/test/patterns/prog.rb +21 -0
- metadata +14 -5
data/ext/Makefile
CHANGED
@@ -45,7 +45,7 @@ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
|
|
45
45
|
|
46
46
|
RUBY_EXTCONF_H =
|
47
47
|
CFLAGS = -fPIC -fno-strict-aliasing -g -g -O2 -fPIC $(cflags)
|
48
|
-
INCFLAGS = -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.
|
48
|
+
INCFLAGS = -I. -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.
|
49
49
|
DEFS =
|
50
50
|
CPPFLAGS =
|
51
51
|
CXXFLAGS = $(CFLAGS)
|
@@ -86,7 +86,7 @@ extout =
|
|
86
86
|
extout_prefix =
|
87
87
|
target_prefix =
|
88
88
|
LOCAL_LIBS =
|
89
|
-
LIBS = $(LIBRUBYARG_SHARED) -lpthread -lrt -ldl -lcrypt -lm -lc
|
89
|
+
LIBS = $(LIBRUBYARG_SHARED) -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc
|
90
90
|
SRCS = ruby_grok.c ruby_grokmatch.c ruby_grokdiscover.c
|
91
91
|
OBJS = ruby_grok.o ruby_grokmatch.o ruby_grokdiscover.o
|
92
92
|
TARGET = Grok
|
data/ext/extconf.rb
CHANGED
@@ -2,5 +2,5 @@ require "mkmf"
|
|
2
2
|
find_header("tcutil.h", "/usr/local/include")
|
3
3
|
find_header("pcre.h", "/usr/local/include")
|
4
4
|
find_header("grok.h", "/usr/local/include", "../../")
|
5
|
-
find_library("grok", "grok_init", "../", "/usr/local/lib")
|
5
|
+
find_library("grok", "grok_init", "../", "../../", "/usr/local/lib")
|
6
6
|
create_makefile("Grok")
|
data/ext/mkmf.log
CHANGED
@@ -21,20 +21,6 @@ checked program was:
|
|
21
21
|
find_header: checking for grok.h in /usr/local/include,../../... -------------------- yes
|
22
22
|
|
23
23
|
"gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -o conftest.i"
|
24
|
-
conftest.c:1:18: error: grok.h: No such file or directory
|
25
|
-
checked program was:
|
26
|
-
/* begin */
|
27
|
-
1: #include <grok.h>
|
28
|
-
/* end */
|
29
|
-
|
30
|
-
"gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC -I/usr/local/include conftest.c -o conftest.i"
|
31
|
-
conftest.c:1:18: error: grok.h: No such file or directory
|
32
|
-
checked program was:
|
33
|
-
/* begin */
|
34
|
-
1: #include <grok.h>
|
35
|
-
/* end */
|
36
|
-
|
37
|
-
"gcc -E -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC -I../../ conftest.c -o conftest.i"
|
38
24
|
checked program was:
|
39
25
|
/* begin */
|
40
26
|
1: #include <grok.h>
|
@@ -42,53 +28,9 @@ checked program was:
|
|
42
28
|
|
43
29
|
--------------------
|
44
30
|
|
45
|
-
find_library: checking for grok_init() in -lgrok... --------------------
|
46
|
-
|
47
|
-
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -I../../ -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc"
|
48
|
-
conftest.c: In function 't':
|
49
|
-
conftest.c:3: error: 'grok_init' undeclared (first use in this function)
|
50
|
-
conftest.c:3: error: (Each undeclared identifier is reported only once
|
51
|
-
conftest.c:3: error: for each function it appears in.)
|
52
|
-
checked program was:
|
53
|
-
/* begin */
|
54
|
-
1: /*top*/
|
55
|
-
2: int main() { return 0; }
|
56
|
-
3: int t() { void ((*volatile p)()); p = (void ((*)()))grok_init; return 0; }
|
57
|
-
/* end */
|
58
|
-
|
59
|
-
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -I../../ -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc"
|
60
|
-
/usr/bin/ld: cannot find -lgrok
|
61
|
-
collect2: ld returned 1 exit status
|
62
|
-
checked program was:
|
63
|
-
/* begin */
|
64
|
-
1: /*top*/
|
65
|
-
2: int main() { return 0; }
|
66
|
-
3: int t() { grok_init(); return 0; }
|
67
|
-
/* end */
|
68
|
-
|
69
|
-
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -I../../ -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L../ -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc"
|
70
|
-
conftest.c: In function 't':
|
71
|
-
conftest.c:3: error: 'grok_init' undeclared (first use in this function)
|
72
|
-
conftest.c:3: error: (Each undeclared identifier is reported only once
|
73
|
-
conftest.c:3: error: for each function it appears in.)
|
74
|
-
checked program was:
|
75
|
-
/* begin */
|
76
|
-
1: /*top*/
|
77
|
-
2: int main() { return 0; }
|
78
|
-
3: int t() { void ((*volatile p)()); p = (void ((*)()))grok_init; return 0; }
|
79
|
-
/* end */
|
80
|
-
|
81
|
-
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -I../../ -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L../ -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc"
|
82
|
-
/usr/bin/ld: cannot find -lgrok
|
83
|
-
collect2: ld returned 1 exit status
|
84
|
-
checked program was:
|
85
|
-
/* begin */
|
86
|
-
1: /*top*/
|
87
|
-
2: int main() { return 0; }
|
88
|
-
3: int t() { grok_init(); return 0; }
|
89
|
-
/* end */
|
31
|
+
find_library: checking for grok_init() in -lgrok... -------------------- yes
|
90
32
|
|
91
|
-
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.
|
33
|
+
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc"
|
92
34
|
conftest.c: In function 't':
|
93
35
|
conftest.c:3: error: 'grok_init' undeclared (first use in this function)
|
94
36
|
conftest.c:3: error: (Each undeclared identifier is reported only once
|
@@ -100,9 +42,7 @@ checked program was:
|
|
100
42
|
3: int t() { void ((*volatile p)()); p = (void ((*)()))grok_init; return 0; }
|
101
43
|
/* end */
|
102
44
|
|
103
|
-
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I.
|
104
|
-
/usr/bin/ld: cannot find -lgrok
|
105
|
-
collect2: ld returned 1 exit status
|
45
|
+
"gcc -o conftest -I. -I/usr/lib/ruby/1.8/x86_64-linux -I. -fno-strict-aliasing -g -g -O2 -fPIC conftest.c -L. -L/usr/lib -L. -Wl,-Bsymbolic-functions -rdynamic -Wl,-export-dynamic -lruby1.8-static -lgrok -lpthread -lrt -ldl -lcrypt -lm -lc"
|
106
46
|
checked program was:
|
107
47
|
/* begin */
|
108
48
|
1: /*top*/
|
data/ext/ruby_grok.c
CHANGED
@@ -5,6 +5,39 @@
|
|
5
5
|
|
6
6
|
VALUE cGrok; /* Grok class object */
|
7
7
|
|
8
|
+
/*
|
9
|
+
* Document-class: Grok
|
10
|
+
* Grok ruby bindings.
|
11
|
+
*
|
12
|
+
* For an intro to grok, see:
|
13
|
+
* See http://code.google.com/p/semicomplete/wiki/Grok
|
14
|
+
* and http://code.google.com/p/semicomplete/wiki/GrokRuby
|
15
|
+
*
|
16
|
+
* General usage of grok is as follows:
|
17
|
+
*
|
18
|
+
* grok = Grok.new
|
19
|
+
* grok.add_patterns_from_file("/path/to/patterns")
|
20
|
+
* grok.add_pattern("WORD", "\b\w+\b")
|
21
|
+
* grok.compile("%{WORD} world!")
|
22
|
+
* m = grok.match("Hello world!")
|
23
|
+
* if m
|
24
|
+
* puts m.captures["WORD"]
|
25
|
+
* else
|
26
|
+
* puts "No match."
|
27
|
+
* fi
|
28
|
+
*
|
29
|
+
* Grok autodiscovery:
|
30
|
+
* grok = Grok.new
|
31
|
+
* grok.add_patterns_from_file("/path/to/patterns")
|
32
|
+
*
|
33
|
+
* # Assuming you loaded the default pattern set
|
34
|
+
* grok.discover("2009-04-18")
|
35
|
+
* #=> "\\Q\\E%{DATE_EU}\\Q\\E"
|
36
|
+
* grok.discover("Visit http://www.google.com/")
|
37
|
+
* #=> "\\QVisit \\E%{URI}\\Q\\E"
|
38
|
+
*
|
39
|
+
*/
|
40
|
+
|
8
41
|
extern VALUE cGrokMatch;
|
9
42
|
extern VALUE cGrokDiscover;
|
10
43
|
extern void Init_GrokMatch();
|
@@ -44,6 +77,13 @@ VALUE rGrok_new_from_grok(grok_t *grok) {
|
|
44
77
|
return rgrok;
|
45
78
|
}
|
46
79
|
|
80
|
+
/*
|
81
|
+
* Compiles an expression.
|
82
|
+
*
|
83
|
+
* call-seq:
|
84
|
+
* grok.compile(pattern)
|
85
|
+
*
|
86
|
+
*/
|
47
87
|
VALUE rGrok_compile(VALUE self, VALUE pattern) {
|
48
88
|
grok_t *grok;
|
49
89
|
char *c_pattern = NULL;
|
@@ -53,7 +93,9 @@ VALUE rGrok_compile(VALUE self, VALUE pattern) {
|
|
53
93
|
Data_Get_Struct(self, grok_t, grok);
|
54
94
|
|
55
95
|
/* Need strdup here in case 'pattern' object is deleted later in
|
56
|
-
* the ruby code
|
96
|
+
* the ruby code
|
97
|
+
* TODO(sissel): Really, just mark that we are using this string
|
98
|
+
* rather than strduping. */
|
57
99
|
str = rb_str2cstr(pattern, &len);
|
58
100
|
c_pattern = malloc(len);
|
59
101
|
memcpy(c_pattern, str, len);
|
data/ext/ruby_grok.o
CHANGED
Binary file
|
data/ext/ruby_grokdiscover.o
CHANGED
Binary file
|
data/ext/ruby_grokmatch.o
CHANGED
Binary file
|
data/lib/grok.rb
CHANGED
@@ -1,13 +1,16 @@
|
|
1
1
|
require "Grok"
|
2
|
+
require "grok/pile"
|
2
3
|
|
3
4
|
# extend Grok to add simpler access to the discover feature.
|
4
5
|
class Grok
|
6
|
+
public
|
5
7
|
def discover(input)
|
6
8
|
init_discover if @discover == nil
|
7
9
|
|
8
10
|
return @discover.discover(input)
|
9
11
|
end
|
10
12
|
|
13
|
+
private
|
11
14
|
def init_discover
|
12
15
|
@discover = GrokDiscover.new(self)
|
13
16
|
end
|
data/lib/pile.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require "grok"
|
2
|
+
|
3
|
+
# A grok pile is an easy way to have multiple patterns together so that
|
4
|
+
# you can try to match against each one.
|
5
|
+
class Grok::Pile
|
6
|
+
def initialize
|
7
|
+
@groks = []
|
8
|
+
@patterns = {}
|
9
|
+
@pattern_files = []
|
10
|
+
end # def initialize
|
11
|
+
|
12
|
+
def add_pattern(name, string)
|
13
|
+
@patterns[name] = string
|
14
|
+
end # def add_pattern
|
15
|
+
|
16
|
+
def add_patterns_from_file(path)
|
17
|
+
if !File.exists?(path)
|
18
|
+
raise "File does not exist: #{path}"
|
19
|
+
end
|
20
|
+
@pattern_files << path
|
21
|
+
end # def add_patterns_from_file
|
22
|
+
|
23
|
+
def compile(pattern)
|
24
|
+
grok = Grok.new
|
25
|
+
@patterns.each do |name, value|
|
26
|
+
grok.add_patterne(name, value)
|
27
|
+
end
|
28
|
+
@pattern_files.each do |path|
|
29
|
+
grok.add_patterns_from_file(path)
|
30
|
+
end
|
31
|
+
grok.compile(pattern)
|
32
|
+
@groks << grok
|
33
|
+
end # def compile
|
34
|
+
|
35
|
+
def match(string)
|
36
|
+
@groks.each do |grok|
|
37
|
+
match = grok.match(string)
|
38
|
+
if match
|
39
|
+
return [grok, match]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end # def match
|
43
|
+
end # class Grok::Pile
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'grok'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class ProgPatternsTest < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@grok = Grok.new
|
7
|
+
path = "#{File.dirname(__FILE__)}/../../../patterns/base"
|
8
|
+
@grok.add_patterns_from_file(path)
|
9
|
+
@grok.compile("^%{PROG}$")
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_progs
|
13
|
+
progs = %w{kernel foo-bar foo_bar foo/bar/baz}
|
14
|
+
progs.each do |prog|
|
15
|
+
match = @grok.match(prog)
|
16
|
+
assert_not_equal(false, prog, "Expected #{prog} to match.")
|
17
|
+
assert_equal(prog, match.captures["PROG"][0], "Expected #{prog} to match capture.")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jls-grok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 3068
|
9
|
+
version: 0.1.3068
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Jordan Sissel
|
@@ -9,7 +14,7 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date: 2010-
|
17
|
+
date: 2010-10-17 00:00:00 -07:00
|
13
18
|
default_executable:
|
14
19
|
dependencies: []
|
15
20
|
|
@@ -49,8 +54,10 @@ files:
|
|
49
54
|
- test/patterns/path.rb
|
50
55
|
- test/patterns/month.rb
|
51
56
|
- test/patterns/uri.rb
|
57
|
+
- test/patterns/prog.rb
|
52
58
|
- test/run.sh
|
53
59
|
- lib/grok.rb
|
60
|
+
- lib/pile.rb
|
54
61
|
has_rdoc: true
|
55
62
|
homepage: http://code.google.com/p/semicomplete/wiki/Grok
|
56
63
|
licenses: []
|
@@ -65,18 +72,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
65
72
|
requirements:
|
66
73
|
- - ">="
|
67
74
|
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
68
77
|
version: "0"
|
69
|
-
version:
|
70
78
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
79
|
requirements:
|
72
80
|
- - ">="
|
73
81
|
- !ruby/object:Gem::Version
|
82
|
+
segments:
|
83
|
+
- 0
|
74
84
|
version: "0"
|
75
|
-
version:
|
76
85
|
requirements: []
|
77
86
|
|
78
87
|
rubyforge_project:
|
79
|
-
rubygems_version: 1.3.
|
88
|
+
rubygems_version: 1.3.6
|
80
89
|
signing_key:
|
81
90
|
specification_version: 3
|
82
91
|
summary: grok bindings for ruby
|