File: parsernoexpandinclude.c

package info (click to toggle)
yodl 4.05.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,724 kB
  • sloc: ansic: 7,803; perl: 683; cpp: 570; sh: 411; xml: 190; makefile: 163
file content (41 lines) | stat: -rw-r--r-- 1,068 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
#include "parser.ih"

void parser_noexpand_include(register Parser *pp, char const *filename,
                                bool searchPath)
{
    char *pathname =
            searchPath ?
                file_fullpath(pp->d_symtab_ptr, filename)
            :
                new_str(filename);

//fprintf(stderr, "In %s: looking for %s\n", new_getcwd(), pathname);

    if (access(pathname, R_OK) != 0)
    {
        if (message_show(MSG_ERR))
            message("%s: Can't find `%s'", parser_fun(), filename);
    }
    else
    {
        FILE *f;
        register char *buffer;

        if (message_show(MSG_NOTICE))
            message("%s `%s'", parser_fun(), pathname);

        f = file_open(pathname, "r");
        buffer = new_memory(MAX_LINE_LENGTH, sizeof(char));

        while (fgets (buffer, MAX_LINE_LENGTH, f))
            (*pp->d_insert)(pp, buffer);

        fclose(f);
        free(buffer);
        if (message_show(MSG_INFO))
            message("%s `%s' included", parser_fun(), pathname);
    }

    if (searchPath)
        free(pathname);
}