-
Notifications
You must be signed in to change notification settings - Fork 4
/
part1-3-1.xml
352 lines (352 loc) · 10.2 KB
/
part1-3-1.xml
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<?xml version="1.0" encoding="UTF-8"?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/xml; charset=utf-8"/>
<title>Case Study</title>
<link rel="stylesheet" href="css/book.css" type="text/css"/>
</head>
<body>
<h3>
Case Study
</h3>
<p>
I now introduce a case study of a real-world function library manual, in particular the manual for the <span
class="func">getc</span>, <span class="func">fgetc</span>, <span class="func">getw</span>, and <span
class="func">getchar</span> functions from <a class="term" href="glossary.xml#openbsd">OpenBSD</a>. The
original file may be viewed on-line at <a class="external"
href="http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdio/getc.3">src/lib/libc/stdio/getc.3</a>,
file version 1.12. This is not the manual for the full function library, but only a handful of similar functions.
</p>
<div class="mdocin">
.\" $​OpenBSD: getc.3,v 1.12 2007/05/31 19:19:31 jmc Exp ​$
<br />
.\"
<br />
.\" Copyright (c) 1990, 1991, 1993
<br />
.\" The Regents of the University of California. All rights reserved.
<br />
.\"
<br />
.\" This code is derived from software contributed to Berkeley by
<br />
.\" Chris Torek and the American National Standards Committee X3,
<br />
.\" on Information Processing Systems.
<br />
.\"
<br />
.\" Redistribution and use in source and binary forms, with or without
<br />
.\" modification, are permitted provided that the following conditions
<br />
.\" are met:
<br />
.\" 1. Redistributions of source code must retain the above copyright
<br />
.\" notice, this list of conditions and the following disclaimer.
<br />
.\" 2. Redistributions in binary form must reproduce the above copyright
<br />
.\" notice, this list of conditions and the following disclaimer in the
<br />
.\" documentation and/or other materials provided with the distribution.
<br />
.\" 3. Neither the name of the University nor the names of its contributors
<br />
.\" may be used to endorse or promote products derived from this software
<br />
.\" without specific prior written permission.
<br />
.\"
<br />
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
<br />
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<br />
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
<br />
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
<br />
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<br />
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
<br />
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
<br />
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
<br />
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
<br />
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
<br />
.\" SUCH DAMAGE.
</div>
<p>
This is the standard comment header to manual files in OpenBSD. The <span class="screen">$​OpenBSD$</span> line
is automatically updated by the revision control system, <a href="commands.xml#cmd_cvs" class="cmd">cvs</a>, whenever an
update to the file is committed. The line following is the copyright message, and following that is the text form of
the <a class="term" href="glossary.xml#bsd_license">BSD license</a>.
</p>
<div class="mdocin">
.Dd $​Mdocdate: May 31 2007 ​$
<br />
.Dt GETC 3
<br />
.Os
</div>
<p>
This classifies our manual in category <span class="cat">3</span> as a function or function library. The title of the
manual, <span class="screen">GETC</span>, is chosen as the most general of those functions listed below in the <span
class="sec">NAME</span> section.
</p>
<div class="mdocin">
.Sh NAME
<br />
.Nm fgetc ,
<br />
.Nm getc ,
<br />
.Nm getchar ,
<br />
.Nm getw
<br />
.Nd get next character or word from input stream
</div>
<p>
Lists (alphabetically) all the functions that will be documented, and some general notes about their collective
function. We next jump down into the <span class="sec">SYNOPSIS</span>; since this set of functions is part of the <a
class="term" href="glossary.xml#libc">C Standard Library</a>, it needs no special linking information.
</p>
<div class="mdocin">
.Sh SYNOPSIS
<br />
.Fd #include <stdio.h>
<br />
.Ft int
<br />
.Fn fgetc "FILE *stream"
<br />
.Ft int
<br />
.Fn getc "FILE *stream"
<br />
.Ft int
<br />
.Fn getchar "void"
<br />
.Ft int
<br />
.Fn getw "FILE *stream"
</div>
<p>
This documents the calling syntax of all functions. Note that the <a href="macros.xml#macro_fd" class="macro">Fd</a>
macro is used instead of the <a href="macros.xml#macro_in" class="macro">In</a> macro. This invocation is
historically relevant, but new manuals should always use <a href="macros.xml#macro_in" class="macro">In</a>.
</p>
<div class="mdocin">
.In stdio.h
</div>
<p>
Next, each function and its arguments is explained as a free-flowing paragraph. This was probably chosen instead of
using a list item for each argument (with <a href="macros.xml#macro_bl" class="macro">Bl</a>) due to the small number
of arguments.
</p>
<div class="mdocin">
.Sh DESCRIPTION
<br />
The
<br />
.Fn fgetc
<br />
function obtains the next input character (if present) from the stream
<br />
pointed at by
<br />
.Fa stream ,
<br />
or the next character pushed back on the stream via
<br />
.Xr ungetc 3 .
<br />
.Pp
<br />
The
<br />
.Fn getc
<br />
function acts essentially identically to
<br />
.Fn fgetc ,
<br />
but is a macro that expands in-line.
<br />
.Pp
<br />
The
<br />
.Fn getchar
<br />
function is equivalent to
<br />
.Fn getc
<br />
with the argument
<br />
.Em stdin .
<br />
.Pp
<br />
The
<br />
.Fn getw
<br />
function obtains the next
<br />
.Li int
<br />
(if present)
<br />
from the stream pointed at by
<br />
.Fa stream .
</div>
<p>
The usage of the <a href="macros.xml#macro_em" class="macro">Em</a> macro is not correct: the <a
href="macros.xml#macro_va" class="macro">Va</a> or <a href="macros.xml#macro_dv" class="macro">Dv</a> macro
would have been more appropriate. The same applies to the <a href="macros.xml#macro_li" class="macro">Li</a>. The
<span class="lang">mdoc</span> language is semantic, so using presentation macros such as <a
href="macros.xml#macro_li" class="macro">Li</a> and <a href="macros.xml#macro_em" class="macro">Em</a> is
discouraged.
</p>
<div class="mdocin">
.Sh RETURN VALUES
<br />
If successful, these routines return the next requested object from the
<br />
.Fa stream .
<br />
If the stream is at end-of-file or a read error occurs, the routines return
<br />
.Dv EOF .
<br />
The routines
<br />
.Xr feof 3
and
<br />
.Xr ferror 3
<br />
must be used to distinguish between end-of-file and error.
<br />
If an error occurs, the global variable
<br />
.Va errno
<br />
is set to indicate the error.
<br />
The end-of-file condition is remembered, even on a terminal, and all
<br />
subsequent attempts to read will return
<br />
.Dv EOF
<br />
until the condition is cleared with
<br />
.Xr clearerr 3 .
<br />
.Sh SEE ALSO
<br />
.Xr ferror 3 ,
<br />
.Xr fopen 3 ,
<br />
.Xr fread 3 ,
<br />
.Xr putc 3 ,
<br />
.Xr ungetc 3
</div>
<p>
All possible return values are correctly documented in the <span class="sec">RETURN VALUES</span> section and relevant
functions cross-linked in the <span class="sec">SEE ALSO</span> section. Note that the cross-linked manuals are also
alphabetically sorted.
</p>
<div class="mdocin">
.Sh STANDARDS
<br />
The
<br />
.Fn fgetc ,
<br />
.Fn getc ,
<br />
and
<br />
.Fn getchar
<br />
functions conform to
<br />
.St -ansiC .
</div>
<p>
Noting standards conformance is extremely important: it allows programmers and administrators to depend on your
component in a cross-platform fashion. These functions are part of the <a class="term" href="glossary.xml#libc">C
Standard Library</a>.
</p>
<div class="mdocin">
.Sh BUGS
<br />
Since
<br />
.Dv EOF
<br />
is a valid integer value,
<br />
.Xr feof 3
<br />
and
<br />
.Xr ferror 3
<br />
must be used to check for failure after calling
<br />
.Fn getw .
<br />
.Pp
<br />
Since the size and byte order of an
<br />
.Vt int
<br />
may vary from one machine to another,
<br />
.Fn getw
<br />
is not recommended for portable applications.
</div>
<p>
The <span class="sec">BUGS</span> section should be used very carefully — bugs preferably should be fixed. In
this section, design bugs have been documented. Whether the <span class="sec">CAVEATS</span> section would be more
appropriate is up to the manual author.
</p>
<p>
We found several inconsistent uses of <span class="lang">mdoc</span> in this manual. In general, if you find unusual or
erroneous macros or styles in UNIX manuals, notify the authors! A bug in a manual is just as important as a bug in the
code.
</p>
<table class="nav">
<tbody>
<tr>
<td class="nav-contents"><a href="toc.xml">Contents</a></td>
<td class="nav-next"><a href="part1-4.xml">Next</a></td>
<td class="nav-home"><a href="http://manpages.bsd.lv/index.html">Home</a></td>
<td class="nav-history"><a href="http://manpages.bsd.lv/cgi-bin/cvsweb/part1-3-1.xml?cvsroot=manpages">History</a></td>
</tr>
</tbody>
</table>
<p class="edits">
Last edited by $Author$ on $Date$. Copyright © 2011, Kristaps Dzonsons. CC BY-SA.
</p>
</body>
</html>