File: pushfile.c

package info (click to toggle)
icmake 7.18.00-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,840 kB
  • sloc: ansic: 7,784; makefile: 3,811; sh: 319; cpp: 83
file content (60 lines) | stat: -rw-r--r-- 2,065 bytes parent folder | download | duplicates (3)
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
/*
\funcref{pushfile}{void pushfile (\params)}
    {
        {char} {*name} {file name}
    }
    {}
    {error(), xrealloc(), xstrdup()}
    {popfile()}
    {pushfile.c}
    {
        Function {\em pushfile()} is called whenever an input file should be
        processed. The first time, {\em pushfile()} is called from {\em main()}
        with the name of the main input file as argument. Subsequently, {\em
        pushfile()} may be called from {\em directive()} when an {\em
        \#include} directive is encountered.

        The files to process are kept on a filestack. This array of {\em
        FILESTACK\_} structs is indexed by the variable {\em filesp}: this
        index always points to the currently processed file. The filestack is
        relocatable and grows upward: hence, {\em filesp} is initially --1 and
        is increased to 0 when the first input file is opened.

        The elements of the filestack contain the following fields:

        \begin{itemize}

            \item {\em char $*$n} points to the name of the input file. This is
            an area of allocated memory where a duplicate of the name is
            stored.

            \item {\em FILE $*$f} is the associated file pointer.

            \item {\em int l} is the number of the currently processed line.

        \end{itemize}

        When {\em pushfile()} is called, {\em filesp} is increased by 1 and the
        filestack is reallocated to hold information about the input file.
        Next, the fields of the new stack element are assigned using {\em
        xrealloc()} and {\em fopen()}. When the input file cannot be opened for
        reading, an error occurs.
    }
*/

#include "icm-pp.h"

void pushfile(name)
char *name;
{
    filesp++;

    filestack = xrealloc(filestack, (filesp + 1) * sizeof(FILESTACK_));
    filestack[filesp].n = xstrdup(name);
    if (! (filestack[filesp].f = fopen(name, "r")) )
        error("cannot open #include file %s", name);
    filestack[filesp].l = 1;

    if (! nofileinfo)
    fprintf(outfile, "#%s\n", name);
}