static int opt_objfile_handler(char *cmd, /*@null@*/ char *param, int extra);
static int opt_warning_handler(char *cmd, /*@null@*/ char *param, int extra);
static int preproc_only_handler(char *cmd, /*@null@*/ char *param, int extra);
+static int opt_preproc_include_path(char *cmd, /*@null@*/ char *param,
+ int extra);
+static int opt_preproc_include_file(char *cmd, /*@null@*/ char *param,
+ int extra);
static /*@only@*/ char *replace_extension(const char *orig, /*@null@*/
const char *ext, const char *def);
static void print_yasm_warning(const char *filename, unsigned long line,
const char *msg);
+static void apply_preproc_saved_options(void);
+
/* values for special_options */
#define SPECIAL_SHOW_HELP 0x01
#define SPECIAL_SHOW_VERSION 0x02
N_("enables/disables warning"), NULL },
{ 'e', "preproc-only", 0, preproc_only_handler, 0,
N_("preprocess only (writes output to stdout by default)"), NULL },
+ { 'I', NULL, 1, opt_preproc_include_path, 0,
+ N_("add include path"), N_("path") },
+ { 'P', NULL, 1, opt_preproc_include_file, 0,
+ N_("pre-include file"), N_("filename") },
};
/* version message */
"\n"
"Report bugs to bug-yasm@tortall.net\n");
+/* parsed command line storage until appropriate modules have been loaded */
+typedef STAILQ_HEAD(constcharparam_head, constcharparam) constcharparam_head;
+
+typedef struct constcharparam {
+ STAILQ_ENTRY(constcharparam) link;
+ const char *param;
+} constcharparam;
+
+static constcharparam_head includepaths;
+static constcharparam_head includefiles;
+
/* main function */
/*@-globstate -unrecog@*/
int
}
#endif
+ /* Initialize parameter storage */
+ STAILQ_INIT(&includepaths);
+ STAILQ_INIT(&includefiles);
+
if (parse_cmdline(argc, argv, options, NELEMS(options), print_error))
return EXIT_FAILURE;
return EXIT_FAILURE;
}
+ apply_preproc_saved_options();
+
/* Pre-process until done */
cur_preproc->initialize(in, in_filename, &yasm_std_linemgr);
while ((got = cur_preproc->input(preproc_buf, PREPROC_BUF_SIZE)) != 0)
return EXIT_FAILURE;
}
}
+ apply_preproc_saved_options();
/* Get initial x86 BITS setting from object format */
if (strcmp(cur_arch->keyword, "x86") == 0) {
return 0;
}
+static int
+opt_preproc_include_path(/*@unused@*/ char *cmd, char *param,
+ /*@unused@*/ int extra)
+{
+ constcharparam *cp;
+ cp = yasm_xmalloc(sizeof(constcharparam));
+ cp->param = param;
+ STAILQ_INSERT_TAIL(&includepaths, cp, link);
+ return 0;
+}
+
+static void
+apply_preproc_saved_options()
+{
+ constcharparam *cp;
+ constcharparam *cpnext;
+
+ if (cur_preproc->add_include_path != NULL) {
+ STAILQ_FOREACH(cp, &includepaths, link) {
+ cur_preproc->add_include_path(cp->param);
+ }
+ }
+
+ cp = STAILQ_FIRST(&includepaths);
+ while (cp != NULL) {
+ cpnext = STAILQ_NEXT(cp, link);
+ yasm_xfree(cp);
+ cp = cpnext;
+ }
+ STAILQ_INIT(&includepaths);
+
+ if (cur_preproc->add_include_file != NULL) {
+ STAILQ_FOREACH(cp, &includefiles, link) {
+ cur_preproc->add_include_file(cp->param);
+ }
+ }
+
+ cp = STAILQ_FIRST(&includepaths);
+ while (cp != NULL) {
+ cpnext = STAILQ_NEXT(cp, link);
+ yasm_xfree(cp);
+ cp = cpnext;
+ }
+ STAILQ_INIT(&includepaths);
+}
+
+static int
+opt_preproc_include_file(/*@unused@*/ char *cmd, char *param,
+ /*@unused@*/ int extra)
+{
+ constcharparam *cp;
+ cp = yasm_xmalloc(sizeof(constcharparam));
+ cp->param = param;
+ STAILQ_INSERT_TAIL(&includefiles, cp, link);
+ return 0;
+}
+
/* Replace extension on a filename (or append one if none is present).
* If output filename would be identical to input (same extension out as in),
* returns (copy of) def.