chiark / gitweb /
Remove CVS cruft.
[quine] / README
CommitLineData
267c6003 1Quine
2~~~~~
3
4The `Jargon File' (well, my GNU Info edition) defines a `quine' as:
5
6:quine: /kwi:n/ n. [from the name of the logician Willard
7 van Orman Quine, via Douglas Hofstadter] A program that generates a
8 copy of its own source text as its complete output. Devising the
9 shortest possible quine in some given programming language is a
10 common hackish amusement. Here is one classic quine:
11
12 ((lambda (x)
13 (list x (list (quote quote) x)))
14 (quote
15 (lambda (x)
16 (list x (list (quote quote) x)))))
17
18 This one works in LISP or Scheme. It's relatively easy to write
19 quines in other languages such as Postscript which readily handle
20 programs as data; much harder (and thus more challenging!) in
21 languages like C which do not. Here is a classic C quine for ASCII
22 machines:
23
24 char*f="char*f=%c%s%c;main()
25 {printf(f,34,f,34,10);}%c";
26 main(){printf(f,34,f,34,10);}
27
28 For excruciatingly exact quinishness, remove the interior line
29 breaks. Some infamous *note Obfuscated C Contest:: entries have been
30 quines that reproduced in exotic ways.
31
32Small quines, like the one above (or the author's strictly conformant
33ANSI C version) have been around for ages. However, I'm not aware of
34any programs which provide quine support for arbitrary pieces of
35software. The `quine' program is intended to remedy this omission.
36
37Building the package is easy. Run the `configure' script, and then say
38`make'. This then gowes through the rather convoluted build process
39automatically, and produces a binary `quine'.
40
41As an example of `quine's ability to enquine programs, it is (of course)
42a quine itself. To demonstrate this, run the command
43
44 ./quine --quine
45
46It should (very quickly) create a `quine' source distribution in the
47current directory.
48
49Conferring quineishness upon other programs isn't hard. You require the
50`quine.h' file from the source distribution (`make install' will install
51it in some standard place for you), and the `quine' binary.
52
53The `quine' program works by writing a file describing the contents of
54your source files, and the code necessary to recreate them. It reads
55the names of your sources from standard input and writes (by default) to
56`qqout.c'; thus an incantation like
57
58 find . -type f -print | quine
59
60should be sufficient to build the `qqout.c' file. Then all you need to
61do to your code to output the source code is call `qq_create' to build a
62distribution directory, or `qq_dump(STREAM)' to dump the source code to
63the output stream STREAM. Easy, no?
64
65The author's own preference for creating source distributions is to
66create a distribution directory (with `make distdir') and use `find'
67within that to build the `qqout.c' file. See the `Makefile.am' to see
68how this was achieved for `quine' itself. (Note that `quine' has to use
69itself to build its `qqout.c' file, which makes the whole procedure a
70little more interesting.)
71
72I'll admit it: this isn't what you'd call a `useful' program.