378 lines
15 KiB
HTML
378 lines
15 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
|
|
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
|
|
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
|
|
<title>File Format Notation</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
|
|
<basefont size="3"> <!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h2><a name="tag_05"></a>File Format Notation</h2>
|
|
|
|
<p>The STDIN, STDOUT, STDERR, INPUT FILES, and OUTPUT FILES sections of the utility descriptions use a syntax to describe the data
|
|
organization within the files, when that organization is not otherwise obvious. The syntax is similar to that used by the System
|
|
Interfaces volume of IEEE Std 1003.1-2001 <a href="../functions/printf.html"><i>printf</i>()</a> function, as described
|
|
in this chapter. When used in STDIN or INPUT FILES sections of the utility descriptions, this syntax describes the format that
|
|
could have been used to write the text to be read, not a format that could be used by the System Interfaces volume of
|
|
IEEE Std 1003.1-2001 <a href="../functions/scanf.html"><i>scanf</i>()</a> function to read the input file.</p>
|
|
|
|
<p>The description of an individual record is as follows:</p>
|
|
|
|
<blockquote>
|
|
<pre>
|
|
<tt>"<</tt><i>format</i><tt>>",</tt> <b>[</b><tt><</tt><i>arg1</i><tt>>, <</tt><i>arg2</i><tt>>,..., <</tt><i>argn</i><tt>></tt><b>]
|
|
</b>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<p>The <i>format</i> is a character string that contains three types of objects defined below:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p><i>Characters</i> that are not "escape sequences" or "conversion specifications", as described below, shall be copied to the
|
|
output.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p><i>Escape Sequences</i> represent non-graphic characters.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p><i>Conversion Specifications</i> specify the output format of each argument; see below.</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<p>The following characters have the following special meaning in the format string:</p>
|
|
|
|
<dl compact>
|
|
<dt><tt>''</tt></dt>
|
|
|
|
<dd>(An empty character position.) Represents one or more <blank>s.</dd>
|
|
|
|
<dt><tt><img src="../images/delta.gif" border="0"></tt></dt>
|
|
|
|
<dd>Represents exactly one <space>.</dd>
|
|
</dl>
|
|
|
|
<p><a href="#tagtcjh_2">Escape Sequences and Associated Actions</a> lists escape sequences and associated actions on display
|
|
devices capable of the action.<br>
|
|
</p>
|
|
|
|
<center><b><a name="tagtcjh_2"></a> Table: Escape Sequences and Associated Actions</b></center>
|
|
|
|
<center>
|
|
<table border="1" cellpadding="3" align="center">
|
|
<tr valign="top">
|
|
<th align="center">
|
|
<p class="tent"><b>Escape</b></p>
|
|
</th>
|
|
<th align="center">
|
|
<p class="tent"><b>Represents</b></p>
|
|
</th>
|
|
<th align="center">
|
|
<p class="tent"><b> </b></p>
|
|
</th>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<th align="center">
|
|
<p class="tent"><b>Sequence</b></p>
|
|
</th>
|
|
<th align="center">
|
|
<p class="tent"><b>Character</b></p>
|
|
</th>
|
|
<th align="center">
|
|
<p class="tent"><b>Terminal Action</b></p>
|
|
</th>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="center">
|
|
<p class="tent"><tt>'\\'</tt> </p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">backslash</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Print the character <tt>'\'</tt> .</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="center">
|
|
<p class="tent"><tt>'\a'</tt> </p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">alert</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Attempt to alert the user through audible or visible notification.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="center">
|
|
<p class="tent"><tt>'\b'</tt> </p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">backspace</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Move the printing position to one column before the current position, unless the current position is the start of a
|
|
line.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="center">
|
|
<p class="tent"><tt>'\f'</tt> </p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">form-feed</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Move the printing position to the initial printing position of the next logical page.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="center">
|
|
<p class="tent"><tt>'\n'</tt> </p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">newline</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Move the printing position to the start of the next line.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="center">
|
|
<p class="tent"><tt>'\r'</tt> </p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">carriage-return</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Move the printing position to the start of the current line.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="center">
|
|
<p class="tent"><tt>'\t'</tt> </p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">tab</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Move the printing position to the next tab position on the current line. If there are no more tab positions
|
|
remaining on the line, the behavior is undefined.</p>
|
|
</td>
|
|
</tr>
|
|
|
|
<tr valign="top">
|
|
<td align="center">
|
|
<p class="tent"><tt>'\v'</tt> </p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">vertical-tab</p>
|
|
</td>
|
|
<td align="left">
|
|
<p class="tent">Move the printing position to the start of the next vertical tab position. If there are no more vertical tab
|
|
positions left on the page, the behavior is undefined.</p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
|
|
<p>Each conversion specification is introduced by the percent-sign character ( <tt>'%'</tt> ). After the character <tt>'%'</tt> ,
|
|
the following shall appear in sequence:</p>
|
|
|
|
<dl compact>
|
|
<dt><i>flags</i></dt>
|
|
|
|
<dd>Zero or more <i>flags</i>, in any order, that modify the meaning of the conversion specification.</dd>
|
|
|
|
<dt><i>field width</i></dt>
|
|
|
|
<dd>An optional string of decimal digits to specify a minimum field width. For an output field, if the converted value has fewer
|
|
bytes than the field width, it shall be padded on the left (or right, if the left-adjustment flag ( <tt>'-'</tt> ), described
|
|
below, has been given) to the field width.</dd>
|
|
|
|
<dt><i>precision</i></dt>
|
|
|
|
<dd>Gives the minimum number of digits to appear for the <tt>d</tt> , <tt>o</tt> , <tt>i</tt> , <tt>u</tt> , <tt>x</tt> , or
|
|
<tt>X</tt> conversion specifiers (the field is padded with leading zeros), the number of digits to appear after the radix character
|
|
for the <tt>e</tt> and <tt>f</tt> conversion specifiers, the maximum number of significant digits for the <tt>g</tt> conversion
|
|
specifier; or the maximum number of bytes to be written from a string in the <tt>s</tt> conversion specifier. The precision shall
|
|
take the form of a period ( <tt>'.'</tt> ) followed by a decimal digit string; a null digit string is treated as zero.</dd>
|
|
|
|
<dt><i>conversion specifier characters</i></dt>
|
|
|
|
<dd><br>
|
|
A conversion specifier character (see below) that indicates the type of conversion to be applied.</dd>
|
|
</dl>
|
|
|
|
<p>The <i>flag</i> characters and their meanings are:</p>
|
|
|
|
<dl compact>
|
|
<dt><tt>-</tt></dt>
|
|
|
|
<dd>The result of the conversion shall be left-justified within the field.</dd>
|
|
|
|
<dt><tt>+</tt></dt>
|
|
|
|
<dd>The result of a signed conversion shall always begin with a sign ( <tt>'+'</tt> or <tt>'-'</tt> ).</dd>
|
|
|
|
<dt><space></dt>
|
|
|
|
<dd>If the first character of a signed conversion is not a sign, a <space> shall be prefixed to the result. This means that
|
|
if the <space> and <tt>'+'</tt> flags both appear, the <space> flag shall be ignored.</dd>
|
|
|
|
<dt><tt>#</tt></dt>
|
|
|
|
<dd>The value shall be converted to an alternative form. For <tt>c</tt> , <tt>d</tt> , <tt>i</tt> , <tt>u</tt> , and <tt>s</tt>
|
|
conversion specifiers, the behavior is undefined. For the <tt>o</tt> conversion specifier, it shall increase the precision to force
|
|
the first digit of the result to be a zero. For <tt>x</tt> or <tt>X</tt> conversion specifiers, a non-zero result has 0x or 0X
|
|
prefixed to it, respectively. For <tt>e</tt> , <tt>E</tt> , <tt>f</tt> , <tt>g</tt> , and <tt>G</tt> conversion specifiers, the
|
|
result shall always contain a radix character, even if no digits follow the radix character. For <tt>g</tt> and <tt>G</tt>
|
|
conversion specifiers, trailing zeros shall not be removed from the result as they usually are.</dd>
|
|
|
|
<dt><tt>0</tt></dt>
|
|
|
|
<dd>For <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , <tt>X</tt> , <tt>e</tt> , <tt>E</tt> , <tt>f</tt> ,
|
|
<tt>g</tt> , and <tt>G</tt> conversion specifiers, leading zeros (following any indication of sign or base) shall be used to pad to
|
|
the field width; no space padding is performed. If the <tt>'0'</tt> and <tt>'-'</tt> flags both appear, the <tt>'0'</tt> flag shall
|
|
be ignored. For <tt>d</tt> , <tt>i</tt> , <tt>o</tt> , <tt>u</tt> , <tt>x</tt> , and <tt>X</tt> conversion specifiers, if a
|
|
precision is specified, the <tt>'0'</tt> flag shall be ignored. For other conversion specifiers, the behavior is undefined.</dd>
|
|
</dl>
|
|
|
|
<p>Each conversion specifier character shall result in fetching zero or more arguments. The results are undefined if there are
|
|
insufficient arguments for the format. If the format is exhausted while arguments remain, the excess arguments shall be
|
|
ignored.</p>
|
|
|
|
<p>The conversion specifiers and their meanings are:</p>
|
|
|
|
<dl compact>
|
|
<dt><tt>d</tt>,<tt>i</tt>,<tt>o</tt>,<tt>u</tt>,<tt>x</tt>,<tt>X</tt></dt>
|
|
|
|
<dd>The integer argument shall be written as signed decimal ( <tt>d</tt> or <tt>i</tt> ), unsigned octal ( <tt>o</tt> ), unsigned
|
|
decimal ( <tt>u</tt> ), or unsigned hexadecimal notation ( <tt>x</tt> and <tt>X</tt> ). The <tt>d</tt> and <tt>i</tt> specifiers
|
|
shall convert to signed decimal in the style <tt>"[-]</tt><i>dddd</i><tt>"</tt>. The <tt>x</tt> conversion specifier shall use the
|
|
numbers and letters <tt>"0123456789abcdef"</tt> and the <tt>X</tt> conversion specifier shall use the numbers and letters
|
|
<tt>"0123456789ABCDEF"</tt> . The <i>precision</i> component of the argument shall specify the minimum number of digits to appear.
|
|
If the value being converted can be represented in fewer digits than the specified minimum, it shall be expanded with leading
|
|
zeros. The default precision shall be 1. The result of converting a zero value with a precision of 0 shall be no characters. If
|
|
both the field width and precision are omitted, the implementation may precede, follow, or precede and follow numeric arguments of
|
|
types <tt>d</tt> , <tt>i</tt> , and <tt>u</tt> with <blank>s; arguments of type <tt>o</tt> (octal) may be preceded with
|
|
leading zeros.</dd>
|
|
|
|
<dt><tt>f</tt></dt>
|
|
|
|
<dd>The floating-point number argument shall be written in decimal notation in the style <b>[</b>-<b>]</b><i>ddd.ddd</i>, where the
|
|
number of digits after the radix character (shown here as a decimal point) shall be equal to the <i>precision</i> specification.
|
|
The <i>LC_NUMERIC</i> locale category shall determine the radix character to use in this format. If the <i>precision</i> is omitted
|
|
from the argument, six digits shall be written after the radix character; if the <i>precision</i> is explicitly 0, no radix
|
|
character shall appear.</dd>
|
|
|
|
<dt><tt>e</tt>,<tt>E</tt></dt>
|
|
|
|
<dd>The floating-point number argument shall be written in the style <b>[</b>-<b>]</b><i>d.ddd</i>e<i>±dd</i> (the symbol
|
|
<tt>'±'</tt> indicates either a plus or minus sign), where there is one digit before the radix character (shown here as a
|
|
decimal point) and the number of digits after it is equal to the precision. The <i>LC_NUMERIC</i> locale category shall determine
|
|
the radix character to use in this format. When the precision is missing, six digits shall be written after the radix character; if
|
|
the precision is 0, no radix character shall appear. The <tt>E</tt> conversion specifier shall produce a number with <tt>E</tt>
|
|
instead of <tt>e</tt> introducing the exponent. The exponent shall always contain at least two digits. However, if the value to be
|
|
written requires an exponent greater than two digits, additional exponent digits shall be written as necessary.</dd>
|
|
|
|
<dt><tt>g</tt>,<tt>G</tt></dt>
|
|
|
|
<dd>The floating-point number argument shall be written in style <tt>f</tt> or <tt>e</tt> (or in style <tt>F</tt> or <tt>E</tt> in
|
|
the case of a <tt>G</tt> conversion specifier), with the precision specifying the number of significant digits. The style used
|
|
depends on the value converted: style <tt>e</tt> (or <tt>E</tt> ) shall be used only if the exponent resulting from the conversion
|
|
is less than -4 or greater than or equal to the precision. Trailing zeros are removed from the result. A radix character shall
|
|
appear only if it is followed by a digit.</dd>
|
|
|
|
<dt><tt>c</tt></dt>
|
|
|
|
<dd>The integer argument shall be converted to an <b>unsigned char</b> and the resulting byte shall be written.</dd>
|
|
|
|
<dt><tt>s</tt></dt>
|
|
|
|
<dd>The argument shall be taken to be a string and bytes from the string shall be written until the end of the string or the number
|
|
of bytes indicated by the <i>precision</i> specification of the argument is reached. If the precision is omitted from the argument,
|
|
it shall be taken to be infinite, so all bytes up to the end of the string shall be written.</dd>
|
|
|
|
<dt><tt>%</tt></dt>
|
|
|
|
<dd>Write a <tt>'%'</tt> character; no argument is converted.</dd>
|
|
</dl>
|
|
|
|
<p>In no case does a nonexistent or insufficient field width cause truncation of a field; if the result of a conversion is wider
|
|
than the field width, the field is simply expanded to contain the conversion result. The term "field width" should not be
|
|
confused with the term "precision" used in the description of <tt>%s</tt> .</p>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h5><a name="tag_05_00_00_01"></a>Examples</h5>
|
|
|
|
<p>To represent the output of a program that prints a date and time in the form Sunday, July 3, 10:02, where <i>weekday</i> and
|
|
<i>month</i> are strings:</p>
|
|
|
|
<blockquote>
|
|
<pre>
|
|
<tt>"%s,<img src="../images/delta.gif" border="0">%s<img src="../images/delta.gif" border="0">%d,<img src="../images/delta.gif"
|
|
border=
|
|
"0">%d:%.2d\n" <</tt><i>weekday</i><tt>>, <</tt><i>month</i><tt>>, <</tt><i>day</i><tt>>, <</tt><i>hour</i><tt>>, <</tt><i>min</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<p>To show <tt>'<img src="../images/pi.gif" border="0">'</tt> written to 5 decimal places:</p>
|
|
|
|
<blockquote>
|
|
<pre>
|
|
<tt>"pi<img src="../images/delta.gif" border="0">=<img src="../images/delta.gif" border=
|
|
"0">%.5f\n",<</tt><i>value of</i> <tt><img src="../images/pi.gif" border="0">>
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<p>To show an input file format consisting of five colon-separated fields:</p>
|
|
|
|
<blockquote>
|
|
<pre>
|
|
<tt>"%s:%s:%s:%s:%s\n", <</tt><i>arg1</i><tt>>, <</tt><i>arg2</i><tt>>, <</tt><i>arg3</i><tt>>, <</tt><i>arg4</i><tt>>, <</tt><i>arg5</i><tt>>
|
|
</tt>
|
|
</pre>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® is a registered Trademark of The IEEE.<br>
|
|
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
|
|
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
|
|
]</font></center>
|
|
|
|
<!--footer end-->
|
|
<hr size="2" noshade>
|
|
</body>
|
|
</html>
|
|
|