rconio 0.1.0-x86-mingw32

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.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ (The MIT License)
2
+
3
+ Copyright (c) 2011 Peter Dodds
4
+
5
+ Prmission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF R IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,32 @@
1
+ = RConio
2
+
3
+ A wrapper for MS-DOS conio.h
4
+
5
+ == Methods
6
+
7
+ * `kbhit`: Determines if a keyboard key was pressed.
8
+ * `getch`: Reads a character directly from the console without buffer, and without echo.
9
+ * `getche`: Reads a character directly from the console without buffer, but with echo.
10
+ * `ungetch(number)`: Puts a character back into the keyboard buffer.
11
+ * `putch(number)`: Writes a character directly to the console.
12
+ * `cgets(number=254)`: Reads a string of given length directly from the console.
13
+ * `cputs(string)`: Writes a string directly to the console.
14
+
15
+ === Todo
16
+
17
+ These methods in conio.h have not been implemented:
18
+
19
+ * `cscanf(char *format, arg0,... argn)`: Reads formatted values directly from the console.
20
+ * `cprintf(const char *format, arg0,... argn)`: Formats values and writes them directly to the console.
21
+
22
+ == Install
23
+
24
+ gem install rconio
25
+
26
+ == License
27
+
28
+ see LICENSE
29
+
30
+ == Credits
31
+
32
+ * Peter Dodds, {website}[http://pddds.com]
@@ -0,0 +1,44 @@
1
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
2
+ require 'rubygems/package_task'
3
+ require 'rake/extensiontask'
4
+
5
+ spec = Gem::Specification.new do |s|
6
+ s.name = "rconio"
7
+ s.version = "0.1.0"
8
+ s.license = "MIT"
9
+ s.author = "Peter Dodds"
10
+ s.email = "peter@pddds.com"
11
+ s.homepage = "https://github.com/m0tive/rconio"
12
+ s.summary = "A wrapper for MS-DOS conio.h"
13
+ s.description = "RConio is a wrapper for MS-DOS conio.h"
14
+
15
+ s.platform = Gem::Platform::CURRENT
16
+ s.has_rdoc = false
17
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE"]
18
+
19
+ s.require_path = 'lib'
20
+
21
+ s.files = FileList["ext/**/*.{c,rb}", "Rakefile", "README.rdoc", "LICENSE"]
22
+ s.extensions = FileList["ext/**/extconf.rb"]
23
+ end
24
+
25
+ task :default => :compile
26
+
27
+ Rake::ExtensionTask.new('rconio', spec) do |ext|
28
+ ext.cross_compile = false
29
+ end
30
+
31
+ Gem::PackageTask.new(spec) do |pkg|
32
+ pkg.need_zip = false
33
+ pkg.need_tar = false
34
+ end
35
+
36
+ task :test => [:compile] do
37
+ ruby %q(-Ilib -rrconio -e "puts 'done'")
38
+ end
39
+
40
+ desc "install the gem locally"
41
+ task :install => [:package] do
42
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
43
+ end
44
+
@@ -0,0 +1,3 @@
1
+ require 'mkmf'
2
+
3
+ create_makefile('rconio')
@@ -0,0 +1,170 @@
1
+ /*
2
+ * RConio
3
+ *
4
+ * MS-DOS conio.h wrapper
5
+ *
6
+ */
7
+
8
+ #include <conio.h>
9
+
10
+ #include "ruby.h"
11
+
12
+ VALUE RConio = Qnil;
13
+
14
+ /*
15
+ * call-seq:
16
+ * kbhit() -> number
17
+ *
18
+ * Determines if a keyboard key was pressed.
19
+ */
20
+ VALUE method_kbhit(VALUE self)
21
+ {
22
+ int ret = _kbhit();
23
+ return INT2NUM(ret);
24
+ }
25
+
26
+ /*
27
+ * call-seq:
28
+ * getch() -> number
29
+ *
30
+ * Reads a character directly from the console without buffer, and without echo.
31
+ */
32
+ VALUE method_getch(VALUE self)
33
+ {
34
+ int ret = _getch();
35
+ return INT2NUM(ret);
36
+ }
37
+
38
+ /*
39
+ * call-seq:
40
+ * getche() -> number
41
+ *
42
+ * Reads a character directly from the console without buffer, but with echo.
43
+ */
44
+ VALUE method_getche(VALUE self)
45
+ {
46
+ int ret = _getche();
47
+ return INT2NUM(ret);
48
+ }
49
+
50
+ /*
51
+ * call-seq:
52
+ * ungetch(character) -> number
53
+ *
54
+ * Puts the character c back into the keyboard buffer.
55
+ */
56
+ VALUE method_ungetch(VALUE self, VALUE int_character)
57
+ {
58
+ int character = NUM2INT(int_character);
59
+ int ret = _ungetch(character);
60
+ return INT2NUM(ret);
61
+ }
62
+
63
+ /*
64
+ * call-seq:
65
+ * cgets(maxlength=256) -> string
66
+ *
67
+ * Reads a string directly from the console.
68
+ */
69
+ VALUE method_cgets(int argc, VALUE* argv, VALUE self)
70
+ {
71
+ // get the optional arg `maxlength`
72
+ VALUE int_maxlength;
73
+ rb_scan_args(argc, argv, "01", &int_maxlength);
74
+
75
+ // use 254 if `maxlength` isn't set
76
+ int maxlength = NIL_P(int_maxlength) ? 254 : NUM2INT(int_maxlength);
77
+ if (maxlength < 1)
78
+ {
79
+ rb_raise(rb_eArgError, "size must be atleast 1");
80
+ return Qnil;
81
+ }
82
+
83
+ char* buffer = malloc((maxlength+2) * sizeof(char));
84
+ if(!buffer)
85
+ {
86
+ rb_raise(rb_eNoMemError, "out of memory");
87
+ return Qnil;
88
+ }
89
+ buffer[1] = buffer[2] = 0;
90
+ buffer[0] = maxlength;
91
+
92
+ char* ret = _cgets(buffer);
93
+
94
+ if (buffer[1] < 1)
95
+ {
96
+ if (buffer[1] < 0)
97
+ rb_raise(rb_eSystemCallError, "_cgets() returned string length of -1");
98
+ return Qnil;
99
+ }
100
+
101
+ VALUE string_ret = rb_str_new(ret, buffer[1]);
102
+
103
+ free(buffer);
104
+
105
+ return string_ret;
106
+ }
107
+
108
+ /*
109
+ * call-seq:
110
+ * putch(character) -> number
111
+ *
112
+ * Writes a character directly to the console.
113
+ */
114
+ VALUE method_putch(VALUE self, VALUE int_character)
115
+ {
116
+ int character = NUM2INT(int_character);
117
+ int ret = _putch(character);
118
+ return INT2NUM(ret);
119
+ }
120
+
121
+ /*
122
+ * call-seq:
123
+ * cputs(string) -> number
124
+ *
125
+ * Writes a string directly to the console.
126
+ */
127
+ VALUE method_cputs(VALUE self, VALUE string_string)
128
+ {
129
+ const char* title = StringValuePtr(string_string);
130
+ int ret = _cputs(title);
131
+ return INT2NUM(ret);
132
+ }
133
+
134
+ #if 0
135
+ /*
136
+ * call-seq:
137
+ * cscanf(format, ??) -> number
138
+ *
139
+ * Reads formatted values directly from the console.
140
+ */
141
+ VALUE method_cscanf(int argc, VALUE* argv, VALUE self)
142
+ {
143
+ }
144
+ #endif
145
+
146
+ #if 0
147
+ /*
148
+ * call-seq:
149
+ * cprintf(format, arguments...) -> number
150
+ *
151
+ * Formats values and writes them directly to the console.
152
+ */
153
+ VALUE method_cprintf(int argc, VALUE* argv, VALUE self)
154
+ {
155
+ }
156
+ #endif
157
+
158
+
159
+ void Init_rconio()
160
+ {
161
+ RConio = rb_define_module("RConio");
162
+
163
+ rb_define_module_function(RConio, "kbhit", method_kbhit, 0);
164
+ rb_define_module_function(RConio, "getch", method_getch, 0);
165
+ rb_define_module_function(RConio, "getche", method_getche, 0);
166
+ rb_define_module_function(RConio, "ungetch", method_ungetch, 1);
167
+ rb_define_module_function(RConio, "cgets", method_cgets,-1);
168
+ rb_define_module_function(RConio, "putch", method_putch, 1);
169
+ rb_define_module_function(RConio, "cputs", method_cputs, 1);
170
+ }
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rconio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: x86-mingw32
7
+ authors:
8
+ - Peter Dodds
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-11-03 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: RConio is a wrapper for MS-DOS conio.h
15
+ email: peter@pddds.com
16
+ executables: []
17
+ extensions:
18
+ - ext/rconio/extconf.rb
19
+ extra_rdoc_files:
20
+ - README.rdoc
21
+ - LICENSE
22
+ files:
23
+ - ext/rconio/rconio.c
24
+ - ext/rconio/extconf.rb
25
+ - Rakefile
26
+ - README.rdoc
27
+ - LICENSE
28
+ homepage: https://github.com/m0tive/rconio
29
+ licenses:
30
+ - MIT
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.11
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: A wrapper for MS-DOS conio.h
53
+ test_files: []