+ addSetHead (&pipeSet, yyin);
+ }
+
+ return 0;
+}
+
+/* Set bin paths */
+static void
+setBinPaths(const char *argv0)
+{
+ char *p;
+ char buf[PATH_MAX];
+
+ /*
+ * Search logic:
+ *
+ * 1. - $SDCCDIR/PREFIX2BIN_DIR
+ * 2. - path(argv[0])
+ * 3. - $PATH
+ */
+
+ /* do it in reverse mode, so that addSetHead() can be used
+ instead of slower addSet() */
+
+ if ((p = getBinPath(argv0)) != NULL)
+ addSetHead(&binPathSet, Safe_strdup(p));
+
+ if ((p = getenv(SDCC_DIR_NAME)) != NULL) {
+ SNPRINTF(buf, sizeof buf, "%s" PREFIX2BIN_DIR, p);
+ addSetHead(&binPathSet, Safe_strdup(buf));
+ }
+
+ if (options.printSearchDirs) {
+ printf("programs: ");
+ if (NULL != (p = (char *)setFirstItem(binPathSet))) {
+ printf("%s", p);
+ while (NULL != (p = (char *)setNextItem(binPathSet)))
+ printf(":%s", p);
+ }
+ putchar('\n');
+ }
+}
+
+/* Set system include path */
+static void
+setIncludePath(const char *datadir)
+{
+ char *p;
+ char buf[PATH_MAX];
+
+ /*
+ * Search logic:
+ *
+ * 1. - $SDCC_INCLUDE
+ * 2. - $SDCC_HOME/PREFIX2DATA_DIR/INCLUDE_DIR_SUFFIX
+ * 3. - path(argv[0])/BIN2DATA_DIR/INCLUDE_DIR_SUFFIX
+ * 4. - DATADIR/INCLUDE_DIR_SUFFIX (only on *nix)
+ */
+
+ if ((p = getenv(SDCC_INCLUDE_NAME)) == NULL) {
+ SNPRINTF(buf, sizeof buf, "%s" INCLUDE_DIR_SUFFIX, datadir);
+ p = buf;
+ }
+
+ if (options.printSearchDirs)
+ printf("includedir: %s\n", p);
+
+ setMainValue ("includedir", p);
+}
+
+/* Set system lib path */
+static void
+setLibPath(const char *datadir)
+{
+ char *p;
+ char buf[PATH_MAX];
+
+ /*
+ * Search logic:
+ *
+ * 1. - $SDCC_LIB
+ * 2. - $SDCC_HOME/PREFIX2DATA_DIR/LIB_DIR_SUFFIX/<model>
+ * 3. - path(argv[0])/BIN2DATA_DIR/LIB_DIR_SUFFIX/<model>
+ * 4. - DATADIR/LIB_DIR_SUFFIX/<model> (only on *nix)
+ */
+
+ if ((p = getenv(SDCC_LIB_NAME)) == NULL) {
+ SNPRINTF(buf, sizeof buf, "%s" LIB_DIR_SUFFIX, datadir);
+ p = buf;
+ }
+
+ if (options.printSearchDirs)
+ printf("libdir: %s\n", p);
+
+ setMainValue ("libdir", p);
+}
+
+/* Set data path */
+static void
+setDataPaths(const char *argv0)
+{
+ char *p;
+ char buf[PATH_MAX];
+
+ /*
+ * Search logic:
+ *
+ * 1. - $SDCC_HOME/PREFIX2DATA_DIR
+ * 2. - path(argv[0])/BIN2DATA_DIR
+ * 3. - DATADIR (only on *nix)
+ */
+
+ if ((p = getenv(SDCC_DIR_NAME)) != NULL) {
+ SNPRINTF(buf, sizeof buf, "%s" PREFIX2DATA_DIR, p);
+ p = buf;
+ }
+ else if ((p = getBinPath(argv0)) != NULL) {
+ SNPRINTF(buf, sizeof buf, "%s" BIN2DATA_DIR, p);
+ p = buf;
+ }
+#ifdef _WIN32
+ else {
+ /* this should never happen... */
+ wassertl(0, "Can't get binary path");
+ p = ".";
+ }
+#else
+ if (!pathExists(p))
+ p = DATADIR; /* last resort */
+#endif
+
+ if (options.printSearchDirs)
+ printf("datadir: %s\n", p);
+
+ setIncludePath(p);
+ setLibPath(p);
+
+ setMainValue ("datadir", p);
+}
+
+static void
+initValues (void)
+{
+ populateMainValues (_baseValues);
+ setMainValue ("port", port->target);
+ setMainValue ("objext", port->linker.rel_ext);
+ setMainValue ("asmext", port->assembler.file_ext);
+
+ setMainValue ("dstfilename", dstFileName);
+ setMainValue ("fullsrcfilename", fullSrcFileName ? fullSrcFileName : "fullsrcfilename");
+
+ if (options.cc_only && fullDstFileName)
+ /* compile + assemble and -o given: -o specifies name of object file */
+ {
+ setMainValue ("objdstfilename", fullDstFileName);