1 /* ----------------------------------------------------------------------- *
3 * Copyright 1996-2016 The NASM Authors - All Rights Reserved
4 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * ----------------------------------------------------------------------- */
35 * This is a null preprocessor which just copies lines from input
36 * to output. It's used when someone explicitly requests that NASM
37 * not preprocess their source file.
58 static int32_t nop_lineinc
;
60 static void nop_init(void)
65 static void nop_reset(char *file
, int pass
, StrList
**deplist
)
69 nop_fp
= nasm_open_read(file
, NF_TEXT
);
72 nasm_fatal(ERR_NOFILE
, "unable to open input file `%s'", file
);
73 (void)pass
; /* placate compilers */
75 nasm_add_string_to_strlist(deplist
, file
);
78 static char *nop_getline(void)
84 buffer
= nasm_malloc(BUF_DELTA
);
85 src_set_linnum(src_get_linnum() + nop_lineinc
);
87 while (1) { /* Loop to handle %line */
90 while (1) { /* Loop to handle long lines */
91 q
= fgets(p
, bufsize
- (p
- buffer
), nop_fp
);
95 if (p
> buffer
&& p
[-1] == '\n')
97 if (p
- buffer
> bufsize
- 10) {
100 bufsize
+= BUF_DELTA
;
101 buffer
= nasm_realloc(buffer
, bufsize
);
106 if (!q
&& p
== buffer
) {
112 * Play safe: remove CRs, LFs and any spurious ^Zs, if any of
113 * them are present at the end of the line.
115 buffer
[strcspn(buffer
, "\r\n\032")] = '\0';
117 if (!nasm_strnicmp(buffer
, "%line", 5)) {
120 char *nm
= nasm_malloc(strlen(buffer
));
121 if (sscanf(buffer
+ 5, "%"PRId32
"+%d %s", &ln
, &li
, nm
) == 3) {
132 lfmt
->line(LIST_READ
, buffer
);
137 static void nop_cleanup(int pass
)
139 (void)pass
; /* placate GCC */
146 static void nop_extra_stdmac(macros_t
*macros
)
151 static void nop_pre_define(char *definition
)
156 static void nop_pre_undefine(char *definition
)
161 static void nop_pre_include(char *fname
)
166 static void nop_include_path(char *path
)
171 static void nop_error_list_macros(int severity
)
176 const struct preproc_ops preproc_nop
= {
186 nop_error_list_macros
,