#include <stdio.h>
#include <stdlib.h>
+#include <assert.h>
#include <string.h>
#include "ulas.h"
#include <unistd.h>
#define ULAS_OPTS "hvVp"
// args with value
-#define ULAS_OPTS_ARG "o:l:s:"
+#define ULAS_OPTS_ARG "o:l:s:i:"
#define ULAS_HELP(a, desc) printf("\t-%s\t%s\n", (a), desc);
+#define ULAS_INCPATHSMAX 256
+
+const char *incpaths[ULAS_INCPATHSMAX];
+long incpathslen = 0;
+
void ulas_help(void) {
printf("%s\n", ULAS_NAME);
printf("Usage %s [-%s] [-o=path] [input]\n\n", ULAS_NAME, ULAS_OPTS);
ULAS_HELP("o=path", "Output file");
ULAS_HELP("l=path", "Listing file");
ULAS_HELP("s=path", "Symbols file");
+ ULAS_HELP("i=path", "Add include search path");
}
void ulas_version(void) { printf("%s version %s\n", ULAS_NAME, ULAS_VER); }
case 'l':
cfg->lst_path = strndup(optarg, ULAS_PATHMAX);
break;
+ case 'i':
+ assert(incpathslen < ULAS_INCPATHSMAX);
+ incpaths[incpathslen++] = strndup(optarg, ULAS_PATHMAX);
case '?':
break;
default:
struct ulas_config cfg = ulas_cfg_from_env();
ulas_getopt(argc, argv, &cfg);
+ cfg.incpaths = incpaths;
+ cfg.incpathslen = incpathslen;
int res = ulas_main(cfg);
free(cfg.lst_path);
}
+ for (int i = 0; i < incpathslen; i++) {
+ free(incpaths[i]);
+ }
+
return res;
}
int baselen = strlen(path);
// check all include paths
- for (int i = 0; i < ulas.include_paths_len; i++) {
+ for (int i = 0; i < ulascfg.incpathslen; i++) {
pathbuf[0] = '\0';
- char *ip = ulas.include_paths[i];
+ char *ip = ulascfg.incpaths[i];
int len = strlen(ip);
if (len + baselen + 1 >= ULAS_PATHMAX) {
continue;