talkfilters 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/extconf.rb +12 -0
- data/lib/talkfilters.c +75 -0
- metadata +46 -0
data/lib/extconf.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'mkmf'
|
3
|
+
|
4
|
+
if have_library("talkfilters", "gtf_filter_lookup") and
|
5
|
+
have_library("talkfilters", "gtf_filter_list") and
|
6
|
+
have_library("talkfilters", "gtf_filter_count") and
|
7
|
+
have_header("talkfilters.h")
|
8
|
+
create_makefile("talkfilters")
|
9
|
+
else
|
10
|
+
rm_f "Makefile"
|
11
|
+
end
|
12
|
+
|
data/lib/talkfilters.c
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
#include <talkfilters.h>
|
2
|
+
#include <string.h>
|
3
|
+
#include <ruby.h>
|
4
|
+
#include <strings.h>
|
5
|
+
|
6
|
+
#define TF_REALLOC_SIZE 1024
|
7
|
+
|
8
|
+
VALUE tf_list_filters(void);
|
9
|
+
VALUE tf_translate(VALUE dummy, VALUE type, VALUE string);
|
10
|
+
|
11
|
+
void Init_talkfilters(void) {
|
12
|
+
VALUE tf;
|
13
|
+
tf = rb_define_class("TalkFilters", rb_cObject);
|
14
|
+
rb_define_singleton_method(tf, "list_filters", tf_list_filters, 0);
|
15
|
+
rb_define_singleton_method(tf, "translate", tf_translate, 2);
|
16
|
+
}
|
17
|
+
|
18
|
+
/* TalkFilters.translate(filter_name, string):
|
19
|
+
*
|
20
|
+
* Runs string throught the named filter and returns a string result.
|
21
|
+
*
|
22
|
+
* In the case that it cannot allocate enough memory for the translation, and
|
23
|
+
* exception will be raised.
|
24
|
+
*
|
25
|
+
*/
|
26
|
+
VALUE tf_translate(VALUE dummy, VALUE type, VALUE string) {
|
27
|
+
char *buf, *tmpbuf;
|
28
|
+
gtf_filter_t *filter;
|
29
|
+
size_t bufsize;
|
30
|
+
|
31
|
+
bufsize = RSTRING(string)->len + 2;
|
32
|
+
|
33
|
+
buf = (char *) malloc(bufsize);
|
34
|
+
bzero(buf, bufsize);
|
35
|
+
|
36
|
+
filter = (gtf_filter_t *) gtf_filter_lookup(RSTRING(type)->ptr);
|
37
|
+
|
38
|
+
while (filter->filter(RSTRING(string)->ptr, buf, bufsize)) {
|
39
|
+
tmpbuf = realloc(buf, bufsize + TF_REALLOC_SIZE);
|
40
|
+
if (tmpbuf == NULL) {
|
41
|
+
rb_raise(rb_eException, "Allocation Error");
|
42
|
+
return rb_str_new2("");
|
43
|
+
} else {
|
44
|
+
buf = tmpbuf;
|
45
|
+
bufsize += TF_REALLOC_SIZE;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
return rb_str_new2(buf);
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* TalkFilters.list_filters():
|
54
|
+
*
|
55
|
+
* Returns an array with all the filters supported by the installed GNU
|
56
|
+
* talkfilters library.
|
57
|
+
*
|
58
|
+
*/
|
59
|
+
|
60
|
+
VALUE tf_list_filters(void) {
|
61
|
+
VALUE ary;
|
62
|
+
int ct, i;
|
63
|
+
gtf_filter_t *filters;
|
64
|
+
|
65
|
+
ary = rb_ary_new();
|
66
|
+
|
67
|
+
ct = gtf_filter_count();
|
68
|
+
filters = (gtf_filter_t *) gtf_filter_list();
|
69
|
+
|
70
|
+
for (i = 0; i < ct; i++, filters++) {
|
71
|
+
rb_ary_push(ary, rb_str_new2(filters->name));
|
72
|
+
}
|
73
|
+
|
74
|
+
return ary;
|
75
|
+
}
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.2
|
3
|
+
specification_version: 1
|
4
|
+
name: talkfilters
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-05-13 00:00:00 -07:00
|
8
|
+
summary: Ruby interface to GNU Talkfilters
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: erik@hollensbe.org
|
12
|
+
homepage: http://rubyforge.org/projects/ngslib
|
13
|
+
rubyforge_project: ngslib
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Erik Hollensbe
|
31
|
+
files:
|
32
|
+
- lib/talkfilters.c
|
33
|
+
test_files: []
|
34
|
+
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
extra_rdoc_files: []
|
38
|
+
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions:
|
42
|
+
- lib/extconf.rb
|
43
|
+
requirements: []
|
44
|
+
|
45
|
+
dependencies: []
|
46
|
+
|