7 static void RUN (char *outfile
, char **argv
)
11 fprintf (stderr
, "Running: ");
12 for (i
= 0; argv
[i
]; i
++)
13 fprintf (stderr
, "%s ", argv
[i
]);
14 fprintf (stderr
, "\n");
19 if (outfile
) if(!freopen (outfile
, "w", stdout
))
21 execvp (argv
[0], argv
);
25 waitpid (pid
, &status
, 0);
26 if (WEXITSTATUS (status
) != 0) {
27 fprintf (stderr
, "Preprocessor failed..\n");
32 static bool issource (char *f
)
34 char *e
= f
+ strlen (f
) - 1;
36 return *e
== 'c' || *e
== 'h' || *e
== 'C' || *e
== 'i';
38 return *(e
-1) == 'c' && *e
== '+';
39 return *(e
-3) == '.' && (*(e
-2) == 'c' || *(e
-2) == 'C');
42 const static char banner
[] =
43 "Lightweight C++ preprocessor Version "LWC_VERSION
" [compiled "__DATE__
", adapted to: "COMPILER
"]\n"
44 "Developed by Stelios Xanthakis and Carl Rosmann\n"
45 "Internet: http://students.ceid.upatras.gr/~sxanth/lwc/\n"
46 "This program is *Freeware*. Save the trees\n\n";
57 void preproc (int argc
, char **argv
)
59 char **cppopt
= (char**) alloca ((argc
+ 5) * sizeof (char*));
63 /* The -gcc option seems to have been obsoleted and cpp reports
64 that it doesn't recognize it. Still, it makes a difference */
66 cppopt
[1] = "-D__LWC__";
78 cppopt
[1] = "-D__LWC__";
87 for (i
= 0; i
< argc
; i
++)
88 if (issource (cppopt
[ncppopt
++] = argv
[i
]))
89 if (current_file
) fatal ("multiple files?");
90 else current_file
= strdup (argv
[i
]);
91 else if (!strcmp (argv
[i
], "-D__REENTRANT"))
93 else if (!strcmp (argv
[i
], "-sys_cpp"))
95 cppopt
[ncppopt
] = NULL
;
98 fputs (banner
, stderr
);
103 main_file
= PREPROCFILE
;
104 RUN (PREPROCFILE
, cppopt
);
107 main_file
= strdup (current_file
);
108 setup_cpp (argc
, argv
);