Index: /trunk/ippTools/src/Makefile.am
===================================================================
--- /trunk/ippTools/src/Makefile.am	(revision 12074)
+++ /trunk/ippTools/src/Makefile.am	(revision 12075)
@@ -31,4 +31,5 @@
 	pxadmin.h \
 	pxinject.h \
+	pxdata.h \
 	pxtag.h \
 	pzgetexp.h \
@@ -46,4 +47,5 @@
 	pxfault.c \
 	pxtables.c \
+	pxdata.c \
 	pxtag.c
 
@@ -151,2 +153,9 @@
 pxtoolsErrorCodes.c : pxtoolsErrorCodes.dat pxtoolsErrorCodes.c.in pxtoolsErrorCodes.h
 	$(ERRORCODES) --data=pxtoolsErrorCodes.dat --outdir=. pxtoolsErrorCodes.c
+
+BUILT_SOURCES += pxdata.c
+EXTRA_DIST += pxdata.c.template
+
+pxdata.c: $(srcdir)/pxdata.c.template
+	$(PERL) -pe 's|PKGDATADIR|$(pkgdatadir)|' $? > $@
+
Index: /trunk/ippTools/src/pxdata.c.template
===================================================================
--- /trunk/ippTools/src/pxdata.c.template	(revision 12075)
+++ /trunk/ippTools/src/pxdata.c.template	(revision 12075)
@@ -0,0 +1,87 @@
+/*
+ * pxdata.c
+ *
+ * Copyright (C) 2006  Joshua Hoblitt
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifdef HAVB_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h> // getenv
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include <pslib.h>
+
+#include "pxtools.h"
+#include "pxdata.h"
+
+int test_f(const char *path);
+
+psString pxDataGet(const char *filename)
+{
+    PS_ASSERT_PTR_NON_NULL(filename, NULL);
+
+    psString filepath = NULL;
+
+    // look to see if PXDATA is set
+    char *PXDATA = getenv("PXDATA");
+    if (PXDATA) {
+        // if it is, then prepend filename to PXDATA
+        psStringAppend(&filepath, "%s/%s", PXDATA, filename);
+    }
+
+    // see if we have a valid filename
+    if (test_f(filepath)) {
+        // if we do, slurp the file
+        psString text = psSlurpFilename(filepath);
+        psFree(filepath);
+
+        return text;
+    }
+
+    // look under our share path
+    psStringAppend(&filepath, "%s/%s", "PKGDATADIR", filename);
+
+    // see if we have a valid filename
+    if (test_f(filepath)) {
+        // if we don't, then we're hosed
+        psError(PS_ERR_IO, true, "can't find a file in search path(s) to match : %s", filename);
+        psFree(filepath);
+
+        return NULL;
+    }
+
+    // slurp the file
+    psString text = psSlurpFilename(filepath);
+    psFree(filepath);
+    if (!text) {
+        psError(PS_ERR_IO, false, "failed to slurp %s", filepath);
+        return NULL;
+    }
+
+    return text;
+}
+
+int test_f(const char *path)
+{
+        // copied from coreutils 6.4 test.c licenced under GPL v2 
+        struct stat stat_buf;
+        return (stat (path, &stat_buf) == 0
+                   && S_ISREG (stat_buf.st_mode));
+}
Index: /trunk/ippTools/src/pxdata.h
===================================================================
--- /trunk/ippTools/src/pxdata.h	(revision 12075)
+++ /trunk/ippTools/src/pxdata.h	(revision 12075)
@@ -0,0 +1,27 @@
+/*
+ * pxdata.h
+ *
+ * Copyright (C) 2006  Joshua Hoblitt
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * program; see the file COPYING. If not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef PXDATA_H
+#define PXDATA_H 1
+
+#include <pslib.h>
+
+psString pxDataGet(const char *filename);
+
+#endif // PXDATA_H
