pebbles-sl 0.9.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.
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+
6
+ Makefile
7
+ *.o
8
+ *.log
9
+ *.bundle
10
+ *.so
data/COPYRIGHT.md ADDED
@@ -0,0 +1,24 @@
1
+ # Copyright
2
+
3
+ ## Upstream
4
+
5
+ Upstream Author: Toyoda Masashi <toyoda@is.titech.ac.jp>
6
+
7
+ Copyright 1993,1998 Toyoda Masashi (toyoda@is.titech.ac.jp)
8
+
9
+ Everyone is permitted to do anything on this program including copying,
10
+ modifying, and improving, unless you try to pretend that you wrote it.
11
+ i.e., the above copyright notice has to appear in all copies.
12
+ THE AUTHOR DISCLAIMS ANY RESPONSIBILITY WITH REGARD TO THIS SOFTWARE.
13
+
14
+
15
+ ## This package
16
+
17
+ Author: SAWADA Tadashi <cesare@mayverse.jp>
18
+
19
+ Copyright 2011 SAWADA Tadashi <cesare@mayverse.jp>
20
+
21
+ Everyone is permitted to do anything on this program including copying,
22
+ modifying, and improving, unless you try to pretend that you wrote it.
23
+ i.e., the above copyright notice has to appear in all copies.
24
+ THE AUTHOR DISCLAIMS ANY RESPONSIBILITY WITH REGARD TO THIS SOFTWARE.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pebbles-sl.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Overview
2
+
3
+ Run the SL on your terminal.
4
+
5
+ # Installation
6
+
7
+ $ gem install pebbles-sl
8
+
9
+ # Usage
10
+
11
+ $ sl
12
+
13
+ in your terminal, or
14
+
15
+ require 'pebbles-sl'
16
+ Pebbles::SL.run
17
+
18
+ in your Ruby script
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => :build
data/bin/sl ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+
4
+ require 'pebbles/sl'
5
+ Pebbles::SL.run(*ARGV)
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("pebbles-sl")
4
+ have_library("curses", "main")
5
+
6
+ create_makefile("pebbles/sl")
data/ext/pebbles/sl.c ADDED
@@ -0,0 +1,242 @@
1
+ /*========================================
2
+ * sl.c:
3
+ * Copyright 1993,1998 Toyoda Masashi
4
+ * (toyoda@is.titech.ac.jp)
5
+ * Last Modified: 1998/ 7/22
6
+ *========================================
7
+ */
8
+ /* sl version 3.03 : add usleep(20000) */
9
+ /* by Toyoda Masashi 1998/ 7/22 */
10
+ /* sl version 3.02 : D51 flies! Change options. */
11
+ /* by Toyoda Masashi 1993/ 1/19 */
12
+ /* sl version 3.01 : Wheel turns smoother */
13
+ /* by Toyoda Masashi 1992/12/25 */
14
+ /* sl version 3.00 : Add d(D51) option */
15
+ /* by Toyoda Masashi 1992/12/24 */
16
+ /* sl version 2.02 : Bug fixed.(dust remains in screen) */
17
+ /* by Toyoda Masashi 1992/12/17 */
18
+ /* sl version 2.01 : Smoke run and disappear. */
19
+ /* Change '-a' to accident option. */
20
+ /* by Toyoda Masashi 1992/12/16 */
21
+ /* sl version 2.00 : Add a(all),l(long),F(Fly!) options. */
22
+ /* by Toyoda Masashi 1992/12/15 */
23
+ /* sl version 1.02 : Add turning wheel. */
24
+ /* by Toyoda Masashi 1992/12/14 */
25
+ /* sl version 1.01 : Add more complex smoke. */
26
+ /* by Toyoda Masashi 1992/12/14 */
27
+ /* sl version 1.00 : SL runs vomitting out smoke. */
28
+ /* by Toyoda Masashi 1992/12/11 */
29
+
30
+ #include <curses.h>
31
+ #include <signal.h>
32
+ #include <unistd.h>
33
+ #include "sl.h"
34
+
35
+ #include <ruby.h>
36
+
37
+ static int ACCIDENT = 0;
38
+ static int LOGO = 0;
39
+ static int FLY = 0;
40
+
41
+ static int my_mvaddstr(int y, int x, char *str);
42
+ static void option(char *str);
43
+ static int add_sl(int x);
44
+ static add_D51(int x);
45
+ static int add_man(int y, int x);
46
+ static int add_smoke(int y, int x);
47
+
48
+
49
+ static int my_mvaddstr(int y, int x, char *str)
50
+ {
51
+ for ( ; x < 0; ++x, ++str)
52
+ if (*str == '\0') return ERR;
53
+ for ( ; *str != '\0'; ++str, ++x)
54
+ if (mvaddch(y, x, *str) == ERR) return ERR;
55
+ return OK;
56
+ }
57
+
58
+ static void option(char *str)
59
+ {
60
+ extern int ACCIDENT, FLY, LONG;
61
+
62
+ while (*str != '\0') {
63
+ switch (*str++) {
64
+ case 'a': ACCIDENT = 1; break;
65
+ case 'F': FLY = 1; break;
66
+ case 'l': LOGO = 1; break;
67
+ default: break;
68
+ }
69
+ }
70
+ }
71
+
72
+ static VALUE run(int argc, VALUE* argv, VALUE self)
73
+ {
74
+ int x, i;
75
+
76
+ for (i = 0; i < argc; ++i) {
77
+ char* arg = RSTRING_PTR(argv[i]);
78
+ if (*arg == '-') {
79
+ option(arg + 1);
80
+ }
81
+ }
82
+ initscr();
83
+ signal(SIGINT, SIG_IGN);
84
+ noecho();
85
+ leaveok(stdscr, TRUE);
86
+ scrollok(stdscr, FALSE);
87
+
88
+ for (x = COLS - 1; ; --x) {
89
+ if (LOGO == 0) {
90
+ if (add_D51(x) == ERR) break;
91
+ } else {
92
+ if (add_sl(x) == ERR) break;
93
+ }
94
+ refresh();
95
+ usleep(20000);
96
+ }
97
+ mvcur(0, COLS - 1, LINES - 1, 0);
98
+ endwin();
99
+ }
100
+
101
+
102
+ static int add_sl(int x)
103
+ {
104
+ static char *sl[LOGOPATTERNS][LOGOHIGHT + 1]
105
+ = {{LOGO1, LOGO2, LOGO3, LOGO4, LWHL11, LWHL12, DELLN},
106
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL21, LWHL22, DELLN},
107
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL31, LWHL32, DELLN},
108
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL41, LWHL42, DELLN},
109
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL51, LWHL52, DELLN},
110
+ {LOGO1, LOGO2, LOGO3, LOGO4, LWHL61, LWHL62, DELLN}};
111
+
112
+ static char *coal[LOGOHIGHT + 1]
113
+ = {LCOAL1, LCOAL2, LCOAL3, LCOAL4, LCOAL5, LCOAL6, DELLN};
114
+
115
+ static char *car[LOGOHIGHT + 1]
116
+ = {LCAR1, LCAR2, LCAR3, LCAR4, LCAR5, LCAR6, DELLN};
117
+
118
+ int i, y, py1 = 0, py2 = 0, py3 = 0;
119
+
120
+ if (x < - LOGOLENGTH) return ERR;
121
+ y = LINES / 2 - 3;
122
+
123
+ if (FLY == 1) {
124
+ y = (x / 6) + LINES - (COLS / 6) - LOGOHIGHT;
125
+ py1 = 2; py2 = 4; py3 = 6;
126
+ }
127
+ for (i = 0; i <= LOGOHIGHT; ++i) {
128
+ my_mvaddstr(y + i, x, sl[(LOGOLENGTH + x) / 3 % LOGOPATTERNS][i]);
129
+ my_mvaddstr(y + i + py1, x + 21, coal[i]);
130
+ my_mvaddstr(y + i + py2, x + 42, car[i]);
131
+ my_mvaddstr(y + i + py3, x + 63, car[i]);
132
+ }
133
+ if (ACCIDENT == 1) {
134
+ add_man(y + 1, x + 14);
135
+ add_man(y + 1 + py2, x + 45); add_man(y + 1 + py2, x + 53);
136
+ add_man(y + 1 + py3, x + 66); add_man(y + 1 + py3, x + 74);
137
+ }
138
+ add_smoke(y - 1, x + LOGOFUNNEL);
139
+ return OK;
140
+ }
141
+
142
+
143
+ static add_D51(int x)
144
+ {
145
+ static char *d51[D51PATTERNS][D51HIGHT + 1]
146
+ = {{D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
147
+ D51WHL11, D51WHL12, D51WHL13, D51DEL},
148
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
149
+ D51WHL21, D51WHL22, D51WHL23, D51DEL},
150
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
151
+ D51WHL31, D51WHL32, D51WHL33, D51DEL},
152
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
153
+ D51WHL41, D51WHL42, D51WHL43, D51DEL},
154
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
155
+ D51WHL51, D51WHL52, D51WHL53, D51DEL},
156
+ {D51STR1, D51STR2, D51STR3, D51STR4, D51STR5, D51STR6, D51STR7,
157
+ D51WHL61, D51WHL62, D51WHL63, D51DEL}};
158
+ static char *coal[D51HIGHT + 1]
159
+ = {COAL01, COAL02, COAL03, COAL04, COAL05,
160
+ COAL06, COAL07, COAL08, COAL09, COAL10, COALDEL};
161
+
162
+ int y, i, dy = 0;
163
+
164
+ if (x < - D51LENGTH) return ERR;
165
+ y = LINES / 2 - 5;
166
+
167
+ if (FLY == 1) {
168
+ y = (x / 7) + LINES - (COLS / 7) - D51HIGHT;
169
+ dy = 1;
170
+ }
171
+ for (i = 0; i <= D51HIGHT; ++i) {
172
+ my_mvaddstr(y + i, x, d51[(D51LENGTH + x) % D51PATTERNS][i]);
173
+ my_mvaddstr(y + i + dy, x + 53, coal[i]);
174
+ }
175
+ if (ACCIDENT == 1) {
176
+ add_man(y + 2, x + 43);
177
+ add_man(y + 2, x + 47);
178
+ }
179
+ add_smoke(y - 1, x + D51FUNNEL);
180
+ return OK;
181
+ }
182
+
183
+
184
+ static int add_man(int y, int x)
185
+ {
186
+ static char *man[2][2] = {{"", "(O)"}, {"Help!", "\\O/"}};
187
+ int i;
188
+
189
+ for (i = 0; i < 2; ++i) {
190
+ my_mvaddstr(y + i, x, man[(LOGOLENGTH + x) / 12 % 2][i]);
191
+ }
192
+ }
193
+
194
+
195
+ static int add_smoke(int y, int x)
196
+ #define SMOKEPTNS 16
197
+ {
198
+ static struct smokes {
199
+ int y, x;
200
+ int ptrn, kind;
201
+ } S[1000];
202
+ static int sum = 0;
203
+ static char *Smoke[2][SMOKEPTNS]
204
+ = {{"( )", "( )", "( )", "( )", "( )",
205
+ "( )" , "( )" , "( )" , "()" , "()" ,
206
+ "O" , "O" , "O" , "O" , "O" ,
207
+ " " },
208
+ {"(@@@)", "(@@@@)", "(@@@@)", "(@@@)", "(@@)",
209
+ "(@@)" , "(@)" , "(@)" , "@@" , "@@" ,
210
+ "@" , "@" , "@" , "@" , "@" ,
211
+ " " }};
212
+ static char *Eraser[SMOKEPTNS]
213
+ = {" ", " ", " ", " ", " ",
214
+ " " , " " , " " , " " , " " ,
215
+ " " , " " , " " , " " , " " ,
216
+ " " };
217
+ static int dy[SMOKEPTNS] = { 2, 1, 1, 1, 0, 0, 0, 0, 0, 0,
218
+ 0, 0, 0, 0, 0, 0 };
219
+ static int dx[SMOKEPTNS] = {-2, -1, 0, 1, 1, 1, 1, 1, 2, 2,
220
+ 2, 2, 2, 3, 3, 3 };
221
+ int i;
222
+
223
+ if (x % 4 == 0) {
224
+ for (i = 0; i < sum; ++i) {
225
+ my_mvaddstr(S[i].y, S[i].x, Eraser[S[i].ptrn]);
226
+ S[i].y -= dy[S[i].ptrn];
227
+ S[i].x += dx[S[i].ptrn];
228
+ S[i].ptrn += (S[i].ptrn < SMOKEPTNS - 1) ? 1 : 0;
229
+ my_mvaddstr(S[i].y, S[i].x, Smoke[S[i].kind][S[i].ptrn]);
230
+ }
231
+ my_mvaddstr(y, x, Smoke[sum % 2][0]);
232
+ S[sum].y = y; S[sum].x = x;
233
+ S[sum].ptrn = 0; S[sum].kind = sum % 2;
234
+ sum ++;
235
+ }
236
+ }
237
+
238
+ void Init_sl() {
239
+ VALUE pebblesModule = rb_define_module("Pebbles");
240
+ VALUE pebblesSlModule = rb_define_module_under(pebblesModule, "SL");
241
+ rb_define_singleton_method(pebblesSlModule, "run", run, -1);
242
+ }
data/ext/pebbles/sl.h ADDED
@@ -0,0 +1,104 @@
1
+ /*========================================
2
+ * sl.h: Text data of SL version 3.01
3
+ * Copyright 1993 Toyoda Masashi
4
+ * (toyoda@is.titech.ac.jp)
5
+ * Last Modified: 1992/12/23
6
+ *========================================
7
+ */
8
+
9
+ #define D51HIGHT 10
10
+ #define D51FUNNEL 7
11
+ #define D51LENGTH 83
12
+ #define D51PATTERNS 6
13
+
14
+
15
+ #define D51STR1 " ==== ________ ___________ "
16
+ #define D51STR2 " _D _| |_______/ \\__I_I_____===__|_________| "
17
+ #define D51STR3 " |(_)--- | H\\________/ | | =|___ ___| "
18
+ #define D51STR4 " / | | H | | | | ||_| |_|| "
19
+ #define D51STR5 " | | | H |__--------------------| [___] | "
20
+ #define D51STR6 " | ________|___H__/__|_____/[][]~\\_______| | "
21
+ #define D51STR7 " |/ | |-----------I_____I [][] [] D |=======|__ "
22
+
23
+ #define D51WHL11 "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ "
24
+ #define D51WHL12 " |/-=|___|= || || || |_____/~\\___/ "
25
+ #define D51WHL13 " \\_/ \\O=====O=====O=====O_/ \\_/ "
26
+
27
+ #define D51WHL21 "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ "
28
+ #define D51WHL22 " |/-=|___|=O=====O=====O=====O |_____/~\\___/ "
29
+ #define D51WHL23 " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
30
+
31
+ #define D51WHL31 "__/ =| o |=-O=====O=====O=====O \\ ____Y___________|__ "
32
+ #define D51WHL32 " |/-=|___|= || || || |_____/~\\___/ "
33
+ #define D51WHL33 " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
34
+
35
+ #define D51WHL41 "__/ =| o |=-~O=====O=====O=====O\\ ____Y___________|__ "
36
+ #define D51WHL42 " |/-=|___|= || || || |_____/~\\___/ "
37
+ #define D51WHL43 " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
38
+
39
+ #define D51WHL51 "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ "
40
+ #define D51WHL52 " |/-=|___|= O=====O=====O=====O|_____/~\\___/ "
41
+ #define D51WHL53 " \\_/ \\__/ \\__/ \\__/ \\__/ \\_/ "
42
+
43
+ #define D51WHL61 "__/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y___________|__ "
44
+ #define D51WHL62 " |/-=|___|= || || || |_____/~\\___/ "
45
+ #define D51WHL63 " \\_/ \\_O=====O=====O=====O/ \\_/ "
46
+
47
+ #define D51DEL " "
48
+
49
+ #define COAL01 " "
50
+ #define COAL02 " "
51
+ #define COAL03 " _________________ "
52
+ #define COAL04 " _| \\_____A "
53
+ #define COAL05 " =| | "
54
+ #define COAL06 " -| | "
55
+ #define COAL07 "__|________________________|_ "
56
+ #define COAL08 "|__________________________|_ "
57
+ #define COAL09 " |_D__D__D_| |_D__D__D_| "
58
+ #define COAL10 " \\_/ \\_/ \\_/ \\_/ "
59
+
60
+ #define COALDEL " "
61
+
62
+ #define LOGOHIGHT 6
63
+ #define LOGOFUNNEL 4
64
+ #define LOGOLENGTH 84
65
+ #define LOGOPATTERNS 6
66
+
67
+ #define LOGO1 " ++ +------ "
68
+ #define LOGO2 " || |+-+ | "
69
+ #define LOGO3 " /---------|| | | "
70
+ #define LOGO4 " + ======== +-+ | "
71
+
72
+ #define LWHL11 " _|--O========O~\\-+ "
73
+ #define LWHL12 "//// \\_/ \\_/ "
74
+
75
+ #define LWHL21 " _|--/O========O\\-+ "
76
+ #define LWHL22 "//// \\_/ \\_/ "
77
+
78
+ #define LWHL31 " _|--/~O========O-+ "
79
+ #define LWHL32 "//// \\_/ \\_/ "
80
+
81
+ #define LWHL41 " _|--/~\\------/~\\-+ "
82
+ #define LWHL42 "//// \\_O========O "
83
+
84
+ #define LWHL51 " _|--/~\\------/~\\-+ "
85
+ #define LWHL52 "//// \\O========O/ "
86
+
87
+ #define LWHL61 " _|--/~\\------/~\\-+ "
88
+ #define LWHL62 "//// O========O_/ "
89
+
90
+ #define LCOAL1 "____ "
91
+ #define LCOAL2 "| \\@@@@@@@@@@@ "
92
+ #define LCOAL3 "| \\@@@@@@@@@@@@@_ "
93
+ #define LCOAL4 "| | "
94
+ #define LCOAL5 "|__________________| "
95
+ #define LCOAL6 " (O) (O) "
96
+
97
+ #define LCAR1 "____________________ "
98
+ #define LCAR2 "| ___ ___ ___ ___ | "
99
+ #define LCAR3 "| |_| |_| |_| |_| | "
100
+ #define LCAR4 "|__________________| "
101
+ #define LCAR5 "|__________________| "
102
+ #define LCAR6 " (O) (O) "
103
+
104
+ #define DELLN " "
@@ -0,0 +1,20 @@
1
+ # -*- mode: ruby; coding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "pebbles-sl"
5
+ s.version = "0.9.1"
6
+ s.authors = ["SAWADA Tadashi"]
7
+ s.email = ["cesare@mayverse.jp"]
8
+ s.homepage = "https://github.com/cesare/pebbles-sl"
9
+ s.summary = %q{SL for Ruby}
10
+ s.description = %q{Run SL on your terminal}
11
+
12
+ s.rubyforge_project = "pebbles-sl"
13
+
14
+ s.files = [".gitignore", "Gemfile", "COPYRIGHT.md", "README.md", "Rakefile", "bin/sl", "ext/pebbles/extconf.rb", "ext/pebbles/sl.c", "ext/pebbles/sl.h", "pebbles-sl.gemspec"]
15
+ s.executables = ["sl"]
16
+ s.require_paths = ["ext"]
17
+ s.extensions = ["ext/pebbles/extconf.rb"]
18
+
19
+ s.add_runtime_dependency "pebbles"
20
+ end
metadata ADDED
@@ -0,0 +1,76 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pebbles-sl
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.9.1
6
+ platform: ruby
7
+ authors:
8
+ - SAWADA Tadashi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-10-17 00:00:00 +09:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: pebbles
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "0"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: Run SL on your terminal
28
+ email:
29
+ - cesare@mayverse.jp
30
+ executables:
31
+ - sl
32
+ extensions:
33
+ - ext/pebbles/extconf.rb
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - COPYRIGHT.md
40
+ - README.md
41
+ - Rakefile
42
+ - bin/sl
43
+ - ext/pebbles/extconf.rb
44
+ - ext/pebbles/sl.c
45
+ - ext/pebbles/sl.h
46
+ - pebbles-sl.gemspec
47
+ has_rdoc: true
48
+ homepage: https://github.com/cesare/pebbles-sl
49
+ licenses: []
50
+
51
+ post_install_message:
52
+ rdoc_options: []
53
+
54
+ require_paths:
55
+ - ext
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ requirements: []
69
+
70
+ rubyforge_project: pebbles-sl
71
+ rubygems_version: 1.5.0
72
+ signing_key:
73
+ specification_version: 3
74
+ summary: SL for Ruby
75
+ test_files: []
76
+