langscan 1.2-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. data/AUTHORS.txt +19 -0
  2. data/History.txt +126 -0
  3. data/Manifest.txt +167 -0
  4. data/README.rdoc +91 -0
  5. data/Rakefile +40 -0
  6. data/ext/langscan/_make_c.rb +20 -0
  7. data/ext/langscan/_make_h.rb +30 -0
  8. data/ext/langscan/_template.c +134 -0
  9. data/ext/langscan/_template.h +53 -0
  10. data/ext/langscan/c/c/Makefile +188 -0
  11. data/ext/langscan/c/c/c.c +134 -0
  12. data/ext/langscan/c/c/c.h +66 -0
  13. data/ext/langscan/c/c/ctok.c +4629 -0
  14. data/ext/langscan/c/c/ctok.l +212 -0
  15. data/ext/langscan/c/c/extconf.rb +3 -0
  16. data/ext/langscan/c/c/modulename.txt +1 -0
  17. data/ext/langscan/c/c/tokenlist.txt +13 -0
  18. data/ext/langscan/csharp/csharp/Makefile +188 -0
  19. data/ext/langscan/csharp/csharp/csharp.c +134 -0
  20. data/ext/langscan/csharp/csharp/csharp.h +65 -0
  21. data/ext/langscan/csharp/csharp/csharptok.c +2971 -0
  22. data/ext/langscan/csharp/csharp/csharptok.l +200 -0
  23. data/ext/langscan/csharp/csharp/extconf.rb +3 -0
  24. data/ext/langscan/csharp/csharp/modulename.txt +1 -0
  25. data/ext/langscan/csharp/csharp/tokenlist.txt +12 -0
  26. data/ext/langscan/d/d/Makefile +188 -0
  27. data/ext/langscan/d/d/d.c +134 -0
  28. data/ext/langscan/d/d/d.h +64 -0
  29. data/ext/langscan/d/d/dtok.c +5468 -0
  30. data/ext/langscan/d/d/dtok.l +282 -0
  31. data/ext/langscan/d/d/extconf.rb +3 -0
  32. data/ext/langscan/d/d/modulename.txt +1 -0
  33. data/ext/langscan/d/d/tokenlist.txt +11 -0
  34. data/ext/langscan/elisp/elisp/Makefile +188 -0
  35. data/ext/langscan/elisp/elisp/elisp.c +134 -0
  36. data/ext/langscan/elisp/elisp/elisp.h +62 -0
  37. data/ext/langscan/elisp/elisp/elisptok.c +2108 -0
  38. data/ext/langscan/elisp/elisp/elisptok.l +151 -0
  39. data/ext/langscan/elisp/elisp/extconf.rb +3 -0
  40. data/ext/langscan/elisp/elisp/modulename.txt +1 -0
  41. data/ext/langscan/elisp/elisp/tokenlist.txt +9 -0
  42. data/ext/langscan/java/java/Makefile +188 -0
  43. data/ext/langscan/java/java/extconf.rb +3 -0
  44. data/ext/langscan/java/java/java.c +134 -0
  45. data/ext/langscan/java/java/java.h +64 -0
  46. data/ext/langscan/java/java/javatok.c +2097 -0
  47. data/ext/langscan/java/java/javatok.l +155 -0
  48. data/ext/langscan/java/java/modulename.txt +1 -0
  49. data/ext/langscan/java/java/tokenlist.txt +11 -0
  50. data/ext/langscan/javascript/javascript/Makefile +188 -0
  51. data/ext/langscan/javascript/javascript/extconf.rb +3 -0
  52. data/ext/langscan/javascript/javascript/javascript.c +134 -0
  53. data/ext/langscan/javascript/javascript/javascript.h +63 -0
  54. data/ext/langscan/javascript/javascript/javascripttok.c +2058 -0
  55. data/ext/langscan/javascript/javascript/javascripttok.l +147 -0
  56. data/ext/langscan/javascript/javascript/modulename.txt +1 -0
  57. data/ext/langscan/javascript/javascript/tokenlist.txt +10 -0
  58. data/ext/langscan/pairmatcher/pairmatcher/Makefile +188 -0
  59. data/ext/langscan/pairmatcher/pairmatcher/extconf.rb +3 -0
  60. data/ext/langscan/pairmatcher/pairmatcher/pairmatcher.c +890 -0
  61. data/ext/langscan/php/php/Makefile +188 -0
  62. data/ext/langscan/php/php/extconf.rb +3 -0
  63. data/ext/langscan/php/php/modulename.txt +1 -0
  64. data/ext/langscan/php/php/php.c +134 -0
  65. data/ext/langscan/php/php/php.h +64 -0
  66. data/ext/langscan/php/php/phptok.c +2413 -0
  67. data/ext/langscan/php/php/phptok.l +212 -0
  68. data/ext/langscan/php/php/tokenlist.txt +11 -0
  69. data/ext/langscan/post-distclean.rb +21 -0
  70. data/ext/langscan/pre-config.rb +57 -0
  71. data/ext/langscan/python/python/Makefile +188 -0
  72. data/ext/langscan/python/python/extconf.rb +3 -0
  73. data/ext/langscan/python/python/modulename.txt +1 -0
  74. data/ext/langscan/python/python/python.c +134 -0
  75. data/ext/langscan/python/python/python.h +61 -0
  76. data/ext/langscan/python/python/pythontok.c +2109 -0
  77. data/ext/langscan/python/python/pythontok.l +155 -0
  78. data/ext/langscan/python/python/tokenlist.txt +8 -0
  79. data/ext/langscan/ruby/compat/ripper/Makefile +189 -0
  80. data/ext/langscan/ruby/compat/ripper/depend +1 -0
  81. data/ext/langscan/ruby/compat/ripper/extconf.rb +4 -0
  82. data/ext/langscan/ruby/compat/ripper/include/eventids1.c +251 -0
  83. data/ext/langscan/ruby/compat/ripper/include/eventids2.c +277 -0
  84. data/ext/langscan/ruby/compat/ripper/include/lex.c +138 -0
  85. data/ext/langscan/ruby/compat/ripper/ripper.c +14420 -0
  86. data/ext/langscan/scheme/scheme/Makefile +188 -0
  87. data/ext/langscan/scheme/scheme/extconf.rb +3 -0
  88. data/ext/langscan/scheme/scheme/modulename.txt +1 -0
  89. data/ext/langscan/scheme/scheme/scheme.c +134 -0
  90. data/ext/langscan/scheme/scheme/scheme.h +60 -0
  91. data/ext/langscan/scheme/scheme/schemetok.c +2454 -0
  92. data/ext/langscan/scheme/scheme/schemetok.l +177 -0
  93. data/ext/langscan/scheme/scheme/tokenlist.txt +7 -0
  94. data/ext/langscan/sh/sh/Makefile +188 -0
  95. data/ext/langscan/sh/sh/extconf.rb +3 -0
  96. data/ext/langscan/sh/sh/modulename.txt +1 -0
  97. data/ext/langscan/sh/sh/sh.c +134 -0
  98. data/ext/langscan/sh/sh/sh.h +61 -0
  99. data/ext/langscan/sh/sh/shtok.c +2477 -0
  100. data/ext/langscan/sh/sh/shtok.l +325 -0
  101. data/ext/langscan/sh/sh/tokenlist.txt +8 -0
  102. data/lib/langscan.rb +124 -0
  103. data/lib/langscan/_common.rb +50 -0
  104. data/lib/langscan/_easyscanner.rb +78 -0
  105. data/lib/langscan/_pairmatcher.rb +46 -0
  106. data/lib/langscan/_type.rb +125 -0
  107. data/lib/langscan/autoconf.rb +51 -0
  108. data/lib/langscan/automake.rb +51 -0
  109. data/lib/langscan/brainfuck.rb +48 -0
  110. data/lib/langscan/c.rb +144 -0
  111. data/lib/langscan/c/c.so +0 -0
  112. data/lib/langscan/csharp.rb +101 -0
  113. data/lib/langscan/csharp/csharp.so +0 -0
  114. data/lib/langscan/css.rb +109 -0
  115. data/lib/langscan/d.rb +201 -0
  116. data/lib/langscan/d/d.so +0 -0
  117. data/lib/langscan/eiffel.rb +167 -0
  118. data/lib/langscan/elisp.rb +132 -0
  119. data/lib/langscan/elisp/elisp.so +0 -0
  120. data/lib/langscan/io.rb +84 -0
  121. data/lib/langscan/java.rb +95 -0
  122. data/lib/langscan/java/java.so +0 -0
  123. data/lib/langscan/javascript.rb +97 -0
  124. data/lib/langscan/javascript/javascript.so +0 -0
  125. data/lib/langscan/lua.rb +116 -0
  126. data/lib/langscan/ocaml.rb +298 -0
  127. data/lib/langscan/ocaml/camlexer.ml +28 -0
  128. data/lib/langscan/ocaml/lexer.mll +230 -0
  129. data/lib/langscan/ocaml/types.ml +36 -0
  130. data/lib/langscan/pairmatcher/pairmatcher.so +0 -0
  131. data/lib/langscan/perl.rb +87 -0
  132. data/lib/langscan/perl/tokenizer.pl +231 -0
  133. data/lib/langscan/php.rb +80 -0
  134. data/lib/langscan/php/php.so +0 -0
  135. data/lib/langscan/python.rb +101 -0
  136. data/lib/langscan/python/python.so +0 -0
  137. data/lib/langscan/rpmspec.rb +71 -0
  138. data/lib/langscan/ruby.rb +164 -0
  139. data/lib/langscan/ruby/compat/README +5 -0
  140. data/lib/langscan/ruby/compat/ripper.rb +4 -0
  141. data/lib/langscan/ruby/compat/ripper.so +0 -0
  142. data/lib/langscan/ruby/compat/ripper/core.rb +918 -0
  143. data/lib/langscan/ruby/compat/ripper/filter.rb +70 -0
  144. data/lib/langscan/ruby/compat/ripper/lexer.rb +179 -0
  145. data/lib/langscan/ruby/compat/ripper/sexp.rb +100 -0
  146. data/lib/langscan/scheme.rb +160 -0
  147. data/lib/langscan/scheme/scheme.so +0 -0
  148. data/lib/langscan/sh.rb +116 -0
  149. data/lib/langscan/sh/sh.so +0 -0
  150. data/lib/langscan/text.rb +37 -0
  151. data/metaconfig +2 -0
  152. data/script/console +10 -0
  153. data/script/destroy +14 -0
  154. data/script/generate +14 -0
  155. data/script/makemanifest.rb +21 -0
  156. data/setup.rb +1604 -0
  157. data/tasks/extconf.rake +13 -0
  158. data/tasks/extconf/langscan.rake +42 -0
  159. data/test/langscan/brainfuck/test/test_scan.rb +55 -0
  160. data/test/langscan/c/test/test_scan.rb +216 -0
  161. data/test/langscan/c/test/test_token.rb +41 -0
  162. data/test/langscan/csharp/test/test_scan.rb +157 -0
  163. data/test/langscan/css/test/test_css.rb +79 -0
  164. data/test/langscan/d/test/test_scan.rb +233 -0
  165. data/test/langscan/d/test/test_token.rb +205 -0
  166. data/test/langscan/eiffel/test/test_eiffel.rb +95 -0
  167. data/test/langscan/elisp/test/test_elisp.rb +177 -0
  168. data/test/langscan/io/test/test_io.rb +79 -0
  169. data/test/langscan/java/test/test_java.rb +74 -0
  170. data/test/langscan/javascript/test/test_javascript.rb +39 -0
  171. data/test/langscan/lua/test/test_lua.rb +69 -0
  172. data/test/langscan/ocaml/test/test_ocaml.rb +161 -0
  173. data/test/langscan/php/test/test_scan.rb +138 -0
  174. data/test/langscan/python/test/test_scan.rb +105 -0
  175. data/test/langscan/rpmspec/test/test_rpmspec.rb +51 -0
  176. data/test/langscan/ruby/test/test_scan.rb +71 -0
  177. data/test/langscan/scheme/test/test_scan.rb +198 -0
  178. data/test/test_helper.rb +7 -0
  179. data/test/test_langscan.rb +123 -0
  180. metadata +320 -0
@@ -0,0 +1,30 @@
1
+ require 'fileutils'
2
+ raise unless ARGV.length == 5
3
+ template_file_name = ARGV.shift
4
+ output_directory = ARGV.shift
5
+ token_list_file_name = ARGV.shift
6
+ lang_abbrev = ARGV.shift
7
+ module_name = ARGV.shift
8
+
9
+ token_list = File.open(token_list_file_name).readlines.map {|line| line.chomp }
10
+
11
+ lines = ["#define LANGSCAN_LANGNAME_TOKEN_LIST"]
12
+ token_list.each {|token|
13
+ lines.push(" LANGSCAN_LANGNAME_TOKEN(#{token})")
14
+ }
15
+ macro = lines.join(" \\\n")
16
+
17
+ template = File.read(template_file_name)
18
+ template.gsub!(/@LANGSCAN_LANGNAME_TOKEN_LIST@/, macro)
19
+ template.gsub!(/LANGNAME/, lang_abbrev.upcase)
20
+ template.gsub!(/langname/, lang_abbrev.downcase)
21
+ template.gsub!(/LangName/, module_name)
22
+
23
+ h_file_name = File.join( output_directory, lang_abbrev + ".h" )
24
+ FileUtils.rm_rf(h_file_name)
25
+ File.open(h_file_name, "w") {|f|
26
+ # f.printf("/* %s generated automatically from %s */\n",
27
+ # h_file_name, template_file_name)
28
+ f.print template
29
+ }
30
+ #File.chmod(0444, h_file_name)
@@ -0,0 +1,134 @@
1
+ /* -*- mode: C; indent-tabs-mode: nil; c-basic-offset: 2 c-style: "BSD" -*- */
2
+ /*
3
+ * _template.c - a template file for LangScan modules
4
+ *
5
+ * Copyright (C) 2004-2005 Akira Tanaka <akr@m17n.org>
6
+ * All rights reserved.
7
+ * This is free software with ABSOLUTELY NO WARRANTY.
8
+ *
9
+ * You can redistribute it and/or modify it under the terms of
10
+ * the GNU General Public License version 2.
11
+ */
12
+
13
+
14
+ #include <ruby.h>
15
+ #include "langname.h"
16
+
17
+ static VALUE token_symbol_list[
18
+ #define LANGSCAN_LANGNAME_TOKEN(token) 1 +
19
+ 1 + LANGSCAN_LANGNAME_TOKEN_LIST 0
20
+ #undef LANGSCAN_LANGNAME_TOKEN
21
+ ];
22
+
23
+ #ifndef RSTRING_PTR
24
+ # define RSTRING_PTR(str) (RSTRING(str)->ptr)
25
+ #endif
26
+ #ifndef RSTRING_LEN
27
+ # define RSTRING_LEN(str) (RSTRING(str)->len)
28
+ #endif
29
+
30
+ #ifndef RARRAY_PTR
31
+ # define RARRAY_PTR(str) (RARRAY(str)->ptr)
32
+ #endif
33
+ #ifndef RARRAY_LEN
34
+ # define RARRAY_LEN(str) (RARRAY(str)->len)
35
+ #endif
36
+
37
+ static size_t user_read_str(void **user_data_p, char *buf, size_t maxlen)
38
+ {
39
+ VALUE user_data = (VALUE)*user_data_p;
40
+ VALUE user_str = RARRAY_PTR(user_data)[0];
41
+ VALUE user_off = RARRAY_PTR(user_data)[1];
42
+ long off = NUM2LONG(user_off);
43
+ if (RSTRING_LEN(user_str)-off < maxlen) {
44
+ maxlen = RSTRING_LEN(user_str)-off;
45
+ }
46
+ memcpy(buf, RSTRING_PTR(user_str)+off, maxlen);
47
+ RARRAY_PTR(user_data)[1] = LONG2NUM(off+maxlen);
48
+ return maxlen;
49
+ }
50
+
51
+ static void tokenizer_mark(langscan_langname_tokenizer_t *tokenizer)
52
+ {
53
+ if (tokenizer == NULL)
54
+ return;
55
+ rb_gc_mark((VALUE)langscan_langname_tokenizer_get_user_data(tokenizer));
56
+ }
57
+
58
+ static void tokenizer_free(langscan_langname_tokenizer_t *tokenizer)
59
+ {
60
+ if (tokenizer == NULL)
61
+ return;
62
+ langscan_langname_free_tokenizer(tokenizer);
63
+ }
64
+
65
+ static VALUE tokenizer_s_allocate(VALUE klass)
66
+ {
67
+ return Data_Wrap_Struct(klass, tokenizer_mark, tokenizer_free, NULL);
68
+ }
69
+
70
+ static VALUE tokenizer_initialize(VALUE self, VALUE user_data)
71
+ {
72
+ VALUE tmp;
73
+ user_read_t user_read;
74
+ langscan_langname_tokenizer_t *tokenizer;
75
+ Data_Get_Struct(self, langscan_langname_tokenizer_t, tokenizer);
76
+ StringValue(user_data);
77
+ user_read = user_read_str;
78
+ user_data = rb_ary_new3(2, rb_str_new4(user_data), INT2FIX(0));
79
+ RBASIC(user_data)->klass = 0;
80
+ DATA_PTR(self) = langscan_langname_make_tokenizer(user_read, (void *)user_data);
81
+ return self;
82
+ }
83
+
84
+ static VALUE tokenizer_get_token(VALUE self)
85
+ {
86
+ langscan_langname_tokenizer_t *tokenizer;
87
+ langscan_langname_token_t token;
88
+ Data_Get_Struct(self, langscan_langname_tokenizer_t, tokenizer);
89
+ if (tokenizer == NULL) { return Qnil; }
90
+ token = langscan_langname_get_token(tokenizer);
91
+ if (token == langscan_langname_eof) {
92
+ DATA_PTR(self) = NULL;
93
+ langscan_langname_free_tokenizer(tokenizer);
94
+ return Qnil;
95
+ }
96
+ return rb_ary_new3(8,
97
+ token_symbol_list[token],
98
+ rb_str_new(langscan_langname_curtoken_text(tokenizer), langscan_langname_curtoken_leng(tokenizer)),
99
+ INT2NUM(langscan_langname_curtoken_beg_lineno(tokenizer)),
100
+ INT2NUM(langscan_langname_curtoken_beg_columnno(tokenizer)),
101
+ INT2NUM(langscan_langname_curtoken_beg_byteno(tokenizer)),
102
+ INT2NUM(langscan_langname_curtoken_end_lineno(tokenizer)),
103
+ INT2NUM(langscan_langname_curtoken_end_columnno(tokenizer)),
104
+ INT2NUM(langscan_langname_curtoken_end_byteno(tokenizer)));
105
+ }
106
+
107
+ static VALUE tokenizer_close(VALUE self)
108
+ {
109
+ langscan_langname_tokenizer_t *tokenizer;
110
+ Data_Get_Struct(self, langscan_langname_tokenizer_t, tokenizer);
111
+ if (tokenizer == NULL) { return Qnil; }
112
+ DATA_PTR(self) = NULL;
113
+ langscan_langname_free_tokenizer(tokenizer);
114
+ return Qnil;
115
+ }
116
+
117
+ void Init_langname()
118
+ {
119
+ VALUE LangScan = rb_define_module("LangScan");
120
+ VALUE LangScan_LANGNAME = rb_define_module_under(LangScan, "LangName");
121
+ VALUE Tokenizer = rb_define_class_under(LangScan_LANGNAME, "Tokenizer", rb_cData);
122
+ langscan_langname_token_t token_id;
123
+
124
+ token_id = 0;
125
+ token_symbol_list[token_id++] = Qnil;
126
+ #define LANGSCAN_LANGNAME_TOKEN(token) token_symbol_list[token_id++] = ID2SYM(rb_intern(#token));
127
+ LANGSCAN_LANGNAME_TOKEN_LIST
128
+ #undef LANGSCAN_LANGNAME_TOKEN
129
+
130
+ rb_define_alloc_func(Tokenizer, tokenizer_s_allocate);
131
+ rb_define_method(Tokenizer, "initialize", tokenizer_initialize, 1);
132
+ rb_define_method(Tokenizer, "get_token", tokenizer_get_token, 0);
133
+ rb_define_method(Tokenizer, "close", tokenizer_close, 0);
134
+ }
@@ -0,0 +1,53 @@
1
+ #ifndef LANGSCAN_LANGNAME_H
2
+ #define LANGSCAN_LANGNAME_H
3
+
4
+ @LANGSCAN_LANGNAME_TOKEN_LIST@
5
+
6
+ typedef enum {
7
+ langscan_langname_eof = 0,
8
+ #define LANGSCAN_LANGNAME_TOKEN(name) langscan_langname_##name,
9
+ LANGSCAN_LANGNAME_TOKEN_LIST
10
+ #undef LANGSCAN_LANGNAME_TOKEN
11
+ } langscan_langname_token_t;
12
+
13
+ typedef struct {
14
+ int beg_lineno;
15
+ int beg_columnno;
16
+ int beg_byteno;
17
+ int end_lineno;
18
+ int end_columnno;
19
+ int end_byteno;
20
+ int eof;
21
+ char *text;
22
+ int leng;
23
+ size_t (*user_read)(void **user_data_p, char *buf, size_t maxlen);
24
+ void *user_data;
25
+ } langscan_langname_lex_extra_t;
26
+
27
+ typedef struct langscan_langname_tokenizer_tag {
28
+ langscan_langname_lex_extra_t *extra;
29
+ void *scanner;
30
+ } langscan_langname_tokenizer_t;
31
+
32
+ typedef size_t (*user_read_t)(void **user_data_p, char *buf, size_t maxlen);
33
+
34
+ langscan_langname_tokenizer_t *langscan_langname_make_tokenizer(user_read_t user_read, void *user_data);
35
+ langscan_langname_token_t langscan_langname_get_token(langscan_langname_tokenizer_t *tokenizer);
36
+ void langscan_langname_free_tokenizer(langscan_langname_tokenizer_t *tokenizer);
37
+
38
+ user_read_t langscan_langname_tokenizer_get_user_read(langscan_langname_tokenizer_t *tokenizer);
39
+ void *langscan_langname_tokenizer_get_user_data(langscan_langname_tokenizer_t *tokenizer);
40
+
41
+ const char *langscan_langname_token_name(langscan_langname_token_t token);
42
+ #define langscan_langname_curtoken_beg_lineno(tokenizer) ((tokenizer)->extra->beg_lineno)
43
+ #define langscan_langname_curtoken_beg_columnno(tokenizer) ((tokenizer)->extra->beg_columnno)
44
+ #define langscan_langname_curtoken_beg_byteno(tokenizer) ((tokenizer)->extra->beg_byteno)
45
+ #define langscan_langname_curtoken_end_lineno(tokenizer) ((tokenizer)->extra->end_lineno)
46
+ #define langscan_langname_curtoken_end_columnno(tokenizer) ((tokenizer)->extra->end_columnno)
47
+ #define langscan_langname_curtoken_end_byteno(tokenizer) ((tokenizer)->extra->end_byteno)
48
+ #define langscan_langname_curtoken_text(tokenizer) ((tokenizer)->extra->text)
49
+ #define langscan_langname_curtoken_leng(tokenizer) ((tokenizer)->extra->leng)
50
+
51
+ void langscan_langname_extract_functions(langscan_langname_tokenizer_t *);
52
+
53
+ #endif
@@ -0,0 +1,188 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = .
7
+ topdir = C:/usr/ruby/lib/ruby/1.8/i386-mswin32
8
+ hdrdir = $(topdir)
9
+ VPATH = $(srcdir);$(topdir);$(hdrdir)
10
+
11
+ DESTDIR = C:
12
+ exec_prefix = $(prefix)
13
+ prefix = $(DESTDIR)/usr/ruby
14
+ sharedstatedir = $(DESTDIR)/etc
15
+ mandir = $(prefix)/man
16
+ oldincludedir = $(DESTDIR)/usr/include
17
+ bindir = $(exec_prefix)/bin
18
+ libexecdir = $(exec_prefix)/libexec
19
+ sitedir = $(prefix)/lib/ruby/site_ruby
20
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
21
+ includedir = $(prefix)/include
22
+ infodir = $(prefix)/info
23
+ vendorlibdir = $(vendordir)/$(ruby_version)
24
+ sysconfdir = $(prefix)/etc
25
+ libdir = $(exec_prefix)/lib
26
+ sbindir = $(exec_prefix)/sbin
27
+ rubylibdir = $(libdir)/ruby/$(ruby_version)
28
+ vendordir = $(prefix)/lib/ruby/vendor_ruby
29
+ archdir = $(rubylibdir)/$(arch)
30
+ sitearchdir = $(sitelibdir)/$(sitearch)
31
+ datadir = $(prefix)/share
32
+ localstatedir = $(DESTDIR)/var
33
+ sitelibdir = $(sitedir)/$(ruby_version)
34
+
35
+ CC = cl -nologo
36
+ LIBRUBY = $(RUBY_SO_NAME).lib
37
+ LIBRUBY_A = $(RUBY_SO_NAME)-static.lib
38
+ LIBRUBYARG_SHARED = $(LIBRUBY)
39
+ LIBRUBYARG_STATIC = $(LIBRUBY_A)
40
+
41
+ RUBY_EXTCONF_H =
42
+ CFLAGS = -MT -Zi -O2b2xg- -G6
43
+ INCFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir)
44
+ DEFS =
45
+ CPPFLAGS =
46
+ CXXFLAGS = $(CFLAGS)
47
+ ldflags =
48
+ dldflags = -link -incremental:no -debug -opt:ref -opt:icf -dll $(LIBPATH)
49
+ archflag =
50
+ DLDFLAGS = $(ldflags) $(dldflags) $(archflag)
51
+ LDSHARED = cl -nologo -LD
52
+ AR = lib -nologo
53
+ EXEEXT = .exe
54
+
55
+ RUBY_INSTALL_NAME = ruby
56
+ RUBY_SO_NAME = msvcrt-ruby18
57
+ arch = i386-mswin32
58
+ sitearch = i386-msvcrt
59
+ ruby_version = 1.8
60
+ ruby = C:/usr/ruby/bin/ruby
61
+ RUBY = $(ruby:/=\)
62
+ RM = $(RUBY) -run -e rm -- -f
63
+ MAKEDIRS = @$(RUBY) -run -e mkdir -- -p
64
+ INSTALL = @$(RUBY) -run -e install -- -vp
65
+ INSTALL_PROG = $(INSTALL) -m 0755
66
+ INSTALL_DATA = $(INSTALL) -m 0644
67
+ COPY = copy > nul
68
+
69
+ #### End of system configuration section. ####
70
+
71
+ preload =
72
+
73
+ libpath = . $(libdir)
74
+ LIBPATH = -libpath:"." -libpath:"$(libdir)"
75
+ DEFFILE = $(TARGET)-$(arch).def
76
+
77
+ CLEANFILES = mkmf.log
78
+ DISTCLEANFILES = vc*.pdb $(DEFFILE)
79
+
80
+ extout =
81
+ extout_prefix =
82
+ target_prefix = /langscan/c
83
+ LOCAL_LIBS =
84
+ LIBS = $(LIBRUBYARG_SHARED) oldnames.lib user32.lib advapi32.lib shell32.lib ws2_32.lib
85
+ SRCS = c.c ctok.c
86
+ OBJS = c.obj ctok.obj
87
+ TARGET = c
88
+ DLLIB = $(TARGET).so
89
+ EXTSTATIC =
90
+ STATIC_LIB =
91
+
92
+ BINDIR = $(bindir)
93
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
94
+ RUBYLIBDIR = C:/devel/gem/git/langscan/pkg/langscan-1.2.gem.build/lib$(target_prefix)
95
+ RUBYARCHDIR = C:/devel/gem/git/langscan/pkg/langscan-1.2.gem.build/lib$(target_prefix)
96
+
97
+ TARGET_SO = $(DLLIB)
98
+ CLEANLIBS = $(TARGET).so $(TARGET).il? $(TARGET).tds $(TARGET).map
99
+ CLEANOBJS = *.obj *.lib *.s[ol] *.pdb *.exp *.bak
100
+
101
+ all: $(DLLIB)
102
+ static: $(STATIC_LIB)
103
+
104
+ clean:
105
+ @-$(RM) $(CLEANLIBS:/=\) $(CLEANOBJS:/=\) $(CLEANFILES:/=\)
106
+
107
+ distclean: clean
108
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
109
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES:/=\)
110
+
111
+ realclean: distclean
112
+ install: install-so install-rb
113
+
114
+ install-so: $(RUBYARCHDIR)
115
+ install-so: $(RUBYARCHDIR)/$(DLLIB)
116
+ $(RUBYARCHDIR)/$(DLLIB): $(DLLIB)
117
+ $(INSTALL_PROG) $(DLLIB:/=\) $(RUBYARCHDIR:/=\)
118
+ install-rb: pre-install-rb install-rb-default
119
+ install-rb-default: pre-install-rb-default
120
+ pre-install-rb: Makefile
121
+ pre-install-rb-default: Makefile
122
+ $(RUBYARCHDIR):
123
+ $(MAKEDIRS) $@
124
+
125
+ site-install: site-install-so site-install-rb
126
+ site-install-so: install-so
127
+ site-install-rb: install-rb
128
+
129
+ .SUFFIXES: .c .m .cc .cxx .cpp .obj
130
+
131
+ {$(hdrdir)}.cc{}.obj:
132
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
133
+
134
+ {$(topdir)}.cc{}.obj:
135
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
136
+
137
+ {$(srcdir)}.cc{}.obj:
138
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
139
+
140
+ .cc.obj:
141
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
142
+
143
+ {$(hdrdir)}.cxx{}.obj:
144
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
145
+
146
+ {$(topdir)}.cxx{}.obj:
147
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
148
+
149
+ {$(srcdir)}.cxx{}.obj:
150
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
151
+
152
+ .cxx.obj:
153
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
154
+
155
+ {$(hdrdir)}.cpp{}.obj:
156
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
157
+
158
+ {$(topdir)}.cpp{}.obj:
159
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
160
+
161
+ {$(srcdir)}.cpp{}.obj:
162
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
163
+
164
+ .cpp.obj:
165
+ $(CXX) $(INCFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c -Tp$(<:\=/)
166
+
167
+ {$(hdrdir)}.c{}.obj:
168
+ $(CC) $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:\=/)
169
+
170
+ {$(topdir)}.c{}.obj:
171
+ $(CC) $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:\=/)
172
+
173
+ {$(srcdir)}.c{}.obj:
174
+ $(CC) $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:\=/)
175
+
176
+ .c.obj:
177
+ $(CC) $(INCFLAGS) $(CFLAGS) $(CPPFLAGS) -c -Tc$(<:\=/)
178
+
179
+ $(DLLIB): $(DEFFILE) $(OBJS) Makefile
180
+ @-$(RM) $@
181
+ $(LDSHARED) -Fe$(@) $(OBJS) $(LIBS) $(LOCAL_LIBS) $(DLDFLAGS) -implib:$(*F:.so=)-$(arch).lib -pdb:$(*F:.so=)-$(arch).pdb -def:$(DEFFILE)
182
+
183
+
184
+
185
+ $(DEFFILE):
186
+ $(RUBY) -e "puts 'EXPORTS', 'Init_$(TARGET)'" > $@
187
+
188
+ $(OBJS): {.;$(VPATH)}ruby.h {.;$(VPATH)}defines.h
@@ -0,0 +1,134 @@
1
+ /* -*- mode: C; indent-tabs-mode: nil; c-basic-offset: 2 c-style: "BSD" -*- */
2
+ /*
3
+ * _template.c - a template file for LangScan modules
4
+ *
5
+ * Copyright (C) 2004-2005 Akira Tanaka <akr@m17n.org>
6
+ * All rights reserved.
7
+ * This is free software with ABSOLUTELY NO WARRANTY.
8
+ *
9
+ * You can redistribute it and/or modify it under the terms of
10
+ * the GNU General Public License version 2.
11
+ */
12
+
13
+
14
+ #include <ruby.h>
15
+ #include "c.h"
16
+
17
+ static VALUE token_symbol_list[
18
+ #define LANGSCAN_C_TOKEN(token) 1 +
19
+ 1 + LANGSCAN_C_TOKEN_LIST 0
20
+ #undef LANGSCAN_C_TOKEN
21
+ ];
22
+
23
+ #ifndef RSTRING_PTR
24
+ # define RSTRING_PTR(str) (RSTRING(str)->ptr)
25
+ #endif
26
+ #ifndef RSTRING_LEN
27
+ # define RSTRING_LEN(str) (RSTRING(str)->len)
28
+ #endif
29
+
30
+ #ifndef RARRAY_PTR
31
+ # define RARRAY_PTR(str) (RARRAY(str)->ptr)
32
+ #endif
33
+ #ifndef RARRAY_LEN
34
+ # define RARRAY_LEN(str) (RARRAY(str)->len)
35
+ #endif
36
+
37
+ static size_t user_read_str(void **user_data_p, char *buf, size_t maxlen)
38
+ {
39
+ VALUE user_data = (VALUE)*user_data_p;
40
+ VALUE user_str = RARRAY_PTR(user_data)[0];
41
+ VALUE user_off = RARRAY_PTR(user_data)[1];
42
+ long off = NUM2LONG(user_off);
43
+ if (RSTRING_LEN(user_str)-off < maxlen) {
44
+ maxlen = RSTRING_LEN(user_str)-off;
45
+ }
46
+ memcpy(buf, RSTRING_PTR(user_str)+off, maxlen);
47
+ RARRAY_PTR(user_data)[1] = LONG2NUM(off+maxlen);
48
+ return maxlen;
49
+ }
50
+
51
+ static void tokenizer_mark(langscan_c_tokenizer_t *tokenizer)
52
+ {
53
+ if (tokenizer == NULL)
54
+ return;
55
+ rb_gc_mark((VALUE)langscan_c_tokenizer_get_user_data(tokenizer));
56
+ }
57
+
58
+ static void tokenizer_free(langscan_c_tokenizer_t *tokenizer)
59
+ {
60
+ if (tokenizer == NULL)
61
+ return;
62
+ langscan_c_free_tokenizer(tokenizer);
63
+ }
64
+
65
+ static VALUE tokenizer_s_allocate(VALUE klass)
66
+ {
67
+ return Data_Wrap_Struct(klass, tokenizer_mark, tokenizer_free, NULL);
68
+ }
69
+
70
+ static VALUE tokenizer_initialize(VALUE self, VALUE user_data)
71
+ {
72
+ VALUE tmp;
73
+ user_read_t user_read;
74
+ langscan_c_tokenizer_t *tokenizer;
75
+ Data_Get_Struct(self, langscan_c_tokenizer_t, tokenizer);
76
+ StringValue(user_data);
77
+ user_read = user_read_str;
78
+ user_data = rb_ary_new3(2, rb_str_new4(user_data), INT2FIX(0));
79
+ RBASIC(user_data)->klass = 0;
80
+ DATA_PTR(self) = langscan_c_make_tokenizer(user_read, (void *)user_data);
81
+ return self;
82
+ }
83
+
84
+ static VALUE tokenizer_get_token(VALUE self)
85
+ {
86
+ langscan_c_tokenizer_t *tokenizer;
87
+ langscan_c_token_t token;
88
+ Data_Get_Struct(self, langscan_c_tokenizer_t, tokenizer);
89
+ if (tokenizer == NULL) { return Qnil; }
90
+ token = langscan_c_get_token(tokenizer);
91
+ if (token == langscan_c_eof) {
92
+ DATA_PTR(self) = NULL;
93
+ langscan_c_free_tokenizer(tokenizer);
94
+ return Qnil;
95
+ }
96
+ return rb_ary_new3(8,
97
+ token_symbol_list[token],
98
+ rb_str_new(langscan_c_curtoken_text(tokenizer), langscan_c_curtoken_leng(tokenizer)),
99
+ INT2NUM(langscan_c_curtoken_beg_lineno(tokenizer)),
100
+ INT2NUM(langscan_c_curtoken_beg_columnno(tokenizer)),
101
+ INT2NUM(langscan_c_curtoken_beg_byteno(tokenizer)),
102
+ INT2NUM(langscan_c_curtoken_end_lineno(tokenizer)),
103
+ INT2NUM(langscan_c_curtoken_end_columnno(tokenizer)),
104
+ INT2NUM(langscan_c_curtoken_end_byteno(tokenizer)));
105
+ }
106
+
107
+ static VALUE tokenizer_close(VALUE self)
108
+ {
109
+ langscan_c_tokenizer_t *tokenizer;
110
+ Data_Get_Struct(self, langscan_c_tokenizer_t, tokenizer);
111
+ if (tokenizer == NULL) { return Qnil; }
112
+ DATA_PTR(self) = NULL;
113
+ langscan_c_free_tokenizer(tokenizer);
114
+ return Qnil;
115
+ }
116
+
117
+ void Init_c()
118
+ {
119
+ VALUE LangScan = rb_define_module("LangScan");
120
+ VALUE LangScan_C = rb_define_module_under(LangScan, "C");
121
+ VALUE Tokenizer = rb_define_class_under(LangScan_C, "Tokenizer", rb_cData);
122
+ langscan_c_token_t token_id;
123
+
124
+ token_id = 0;
125
+ token_symbol_list[token_id++] = Qnil;
126
+ #define LANGSCAN_C_TOKEN(token) token_symbol_list[token_id++] = ID2SYM(rb_intern(#token));
127
+ LANGSCAN_C_TOKEN_LIST
128
+ #undef LANGSCAN_C_TOKEN
129
+
130
+ rb_define_alloc_func(Tokenizer, tokenizer_s_allocate);
131
+ rb_define_method(Tokenizer, "initialize", tokenizer_initialize, 1);
132
+ rb_define_method(Tokenizer, "get_token", tokenizer_get_token, 0);
133
+ rb_define_method(Tokenizer, "close", tokenizer_close, 0);
134
+ }