.de CW \&\f(CW\\$1\fP\\$2 .. .TL Old Software Treasuries .br \fRand\fP .br troff and friends .AU markus schnalke .AB Old software is not obsolete per se. In contrast, some software tools are still alive despite their age. Others became mostly forgotten but are still valuable helpers. No matter which group programs belong to, one should be able to use the classic Unix tools \(en those that are available on every Unix machine. \f(CWEd\fP, \f(CWsed\fP, and \f(CWawk\fP are three of them. .PP \f(CWTroff\fP, \f(CWnroff\fP, and their friends (\f(CWtbl\fP, \f(CWeqn\fP, \f(CWrefer\fP, \f(CWpic\fP) are also mostly vanished from the users view. But they offer high quality typesetting on the level of TeX. Man books were, and still are, typeset with their help. .PP This is the handout to two talks .[ %A Markus Schnalke %B ChaosSeminar %I CCC Ulm %T Old Software Treasuries %D 2009-10-12 %O \s-2\f(CWhttp://ulm.ccc.de/ChaosSeminar/2009/ 10_Softwareschaetze\fP\s0 .] \^ .[ %A Markus Schnalke %B ChaosSeminar %I CCC Ulm %T troff and friends %D 2009-11-09 %O \s-2\f(CWhttp://ulm.ccc.de/ChaosSeminar/2009/ 11_troff-and-friends\fP\s0 .] which introduce these tools, explain why they are the way they are, and show how to use them. .AE .2C .SH Historical background .LP To understand why these tools are like they are, one needs to know how computing was back then when Unix was written. .PP It was in the late sixties and early seventies at Bell Labs: Computers were as large as closets and people used them through terminals. Terminals consisted of a keyboard and a line printer; no screen terminals. Those line printers were quite slow, about 10\(en15 characters per second, thus output needed to be low to increase the working speed. The word ``screen-orientation'' was not even invented and editors were line editors, like \f(CWed\fP. .SH Ed .LP Thompson wrote .CW ed in the early seventies, based upon .CW qed , which was a popular editor at that time. He equipped .CW ed with the first implementation of Regular Expressions, a powerful pattern matching language. .PP Until the rise of screen-oriented (or visual) editors, .CW ed was the primary Unix editor \(en the standard. Today, .CW vi , .CW emacs , or even graphical editors are what programmers use. Nonetheless, .CW ed is still the standard. It's the only editor that resides in .CW /bin . It is universally available and usable with any terminal setup. .PP It is definately worth and enlightening to learn .CW ed . .SH Sed .LP McMahon's .CW sed is a modified .CW ed to be used in pipelines. This at least is how the ``stream editor'' started. .PP It is not a hacked .CW ed anymore, but a stand-alone tool in the Unix toolchest which one doesn't want to miss. Today, .CW sed is, besides .CW grep , one of the best known helpers on a Unix system. .PP As .CW ed and .CW sed share about eighty percent of their commands, one gets two tools for the price of one. .SH Awk .LP In the late seventies, Aho, Weinberger, and Kernighan developed the pattern matching language .CW awk to avoid complex text processing constructs in the shell. .PP .CW Awk is a real programming language with variables and program flow control. It is mainly designed to write small programs with a few lines, thus it is perfectly suited for the daily needs in shell sessions. .PP In contrast to .CW perl , .CW awk is available on every Unix system. And it offers almost all of .CW perl 's text processing features. .SH Troff and nroff .LP The main two document preparation program in Unix are .CW troff and .CW nroff . .PP First was .CW nroff which was written by Joe Ossanna, based on .CW roff , which is McIlroy's Unix version of .CW RUNOFF . .CW Nroff generates plain text output for line printers. .PP A few years later, when the Bell Labs got a phototypesetter, Ossanna wrote an improved version called .CW troff . This one supported the new features of the phototypesetter, like different fonts, different font sizes, more characters, fine resolution movements, and the like. .PP After the advent of .CW troff , .CW nroff did not vanish, but it stayed to render plain text files, like man pages for instance. (The following text includes .CW nroff when the term ``\f(CWtroff\fP'' is used.) .SH Macro packages .LP Naked .CW troff becomes a pain as documents grow. This problem is solved with macro packages. They encapsulate formating commands into logical entities like headings, footnotes, and paragraphs. .PP Using a macro package is much like programming in a high-level programming language instead of assembler. Thus it is not surprising, that macro packages are widely used. Popular ones are: ms (the standard macros), mm (the successor of ms), man (for man pages), and me. .PP Formating a document with the ms macros is done like this: .DS .CW "troff -ms doc.ms .DE .SH Preprocessors .LP .CW Troff is able to generate any possible output, but this will end up in composing everything out of small lines. This is not what users want to do by hand. .PP Thus a set of preprocessors were developed, which take some high-level input and convert it to low-level drawing commands for .CW troff . .PP Popular preprocessors are: .IP \(bu .CW tbl which formats tabulars .IP \(bu .CW eqn for formulas in arbitrary complexity .IP \(bu .CW refer for literature references .IP \(bu .CW pic to generate diagrams .LP Preprocessors get prepended to .CW troff in a pipeline, as they pass everything through which is not for themselfs: .DS .CW "tbl doc.ms | eqn | troff -ms .DE Many more preprocessors are available and it is easy to write one yourself. .PP This pattern of extending software is a great way to avoid complexity when adding features. .SH Get the software .LP The here presented software is all freely available. It is even available in different implementations. The GNU versions are probably best known, but are very often bloated. .PP The better choice are the Heirloom project tools .[ %T The Heirloom Tools %A Gunnar Ritter %O \f(CW\s-2http://heirloom.sf.net\s0\fP .] which base on original Unix source code. They all support UTF-8 and some include new features, which were always added with the Unix Philosophy in mind. .[ %T The Unix Programming Environment %A Brian\ W.\ Kernighan %A Rob Pike %D 1984 .] .[ $LIST$ .]