Advertisement
sheffield

coffee.txt

Apr 18th, 2013
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. http://www.linuxjournal.com/article/1158?page=0,0
  2.  
  3. Don't let the amount of obscurity in this source file frighten you. It helps to know that the character sequences \fB, \fI, and \fR are used to change the font to boldface, italics, and roman type, respectively. \fP sets the font to the one previously selected.
  4.  
  5. Other groff requests appear on lines beginning with a dot (.). On line 1, we see that the .TH request is used to set the title of the man page to COFFEE, the man section to 1, and the date of the last man page revision. (Recall that man section 1 is used for user commands, section 2 is for system calls, and so forth. The man man command details each section number.) On line 2, the .SH request is used to start a section, entitled NAME. Note that almost all Unix man pages use the section progression NAME, SYNOPSIS, DESCRIPTION, FILES, SEE ALSO, NOTES, AUTHOR, and BUGS, with extra, optional sections as needed. This is just a convention used when writing man pages and isn't enforced by the software at all.
  6.  
  7. Line 3 gives the name of the command and a short description, after a dash ([mi]). You should use this format for the NAME section so that your man page can be added to the whatis database used by the man -k and apropos commands.
  8.  
  9. On lines 4—6 we give the synopsis of the command syntax for coffee. Note that italic type \fI...\fP is used to denote parameters on the command line, and that optional arguments are enclosed in square brackets.
  10.  
  11. Lines 7—12 give a brief description of the command. Boldface type is generally used to denote program and file names. On line 13, a subsection named Options is started with the .SS request. Following this on lines 14—25 is a list of options, presented using a tagged list. Each item in the tagged list is marked with the .TP request; the line after .TP is the tag, after which follows the item text itself. For example, the source on lines 14—16:
  12.  
  13. .TP
  14. \fB-h\P
  15. Brew hot coffee. Cold is the default.
  16. will appear as the following in the output:
  17.  
  18. -h Brew hot coffee. Cold is the default.
  19. You should document each command-line option for your program in this way.
  20.  
  21. Lines 26—29 make up the FILES section of the man page, which describes any files that the command might use to do its work. A tagged list using the .TP request is used for this as well.
  22.  
  23. On lines 30—31, the SEE ALSO section is given, which provides cross-references to other man pages of note. Notice that the string <\#34>SEE ALSO<\#34> following the .SH request on line 30 is in quotes; this is because .SH uses the first whitespace-delimited argument as the section title. Therefore any section titles that are more than one word need to be enclosed in quotes to make up a single argument. Finally, on lines 32—34, the BUGS section is presented.
  24. --------------
  25.  
  26.  
  27.  
  28. groff -Tascii -man coffee.man | more
  29.  
  30. The -Tascii option tells groff to produce plain-ASCII output; -man tells groff to use the man page macro set. If all goes well, the man page should be displayed as shown in Figure 1.
  31.  
  32. COFFEE(1) COFFEE(1)
  33. NAME
  34. coffee - Control remote coffee machine
  35. SYNOPSIS
  36. coffee [ -h | -b ] [ -t type ] amount
  37. DESCRIPTION
  38. coffee queues a request to the remote coffee machine at
  39. the device /dev/cf0. The required amount argument speci-
  40. fies the number of cups, generally between 0 and 12 on ISO
  41. standard coffee machines.
  42. Options
  43. -h Brew hot coffee. Cold is the default.
  44. -b Burn coffee. Especially useful when executing cof-
  45. fee on behalf of your boss.
  46. -t type
  47. Specify the type of coffee to brew, where type is
  48. one of columbian, regular, or decaf.
  49. FILES
  50. /dev/cf0
  51. The remote coffee machine device
  52. SEE ALSO
  53. milk(5), sugar(5)
  54. BUGS
  55. May require human intervention if coffee supply is
  56. exhausted.
  57.  
  58.  
  59.  
  60. As mentioned before, groff is capable of producing other types of output. Using the -Tps option in place of -Tascii will produce PostScript output that you can save to a file, view with GhostView, or print on a PostScript printer. -Tdvi will produce device-independent .dvi output similar to that produced by TeX.
  61.  
  62. If you wish to make the man page available for others to view on your system, you need to install the groff source in a directory that is present in other users' MANPATH. The location for standard man pages is /usr/man. The source for section 1 man pages should therefore go in /usr/man/man1. Therefore, the command:
  63.  
  64. $ cp coffee.man /usr/man/man1/coffee.1
  65. will install this man page in /usr/man for all to use (note the use of the .1 file name extension, instead of .man). When man coffee is subsequently invoked, the man page will be automatically reformatted, and the viewable text saved in /usr/man/cat1/coffee.1.Z.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement