ray 0.0.1 → 0.1.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.yardopts +4 -0
- data/README.md +17 -21
- data/Rakefile +18 -139
- data/VERSION +1 -1
- data/ext/audio.cpp +723 -0
- data/ext/{color.c → color.cpp} +25 -13
- data/ext/drawable.cpp +91 -0
- data/ext/event.cpp +460 -0
- data/ext/extconf.rb +5 -104
- data/ext/font.cpp +190 -0
- data/ext/image.cpp +733 -0
- data/ext/input.cpp +74 -0
- data/ext/ray.cpp +168 -0
- data/ext/ray.hpp +356 -0
- data/ext/{rect.c → rect.cpp} +51 -37
- data/ext/shader.cpp +169 -0
- data/ext/shape.cpp +409 -0
- data/ext/sprite.cpp +306 -0
- data/ext/text.cpp +181 -0
- data/ext/vector.cpp +215 -0
- data/guide.md +619 -0
- data/lib/ray/audio.rb +0 -41
- data/lib/ray/color.rb +32 -10
- data/lib/ray/drawable.rb +16 -0
- data/lib/ray/dsl/event_listener.rb +25 -2
- data/lib/ray/dsl/event_runner.rb +33 -5
- data/lib/ray/dsl/event_translator.rb +66 -30
- data/lib/ray/dsl/handler.rb +3 -2
- data/lib/ray/dsl/matcher.rb +58 -14
- data/lib/ray/font.rb +38 -96
- data/lib/ray/font_set.rb +8 -8
- data/lib/ray/game.rb +87 -66
- data/lib/ray/helper.rb +105 -10
- data/lib/ray/image.rb +150 -24
- data/lib/ray/image_set.rb +3 -1
- data/lib/ray/input.rb +10 -0
- data/lib/ray/music_set.rb +5 -3
- data/lib/ray/ray.rb +21 -9
- data/lib/ray/rect.rb +48 -7
- data/lib/ray/rmagick.rb +41 -0
- data/lib/ray/scene.rb +99 -43
- data/lib/ray/scene_list.rb +67 -0
- data/lib/ray/shape.rb +132 -0
- data/lib/ray/sound_set.rb +4 -2
- data/lib/ray/sprite.rb +49 -111
- data/lib/ray/text.rb +101 -0
- data/lib/ray/text_helper.rb +37 -0
- data/lib/ray/turtle.rb +215 -0
- data/lib/ray/vector.rb +226 -0
- data/samples/audio/spacial.rb +44 -0
- data/samples/hello_world/hello.rb +9 -13
- data/samples/hello_world/hello_dsl.rb +8 -12
- data/samples/hello_world/text.rb +15 -0
- data/samples/opengl/binding.rb +38 -0
- data/samples/opengl/image.rb +32 -0
- data/samples/opengl/opengl.rb +34 -0
- data/samples/opengl/shader.rb +42 -0
- data/samples/pong/pong.rb +14 -10
- data/samples/run_scene.rb +53 -0
- data/samples/shaders/scene.rb +40 -0
- data/samples/shaders/shaders.rb +42 -0
- data/samples/shaders/shape.rb +34 -0
- data/samples/sokoban/sokoban.rb +18 -18
- data/samples/test/actual_scene.rb +41 -0
- data/samples/test/scene_riot.rb +39 -0
- data/samples/test/scene_spec.rb +32 -0
- data/samples/test/scene_test_unit.rb +25 -0
- data/samples/turtle/byzantium.rb +45 -0
- data/samples/turtle/hilbert.rb +48 -0
- data/samples/turtle/koch.rb +55 -0
- data/samples/turtle/mandala.rb +61 -0
- data/samples/turtle/tree.rb +57 -0
- data/test/audio_test.rb +69 -0
- data/test/color_test.rb +77 -0
- data/test/drawable_test.rb +19 -0
- data/test/dsl_test.rb +93 -0
- data/test/font_test.rb +57 -0
- data/test/helpers.rb +94 -0
- data/test/image_test.rb +82 -0
- data/test/ray_test.rb +25 -0
- data/test/rect_test.rb +121 -0
- data/{spec → test}/res/VeraMono.ttf +0 -0
- data/{spec → test}/res/aqua.bmp +0 -0
- data/{spec → test}/res/aqua.png +0 -0
- data/{spec → test}/res/aqua2.bmp +0 -0
- data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
- data/{spec → test}/res/pop.wav +0 -0
- data/test/resource_set_test.rb +99 -0
- data/test/run_all.rb +7 -0
- data/test/shape_test.rb +101 -0
- data/test/sprite_test.rb +89 -0
- data/test/text_test.rb +78 -0
- data/test/turtle_test.rb +176 -0
- data/test/vector_test.rb +111 -0
- data/yard_ext.rb +0 -28
- metadata +95 -139
- data/.gitignore +0 -23
- data/.gitmodules +0 -3
- data/.rspec +0 -3
- data/ext/audio.c +0 -473
- data/ext/event.c +0 -557
- data/ext/font.c +0 -287
- data/ext/image.c +0 -933
- data/ext/joystick.c +0 -145
- data/ext/ray.c +0 -489
- data/ext/ray.h +0 -245
- data/ext/ray_osx.m +0 -161
- data/lib/ray/joystick.rb +0 -30
- data/psp/SDL_psp_main.c +0 -84
- data/psp/bigdecimal/README +0 -60
- data/psp/bigdecimal/bigdecimal.c +0 -4697
- data/psp/bigdecimal/bigdecimal.h +0 -216
- data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
- data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
- data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
- data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
- data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
- data/psp/digest/bubblebabble/bubblebabble.c +0 -142
- data/psp/digest/defs.h +0 -20
- data/psp/digest/digest.c +0 -643
- data/psp/digest/digest.h +0 -32
- data/psp/digest/lib/digest.rb +0 -50
- data/psp/digest/lib/md5.rb +0 -27
- data/psp/digest/lib/sha1.rb +0 -27
- data/psp/digest/md5/md5.c +0 -420
- data/psp/digest/md5/md5.h +0 -80
- data/psp/digest/md5/md5init.c +0 -40
- data/psp/digest/rmd160/rmd160.c +0 -457
- data/psp/digest/rmd160/rmd160.h +0 -56
- data/psp/digest/rmd160/rmd160init.c +0 -40
- data/psp/digest/sha1/sha1.c +0 -269
- data/psp/digest/sha1/sha1.h +0 -39
- data/psp/digest/sha1/sha1init.c +0 -40
- data/psp/digest/sha2/lib/sha2.rb +0 -73
- data/psp/digest/sha2/sha2.c +0 -919
- data/psp/digest/sha2/sha2.h +0 -109
- data/psp/digest/sha2/sha2init.c +0 -52
- data/psp/enumerator/enumerator.c +0 -298
- data/psp/etc/etc.c +0 -559
- data/psp/ext.c +0 -289
- data/psp/fcntl/fcntl.c +0 -187
- data/psp/lib/rbconfig.rb +0 -178
- data/psp/nkf/lib/kconv.rb +0 -367
- data/psp/nkf/nkf-utf8/config.h +0 -88
- data/psp/nkf/nkf-utf8/nkf.c +0 -6040
- data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
- data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
- data/psp/nkf/nkf.c +0 -654
- data/psp/socket/addrinfo.h +0 -173
- data/psp/socket/getaddrinfo.c +0 -676
- data/psp/socket/getnameinfo.c +0 -270
- data/psp/socket/pspsocket.c +0 -71
- data/psp/socket/pspsocket.h +0 -28
- data/psp/socket/socket.c +0 -4662
- data/psp/socket/sockport.h +0 -76
- data/psp/stringio/stringio.c +0 -1306
- data/psp/strscan/strscan.c +0 -1320
- data/psp/syck/bytecode.c +0 -1166
- data/psp/syck/emitter.c +0 -1242
- data/psp/syck/gram.c +0 -1894
- data/psp/syck/gram.h +0 -79
- data/psp/syck/handler.c +0 -174
- data/psp/syck/implicit.c +0 -2990
- data/psp/syck/node.c +0 -408
- data/psp/syck/rubyext.c +0 -2367
- data/psp/syck/syck.c +0 -504
- data/psp/syck/syck.h +0 -456
- data/psp/syck/token.c +0 -2725
- data/psp/syck/yaml2byte.c +0 -257
- data/psp/syck/yamlbyte.h +0 -170
- data/psp/thread/thread.c +0 -1175
- data/psp/zlib/zlib.c +0 -3547
- data/script.rb +0 -10
- data/spec/ray/audio_spec.rb +0 -146
- data/spec/ray/color_spec.rb +0 -57
- data/spec/ray/event_spec.rb +0 -80
- data/spec/ray/font_spec.rb +0 -93
- data/spec/ray/image_set_spec.rb +0 -48
- data/spec/ray/image_spec.rb +0 -162
- data/spec/ray/joystick_spec.rb +0 -21
- data/spec/ray/matcher_spec.rb +0 -50
- data/spec/ray/ray_spec.rb +0 -88
- data/spec/ray/rect_spec.rb +0 -154
- data/spec/ray/resource_set_spec.rb +0 -105
- data/spec/ray/sprite_spec.rb +0 -163
- data/spec/spec.opts +0 -4
- data/spec/spec_helper.rb +0 -8
data/psp/ext.c
DELETED
@@ -1,289 +0,0 @@
|
|
1
|
-
/*Copyright (C) 2009-2010 Verhetsel Kilian
|
2
|
-
|
3
|
-
This program is free software; you can redistribute it and/or modify
|
4
|
-
it under the terms of the GNU General Public License as published by
|
5
|
-
the Free Software Foundation; either version 2 of the License, or
|
6
|
-
(at your option) any later version.
|
7
|
-
|
8
|
-
This program is distributed in the hope that it will be useful,
|
9
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
-
GNU General Public License for more details.
|
12
|
-
|
13
|
-
You should have received a copy of the GNU General Public License along
|
14
|
-
with this program; if not, write to the Free Software Foundation, Inc.,
|
15
|
-
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.*/
|
16
|
-
|
17
|
-
#include "ray.h"
|
18
|
-
|
19
|
-
#include <pspwlan.h>
|
20
|
-
|
21
|
-
#include <pspnet.h>
|
22
|
-
#include <pspnet_inet.h>
|
23
|
-
#include <pspnet_resolver.h>
|
24
|
-
#include <pspnet_apctl.h>
|
25
|
-
|
26
|
-
#include <psputility.h>
|
27
|
-
|
28
|
-
#include <time.h>
|
29
|
-
|
30
|
-
VALUE ray_mWlan = Qnil;
|
31
|
-
VALUE ray_eTimeoutError = Qnil;
|
32
|
-
|
33
|
-
void Init_socket();
|
34
|
-
void Init_bigdecimal();
|
35
|
-
void Init_digest();
|
36
|
-
void Init_bubblebabble();
|
37
|
-
void Init_md5();
|
38
|
-
void Init_sha1();
|
39
|
-
void Init_sha2();
|
40
|
-
void Init_enumerator();
|
41
|
-
void Init_fcntl();
|
42
|
-
void Init_stringio();
|
43
|
-
void Init_strscan();
|
44
|
-
void Init_thread();
|
45
|
-
void Init_zlib();
|
46
|
-
void Init_nkf();
|
47
|
-
void Init_etc();
|
48
|
-
void Init_syck();
|
49
|
-
|
50
|
-
/*
|
51
|
-
Inits the wlan connection. You have to call this before calling the socket
|
52
|
-
function.
|
53
|
-
*/
|
54
|
-
VALUE Wlan_init(VALUE self) {
|
55
|
-
int err;
|
56
|
-
err = sceUtilityLoadNetModule(PSP_NET_MODULE_COMMON);
|
57
|
-
if (err < 0)
|
58
|
-
rb_raise(rb_eRuntimeError, "Failled to load net module");
|
59
|
-
|
60
|
-
err = sceUtilityLoadNetModule(PSP_NET_MODULE_INET);
|
61
|
-
if (err < 0)
|
62
|
-
rb_raise(rb_eRuntimeError, "Failled to load inet module");
|
63
|
-
|
64
|
-
err = sceNetInit(0x20000, 0x20, 0x1000, 0x20, 0x1000);
|
65
|
-
if (err < 0)
|
66
|
-
rb_raise(rb_eRuntimeError, "Failled to init net module");
|
67
|
-
|
68
|
-
err = sceNetInetInit();
|
69
|
-
if (err < 0)
|
70
|
-
rb_raise(rb_eRuntimeError, "Failled to init inet module");
|
71
|
-
|
72
|
-
err = sceNetResolverInit();
|
73
|
-
if (err < 0)
|
74
|
-
rb_raise(rb_eRuntimeError, "Failled to init resolver");
|
75
|
-
|
76
|
-
err = sceNetApctlInit(0x1400, 0x42);
|
77
|
-
if (err < 0)
|
78
|
-
rb_raise(rb_eRuntimeError, "Failled to init apctl");
|
79
|
-
|
80
|
-
return Qnil;
|
81
|
-
}
|
82
|
-
|
83
|
-
/*
|
84
|
-
Connects to a given acces point. You can specify a timeout in seconds.
|
85
|
-
If the connection isn't established after the specified timeout,
|
86
|
-
a TimeoutError is raised.
|
87
|
-
*/
|
88
|
-
VALUE Wlan_connect(VALUE self, VALUE config, VALUE timeout) {
|
89
|
-
if (sceNetApctlConnect(FIX2INT(config)))
|
90
|
-
rb_raise(rb_eRuntimeError, "Failled to connect to acces point %d",
|
91
|
-
FIX2INT(config));
|
92
|
-
|
93
|
-
time_t startTime, currTime;
|
94
|
-
time(&startTime);
|
95
|
-
|
96
|
-
int last_state = -1;
|
97
|
-
|
98
|
-
while (1) {
|
99
|
-
time(&currTime);
|
100
|
-
if (currTime - startTime >= FIX2INT(timeout)) {
|
101
|
-
sceNetApctlDisconnect();
|
102
|
-
rb_raise(ray_eTimeoutError, "Connection timeouted after %d seconds",
|
103
|
-
FIX2INT(timeout));
|
104
|
-
break;
|
105
|
-
}
|
106
|
-
|
107
|
-
int state;
|
108
|
-
if (sceNetApctlGetState(&state)) {
|
109
|
-
rb_raise(rb_eRuntimeError,
|
110
|
-
"Error occured while getting connection state");
|
111
|
-
break;
|
112
|
-
}
|
113
|
-
|
114
|
-
if (state > last_state) {
|
115
|
-
last_state = state;
|
116
|
-
}
|
117
|
-
|
118
|
-
if (state == PSP_NET_APCTL_STATE_GOT_IP)
|
119
|
-
break;
|
120
|
-
|
121
|
-
sceKernelDelayThread(50 * 1000);
|
122
|
-
}
|
123
|
-
|
124
|
-
return Qnil;
|
125
|
-
}
|
126
|
-
|
127
|
-
/*
|
128
|
-
Ends a Wlan connection.
|
129
|
-
*/
|
130
|
-
VALUE Wlan_disconnect(VALUE self) {
|
131
|
-
sceNetApctlDisconnect();
|
132
|
-
return Qnil;
|
133
|
-
}
|
134
|
-
|
135
|
-
/*
|
136
|
-
Unloads net modules.
|
137
|
-
*/
|
138
|
-
VALUE Wlan_stop(VALUE self) {
|
139
|
-
sceNetApctlTerm();
|
140
|
-
|
141
|
-
sceUtilityUnloadNetModule(PSP_NET_MODULE_INET);
|
142
|
-
sceUtilityUnloadNetModule(PSP_NET_MODULE_COMMON);
|
143
|
-
|
144
|
-
return Qnil;
|
145
|
-
}
|
146
|
-
|
147
|
-
/*
|
148
|
-
Returns whether the wlan button is enabled.
|
149
|
-
*/
|
150
|
-
VALUE Wlan_button_enabled(VALUE self) {
|
151
|
-
return sceWlanDevIsPowerOn() ? Qtrue : Qfalse;
|
152
|
-
}
|
153
|
-
|
154
|
-
/*
|
155
|
-
Returns whether we're connected to an acces point.
|
156
|
-
*/
|
157
|
-
VALUE Wlan_is_connected(VALUE self) {
|
158
|
-
union SceNetApctlInfo apctlInfo;
|
159
|
-
return sceNetApctlGetInfo(PSP_NET_APCTL_INFO_IP, &apctlInfo) == 0 ?
|
160
|
-
Qtrue :
|
161
|
-
Qfalse;
|
162
|
-
}
|
163
|
-
|
164
|
-
/*
|
165
|
-
Returns the wlan access points in an array of arrays.
|
166
|
-
It returns something in the following form :
|
167
|
-
[
|
168
|
-
["ip", "name"], # Access point at 1
|
169
|
-
["ip", "name"], # Access point at 2
|
170
|
-
["ip", "name"], # Access point at 3
|
171
|
-
...
|
172
|
-
]
|
173
|
-
*/
|
174
|
-
VALUE Wlan_configs(VALUE self) {
|
175
|
-
VALUE ret = rb_ary_new();
|
176
|
-
|
177
|
-
int i = 0;
|
178
|
-
for (i = 1; i < 20; ++i) {
|
179
|
-
if (sceUtilityCheckNetParam(i))
|
180
|
-
break;
|
181
|
-
|
182
|
-
VALUE entry = rb_ary_new();
|
183
|
-
|
184
|
-
netData data;
|
185
|
-
sceUtilityGetNetParam(i, PSP_NETPARAM_IP, &data);
|
186
|
-
rb_ary_push(entry, rb_str_new2(data.asString));
|
187
|
-
|
188
|
-
sceUtilityGetNetParam(i, PSP_NETPARAM_NAME, &data);
|
189
|
-
rb_ary_push(entry, rb_str_new2(data.asString));
|
190
|
-
|
191
|
-
rb_ary_push(ret, entry);
|
192
|
-
}
|
193
|
-
|
194
|
-
return ret;
|
195
|
-
}
|
196
|
-
|
197
|
-
/*
|
198
|
-
Returns our IP.
|
199
|
-
*/
|
200
|
-
VALUE Wlan_ip(VALUE self) {
|
201
|
-
union SceNetApctlInfo apctlInfo;
|
202
|
-
sceNetApctlGetInfo(PSP_NET_APCTL_INFO_IP, &apctlInfo);
|
203
|
-
|
204
|
-
return rb_str_new2(apctlInfo.ip);
|
205
|
-
}
|
206
|
-
|
207
|
-
/*
|
208
|
-
Inits a builtin module. You should never call it by yourself.
|
209
|
-
This avoids to load unneeded module from the stdlib (Ray's are all loaded
|
210
|
-
anyway). For instance, the zlib library needs to be enabled by this function.
|
211
|
-
|
212
|
-
@note This method is only available on the PSP.
|
213
|
-
*/
|
214
|
-
VALUE ray_init_internal(VALUE self, VALUE module_name) {
|
215
|
-
VALUE rb_str = rb_obj_as_string(module_name);
|
216
|
-
char *str = StringValuePtr(rb_str);
|
217
|
-
|
218
|
-
if (strcmp(str, "socket") == 0)
|
219
|
-
Init_socket();
|
220
|
-
else if (strcmp(str, "bigdecimal") == 0)
|
221
|
-
Init_bigdecimal();
|
222
|
-
else if (strcmp(str, "digest") == 0)
|
223
|
-
Init_digest();
|
224
|
-
else if (strcmp(str, "bubblebabble") == 0)
|
225
|
-
Init_bubblebabble();
|
226
|
-
else if (strcmp(str, "md5") == 0)
|
227
|
-
Init_md5();
|
228
|
-
else if (strcmp(str, "sha1") == 0)
|
229
|
-
Init_sha1();
|
230
|
-
else if (strcmp(str, "sha2") == 0)
|
231
|
-
Init_sha2();
|
232
|
-
else if (strcmp(str, "enumerator") == 0)
|
233
|
-
Init_enumerator();
|
234
|
-
else if (strcmp(str, "fcntl") == 0)
|
235
|
-
Init_fcntl();
|
236
|
-
else if (strcmp(str, "stringio") == 0)
|
237
|
-
Init_stringio();
|
238
|
-
else if (strcmp(str, "strscan") == 0)
|
239
|
-
Init_strscan();
|
240
|
-
else if (strcmp(str, "thread") == 0)
|
241
|
-
Init_thread();
|
242
|
-
else if (strcmp(str, "zlib") == 0)
|
243
|
-
Init_zlib();
|
244
|
-
else if (strcmp(str, "nkf") == 0)
|
245
|
-
Init_nkf();
|
246
|
-
else if (strcmp(str, "etc") == 0)
|
247
|
-
Init_etc();
|
248
|
-
else if (strcmp(str, "syck") == 0)
|
249
|
-
Init_syck();
|
250
|
-
|
251
|
-
return Qnil;
|
252
|
-
}
|
253
|
-
|
254
|
-
/*
|
255
|
-
Document-class: Ray::Wlan
|
256
|
-
|
257
|
-
Ruby's stdlib includes a Socket class, as well as classes easying
|
258
|
-
the use of HTTP and FTP protocols. These classes can be used,
|
259
|
-
but the PSP requires some initialisation before being able to use them.
|
260
|
-
|
261
|
-
This module contains the basic methods which can allow you to use
|
262
|
-
theme. This means :
|
263
|
-
|
264
|
-
* Loading net modules
|
265
|
-
* Connecting to one of the access points
|
266
|
-
* Checking the access points
|
267
|
-
|
268
|
-
Once you're connected, everything is transparent: you can use sockets as
|
269
|
-
usual.
|
270
|
-
|
271
|
-
@note This module is only available on the PSP.
|
272
|
-
*/
|
273
|
-
void Init_ray_psp() {
|
274
|
-
rb_define_module_function(ray_mRay, "init_internal", ray_init_internal, 1);
|
275
|
-
|
276
|
-
ray_eTimeoutError = rb_define_class_under(ray_mRay, "TimeoutError",
|
277
|
-
rb_eStandardError);
|
278
|
-
|
279
|
-
VALUE ray_mWlan = rb_define_module_under(ray_mRay, "Wlan");
|
280
|
-
rb_define_module_function(ray_mWlan, "init", Wlan_init, 0);
|
281
|
-
rb_define_module_function(ray_mWlan, "stop", Wlan_stop, 0);
|
282
|
-
rb_define_module_function(ray_mWlan, "connect", Wlan_connect, 2);
|
283
|
-
rb_define_module_function(ray_mWlan, "disconnect", Wlan_disconnect, 0);
|
284
|
-
rb_define_module_function(ray_mWlan, "button_enabled?", Wlan_button_enabled,
|
285
|
-
0);
|
286
|
-
rb_define_module_function(ray_mWlan, "configs", Wlan_configs, 0);
|
287
|
-
rb_define_module_function(ray_mWlan, "connected?", Wlan_is_connected, 0);
|
288
|
-
rb_define_module_function(ray_mWlan, "ip", Wlan_ip, 0);
|
289
|
-
}
|
data/psp/fcntl/fcntl.c
DELETED
@@ -1,187 +0,0 @@
|
|
1
|
-
/************************************************
|
2
|
-
|
3
|
-
fcntl.c -
|
4
|
-
|
5
|
-
$Author: shyouhei $
|
6
|
-
created at: Mon Apr 7 18:53:05 JST 1997
|
7
|
-
|
8
|
-
Copyright (C) 1997-2001 Yukihiro Matsumoto
|
9
|
-
|
10
|
-
************************************************/
|
11
|
-
|
12
|
-
/************************************************
|
13
|
-
= NAME
|
14
|
-
|
15
|
-
fcntl - load the C fcntl.h defines
|
16
|
-
|
17
|
-
= SYNOPSIS
|
18
|
-
|
19
|
-
require "fcntl"
|
20
|
-
m = s.fcntl(Fcntl::F_GETFL, 0)
|
21
|
-
f.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK|m)
|
22
|
-
|
23
|
-
= DESCRIPTION
|
24
|
-
|
25
|
-
This module is just a translation of the C <fnctl.h> file.
|
26
|
-
|
27
|
-
= NOTE
|
28
|
-
|
29
|
-
Only #define symbols get translated; you must still correctly
|
30
|
-
pack up your own arguments to pass as args for locking functions, etc.
|
31
|
-
|
32
|
-
************************************************/
|
33
|
-
|
34
|
-
#include <ruby/ruby.h>
|
35
|
-
#include <fcntl.h>
|
36
|
-
|
37
|
-
/* Fcntl loads the constants defined in the system's <fcntl.h> C header
|
38
|
-
* file, and used with both the fcntl(2) and open(2) POSIX system calls.
|
39
|
-
*
|
40
|
-
* Copyright (C) 1997-2001 Yukihiro Matsumoto
|
41
|
-
*
|
42
|
-
* Documented by mathew <meta@pobox.com>
|
43
|
-
*
|
44
|
-
* = Usage
|
45
|
-
*
|
46
|
-
* To perform a fcntl(2) operation, use IO::fcntl in the core classes.
|
47
|
-
*
|
48
|
-
* To perform an open(2) operation, use IO::sysopen.
|
49
|
-
*
|
50
|
-
* The set of operations and constants available depends upon specific OS
|
51
|
-
* platform. Some values listed below may not be supported on your system.
|
52
|
-
*
|
53
|
-
* The constants supported by Ruby for use with IO::fcntl are:
|
54
|
-
*
|
55
|
-
* - F_DUPFD - duplicate a close-on-exec file handle to a non-close-on-exec
|
56
|
-
* file handle.
|
57
|
-
*
|
58
|
-
* - F_GETFD - read the close-on-exec flag of a file handle.
|
59
|
-
*
|
60
|
-
* - F_SETFD - set the close-on-exec flag of a file handle.
|
61
|
-
*
|
62
|
-
* - FD_CLOEXEC - the value of the close-on-exec flag.
|
63
|
-
*
|
64
|
-
* - F_GETFL - get file descriptor flags.
|
65
|
-
*
|
66
|
-
* - F_SETFL - set file descriptor flags.
|
67
|
-
*
|
68
|
-
* - O_APPEND, O_NONBLOCK, etc (see below) - file descriptor flag
|
69
|
-
* values for the above.
|
70
|
-
*
|
71
|
-
* - F_GETLK - determine whether a given region of a file is locked.
|
72
|
-
*
|
73
|
-
* - F_SETLK - acquire a lock on a region of a file.
|
74
|
-
*
|
75
|
-
* - F_SETLKW - acquire a lock on a region of a file, waiting if necessary.
|
76
|
-
*
|
77
|
-
* - F_RDLCK, F_WRLCK, F_UNLCK - types of lock for the above.
|
78
|
-
*
|
79
|
-
* The constants supported by Ruby for use with IO::sysopen are:
|
80
|
-
*
|
81
|
-
* - O_APPEND - open file in append mode.
|
82
|
-
*
|
83
|
-
* - O_NOCTTY - open tty without it becoming controlling tty.
|
84
|
-
*
|
85
|
-
* - O_CREAT - create file if it doesn't exist.
|
86
|
-
*
|
87
|
-
* - O_EXCL - used with O_CREAT, fail if file exists.
|
88
|
-
*
|
89
|
-
* - O_TRUNC - truncate file on open.
|
90
|
-
*
|
91
|
-
* - O_NONBLOCK / O_NDELAY - open in non-blocking mode.
|
92
|
-
*
|
93
|
-
* - O_RDONLY - open read-only.
|
94
|
-
*
|
95
|
-
* - O_WRONLY - open write-only.
|
96
|
-
*
|
97
|
-
* - O_RDWR - open read-write.
|
98
|
-
*
|
99
|
-
* - O_ACCMODE - mask to extract read/write flags.
|
100
|
-
*
|
101
|
-
* Example:
|
102
|
-
*
|
103
|
-
* require 'fcntl'
|
104
|
-
*
|
105
|
-
* fd = IO::sysopen('/tmp/tempfile',
|
106
|
-
* Fcntl::O_WRONLY | Fcntl::O_EXCL | Fcntl::O_CREAT)
|
107
|
-
* f = IO.open(fd)
|
108
|
-
* f.syswrite("TEMP DATA")
|
109
|
-
* f.close
|
110
|
-
*
|
111
|
-
*/
|
112
|
-
void
|
113
|
-
Init_fcntl()
|
114
|
-
{
|
115
|
-
VALUE mFcntl = rb_define_module("Fcntl");
|
116
|
-
#ifdef F_DUPFD
|
117
|
-
rb_define_const(mFcntl, "F_DUPFD", INT2NUM(F_DUPFD));
|
118
|
-
#endif
|
119
|
-
#ifdef F_GETFD
|
120
|
-
rb_define_const(mFcntl, "F_GETFD", INT2NUM(F_GETFD));
|
121
|
-
#endif
|
122
|
-
#ifdef F_GETLK
|
123
|
-
rb_define_const(mFcntl, "F_GETLK", INT2NUM(F_GETLK));
|
124
|
-
#endif
|
125
|
-
#ifdef F_SETFD
|
126
|
-
rb_define_const(mFcntl, "F_SETFD", INT2NUM(F_SETFD));
|
127
|
-
#endif
|
128
|
-
#ifdef F_GETFL
|
129
|
-
rb_define_const(mFcntl, "F_GETFL", INT2NUM(F_GETFL));
|
130
|
-
#endif
|
131
|
-
#ifdef F_SETFL
|
132
|
-
rb_define_const(mFcntl, "F_SETFL", INT2NUM(F_SETFL));
|
133
|
-
#endif
|
134
|
-
#ifdef F_SETLK
|
135
|
-
rb_define_const(mFcntl, "F_SETLK", INT2NUM(F_SETLK));
|
136
|
-
#endif
|
137
|
-
#ifdef F_SETLKW
|
138
|
-
rb_define_const(mFcntl, "F_SETLKW", INT2NUM(F_SETLKW));
|
139
|
-
#endif
|
140
|
-
#ifdef FD_CLOEXEC
|
141
|
-
rb_define_const(mFcntl, "FD_CLOEXEC", INT2NUM(FD_CLOEXEC));
|
142
|
-
#endif
|
143
|
-
#ifdef F_RDLCK
|
144
|
-
rb_define_const(mFcntl, "F_RDLCK", INT2NUM(F_RDLCK));
|
145
|
-
#endif
|
146
|
-
#ifdef F_UNLCK
|
147
|
-
rb_define_const(mFcntl, "F_UNLCK", INT2NUM(F_UNLCK));
|
148
|
-
#endif
|
149
|
-
#ifdef F_WRLCK
|
150
|
-
rb_define_const(mFcntl, "F_WRLCK", INT2NUM(F_WRLCK));
|
151
|
-
#endif
|
152
|
-
#ifdef O_CREAT
|
153
|
-
rb_define_const(mFcntl, "O_CREAT", INT2NUM(O_CREAT));
|
154
|
-
#endif
|
155
|
-
#ifdef O_EXCL
|
156
|
-
rb_define_const(mFcntl, "O_EXCL", INT2NUM(O_EXCL));
|
157
|
-
#endif
|
158
|
-
#ifdef O_NOCTTY
|
159
|
-
rb_define_const(mFcntl, "O_NOCTTY", INT2NUM(O_NOCTTY));
|
160
|
-
#endif
|
161
|
-
#ifdef O_TRUNC
|
162
|
-
rb_define_const(mFcntl, "O_TRUNC", INT2NUM(O_TRUNC));
|
163
|
-
#endif
|
164
|
-
#ifdef O_APPEND
|
165
|
-
rb_define_const(mFcntl, "O_APPEND", INT2NUM(O_APPEND));
|
166
|
-
#endif
|
167
|
-
#ifdef O_NONBLOCK
|
168
|
-
rb_define_const(mFcntl, "O_NONBLOCK", INT2NUM(O_NONBLOCK));
|
169
|
-
#endif
|
170
|
-
#ifdef O_NDELAY
|
171
|
-
rb_define_const(mFcntl, "O_NDELAY", INT2NUM(O_NDELAY));
|
172
|
-
#endif
|
173
|
-
#ifdef O_RDONLY
|
174
|
-
rb_define_const(mFcntl, "O_RDONLY", INT2NUM(O_RDONLY));
|
175
|
-
#endif
|
176
|
-
#ifdef O_RDWR
|
177
|
-
rb_define_const(mFcntl, "O_RDWR", INT2NUM(O_RDWR));
|
178
|
-
#endif
|
179
|
-
#ifdef O_WRONLY
|
180
|
-
rb_define_const(mFcntl, "O_WRONLY", INT2NUM(O_WRONLY));
|
181
|
-
#endif
|
182
|
-
#ifdef O_ACCMODE
|
183
|
-
rb_define_const(mFcntl, "O_ACCMODE", INT2FIX(O_ACCMODE));
|
184
|
-
#else
|
185
|
-
rb_define_const(mFcntl, "O_ACCMODE", INT2FIX(O_RDONLY | O_WRONLY | O_RDWR));
|
186
|
-
#endif
|
187
|
-
}
|