forked from mame/quine-relay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.md.gen.rb
218 lines (147 loc) · 6.59 KB
/
README.md.gen.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
require_relative "code-gen"
require "erb"
require "cairo"
other_packages = %w(cmake libpng-dev libgd-dev groff bison)
other_packages.each do |package|
`dpkg -s #{ package }` # just check the packages
end
pkg_versions = {}
apts = RunSteps.map {|s| s.apt }
`which apt-get >/dev/null && dpkg -s #{ apts.join(" ") }`.b.split("\n\n").each do |s|
name = s[/^Package: (.*)$/, 1]
version = s[/^Version: (.*)$/, 1]
pkg_versions[name] = version if name && version
end
rows = [["\\#", "language", "ubuntu package", "version"]]
rows += RunSteps.map.with_index do |s, idx|
if s.apt.is_a?(Array)
apt = s.apt.join(", ")
ver = pkg_versions.values_at(*s.apt)
raise if ver.uniq.size > 1
ver = ver.first
else
apt = s.apt || "*N/A*"
ver = pkg_versions[apt]
end
[(idx + 1).to_s, s.name, apt, ver || "-"]
end
ws = rows.transpose.map {|row| row.map {|s| s.size }.max + 1 }
rows[1, 0] = [ws.map {|w| "-" * w }]
rows = rows.map do |col|
(col.zip(ws).map {|s, w| s.ljust(w) } * "|").rstrip
end
apt_get = "sudo apt-get install #{ [*apts.flatten.compact.uniq, *other_packages].sort * " " }"
apt_get.gsub!(/.{,70}( |\z)/) do
$&[-1] == " " ? $& + "\\\n " : $&
end
cmds = [*RunSteps, RunStep["Ruby", "QR2.rb"]].each_cons(2).map do |s1, s2|
cmd = s1.cmd_raw
src = s2.src
cmd = cmd.gsub("OUTFILE", src)
cmd = cmd.gsub(/^!/, "")
cmd = cmd.gsub(/.{60,}?&&/, "\\0\n ")
cmd
end
File.write("../README.md", ERB.new(DATA.read, nil, "%").result(binding))
__END__
# Quine Relay
[![Build Status](https://travis-ci.org/mame/quine-relay.svg?branch=laboratory)](https://travis-ci.org/mame/quine-relay)
## What this is
This is a <%= RunSteps[0].name %> program that generates
<%= RunSteps[1].name %> program that generates
<%= RunSteps[2].name %> program that generates
...(through <%= RunSteps.size %> languages in total)...
<%= RunSteps[-1].name %> program that generates
the original <%= RunSteps[0].name %> code again.
![Language Uroboros][langs]
[langs]: langs.png
(If you want to see the old 50-language version, see [50](https://github.com/mame/quine-relay/tree/50) branch.)
## Usage
### Ubuntu
If you are using Ubuntu 17.10 "Artful Aardvark", you can perform the following steps.
#### 1. Install all interpreters/compilers.
First, you have to type the following apt-get command to install all of them.
$ <%= apt_get %>
Then, build the bundled interpreters.
$ sudo apt-get install libpng-dev libgd-dev groff flex bison
$ make -C vendor
#### 2. Run each program on each interpreter/compiler.
$ ulimit -s unlimited
% cmds.each do |cmd|
$ <%= cmd %>
% end
You will see that `QR.rb` is the same as `QR2.rb`.
$ diff QR.rb QR2.rb
Alternatively, just type `make`.
$ make
Note: It may require huge memory to compile some files.
### Arch Linux
Just install [quine-relay-git](https://aur.archlinux.org/packages/quine-relay-git/) from AUR and run `quine-relay`.
Report any problems as comments to the AUR package or to the respective packages, if one of the many compilers should have issues.
### Other platforms
You may find [instructions for other platforms in the wiki](https://github.com/mame/quine-relay/wiki/Installation).
If you are not using these Linux distributions, please find your way yourself.
If you could do it, please let me know. Good luck.
## Tested interpreter/compiler versions
I used the following Ubuntu deb packages to test this program.
% rows.each do |row|
<%= row %>
% end
Note that some languages are not available in Ubuntu (marked as *N/A*).
This repository includes their implementations in `vendor/`.
See also `vendor/README` in detail.
## Frequently asked questions
### Q. Why?
A. [Take your pick](https://github.com/mame/quine-relay/issues/11).
### Q. How?
A. Good news: I published a book, ["The world of obfuscated, esoteric, artistic programming"](http://gihyo.jp/book/2015/978-4-7741-7643-7).
It explains how to write a quine, an ascii-art quine, and a uroboros quine like this quine-relay.
You can buy my book on [amazon.co.jp](http://www.amazon.co.jp/dp/4774176435).
(It also contains my almost all (about forty) works, including
[alphabet-only Ruby program](http://www.slideshare.net/mametter/ruby-esoteric-obfuscated-ruby-programming-5088683),
[radiation-hardened quine](https://github.com/mame/radiation-hardened-quine),
etc., and explains many techniques to write such programs.)
Bad news: It is written in Japanese.
I hope you could translate it to English <strike>and help me earn royalties</strike>.
### Q. Language XXX is missing!
A. See [the criteria for language inclusion][criteria] in detail. (In short: please create a deb package and contribute it to Ubuntu.)
[criteria]: https://github.com/mame/quine-relay/wiki/Criteria-for-language-inclusion
### Q. Does it really work?
A. [![Build Status](https://travis-ci.org/mame/quine-relay.svg?branch=laboratory)](https://travis-ci.org/mame/quine-relay)
### Q. How long did it take you?
A. [Do you try to cross the world line?](https://github.com/mame/quine-relay/issues/60)
### Q. The code does not fit into my display!
A. [Here you go][thumbnail].
[thumbnail]: thumbnail.png
### Q. How was the code generated?
A.
$ sudo apt-get install rake ruby-cairo ruby-rsvg2 ruby-gdk-pixbuf2 \
optipng advancecomp ruby-chunky-png
$ cd src
$ rake2.0 clobber
$ rake2.0
## License
The MIT License applies to all resources
*except* the files in the `vendor/` directory.
The files in the `vendor/` directory are from third-parties
and are distributed under different licenses.
See `vendor/README` in detail.
---
The MIT License (MIT)
Copyright (c) 2013, 2014, 2015, 2016, 2017 Yusuke Endoh (@mametter), @hirekoke
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.