File: getopcod.c

package info (click to toggle)
icmake 6.22-7
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 2,148 kB
  • ctags: 1,042
  • sloc: ansic: 9,241; makefile: 1,134; sh: 235; asm: 126
file content (43 lines) | stat: -rw-r--r-- 934 bytes parent folder | download | duplicates (8)
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
/*
\funcref{getopcode}{OPCODE\_ getopcode (\params)}
    {
        {FILE} {*f} {binary {\em icmake} file}
    }
    {read opcode, or --1 when reading failed}
    {}
    {getstring()}
    {getopcod.c}
    {
        Function {\em getopcode()} attempts to read an opcode from file {\em
        f}. This file must be opened in read/binary mode (see the constant {\em
        READBINARY} in file {\em icm.h}).

        When the reading operation fails, --1 is returned.
    }

Example:
{\footnotesize
    \begin{verbatim}
        // file 'infile' is assumed to be opened
        OPCODE_
            op;

        if ( (op = getopcode (f)) == -1 )
            error ("invalid binary makefile");
        process (op);
    \end{verbatim}
} % end footnotesize
*/

#include "icrssdef.h"

OPCODE_ getopcode (FILE *f)
{
    char
        op = 0;

    if (! fread (&op, sizeof (char), 1, f) )
        op = (char) -1;

    return ( (OPCODE_) op );
}