dtc: [experimental] Process input files with cpp
I'm starting to be convinced by the arguments that we need internal function processing instead of using preprocessor macros. However, in the interests of more bits and pieces to play with, here's an experimental patch that causes dtc to run its input files through cpp before reading them.
This uses a probably not portable option to GNU cpp to make it only recognize # characters in column 0, and disables rather than using the file/line number information the preprocessor would usually include in its output. All fixable, but like I say, this is just for playing with, not an actual proposal.
---
This applies on top of my srcpos / input file rework series.
srcpos.c +17 -3
@@ -46,7 +46,8 @@ struct srcfile_state *current_srcfile; /#define MAX_SRCFILE_DEPTH (100)static int srcfile_depth;/* = 0 */ -FILE *srcfile_relative_open (const char *fname,char **fullnamep) +static FILE *__srcfile_relative_open (const char *fname,char **fullnamep, +int preprocess) {FILE *f;char *fullname;
@@ -61,7 +62,15 @@ FILE *srcfile_relative_open(const char *else fullname =join_path (current_srcfile->dir, fname); - f =fopen (fullname,"r" ); +if (!preprocess) { + f =fopen (fullname,"r" ); + }else { +char *cmd; + +asprintf (&cmd,"cpp -traditional-cpp -undef -P < %s" , fullname); + f =popen (cmd,"r" ); +free (cmd); + }if (!f)die ("Couldn't open \"%s\": %s\n" , fname,strerror (errno));
@@ -75,6 +84,11 @@ FILE *srcfile_relative_open(const char *return f; } +FILE *srcfile_relative_open (const char *fname,char **fullnamep) +{ +return __srcfile_relative_open (fname, fullnamep,0 ); +} +void srcfile_push (const char *fname) {struct srcfile_state *srcfile;
@@ -84,7 +98,7 @@ void srcfile_push(const char *fname) srcfile =xmalloc (sizeof (*srcfile)); - srcfile->f =srcfile_relative_open (fname, &srcfile->name); + srcfile->f =__srcfile_relative_open (fname, &srcfile->name,1 ); srcfile->dir =dirname (srcfile->name); srcfile->prev = current_srcfile;
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson