comment_extractor 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +132 -0
- data/bin/comment_parser_debug +45 -0
- data/lib/comment_extractor/code_object/comment.rb +19 -0
- data/lib/comment_extractor/code_object.rb +12 -0
- data/lib/comment_extractor/code_objects.rb +46 -0
- data/lib/comment_extractor/configuration.rb +50 -0
- data/lib/comment_extractor/encoding.rb +40 -0
- data/lib/comment_extractor/extractor/c.rb +8 -0
- data/lib/comment_extractor/extractor/cc.rb +8 -0
- data/lib/comment_extractor/extractor/class.rb +8 -0
- data/lib/comment_extractor/extractor/clojure.rb +11 -0
- data/lib/comment_extractor/extractor/coffee.rb +13 -0
- data/lib/comment_extractor/extractor/concerns/simple_extractor.rb +189 -0
- data/lib/comment_extractor/extractor/concerns/slash_extractor.rb +16 -0
- data/lib/comment_extractor/extractor/cpp.rb +8 -0
- data/lib/comment_extractor/extractor/cs.rb +8 -0
- data/lib/comment_extractor/extractor/css.rb +8 -0
- data/lib/comment_extractor/extractor/cxx.rb +8 -0
- data/lib/comment_extractor/extractor/d.rb +9 -0
- data/lib/comment_extractor/extractor/erlang.rb +12 -0
- data/lib/comment_extractor/extractor/fortran.rb +11 -0
- data/lib/comment_extractor/extractor/go.rb +8 -0
- data/lib/comment_extractor/extractor/h.rb +8 -0
- data/lib/comment_extractor/extractor/haml.rb +49 -0
- data/lib/comment_extractor/extractor/haskell.rb +12 -0
- data/lib/comment_extractor/extractor/hpp.rb +8 -0
- data/lib/comment_extractor/extractor/html.rb +13 -0
- data/lib/comment_extractor/extractor/java.rb +8 -0
- data/lib/comment_extractor/extractor/java_script.rb +12 -0
- data/lib/comment_extractor/extractor/lisp.rb +11 -0
- data/lib/comment_extractor/extractor/lua.rb +12 -0
- data/lib/comment_extractor/extractor/m.rb +9 -0
- data/lib/comment_extractor/extractor/markdown.rb +7 -0
- data/lib/comment_extractor/extractor/mm.rb +8 -0
- data/lib/comment_extractor/extractor/perl.rb +12 -0
- data/lib/comment_extractor/extractor/php.rb +8 -0
- data/lib/comment_extractor/extractor/python.rb +13 -0
- data/lib/comment_extractor/extractor/ruby.rb +40 -0
- data/lib/comment_extractor/extractor/sass.rb +8 -0
- data/lib/comment_extractor/extractor/scala.rb +8 -0
- data/lib/comment_extractor/extractor/scss.rb +8 -0
- data/lib/comment_extractor/extractor/shell.rb +11 -0
- data/lib/comment_extractor/extractor/sqf.rb +8 -0
- data/lib/comment_extractor/extractor/sql.rb +12 -0
- data/lib/comment_extractor/extractor/sqs.rb +7 -0
- data/lib/comment_extractor/extractor/tex.rb +12 -0
- data/lib/comment_extractor/extractor/text.rb +10 -0
- data/lib/comment_extractor/extractor/yaml.rb +12 -0
- data/lib/comment_extractor/extractor.rb +96 -0
- data/lib/comment_extractor/extractor_manager.rb +158 -0
- data/lib/comment_extractor/file.rb +42 -0
- data/lib/comment_extractor/parser.rb +33 -0
- data/lib/comment_extractor/smart_string_scanner.rb +11 -0
- data/lib/comment_extractor/version.rb +4 -0
- data/lib/comment_extractor.rb +18 -0
- data/spec/assets/binary_file +0 -0
- data/spec/assets/shebang_file +3 -0
- data/spec/assets/source_code/c.c +158 -0
- data/spec/assets/source_code/cc.cc +24 -0
- data/spec/assets/source_code/class +0 -0
- data/spec/assets/source_code/clojure.clj +41 -0
- data/spec/assets/source_code/coffee.coffee +27 -0
- data/spec/assets/source_code/cpp.cpp +130 -0
- data/spec/assets/source_code/cs.cs +53 -0
- data/spec/assets/source_code/css.css +37 -0
- data/spec/assets/source_code/cxx +0 -0
- data/spec/assets/source_code/d.d +110 -0
- data/spec/assets/source_code/erlang.es +34 -0
- data/spec/assets/source_code/fortran.f +41 -0
- data/spec/assets/source_code/golang.go +61 -0
- data/spec/assets/source_code/h +0 -0
- data/spec/assets/source_code/haml.haml +26 -0
- data/spec/assets/source_code/haskell.hs +36 -0
- data/spec/assets/source_code/hpp +0 -0
- data/spec/assets/source_code/html.html +139 -0
- data/spec/assets/source_code/java.java +39 -0
- data/spec/assets/source_code/java_script.js +164 -0
- data/spec/assets/source_code/lisp.el +18 -0
- data/spec/assets/source_code/lua.lua +34 -0
- data/spec/assets/source_code/m +0 -0
- data/spec/assets/source_code/mm +0 -0
- data/spec/assets/source_code/perl.pl +36 -0
- data/spec/assets/source_code/php.php +31 -0
- data/spec/assets/source_code/python.py +139 -0
- data/spec/assets/source_code/ruby.rb +36 -0
- data/spec/assets/source_code/sass.sass +77 -0
- data/spec/assets/source_code/scala.scala +46 -0
- data/spec/assets/source_code/scss.scss +93 -0
- data/spec/assets/source_code/shell.sh +5 -0
- data/spec/assets/source_code/sqf +0 -0
- data/spec/assets/source_code/sql.sql +11 -0
- data/spec/assets/source_code/sqs +0 -0
- data/spec/assets/source_code/tex.tex +20 -0
- data/spec/assets/source_code/text.txt +15 -0
- data/spec/assets/source_code/vim +17 -0
- data/spec/assets/source_code/yaml.yml +44 -0
- data/spec/assets/stripper/children/children +0 -0
- data/spec/assets/stripper/children/children.c +0 -0
- data/spec/assets/stripper/children/children.js +0 -0
- data/spec/assets/stripper/children/children.o +0 -0
- data/spec/assets/stripper/children/children.rb +1 -0
- data/spec/assets/stripper/test +0 -0
- data/spec/assets/stripper/test.c +0 -0
- data/spec/assets/stripper/test.js +0 -0
- data/spec/assets/stripper/test.o +0 -0
- data/spec/assets/stripper/test.rb +1 -0
- data/spec/comment_extractor/code_object/comment_spec.rb +15 -0
- data/spec/comment_extractor/code_object_spec.rb +18 -0
- data/spec/comment_extractor/code_objects_spec.rb +66 -0
- data/spec/comment_extractor/configuration_spec.rb +68 -0
- data/spec/comment_extractor/encoding_spec.rb +77 -0
- data/spec/comment_extractor/extractor/c_spec.rb +9 -0
- data/spec/comment_extractor/extractor/cc_spec.rb +9 -0
- data/spec/comment_extractor/extractor/class_spec.rb +9 -0
- data/spec/comment_extractor/extractor/clojure_spec.rb +9 -0
- data/spec/comment_extractor/extractor/coffee_spec.rb +9 -0
- data/spec/comment_extractor/extractor/cpp_spec.rb +9 -0
- data/spec/comment_extractor/extractor/cs_spec.rb +9 -0
- data/spec/comment_extractor/extractor/css_spec.rb +9 -0
- data/spec/comment_extractor/extractor/cxx_spec.rb +9 -0
- data/spec/comment_extractor/extractor/d_spec.rb +10 -0
- data/spec/comment_extractor/extractor/erlang_spec.rb +10 -0
- data/spec/comment_extractor/extractor/fortran_spec.rb +9 -0
- data/spec/comment_extractor/extractor/go_spec.rb +9 -0
- data/spec/comment_extractor/extractor/h_spec.rb +9 -0
- data/spec/comment_extractor/extractor/haml_spec.rb +9 -0
- data/spec/comment_extractor/extractor/haskell_spec.rb +9 -0
- data/spec/comment_extractor/extractor/hpp_spec.rb +9 -0
- data/spec/comment_extractor/extractor/html_spec.rb +9 -0
- data/spec/comment_extractor/extractor/java_script_spec.rb +10 -0
- data/spec/comment_extractor/extractor/java_spec.rb +9 -0
- data/spec/comment_extractor/extractor/lisp_spec.rb +9 -0
- data/spec/comment_extractor/extractor/lua_spec.rb +9 -0
- data/spec/comment_extractor/extractor/m_spec.rb +9 -0
- data/spec/comment_extractor/extractor/markdown_spec.rb +8 -0
- data/spec/comment_extractor/extractor/mm_spec.rb +9 -0
- data/spec/comment_extractor/extractor/perl_spec.rb +9 -0
- data/spec/comment_extractor/extractor/php_spec.rb +9 -0
- data/spec/comment_extractor/extractor/python_spec.rb +9 -0
- data/spec/comment_extractor/extractor/ruby_spec.rb +12 -0
- data/spec/comment_extractor/extractor/sass_spec.rb +9 -0
- data/spec/comment_extractor/extractor/scala_spec.rb +9 -0
- data/spec/comment_extractor/extractor/scss_spec.rb +9 -0
- data/spec/comment_extractor/extractor/shell_spec.rb +9 -0
- data/spec/comment_extractor/extractor/sqf_spec.rb +9 -0
- data/spec/comment_extractor/extractor/sql_spec.rb +9 -0
- data/spec/comment_extractor/extractor/sqs_spec.rb +9 -0
- data/spec/comment_extractor/extractor/tex_spec.rb +9 -0
- data/spec/comment_extractor/extractor/text_spec.rb +7 -0
- data/spec/comment_extractor/extractor/yaml_spec.rb +9 -0
- data/spec/comment_extractor/extractor_manager_spec.rb +233 -0
- data/spec/comment_extractor/extractor_spec.rb +102 -0
- data/spec/comment_extractor/file_spec.rb +100 -0
- data/spec/comment_extractor/parser_spec.rb +67 -0
- data/spec/comment_extractor/smart_string_scanner_spec.rb +24 -0
- data/spec/comment_extractor/version_spec.rb +8 -0
- data/spec/comment_extractor_spec.rb +15 -0
- data/spec/spec_helper.rb +22 -0
- data/spec/support/rspec/comment_extractor/extractor_example_group.rb +115 -0
- data/spec/support/rspec/comment_extractor/matchers/extract_comment.rb +58 -0
- data/spec/support/rspec/comment_extractor/matchers.rb +7 -0
- data/spec/support/rspec/comment_extractor.rb +6 -0
- metadata +370 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'comment_extractor/encoding'
|
|
2
|
+
|
|
3
|
+
module CommentExtractor
|
|
4
|
+
module DetectableSchemeFile
|
|
5
|
+
THRESHOLD_BINARY = 0.3
|
|
6
|
+
|
|
7
|
+
refine File do
|
|
8
|
+
attr_accessor :content, :shebang
|
|
9
|
+
|
|
10
|
+
# [review] - How can I refine class method?
|
|
11
|
+
def File.shebang(path)
|
|
12
|
+
if File.extname(path).empty?
|
|
13
|
+
line = File.open(path) { |f| f.gets }
|
|
14
|
+
if /\A#!\s*(?<shebang_path>.+)/ =~ line
|
|
15
|
+
shebang_path
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def File.binary?(file_path)
|
|
21
|
+
header = File.read(file_path, File.stat(file_path).blksize) || nil
|
|
22
|
+
|
|
23
|
+
if header.nil? || header.empty?
|
|
24
|
+
false
|
|
25
|
+
else
|
|
26
|
+
chars = header.chars
|
|
27
|
+
(chars.grep(' '..'~').size / chars.size.to_f) <= THRESHOLD_BINARY
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def read_content
|
|
32
|
+
return if File.binary?(self.path)
|
|
33
|
+
|
|
34
|
+
if File.shebang(self.path)
|
|
35
|
+
self.gets # Remove shebang
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
CommentExtractor::Encoding.encode(self.read)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'comment_extractor/file'
|
|
2
|
+
require 'comment_extractor/extractor_manager'
|
|
3
|
+
|
|
4
|
+
using CommentExtractor::DetectableSchemeFile
|
|
5
|
+
|
|
6
|
+
module CommentExtractor
|
|
7
|
+
class Parser
|
|
8
|
+
attr_accessor :extractor
|
|
9
|
+
|
|
10
|
+
def initialize(extractor)
|
|
11
|
+
@extractor = extractor
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def extract_comments
|
|
15
|
+
@extractor.extract_comments
|
|
16
|
+
rescue NoMethodError
|
|
17
|
+
raise TypeError, "#{@extractor} should be a instance of #{Extractor}"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class << self
|
|
21
|
+
def for(file_path)
|
|
22
|
+
if extractor = ExtractorManager.can_extract(file_path)
|
|
23
|
+
content = File.open(file_path, 'r') { |f| f.read_content }
|
|
24
|
+
|
|
25
|
+
# Initialize parser
|
|
26
|
+
code_objects = CodeObjects.new(file: file_path)
|
|
27
|
+
instance_of_extractor = extractor.new(content, code_objects)
|
|
28
|
+
new(instance_of_extractor)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'comment_extractor/code_object'
|
|
2
|
+
require 'comment_extractor/configuration'
|
|
3
|
+
require 'comment_extractor/encoding'
|
|
4
|
+
require 'comment_extractor/extractor'
|
|
5
|
+
require 'comment_extractor/extractor_manager'
|
|
6
|
+
require 'comment_extractor/file'
|
|
7
|
+
require 'comment_extractor/parser'
|
|
8
|
+
require 'comment_extractor/version'
|
|
9
|
+
|
|
10
|
+
module CommentExtractor
|
|
11
|
+
def self.configuration
|
|
12
|
+
@configuration ||= Configuration.new
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def self.configure
|
|
16
|
+
yield(configuration)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
Binary file
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
//[-1-]Attribution-Share Alike 3.0 License, copyright (c) 2010 Pieter Hintjens, modified @alpaca-tc
|
|
2
|
+
//[-2-] Copyright (c) 2010-2013 iMatix Corporation and Contributors
|
|
3
|
+
//[-3-] Lets us build this source without creating a library
|
|
4
|
+
#include "kvmsg.c"
|
|
5
|
+
|
|
6
|
+
//[-6-] zloop reactor handlers
|
|
7
|
+
static int s_snapshots (zloop_t *loop, zmq_pollitem_t *poller, void *args);
|
|
8
|
+
static int s_collector (zloop_t *loop, zmq_pollitem_t *poller, void *args);
|
|
9
|
+
static int s_flush_ttl (zloop_t *loop, int timer_id, void *args);
|
|
10
|
+
|
|
11
|
+
//[-11-] Our server is defined by these properties
|
|
12
|
+
typedef struct {
|
|
13
|
+
zctx_t *ctx; //[-13-] Context wrapper
|
|
14
|
+
zhash_t *kvmap; //[-14-] Key-value store
|
|
15
|
+
zloop_t *loop; //[-15-] zloop reactor
|
|
16
|
+
int port; //[-16-] Main port we're working on
|
|
17
|
+
int64_t sequence; //[-17-] How many updates we're at
|
|
18
|
+
void *snapshot; //[-18-] Handle snapshot requests
|
|
19
|
+
void *publisher; //[-19-] Publish updates to clients
|
|
20
|
+
void *collector; //[-20-] Collect updates from clients
|
|
21
|
+
} clonesrv_t;
|
|
22
|
+
|
|
23
|
+
int main (void)
|
|
24
|
+
{
|
|
25
|
+
clonesrv_t *self = (clonesrv_t *) zmalloc (sizeof (clonesrv_t));
|
|
26
|
+
self->port = 5556;
|
|
27
|
+
self->ctx = zctx_new ();
|
|
28
|
+
self->kvmap = zhash_new ();
|
|
29
|
+
self->loop = zloop_new ();
|
|
30
|
+
zloop_set_verbose (self->loop, false);
|
|
31
|
+
|
|
32
|
+
//[-32-] Set up our clone server sockets
|
|
33
|
+
self->snapshot = zsocket_new (self->ctx, ZMQ_ROUTER);
|
|
34
|
+
|
|
35
|
+
self->publisher = zsocket_new (self->ctx, ZMQ_PUB);
|
|
36
|
+
zsocket_bind (self->publisher, "tcp://*:%d", self->port + 1);
|
|
37
|
+
self->collector = zsocket_new (self->ctx, ZMQ_PULL);
|
|
38
|
+
zsocket_bind (self->collector, "tcp://*:%d", self->port + 2);
|
|
39
|
+
|
|
40
|
+
//[-40-] Register our handlers with reactor
|
|
41
|
+
zmq_pollitem_t poller = { 0, 0, ZMQ_POLLIN };
|
|
42
|
+
poller.socket = self->snapshot;
|
|
43
|
+
zloop_poller (self->loop, &poller, s_snapshots, self);
|
|
44
|
+
poller.socket = self->collector;
|
|
45
|
+
zloop_poller (self->loop, &poller, s_collector, self);
|
|
46
|
+
zloop_timer (self->loop, 1000, 0, s_flush_ttl, self);
|
|
47
|
+
|
|
48
|
+
//[-48-] Run reactor until process interrupted
|
|
49
|
+
zloop_start (self->loop);
|
|
50
|
+
|
|
51
|
+
zloop_destroy (&self->loop);
|
|
52
|
+
zhash_destroy (&self->kvmap);
|
|
53
|
+
zctx_destroy (&self->ctx);
|
|
54
|
+
free (self);
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
typedef struct {
|
|
59
|
+
void *socket; //[-59-] ROUTER socket to send to
|
|
60
|
+
zframe_t *identity; //[-60-] Identity of peer who requested state
|
|
61
|
+
char *subtree; //[-61-] Client subtree specification
|
|
62
|
+
} kvroute_t;
|
|
63
|
+
|
|
64
|
+
static int
|
|
65
|
+
s_send_single (const char *key, void *data, void *args)
|
|
66
|
+
{
|
|
67
|
+
kvroute_t *kvroute = (kvroute_t *) args;
|
|
68
|
+
kvmsg_t *kvmsg = (kvmsg_t *) data;
|
|
69
|
+
if (strlen (kvroute->subtree) <= strlen (kvmsg_key (kvmsg))
|
|
70
|
+
&& memcmp (kvroute->subtree,
|
|
71
|
+
kvmsg_key (kvmsg), strlen (kvroute->subtree)) == 0) {
|
|
72
|
+
zframe_send (&kvroute->identity, //[-72-] Choose recipient
|
|
73
|
+
kvroute->socket, ZFRAME_MORE + ZFRAME_REUSE);
|
|
74
|
+
kvmsg_send (kvmsg, kvroute->socket);
|
|
75
|
+
}
|
|
76
|
+
return 0;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
static int
|
|
80
|
+
s_snapshots (zloop_t *loop, zmq_pollitem_t *poller, void *args)
|
|
81
|
+
{
|
|
82
|
+
clonesrv_t *self = (clonesrv_t *) args;
|
|
83
|
+
|
|
84
|
+
zframe_t *identity = zframe_recv (poller->socket);
|
|
85
|
+
if (identity) {
|
|
86
|
+
char *request = zstr_recv (poller->socket);
|
|
87
|
+
char *subtree = NULL;
|
|
88
|
+
if (streq (request, "ICANHAZ?")) {
|
|
89
|
+
free (request);
|
|
90
|
+
subtree = zstr_recv (poller->socket);
|
|
91
|
+
}
|
|
92
|
+
else
|
|
93
|
+
printf ("E: bad request, aborting\n");
|
|
94
|
+
|
|
95
|
+
if (subtree) {
|
|
96
|
+
kvroute_t routing = { poller->socket, identity, subtree };
|
|
97
|
+
zhash_foreach (self->kvmap, s_send_single, &routing);
|
|
98
|
+
|
|
99
|
+
zclock_log ("I: sending shapshot=%d", (int) self->sequence);
|
|
100
|
+
zframe_send (&identity, poller->socket, ZFRAME_MORE);
|
|
101
|
+
kvmsg_t *kvmsg = kvmsg_new (self->sequence);
|
|
102
|
+
kvmsg_set_key (kvmsg, "KTHXBAI");
|
|
103
|
+
kvmsg_set_body (kvmsg, (byte *) subtree, 0);
|
|
104
|
+
kvmsg_send (kvmsg, poller->socket);
|
|
105
|
+
kvmsg_destroy (&kvmsg);
|
|
106
|
+
free (subtree);
|
|
107
|
+
}
|
|
108
|
+
zframe_destroy(&identity);
|
|
109
|
+
}
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static int
|
|
114
|
+
s_collector (zloop_t *loop, zmq_pollitem_t *poller, void *args)
|
|
115
|
+
{
|
|
116
|
+
clonesrv_t *self = (clonesrv_t *) args;
|
|
117
|
+
|
|
118
|
+
kvmsg_t *kvmsg = kvmsg_recv (poller->socket);
|
|
119
|
+
if (kvmsg) {
|
|
120
|
+
kvmsg_set_sequence (kvmsg, ++self->sequence);
|
|
121
|
+
kvmsg_send (kvmsg, self->publisher);
|
|
122
|
+
int ttl = atoi (kvmsg_get_prop (kvmsg, "ttl"));
|
|
123
|
+
if (ttl)
|
|
124
|
+
kvmsg_set_prop (kvmsg, "ttl",
|
|
125
|
+
"%" PRId64, zclock_time () + ttl * 1000);
|
|
126
|
+
kvmsg_store (&kvmsg, self->kvmap);
|
|
127
|
+
zclock_log ("I: publishing update=%d", (int) self->sequence);
|
|
128
|
+
}
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
//[-132-] .split flush ephemeral values
|
|
133
|
+
static int
|
|
134
|
+
s_flush_single (const char *key, void *data, void *args)
|
|
135
|
+
{
|
|
136
|
+
clonesrv_t *self = (clonesrv_t *) args;
|
|
137
|
+
|
|
138
|
+
kvmsg_t *kvmsg = (kvmsg_t *) data;
|
|
139
|
+
int64_t ttl;
|
|
140
|
+
sscanf (kvmsg_get_prop (kvmsg, "ttl"), "%" PRId64, &ttl);
|
|
141
|
+
if (ttl && zclock_time () >= ttl) {
|
|
142
|
+
kvmsg_set_sequence (kvmsg, ++self->sequence);
|
|
143
|
+
kvmsg_set_body (kvmsg, (byte *) "", 0);
|
|
144
|
+
kvmsg_send (kvmsg, self->publisher);
|
|
145
|
+
kvmsg_store (&kvmsg, self->kvmap);
|
|
146
|
+
zclock_log ("I: publishing delete=%d", (int) self->sequence);
|
|
147
|
+
}
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
static int
|
|
152
|
+
s_flush_ttl (zloop_t *loop, int timer_id, void *args)
|
|
153
|
+
{
|
|
154
|
+
clonesrv_t *self = (clonesrv_t *) args;
|
|
155
|
+
if (self->kvmap)
|
|
156
|
+
zhash_foreach (self->kvmap, s_flush_single, args);
|
|
157
|
+
return 0;
|
|
158
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//[-1-](C) 2013 Sebastian Mach (1983), this file is published under the terms of the
|
|
2
|
+
//[-2-]GNU General Public License, Version 3 (a.k.a. GPLv3).
|
|
3
|
+
//[-3-]See COPYING in the root-folder of the excygen project folder.
|
|
4
|
+
#ifndef INTERSECTION_HH_INCLUDED_20130718
|
|
5
|
+
#define INTERSECTION_HH_INCLUDED_20130718
|
|
6
|
+
|
|
7
|
+
#include "DifferentialGeometry.hh"
|
|
8
|
+
#include "Photometry/Material/Material.hh"
|
|
9
|
+
#include <memory>
|
|
10
|
+
|
|
11
|
+
namespace excyrender {
|
|
12
|
+
|
|
13
|
+
struct Intersection
|
|
14
|
+
{
|
|
15
|
+
DifferentialGeometry dg;
|
|
16
|
+
std::shared_ptr<const Photometry::Material::Material> material;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
inline real distance(Intersection const &i) noexcept {
|
|
20
|
+
return i.dg.d;
|
|
21
|
+
} /*[-21-] multi line [-end-]*/
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
#endif //[-24-]INTERSECTION_HH_INCLUDED_20130718
|
|
File without changes
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
(ns mtrelay
|
|
2
|
+
(:refer-clojure :exclude [send])
|
|
3
|
+
(:require [zhelpers :as mq])
|
|
4
|
+
(:import [org.zeromq ZMQ$Context]))
|
|
5
|
+
|
|
6
|
+
;;[-6-]Attribution-Share Alike 3.0 License, copyright (c) 2010 Pieter Hintjens, modified @alpaca-tc
|
|
7
|
+
;;[-7-]Multithreaded relay in Clojure
|
|
8
|
+
;;[-8-] Isaiah Peng <issaria@gmail.com>
|
|
9
|
+
|
|
10
|
+
(defrecord Step1 [^ZMQ$Context ctx]
|
|
11
|
+
Runnable
|
|
12
|
+
(run [this]
|
|
13
|
+
(let [xmitter (mq/socket ctx mq/pair)]
|
|
14
|
+
(mq/connect xmitter "inproc://step2")
|
|
15
|
+
(println "Step 1 is ready, signaling step 2")
|
|
16
|
+
(mq/send xmitter "READY\u0000")
|
|
17
|
+
(.close xmitter))))
|
|
18
|
+
|
|
19
|
+
(defrecord Step2 [^ZMQ$Context ctx]
|
|
20
|
+
Runnable
|
|
21
|
+
(run [this]
|
|
22
|
+
(let [receiver (mq/socket ctx mq/pair)
|
|
23
|
+
xmitter (mq/socket ctx mq/pair)]
|
|
24
|
+
(mq/bind receiver "inproc://step2")
|
|
25
|
+
(-> ctx Step1. Thread. .start)
|
|
26
|
+
;;[-26-] Wait for signal and pass it on
|
|
27
|
+
(mq/recv-str receiver) ;;[-27-] Wait for signal and pass it on
|
|
28
|
+
(mq/connect xmitter "inproc://step3") ;;;;[-28-] Wait for signal and pass it on
|
|
29
|
+
(println "Step 2 is ready, signaling step 3") ;[-29-] Wait for signal and pass it on
|
|
30
|
+
(mq/send xmitter "READY\u0000")
|
|
31
|
+
(.close xmitter))))
|
|
32
|
+
|
|
33
|
+
(defn -main []
|
|
34
|
+
(let [ctx (mq/context 1)
|
|
35
|
+
receiver (mq/socket ctx mq/pair)]
|
|
36
|
+
(mq/bind receiver "inproc://step3")
|
|
37
|
+
(-> ctx Step2. Thread. .start)
|
|
38
|
+
(mq/recv-str receiver)
|
|
39
|
+
(.close receiver)
|
|
40
|
+
(println "Test successful!")
|
|
41
|
+
(.term ctx)))
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#[-1-] singleline
|
|
2
|
+
class GiftModel
|
|
3
|
+
constructor: (gifts) -> #[-3-] singleline
|
|
4
|
+
@gifts = ko.observableArray gifts
|
|
5
|
+
|
|
6
|
+
@addGift = =>
|
|
7
|
+
@gifts.push({ name: "" })
|
|
8
|
+
|
|
9
|
+
@removeGift = (gift) =>
|
|
10
|
+
@gifts.remove gift
|
|
11
|
+
|
|
12
|
+
regexp = /// #[-12-] regexp comment
|
|
13
|
+
reg(exp) #[-13-] regexp comment
|
|
14
|
+
reg(exp) #[-14-] regexp comment
|
|
15
|
+
///
|
|
16
|
+
@save = (form) =>
|
|
17
|
+
alert "Could now transmit to server: #{ko.utils.stringifyJson @gifts}"
|
|
18
|
+
###[-18-] singleline
|
|
19
|
+
[-19-] multi line
|
|
20
|
+
###
|
|
21
|
+
viewModel = new GiftModel(
|
|
22
|
+
[
|
|
23
|
+
{ name: "Tall Hat", price: "39.95" } #[-23-] singleline
|
|
24
|
+
{ name: "Long Cloak", price: "120.00"}
|
|
25
|
+
])
|
|
26
|
+
ko.applyBindings viewModel
|
|
27
|
+
$("form").validate submitHandler: viewModel.save
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#include "zhelpers.hpp"
|
|
2
|
+
#include <queue>
|
|
3
|
+
//[-3-]Attribution-Share Alike 3.0 License, copyright (c) 2010 Pieter Hintjens, modified @alpaca-tc
|
|
4
|
+
//[-4-]Basic request-reply client using REQ socket
|
|
5
|
+
static void *
|
|
6
|
+
client_thread (void *arg) {
|
|
7
|
+
zmq::context_t context(1);
|
|
8
|
+
zmq::socket_t client (context, ZMQ_REQ);
|
|
9
|
+
s_set_id (client); //[-9-]Makes tracing easier
|
|
10
|
+
client.connect("ipc://frontend.ipc");
|
|
11
|
+
|
|
12
|
+
//[-12-] Send request, get reply
|
|
13
|
+
s_send (client, "HELLO");
|
|
14
|
+
std::string reply = s_recv (client);
|
|
15
|
+
/*[-15-] Send request, get reply [-end-]*/
|
|
16
|
+
return (NULL);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static void *
|
|
20
|
+
worker_thread (void *arg) {
|
|
21
|
+
zmq::context_t context(1);
|
|
22
|
+
zmq::socket_t worker (context, ZMQ_REQ);
|
|
23
|
+
s_set_id (worker);
|
|
24
|
+
worker.connect("ipc://backend.ipc");
|
|
25
|
+
|
|
26
|
+
s_send (worker, "READY");
|
|
27
|
+
|
|
28
|
+
while (1) {
|
|
29
|
+
/*[-29-]
|
|
30
|
+
[-30-]Read and save all frames until we get an empty frame
|
|
31
|
+
[-31-]In this example there is only 1 but it could be more [-end-]*/
|
|
32
|
+
std::string address = s_recv (worker);
|
|
33
|
+
{
|
|
34
|
+
std::string empty = s_recv (worker);
|
|
35
|
+
assert (empty.size() == 0);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
std::string request = s_recv (worker);
|
|
39
|
+
std::cout << "Worker: " << request << std::endl;
|
|
40
|
+
|
|
41
|
+
s_sendmore (worker, address);
|
|
42
|
+
s_sendmore (worker, "");
|
|
43
|
+
s_send (worker, "OK");
|
|
44
|
+
}
|
|
45
|
+
return (NULL);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
int main (int argc, char *argv[])
|
|
49
|
+
{
|
|
50
|
+
|
|
51
|
+
zmq::context_t context(1);
|
|
52
|
+
zmq::socket_t frontend (context, ZMQ_ROUTER);
|
|
53
|
+
zmq::socket_t backend (context, ZMQ_ROUTER);
|
|
54
|
+
frontend.bind("ipc://frontend.ipc");
|
|
55
|
+
backend.bind("ipc://backend.ipc");
|
|
56
|
+
|
|
57
|
+
int client_nbr;
|
|
58
|
+
for (client_nbr = 0; client_nbr < 10; client_nbr++) {
|
|
59
|
+
pthread_t client;
|
|
60
|
+
pthread_create (&client, NULL, client_thread, NULL);
|
|
61
|
+
}
|
|
62
|
+
int worker_nbr;
|
|
63
|
+
for (worker_nbr = 0; worker_nbr < 3; worker_nbr++) {
|
|
64
|
+
pthread_t worker;
|
|
65
|
+
pthread_create (&worker, NULL, worker_thread, NULL);
|
|
66
|
+
}
|
|
67
|
+
std::queue<std::string> worker_queue;
|
|
68
|
+
|
|
69
|
+
while (1) {
|
|
70
|
+
|
|
71
|
+
zmq::pollitem_t items [] = {
|
|
72
|
+
{ backend, 0, ZMQ_POLLIN, 0 },
|
|
73
|
+
{ frontend, 0, ZMQ_POLLIN, 0 }
|
|
74
|
+
};
|
|
75
|
+
if (worker_queue.size())
|
|
76
|
+
zmq::poll (&items [0], 2, -1);
|
|
77
|
+
else
|
|
78
|
+
zmq::poll (&items [0], 1, -1);
|
|
79
|
+
|
|
80
|
+
if (items [0].revents & ZMQ_POLLIN) {
|
|
81
|
+
|
|
82
|
+
worker_queue.push(s_recv (backend));
|
|
83
|
+
|
|
84
|
+
{
|
|
85
|
+
std::string empty = s_recv (backend);
|
|
86
|
+
assert (empty.size() == 0);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
std::string client_addr = s_recv (backend);
|
|
90
|
+
|
|
91
|
+
if (client_addr.compare("READY") != 0) {
|
|
92
|
+
|
|
93
|
+
{
|
|
94
|
+
std::string empty = s_recv (backend);
|
|
95
|
+
assert (empty.size() == 0);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
std::string reply = s_recv (backend);
|
|
99
|
+
s_sendmore (frontend, client_addr);
|
|
100
|
+
s_sendmore (frontend, "");
|
|
101
|
+
s_send (frontend, reply);
|
|
102
|
+
|
|
103
|
+
if (--client_nbr == 0)
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (items [1].revents & ZMQ_POLLIN) {
|
|
108
|
+
|
|
109
|
+
std::string client_addr = s_recv (frontend);
|
|
110
|
+
|
|
111
|
+
{
|
|
112
|
+
std::string empty = s_recv (frontend);
|
|
113
|
+
assert (empty.size() == 0);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
std::string request = s_recv (frontend);
|
|
117
|
+
|
|
118
|
+
std::string worker_addr = worker_queue.front();
|
|
119
|
+
worker_queue.pop();
|
|
120
|
+
|
|
121
|
+
s_sendmore (backend, worker_addr);
|
|
122
|
+
s_sendmore (backend, "");
|
|
123
|
+
s_sendmore (backend, client_addr);
|
|
124
|
+
s_sendmore (backend, "");
|
|
125
|
+
s_send (backend, request);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
sleep (1);
|
|
129
|
+
return 0;
|
|
130
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//[-1-]Attribution-Share Alike 3.0 License, copyright (c) 2010 Pieter Hintjens, modified @alpaca-tc
|
|
2
|
+
//[-2-] Author: Yan Cui
|
|
3
|
+
//[-3-] Email: theburningmonk@gmail.com
|
|
4
|
+
|
|
5
|
+
using System;
|
|
6
|
+
using System.Collections.Generic;
|
|
7
|
+
using System.Threading;
|
|
8
|
+
using ZeroMQ;
|
|
9
|
+
|
|
10
|
+
namespace zguide.clonesrv1
|
|
11
|
+
{
|
|
12
|
+
internal class Program
|
|
13
|
+
{
|
|
14
|
+
public static void Main(string[] args)
|
|
15
|
+
{
|
|
16
|
+
using (var context = ZmqContext.Create())
|
|
17
|
+
{
|
|
18
|
+
using (var publisher = context.CreateSocket(SocketType.PUB))
|
|
19
|
+
{
|
|
20
|
+
publisher.Bind("tcp://*:5556");
|
|
21
|
+
Thread.Sleep(TimeSpan.FromMilliseconds(200));
|
|
22
|
+
|
|
23
|
+
var interrupted = false; //[-23-] single line
|
|
24
|
+
var sequence = 0L;/*[-24-] multi line [-end-]*/
|
|
25
|
+
var random = new Random((int)DateTime.UtcNow.Ticks);
|
|
26
|
+
var dict = new Dictionary<string, KvMsg>();
|
|
27
|
+
/*[-27-]
|
|
28
|
+
[-28-] multi line [-end-]
|
|
29
|
+
*/
|
|
30
|
+
Console.CancelKeyPress += (s, e) => { interrupted = true; };
|
|
31
|
+
|
|
32
|
+
while (!interrupted)
|
|
33
|
+
{
|
|
34
|
+
sequence++;
|
|
35
|
+
var kvmsg = new KvMsg(sequence);
|
|
36
|
+
kvmsg.Key = random.Next(1, 10000).ToString();
|
|
37
|
+
kvmsg.Body = random.Next(1, 1000000).ToString();
|
|
38
|
+
|
|
39
|
+
kvmsg.Send(publisher);
|
|
40
|
+
kvmsg.Store(dict);
|
|
41
|
+
|
|
42
|
+
Console.WriteLine("Published {0}", kvmsg);
|
|
43
|
+
|
|
44
|
+
Thread.Sleep(TimeSpan.FromMilliseconds(100));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
Console.WriteLine(" Interrupted\n{0} messages out\n", sequence);
|
|
48
|
+
Console.ReadKey();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
@charset "UTF-8";
|
|
2
|
+
@font-face {
|
|
3
|
+
font-family: ClumsyRegular;
|
|
4
|
+
src: url(/font/clumsy-webfont.eot);
|
|
5
|
+
src: local("☺"), url(/font/clumsy-webfont.woff) format("woff"), url(/font/clumsy-webfont.ttf) format("truetype"), url(/font/clumsy-webfont.svg#webfontYlE9Voyi) format("svg");
|
|
6
|
+
font-weight: normal;
|
|
7
|
+
font-style: normal;
|
|
8
|
+
}
|
|
9
|
+
/*[-9-] single comment [-end-]*/
|
|
10
|
+
|
|
11
|
+
/*[-11-] multi line comment
|
|
12
|
+
[-12-] multi line comment
|
|
13
|
+
*/
|
|
14
|
+
@font-face {
|
|
15
|
+
font-family: "Courier10BTRoman";
|
|
16
|
+
src: url(/font/courier-10-pitch-bt-webfont.eot);
|
|
17
|
+
src: local("☺"), url(/font/courier-10-pitch-bt-webfont.woff) format("woff"), url(/font/courier-10-pitch-bt-webfont.ttf) format("truetype"), url(/font/courier-10-pitch-bt-webfont.svg#webfontKRtE3TYu) format("svg");
|
|
18
|
+
font-weight: normal;
|
|
19
|
+
font-style: normal;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@font-face {
|
|
23
|
+
font-family: "LietzLindauHamburgRegular";
|
|
24
|
+
src: url(/font/lietzlindauhamburg-webfont.eot);
|
|
25
|
+
src: local("☺"), url(/font/lietzlindauhamburg-webfont.woff) format("woff"), url(/font/lietzlindauhamburg-webfont.ttf) format("truetype"), url(/font/lietzlindauhamburg-webfont.svg#webfont7wlycxIS) format("svg");
|
|
26
|
+
font-weight: normal;
|
|
27
|
+
font-style: normal;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.heading {
|
|
31
|
+
font-family: "PT Serif", "Georgia", "Helvetica Neue", Arial, sans-serif;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.sans, html .gist .gist-file .gist-meta {
|
|
35
|
+
font-family: "PT Sans", "Helvetica Neue", Arial, sans-serif;
|
|
36
|
+
}
|
|
37
|
+
|
|
File without changes
|