Основы программирования в Linux - Мэтью Нейл
Без паники! Самый легкий способ написания новой программы в среде UNIX — начать с уже имеющейся программы и приспособить ее для своих целей, так же нужно поступать и с интерактивным справочным руководством.
В задачу данной книги не входит подробное объяснение множества опций, команд и макросов, которые может применять команда
groffnroffДалее приведен исходный код страницы справочного руководства для приложения myapp, хранящийся в файле myapp.1.
.TH MYAPP 1.SH NAMEMyapp - A simple demonstration application that does very little..SH SYNOPSIS.В myapp[-option ...].SH DESCRIPTION.PPfImyappfP is a complete application that does nothing useful..PPIt was written for demonstration purposes..SH OPTIONS.PPIt doesn't have any, but let's pretend, to make this template complete:.TP.BI -optionIf there was an option, it would not be -option..SH RESOURCES.PPmyapp uses almost no resources..SR DIAGNOSTICSThe program shouldn't output anything, so if you find it doing so there'sprobably something wrong. The return value is zero..SH SEE ALSOThe only other program we know with this little functionality is theubiquitous hello world application..SH COPYRIGHTmyapp is Copyright (c) 2007 Wiley Publishing, Inc.This program is, free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong, with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 021111307 USA..SH BUGSThere probably are some, but we don't know what they are yet..SH AUTHORSNeil Matthew and Rick StonesКак видите, макрос вводится с помощью точки (.) в начале строки и, как правило, дается в сокращенном виде. 1 в конце первой строки — номер раздела руководства, в который помещается команда. Поскольку команды располагаются в разделе 1, именно туда мы и помещаем наше новое приложение.
Вы сможете сгенерировать собственное интерактивное руководство, изменив приведенную страницу и изучив исходный код других страниц. Можно также посмотреть в архиве на Web-странице http://www.tldp.org/ часть Linux Documentation Project (Проект документирования Linux) "Linux Man Page mini-HowTo" ("Краткое руководство по написанию страниц интерактивного руководства в Linux"), написанную Дженс Швейкхардт (Jens Schweikhardt).
Имея исходный текст страницы справочного руководства, можно обработать его утилитой
groffgroff-Tascii-Tps-mangroff$ <b>groff -Tascii -man myapp.1</b>У этой команды следующий вывод.
MYAPP(1) MYAPP(1)<b>NAME</b> Myapp — A simple demonstration application that does very little.<b>SYNOPSIS</b><b> myapp</b> [-option ...]<b>DESCRIPTION</b> myapp is a complete application that does nothing useful. It was written for demonstration purposes.<b>OPTIONS</b> It doesn't have any, but let's pretend, to make this temp- late complete:<b> -option</b> If there was an option, it would not be -option.<b>RESOURCES</b> myapp uses almost no resources.<b>DIAGNOSTICS</b> The program shouldn't output anything, so if you find it doing so there's probably something wrong. The return value is zero.<b>SEE ALSO</b> The only other program we know with this little func-