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.
Files changed (188) hide show
  1. data/.gemtest +0 -0
  2. data/.yardopts +4 -0
  3. data/README.md +17 -21
  4. data/Rakefile +18 -139
  5. data/VERSION +1 -1
  6. data/ext/audio.cpp +723 -0
  7. data/ext/{color.c → color.cpp} +25 -13
  8. data/ext/drawable.cpp +91 -0
  9. data/ext/event.cpp +460 -0
  10. data/ext/extconf.rb +5 -104
  11. data/ext/font.cpp +190 -0
  12. data/ext/image.cpp +733 -0
  13. data/ext/input.cpp +74 -0
  14. data/ext/ray.cpp +168 -0
  15. data/ext/ray.hpp +356 -0
  16. data/ext/{rect.c → rect.cpp} +51 -37
  17. data/ext/shader.cpp +169 -0
  18. data/ext/shape.cpp +409 -0
  19. data/ext/sprite.cpp +306 -0
  20. data/ext/text.cpp +181 -0
  21. data/ext/vector.cpp +215 -0
  22. data/guide.md +619 -0
  23. data/lib/ray/audio.rb +0 -41
  24. data/lib/ray/color.rb +32 -10
  25. data/lib/ray/drawable.rb +16 -0
  26. data/lib/ray/dsl/event_listener.rb +25 -2
  27. data/lib/ray/dsl/event_runner.rb +33 -5
  28. data/lib/ray/dsl/event_translator.rb +66 -30
  29. data/lib/ray/dsl/handler.rb +3 -2
  30. data/lib/ray/dsl/matcher.rb +58 -14
  31. data/lib/ray/font.rb +38 -96
  32. data/lib/ray/font_set.rb +8 -8
  33. data/lib/ray/game.rb +87 -66
  34. data/lib/ray/helper.rb +105 -10
  35. data/lib/ray/image.rb +150 -24
  36. data/lib/ray/image_set.rb +3 -1
  37. data/lib/ray/input.rb +10 -0
  38. data/lib/ray/music_set.rb +5 -3
  39. data/lib/ray/ray.rb +21 -9
  40. data/lib/ray/rect.rb +48 -7
  41. data/lib/ray/rmagick.rb +41 -0
  42. data/lib/ray/scene.rb +99 -43
  43. data/lib/ray/scene_list.rb +67 -0
  44. data/lib/ray/shape.rb +132 -0
  45. data/lib/ray/sound_set.rb +4 -2
  46. data/lib/ray/sprite.rb +49 -111
  47. data/lib/ray/text.rb +101 -0
  48. data/lib/ray/text_helper.rb +37 -0
  49. data/lib/ray/turtle.rb +215 -0
  50. data/lib/ray/vector.rb +226 -0
  51. data/samples/audio/spacial.rb +44 -0
  52. data/samples/hello_world/hello.rb +9 -13
  53. data/samples/hello_world/hello_dsl.rb +8 -12
  54. data/samples/hello_world/text.rb +15 -0
  55. data/samples/opengl/binding.rb +38 -0
  56. data/samples/opengl/image.rb +32 -0
  57. data/samples/opengl/opengl.rb +34 -0
  58. data/samples/opengl/shader.rb +42 -0
  59. data/samples/pong/pong.rb +14 -10
  60. data/samples/run_scene.rb +53 -0
  61. data/samples/shaders/scene.rb +40 -0
  62. data/samples/shaders/shaders.rb +42 -0
  63. data/samples/shaders/shape.rb +34 -0
  64. data/samples/sokoban/sokoban.rb +18 -18
  65. data/samples/test/actual_scene.rb +41 -0
  66. data/samples/test/scene_riot.rb +39 -0
  67. data/samples/test/scene_spec.rb +32 -0
  68. data/samples/test/scene_test_unit.rb +25 -0
  69. data/samples/turtle/byzantium.rb +45 -0
  70. data/samples/turtle/hilbert.rb +48 -0
  71. data/samples/turtle/koch.rb +55 -0
  72. data/samples/turtle/mandala.rb +61 -0
  73. data/samples/turtle/tree.rb +57 -0
  74. data/test/audio_test.rb +69 -0
  75. data/test/color_test.rb +77 -0
  76. data/test/drawable_test.rb +19 -0
  77. data/test/dsl_test.rb +93 -0
  78. data/test/font_test.rb +57 -0
  79. data/test/helpers.rb +94 -0
  80. data/test/image_test.rb +82 -0
  81. data/test/ray_test.rb +25 -0
  82. data/test/rect_test.rb +121 -0
  83. data/{spec → test}/res/VeraMono.ttf +0 -0
  84. data/{spec → test}/res/aqua.bmp +0 -0
  85. data/{spec → test}/res/aqua.png +0 -0
  86. data/{spec → test}/res/aqua2.bmp +0 -0
  87. data/{spec → test}/res/not_a_jpeg.jpeg +0 -0
  88. data/{spec → test}/res/pop.wav +0 -0
  89. data/test/resource_set_test.rb +99 -0
  90. data/test/run_all.rb +7 -0
  91. data/test/shape_test.rb +101 -0
  92. data/test/sprite_test.rb +89 -0
  93. data/test/text_test.rb +78 -0
  94. data/test/turtle_test.rb +176 -0
  95. data/test/vector_test.rb +111 -0
  96. data/yard_ext.rb +0 -28
  97. metadata +95 -139
  98. data/.gitignore +0 -23
  99. data/.gitmodules +0 -3
  100. data/.rspec +0 -3
  101. data/ext/audio.c +0 -473
  102. data/ext/event.c +0 -557
  103. data/ext/font.c +0 -287
  104. data/ext/image.c +0 -933
  105. data/ext/joystick.c +0 -145
  106. data/ext/ray.c +0 -489
  107. data/ext/ray.h +0 -245
  108. data/ext/ray_osx.m +0 -161
  109. data/lib/ray/joystick.rb +0 -30
  110. data/psp/SDL_psp_main.c +0 -84
  111. data/psp/bigdecimal/README +0 -60
  112. data/psp/bigdecimal/bigdecimal.c +0 -4697
  113. data/psp/bigdecimal/bigdecimal.h +0 -216
  114. data/psp/bigdecimal/lib/bigdecimal/jacobian.rb +0 -85
  115. data/psp/bigdecimal/lib/bigdecimal/ludcmp.rb +0 -84
  116. data/psp/bigdecimal/lib/bigdecimal/math.rb +0 -235
  117. data/psp/bigdecimal/lib/bigdecimal/newton.rb +0 -77
  118. data/psp/bigdecimal/lib/bigdecimal/util.rb +0 -65
  119. data/psp/digest/bubblebabble/bubblebabble.c +0 -142
  120. data/psp/digest/defs.h +0 -20
  121. data/psp/digest/digest.c +0 -643
  122. data/psp/digest/digest.h +0 -32
  123. data/psp/digest/lib/digest.rb +0 -50
  124. data/psp/digest/lib/md5.rb +0 -27
  125. data/psp/digest/lib/sha1.rb +0 -27
  126. data/psp/digest/md5/md5.c +0 -420
  127. data/psp/digest/md5/md5.h +0 -80
  128. data/psp/digest/md5/md5init.c +0 -40
  129. data/psp/digest/rmd160/rmd160.c +0 -457
  130. data/psp/digest/rmd160/rmd160.h +0 -56
  131. data/psp/digest/rmd160/rmd160init.c +0 -40
  132. data/psp/digest/sha1/sha1.c +0 -269
  133. data/psp/digest/sha1/sha1.h +0 -39
  134. data/psp/digest/sha1/sha1init.c +0 -40
  135. data/psp/digest/sha2/lib/sha2.rb +0 -73
  136. data/psp/digest/sha2/sha2.c +0 -919
  137. data/psp/digest/sha2/sha2.h +0 -109
  138. data/psp/digest/sha2/sha2init.c +0 -52
  139. data/psp/enumerator/enumerator.c +0 -298
  140. data/psp/etc/etc.c +0 -559
  141. data/psp/ext.c +0 -289
  142. data/psp/fcntl/fcntl.c +0 -187
  143. data/psp/lib/rbconfig.rb +0 -178
  144. data/psp/nkf/lib/kconv.rb +0 -367
  145. data/psp/nkf/nkf-utf8/config.h +0 -88
  146. data/psp/nkf/nkf-utf8/nkf.c +0 -6040
  147. data/psp/nkf/nkf-utf8/utf8tbl.c +0 -8500
  148. data/psp/nkf/nkf-utf8/utf8tbl.h +0 -34
  149. data/psp/nkf/nkf.c +0 -654
  150. data/psp/socket/addrinfo.h +0 -173
  151. data/psp/socket/getaddrinfo.c +0 -676
  152. data/psp/socket/getnameinfo.c +0 -270
  153. data/psp/socket/pspsocket.c +0 -71
  154. data/psp/socket/pspsocket.h +0 -28
  155. data/psp/socket/socket.c +0 -4662
  156. data/psp/socket/sockport.h +0 -76
  157. data/psp/stringio/stringio.c +0 -1306
  158. data/psp/strscan/strscan.c +0 -1320
  159. data/psp/syck/bytecode.c +0 -1166
  160. data/psp/syck/emitter.c +0 -1242
  161. data/psp/syck/gram.c +0 -1894
  162. data/psp/syck/gram.h +0 -79
  163. data/psp/syck/handler.c +0 -174
  164. data/psp/syck/implicit.c +0 -2990
  165. data/psp/syck/node.c +0 -408
  166. data/psp/syck/rubyext.c +0 -2367
  167. data/psp/syck/syck.c +0 -504
  168. data/psp/syck/syck.h +0 -456
  169. data/psp/syck/token.c +0 -2725
  170. data/psp/syck/yaml2byte.c +0 -257
  171. data/psp/syck/yamlbyte.h +0 -170
  172. data/psp/thread/thread.c +0 -1175
  173. data/psp/zlib/zlib.c +0 -3547
  174. data/script.rb +0 -10
  175. data/spec/ray/audio_spec.rb +0 -146
  176. data/spec/ray/color_spec.rb +0 -57
  177. data/spec/ray/event_spec.rb +0 -80
  178. data/spec/ray/font_spec.rb +0 -93
  179. data/spec/ray/image_set_spec.rb +0 -48
  180. data/spec/ray/image_spec.rb +0 -162
  181. data/spec/ray/joystick_spec.rb +0 -21
  182. data/spec/ray/matcher_spec.rb +0 -50
  183. data/spec/ray/ray_spec.rb +0 -88
  184. data/spec/ray/rect_spec.rb +0 -154
  185. data/spec/ray/resource_set_spec.rb +0 -105
  186. data/spec/ray/sprite_spec.rb +0 -163
  187. data/spec/spec.opts +0 -4
  188. data/spec/spec_helper.rb +0 -8
@@ -1,559 +0,0 @@
1
- /************************************************
2
-
3
- etc.c -
4
-
5
- $Author: shyouhei $
6
- $Date: 2007-02-13 08:01:19 +0900 (Tue, 13 Feb 2007) $
7
- created at: Tue Mar 22 18:39:19 JST 1994
8
-
9
- ************************************************/
10
-
11
- #include <ruby/ruby.h>
12
-
13
- #include <sys/types.h>
14
- #ifdef HAVE_UNISTD_H
15
- #include <unistd.h>
16
- #endif
17
-
18
- #ifdef HAVE_GETPWENT
19
- #include <pwd.h>
20
- #endif
21
-
22
- #ifdef HAVE_GETGRENT
23
- #include <grp.h>
24
- #endif
25
-
26
- #ifndef HAVE_TYPE_UID_T
27
- #define uid_t int
28
- #endif
29
-
30
- static VALUE sPasswd, sGroup;
31
-
32
- #ifndef _WIN32
33
- char *getenv();
34
- #endif
35
- char *getlogin();
36
-
37
- /* Returns the short user name of the currently logged in user.
38
- *
39
- * e.g.
40
- * Etc.getlogin -> 'guest'
41
- */
42
- static VALUE
43
- etc_getlogin(obj)
44
- VALUE obj;
45
- {
46
- char *login;
47
-
48
- rb_secure(4);
49
- #ifdef HAVE_GETLOGIN
50
- login = getlogin();
51
- if (!login) login = getenv("USER");
52
- #else
53
- login = getenv("USER");
54
- #endif
55
-
56
- if (login)
57
- return rb_tainted_str_new2(login);
58
- return Qnil;
59
- }
60
-
61
- #if defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT)
62
- static VALUE
63
- safe_setup_str(str)
64
- const char *str;
65
- {
66
- if (str == 0) str = "";
67
- return rb_tainted_str_new2(str);
68
- }
69
- #endif
70
-
71
- #ifdef HAVE_GETPWENT
72
- static VALUE
73
- setup_passwd(pwd)
74
- struct passwd *pwd;
75
- {
76
- if (pwd == 0) rb_sys_fail("/etc/passwd");
77
- return rb_struct_new(sPasswd,
78
- safe_setup_str(pwd->pw_name),
79
- #ifdef HAVE_ST_PW_PASSWD
80
- safe_setup_str(pwd->pw_passwd),
81
- #endif
82
- PW_UID2VAL(pwd->pw_uid),
83
- PW_GID2VAL(pwd->pw_gid),
84
- #ifdef HAVE_ST_PW_GECOS
85
- safe_setup_str(pwd->pw_gecos),
86
- #endif
87
- safe_setup_str(pwd->pw_dir),
88
- safe_setup_str(pwd->pw_shell),
89
- #ifdef HAVE_ST_PW_CHANGE
90
- INT2NUM(pwd->pw_change),
91
- #endif
92
- #ifdef HAVE_ST_PW_QUOTA
93
- INT2NUM(pwd->pw_quota),
94
- #endif
95
- #ifdef HAVE_ST_PW_AGE
96
- PW_AGE2VAL(pwd->pw_age),
97
- #endif
98
- #ifdef HAVE_ST_PW_CLASS
99
- safe_setup_str(pwd->pw_class),
100
- #endif
101
- #ifdef HAVE_ST_PW_COMMENT
102
- safe_setup_str(pwd->pw_comment),
103
- #endif
104
- #ifdef HAVE_ST_PW_EXPIRE
105
- INT2NUM(pwd->pw_expire),
106
- #endif
107
- 0 /*dummy*/
108
- );
109
- }
110
- #endif
111
-
112
- /* Returns the /etc/passwd information for the user with specified integer
113
- * user id (uid).
114
- *
115
- * The information is returned as a Struct::Passwd; see getpwent above for
116
- * details.
117
- *
118
- * e.g. * Etc.getpwuid(0) -> #<struct Struct::Passwd name="root",
119
- * passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
120
- */
121
- static VALUE
122
- etc_getpwuid(argc, argv, obj)
123
- int argc;
124
- VALUE *argv;
125
- VALUE obj;
126
- {
127
- #if defined(HAVE_GETPWENT)
128
- VALUE id;
129
- uid_t uid;
130
- struct passwd *pwd;
131
-
132
- rb_secure(4);
133
- if (rb_scan_args(argc, argv, "01", &id) == 1) {
134
- uid = PW_VAL2UID(id);
135
- }
136
- else {
137
- uid = getuid();
138
- }
139
- pwd = getpwuid(uid);
140
- if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %d", uid);
141
- return setup_passwd(pwd);
142
- #else
143
- return Qnil;
144
- #endif
145
- }
146
-
147
- /* Returns the /etc/passwd information for the user with specified login name.
148
- *
149
- * The information is returned as a Struct::Passwd; see getpwent above for
150
- * details.
151
- *
152
- * e.g. * Etc.getpwnam('root') -> #<struct Struct::Passwd name="root",
153
- * passwd="x", uid=0, gid=0, gecos="root",dir="/root", shell="/bin/bash">
154
- */
155
- static VALUE
156
- etc_getpwnam(obj, nam)
157
- VALUE obj, nam;
158
- {
159
- #ifdef HAVE_GETPWENT
160
- struct passwd *pwd;
161
-
162
- SafeStringValue(nam);
163
- pwd = getpwnam(RSTRING(nam)->ptr);
164
- if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %s", RSTRING(nam)->ptr);
165
- return setup_passwd(pwd);
166
- #else
167
- return Qnil;
168
- #endif
169
- }
170
-
171
- #ifdef HAVE_GETPWENT
172
- static int passwd_blocking = 0;
173
- static VALUE
174
- passwd_ensure()
175
- {
176
- passwd_blocking = Qfalse;
177
- return Qnil;
178
- }
179
-
180
- static VALUE
181
- passwd_iterate()
182
- {
183
- struct passwd *pw;
184
-
185
- setpwent();
186
- while (pw = getpwent()) {
187
- rb_yield(setup_passwd(pw));
188
- }
189
- endpwent();
190
- return Qnil;
191
- }
192
- #endif
193
-
194
- /* Provides a convenient Ruby iterator which executes a block for each entry
195
- * in the /etc/passwd file.
196
- *
197
- * The code block is passed an Etc::Passwd struct; see getpwent above for
198
- * details.
199
- *
200
- * Example:
201
- *
202
- * require 'etc'
203
- *
204
- * Etc.passwd {|u|
205
- * puts u.name + " = " + u.gecos
206
- * }
207
- *
208
- */
209
- static VALUE
210
- etc_passwd(obj)
211
- VALUE obj;
212
- {
213
- #ifdef HAVE_GETPWENT
214
- struct passwd *pw;
215
-
216
- rb_secure(4);
217
- if (rb_block_given_p()) {
218
- if (passwd_blocking) {
219
- rb_raise(rb_eRuntimeError, "parallel passwd iteration");
220
- }
221
- passwd_blocking = Qtrue;
222
- rb_ensure(passwd_iterate, 0, passwd_ensure, 0);
223
- }
224
- if (pw = getpwent()) {
225
- return setup_passwd(pw);
226
- }
227
- #endif
228
- return Qnil;
229
- }
230
-
231
- /* Resets the process of reading the /etc/passwd file, so that the next call
232
- * to getpwent will return the first entry again.
233
- */
234
- static VALUE
235
- etc_setpwent(obj)
236
- VALUE obj;
237
- {
238
- #ifdef HAVE_GETPWENT
239
- setpwent();
240
- #endif
241
- return Qnil;
242
- }
243
-
244
- /* Ends the process of scanning through the /etc/passwd file begun with
245
- * getpwent, and closes the file.
246
- */
247
- static VALUE
248
- etc_endpwent(obj)
249
- VALUE obj;
250
- {
251
- #ifdef HAVE_GETPWENT
252
- endpwent();
253
- #endif
254
- return Qnil;
255
- }
256
-
257
- /* Returns an entry from the /etc/passwd file. The first time it is called it
258
- * opens the file and returns the first entry; each successive call returns
259
- * the next entry, or nil if the end of the file has been reached.
260
- *
261
- * To close the file when processing is complete, call endpwent.
262
- *
263
- * Each entry is returned as a Struct::Passwd:
264
- *
265
- * - Passwd#name contains the short login name of the user as a String.
266
- *
267
- * - Passwd#passwd contains the encrypted password of the user as a String.
268
- * an 'x' is returned if shadow passwords are in use. An '*' is returned
269
- * if the user cannot log in using a password.
270
- *
271
- * - Passwd#uid contains the integer user ID (uid) of the user.
272
- *
273
- * - Passwd#gid contains the integer group ID (gid) of the user's primary group.
274
- *
275
- * - Passwd#gecos contains a longer String description of the user, such as
276
- * a full name. Some Unix systems provide structured information in the
277
- * gecos field, but this is system-dependent.
278
- *
279
- * - Passwd#dir contains the path to the home directory of the user as a String.
280
- *
281
- * - Passwd#shell contains the path to the login shell of the user as a String.
282
- */
283
- static VALUE
284
- etc_getpwent(obj)
285
- VALUE obj;
286
- {
287
- #ifdef HAVE_GETPWENT
288
- struct passwd *pw;
289
-
290
- if (pw = getpwent()) {
291
- return setup_passwd(pw);
292
- }
293
- #endif
294
- return Qnil;
295
- }
296
-
297
- #ifdef HAVE_GETGRENT
298
- static VALUE
299
- setup_group(grp)
300
- struct group *grp;
301
- {
302
- VALUE mem;
303
- char **tbl;
304
-
305
- mem = rb_ary_new();
306
- tbl = grp->gr_mem;
307
- while (*tbl) {
308
- rb_ary_push(mem, safe_setup_str(*tbl));
309
- tbl++;
310
- }
311
- return rb_struct_new(sGroup,
312
- safe_setup_str(grp->gr_name),
313
- #ifdef HAVE_ST_GR_PASSWD
314
- safe_setup_str(grp->gr_passwd),
315
- #endif
316
- PW_GID2VAL(grp->gr_gid),
317
- mem);
318
- }
319
- #endif
320
-
321
- /* Returns information about the group with specified integer group id (gid),
322
- * as found in /etc/group.
323
- *
324
- * The information is returned as a Struct::Group; see getgrent above for
325
- * details.
326
- *
327
- * e.g. Etc.getgrgid(100) -> #<struct Struct::Group name="users", passwd="x",
328
- * gid=100, mem=["meta", "root"]>
329
- *
330
- */
331
- static VALUE
332
- etc_getgrgid(obj, id)
333
- VALUE obj, id;
334
- {
335
- #ifdef HAVE_GETGRENT
336
- gid_t gid;
337
- struct group *grp;
338
-
339
- rb_secure(4);
340
- gid = getgid();
341
- grp = getgrgid(gid);
342
- if (grp == 0) rb_raise(rb_eArgError, "can't find group for %d", gid);
343
- return setup_group(grp);
344
- #else
345
- return Qnil;
346
- #endif
347
- }
348
-
349
- /* Returns information about the group with specified String name, as found
350
- * in /etc/group.
351
- *
352
- * The information is returned as a Struct::Group; see getgrent above for
353
- * details.
354
- *
355
- * e.g. Etc.getgrnam('users') -> #<struct Struct::Group name="users",
356
- * passwd="x", gid=100, mem=["meta", "root"]>
357
- *
358
- */
359
- static VALUE
360
- etc_getgrnam(obj, nam)
361
- VALUE obj, nam;
362
- {
363
- #ifdef HAVE_GETGRENT
364
- struct group *grp;
365
-
366
- rb_secure(4);
367
- SafeStringValue(nam);
368
- grp = getgrnam(RSTRING(nam)->ptr);
369
- if (grp == 0) rb_raise(rb_eArgError, "can't find group for %s", RSTRING(nam)->ptr);
370
- return setup_group(grp);
371
- #else
372
- return Qnil;
373
- #endif
374
- }
375
-
376
- #ifdef HAVE_GETGRENT
377
- static int group_blocking = 0;
378
- static VALUE
379
- group_ensure()
380
- {
381
- group_blocking = Qfalse;
382
- return Qnil;
383
- }
384
-
385
- static VALUE
386
- group_iterate()
387
- {
388
- struct group *pw;
389
-
390
- setgrent();
391
- while (pw = getgrent()) {
392
- rb_yield(setup_group(pw));
393
- }
394
- endgrent();
395
- return Qnil;
396
- }
397
- #endif
398
-
399
- /* Provides a convenient Ruby iterator which executes a block for each entry
400
- * in the /etc/group file.
401
- *
402
- * The code block is passed an Etc::Group struct; see getgrent above for
403
- * details.
404
- *
405
- * Example:
406
- *
407
- * require 'etc'
408
- *
409
- * Etc.group {|g|
410
- * puts g.name + ": " + g.mem.join(', ')
411
- * }
412
- *
413
- */
414
- static VALUE
415
- etc_group(obj)
416
- VALUE obj;
417
- {
418
- #ifdef HAVE_GETGRENT
419
- struct group *grp;
420
-
421
- rb_secure(4);
422
- if (rb_block_given_p()) {
423
- if (group_blocking) {
424
- rb_raise(rb_eRuntimeError, "parallel group iteration");
425
- }
426
- group_blocking = Qtrue;
427
- rb_ensure(group_iterate, 0, group_ensure, 0);
428
- }
429
- if (grp = getgrent()) {
430
- return setup_group(grp);
431
- }
432
- #endif
433
- return Qnil;
434
- }
435
-
436
- /* Resets the process of reading the /etc/group file, so that the next call
437
- * to getgrent will return the first entry again.
438
- */
439
- static VALUE
440
- etc_setgrent(obj)
441
- VALUE obj;
442
- {
443
- #ifdef HAVE_GETGRENT
444
- setgrent();
445
- #endif
446
- return Qnil;
447
- }
448
-
449
- /* Ends the process of scanning through the /etc/group file begun by
450
- * getgrent, and closes the file.
451
- */
452
- static VALUE
453
- etc_endgrent(obj)
454
- VALUE obj;
455
- {
456
- #ifdef HAVE_GETGRENT
457
- endgrent();
458
- #endif
459
- return Qnil;
460
- }
461
-
462
- /* Returns an entry from the /etc/group file. The first time it is called it
463
- * opens the file and returns the first entry; each successive call returns
464
- * the next entry, or nil if the end of the file has been reached.
465
- *
466
- * To close the file when processing is complete, call endgrent.
467
- *
468
- * Each entry is returned as a Struct::Group:
469
- *
470
- * - Group#name contains the name of the group as a String.
471
- *
472
- * - Group#passwd contains the encrypted password as a String. An 'x' is
473
- * returned if password access to the group is not available; an empty
474
- * string is returned if no password is needed to obtain membership of
475
- * the group.
476
- *
477
- * - Group#gid contains the group's numeric ID as an integer.
478
- *
479
- * - Group#mem is an Array of Strings containing the short login names of the
480
- * members of the group.
481
- */
482
- static VALUE
483
- etc_getgrent(obj)
484
- VALUE obj;
485
- {
486
- #ifdef HAVE_GETGRENT
487
- struct group *gr;
488
-
489
- if (gr = getgrent()) {
490
- return setup_group(gr);
491
- }
492
- #endif
493
- return Qnil;
494
- }
495
-
496
- static VALUE mEtc;
497
-
498
- /* The etc module provides access to information from the /etc/passwd and
499
- * /etc/group files on Linux and Unix systems.
500
- *
501
- * Documented by mathew <meta@pobox.com>.
502
- */
503
- void
504
- Init_etc()
505
- {
506
- mEtc = rb_define_module("Etc");
507
-
508
- rb_define_module_function(mEtc, "getlogin", etc_getlogin, 0);
509
-
510
- rb_define_module_function(mEtc, "getpwuid", etc_getpwuid, -1);
511
- rb_define_module_function(mEtc, "getpwnam", etc_getpwnam, 1);
512
- rb_define_module_function(mEtc, "setpwent", etc_setpwent, 0);
513
- rb_define_module_function(mEtc, "endpwent", etc_endpwent, 0);
514
- rb_define_module_function(mEtc, "getpwent", etc_getpwent, 0);
515
- rb_define_module_function(mEtc, "passwd", etc_passwd, 0);
516
-
517
- rb_define_module_function(mEtc, "getgrgid", etc_getgrgid, 1);
518
- rb_define_module_function(mEtc, "getgrnam", etc_getgrnam, 1);
519
- rb_define_module_function(mEtc, "group", etc_group, 0);
520
- rb_define_module_function(mEtc, "setgrent", etc_setgrent, 0);
521
- rb_define_module_function(mEtc, "endgrent", etc_endgrent, 0);
522
- rb_define_module_function(mEtc, "getgrent", etc_getgrent, 0);
523
-
524
- rb_global_variable(&sPasswd);
525
- sPasswd = rb_struct_define("Passwd",
526
- "name", "passwd", "uid", "gid",
527
- #ifdef HAVE_ST_PW_GECOS
528
- "gecos",
529
- #endif
530
- "dir", "shell",
531
- #ifdef HAVE_ST_PW_CHANGE
532
- "change",
533
- #endif
534
- #ifdef HAVE_ST_PW_QUOTA
535
- "quota",
536
- #endif
537
- #ifdef HAVE_ST_PW_AGE
538
- "age",
539
- #endif
540
- #ifdef HAVE_ST_PW_CLASS
541
- "uclass",
542
- #endif
543
- #ifdef HAVE_ST_PW_COMMENT
544
- "comment",
545
- #endif
546
- #ifdef HAVE_ST_PW_EXPIRE
547
- "expire",
548
- #endif
549
- NULL);
550
-
551
- #ifdef HAVE_GETGRENT
552
- rb_global_variable(&sGroup);
553
- sGroup = rb_struct_define("Group", "name",
554
- #ifdef HAVE_ST_GR_PASSWD
555
- "passwd",
556
- #endif
557
- "gid", "mem", NULL);
558
- #endif
559
- }