123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html401/loose.dtd">
- <html>
- <!-- Created on December 10, 2012 by texi2html 1.82
- texi2html was written by:
- Lionel Cons <[email protected]> (original author)
- Karl Berry <[email protected]>
- Olaf Bachmann <[email protected]>
- and many others.
- Maintained by: Many creative people.
- Send bugs and suggestions to <[email protected]>
- -->
- <head>
- <title>avram - a virtual machine code interpreter: 3.3.3 Formatted Input</title>
- <meta name="description" content="avram - a virtual machine code interpreter: 3.3.3 Formatted Input">
- <meta name="keywords" content="avram - a virtual machine code interpreter: 3.3.3 Formatted Input">
- <meta name="resource-type" content="document">
- <meta name="distribution" content="global">
- <meta name="Generator" content="texi2html 1.82">
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <style type="text/css">
- <!--
- a.summary-letter {text-decoration: none}
- blockquote.smallquotation {font-size: smaller}
- pre.display {font-family: serif}
- pre.format {font-family: serif}
- pre.menu-comment {font-family: serif}
- pre.menu-preformatted {font-family: serif}
- pre.smalldisplay {font-family: serif; font-size: smaller}
- pre.smallexample {font-size: smaller}
- pre.smallformat {font-family: serif; font-size: smaller}
- pre.smalllisp {font-size: smaller}
- span.roman {font-family:serif; font-weight:normal;}
- span.sansserif {font-family:sans-serif; font-weight:normal;}
- ul.toc {list-style: none}
- -->
- </style>
- </head>
- <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
- <a name="Formatted-Input"></a>
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Raw-Files.html#Raw-Files" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="Formatted-Output.html#Formatted-Output" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="File-Manipulation.html#File-Manipulation" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <hr size="1">
- <a name="Formatted-Input-1"></a>
- <h3 class="subsection">3.3.3 Formatted Input</h3>
- <p>Some functions relating to the input of text files or data files with
- preambles are declared in the header file ‘<tt>formin.h</tt>’. The usage of
- these functions is as follows.
- </p>
- <dl>
- <dt><a name="index-avm_005fpreamble_005fand_005fcontents"></a><u>Function:</u> list <b>avm_preamble_and_contents</b><i> (FILE *<var>source</var>, char *<var>filename</var>)</i></dt>
- <dd><p>This function loads a file of either text or data format into memory.
- </p>
- <dl compact="compact">
- <dt> <code><var>source</var></code></dt>
- <dd><p>should be initialized by the caller as the address of a file
- already open for reading that will be read from its current position.
- </p></dd>
- <dt> <code><var>filename</var></code></dt>
- <dd><p>should be set by the caller to the address of a null terminated
- character string giving the name of the file that will be used if an i/o
- error message needs to be written about it. If it is a <code>NULL</code>
- pointer, standard input is assumed.
- </p></dd>
- </dl>
- <p>The result returned by the function will be a list whose <code>head</code>
- <a name="index-preamble-6"></a>
- represents the preamble of the file and whose <code>tail</code> represents the
- contents. As a side effect, the input file will be closed, unless the
- <code><var>filename</var></code> parameter is <code>NULL</code>.
- </p>
- <p>If the file conforms to the format described in <a href="File-Format.html#File-Format">File Format</a>, the
- preamble is a list of character strings. In the result returned by the
- function, the <code>head</code> field will be a list with one item for each
- line in the file, and each item will be a list of character
- representations as in <a href="Character-Table.html#Character-Table">Character Table</a>, but with the leading hashes
- stripped. The <code>tail</code> will be the list specified by remainder of the
- file according to <a href="Concrete-Syntax.html#Concrete-Syntax">Concrete Syntax</a>. If the file has an empty
- preamble but is nevertheless a data file, the <code>head</code> will be a list
- whose <code>head</code> and <code>tail</code> are both <code>NULL</code>.
- </p>
- <p>If the file does not conform to the format in <a href="File-Format.html#File-Format">File Format</a>, then
- the <code>head</code> of the result will be <code>NULL</code>, and the <code>tail</code>
- will be a list of lists of character representations, with one for each
- line.
- </p>
- <p>Whether or not the file conforms to the format is determined on the fly,
- so this function is useful for situations in which the format is not
- known in advance. The conventions regarding the preamble and contents
- maintained by this function are the same as those used by virtual code
- applications as described in <a href="Standard-Output-Representation.html#Standard-Output-Representation">Standard Output Representation</a> and
- <a href="Input-Data-Structure.html#Input-Data-Structure">Input Data Structure</a>.
- </p>
- <p>The characters used for line breaks are not explicitly represented in
- <a name="index-line-breaks-1"></a>
- the result. Depending on the host system, line breaks in text files may
- be represented either by the character code 10, or by the sequence 13
- 10. However, in order for the library to deal with binary files in a
- portable way, a line break always corresponds to a 10 as far as this
- function is concerned regardless of the host, and a 13 is treated like
- any other character. Hence, if this function were used on binary files
- that happened to have some 10s in them, the exact contents of a
- file could be reconstructed easily by appending a 10 to all but the last
- line and flattening the list.
- </p>
- <p>A considerable amount of memory may need to be allocated by this
- function in order to store the file as a list. If not enough memory is
- available, the function prints an error message to standard error and
- aborts rather than returning to the caller. However, i/o errors are not
- fatal, and will cause the function to print a warning but attempt to
- continue.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fload"></a><u>Function:</u> list <b>avm_load</b><i> (FILE *<var>source</var>, char *<var>filename</var>, int <var>raw</var>)</i></dt>
- <dd><p>Similarly to <code>avm_preamble_and_contents</code>, this function also loads
- a file into memory, but the format is specified in advance.
- </p>
- <dl compact="compact">
- <dt> <code><var>source</var></code></dt>
- <dd><p>should be set by the caller to the address of an already open file for
- reading, which will be read from its current position.
- </p></dd>
- <dt> <code><var>filename</var></code></dt>
- <dd><p>should be initialized by the caller as a pointer to a null terminated
- string containing the name of the file that will be reported to the user
- in the event of an error reading from it. If it is a <code>NULL</code>
- pointer, standard input is assumed.
- </p></dd>
- <dt> <code><var>raw</var></code></dt>
- <dd><p>is set to a non-zero value by the caller to indicate that the file is
- expected to conform to the format in <a href="File-Format.html#File-Format">File Format</a>. If the file is
- an ordinary text file, then it should be set to zero.
- </p></dd>
- </dl>
- <p>In the case of a data file, which is when <code><var>raw</var></code> is non-zero,
- the result returned by this function will be a list representing the
- data section of the file and ignoring the preamble. In the case of a
- text file, the result will be a list of lists of character
- representations as per <a href="Character-Table.html#Character-Table">Character Table</a>, with one such list for
- each line in the file. Similar comments about line breaks to those
- mentioned under <code>avm_preamble_and_contents</code> are applicable.
- </p>
- <p>As a side effect of this function, the <code><var>source</var></code> file will be
- closed, unless the <code><var>filename</var></code> is a <code>NULL</code> pointer.
- </p>
- <p>This function is useful when the type of file is known in advance. If a
- data file is indicated by the <code><var>raw</var></code> parameter but the format
- is incorrect, an error message is reported and the process
- terminates. The error message will be of the form
- </p>
- <table><tr><td> </td><td><pre class="display"><code><var>program-name</var>: invalid raw file format in <var>filename</var></code>
- </pre></td></tr></table>
- <p>Alternatively, if a text file is indicated by the
- <a name="index-invalid-raw-file-format-2"></a>
- <code><var>raw</var></code> parameter, then no attempt is made to test whether it
- could be interpreted as data, even if it could be. This behavior differs
- from that of <code>avm_preamble_and_contents</code>, where a bad data
- file format causes the file to be treated as text, and a valid data file
- format, even in a “text” file, causes it to be treated as data.
- </p>
- <p>Memory requirements for this function are significant and will cause the
- process to abort with an error message in the event of insufficient free
- memory. Messages pertaining to i/o errors are also possible and are not
- fatal.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005finitialize_005fformin"></a><u>Function:</u> void <b>avm_initialize_formin</b><i> ()</i></dt>
- <dd><p>This function should be called before either of the other functions in
- this section is called, as it initializes some necessary static data
- structures. Results of the other functions are undefined if this one is
- not called first.
- </p></dd></dl>
- <dl>
- <dt><a name="index-avm_005fcount_005fformin"></a><u>Function:</u> void <b>avm_count_formin</b><i> ()</i></dt>
- <dd><p>This function should be called after the last call to any of the other
- functions in this section, as it is necessary for cleaning up and
- reclaiming some internal data. If any storage remains unreclaimed due to
- memory leaks in these functions or to misuse of them, a warning message
- is written to standard error. If the function <code>avm_count_lists</code> is
- also being used by the client program, it should be called after this
- one.
- </p></dd></dl>
- <hr size="1">
- <table cellpadding="1" cellspacing="1" border="0">
- <tr><td valign="middle" align="left">[<a href="Raw-Files.html#Raw-Files" title="Previous section in reading order"> < </a>]</td>
- <td valign="middle" align="left">[<a href="Formatted-Output.html#Formatted-Output" title="Next section in reading order"> > </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="Library-Reference.html#Library-Reference" title="Beginning of this chapter or previous chapter"> << </a>]</td>
- <td valign="middle" align="left">[<a href="File-Manipulation.html#File-Manipulation" title="Up section"> Up </a>]</td>
- <td valign="middle" align="left">[<a href="Character-Table.html#Character-Table" title="Next chapter"> >> </a>]</td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left"> </td>
- <td valign="middle" align="left">[<a href="avram.html#Top" title="Cover (top) of document">Top</a>]</td>
- <td valign="middle" align="left">[<a href="avram_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
- <td valign="middle" align="left">[<a href="Function-Index.html#Function-Index" title="Index">Index</a>]</td>
- <td valign="middle" align="left">[<a href="avram_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
- </tr></table>
- <p>
- <font size="-1">
- This document was generated on <i>December 10, 2012</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 1.82</i></a>.
- </font>
- <br>
- </p>
- </body>
- </html>
|