summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea/tex-file.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2009-11-13 14:43:15 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2009-11-13 14:43:15 +0000
commit4b03955aab00a38ad11244687daec832f83a350a (patch)
tree0d638f8a003f7c17642ca0b11779ba01779870ae /Build/source/texk/kpathsea/tex-file.c
parent56cd2a40f239fb8a84ff7fcfa393f449bec2d41d (diff)
Import dvisvgm-0.8.7
git-svn-id: svn://tug.org/texlive/trunk@16003 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea/tex-file.c')
-rw-r--r--Build/source/texk/kpathsea/tex-file.c144
1 files changed, 143 insertions, 1 deletions
diff --git a/Build/source/texk/kpathsea/tex-file.c b/Build/source/texk/kpathsea/tex-file.c
index 1416f4f0c14..bd29b7504b2 100644
--- a/Build/source/texk/kpathsea/tex-file.c
+++ b/Build/source/texk/kpathsea/tex-file.c
@@ -32,7 +32,7 @@
#include <kpathsea/tex-file.h>
#include <kpathsea/tex-make.h>
#include <kpathsea/variable.h>
-
+#include <kpathsea/c-ctype.h>
/* These are not in the structure
because it's annoying to initialize lists in C. */
@@ -1175,9 +1175,151 @@ kpathsea_in_name_ok (kpathsea kpse, const_string fname)
return kpathsea_name_ok (kpse, fname, "openin_any", "a", ok_reading);
}
+#if defined(WIN32) || defined(__MINGW32__) || defined(__CYGWIN__)
+static int
+Isspace (char c)
+{
+ return (c == ' ' || c == '\t');
+}
+
+static void
+mk_suffixlist (char ***ext)
+{
+ char **p;
+ char *q, *r, *v;
+ int n;
+
+#if defined(__CYGWIN__)
+ v = (char *) xmalloc (71);
+ strcpy (v, ".com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.ws;.tcl;.py;.pyw;.pl");
+#else
+ v = (char *) getenv ("PATHEXT");
+ if (v) /* strlwr() exists also in MingW */
+ (void) strlwr (v);
+ else {
+ v = (char *) xmalloc (71);
+ strcpy (v, ".com;.exe;.bat;.cmd;.vbs;.vbe;.js;.jse;.wsf;.wsh;.ws;.tcl;.py;.pyw;.pl");
+ }
+#endif
+
+ q = v;
+ n = 0;
+
+ while ((r = strchr (q, ';')) != 0) {
+ n++;
+ r++;
+ q = r;
+ }
+ if (*q)
+ n++;
+ *ext = (char **) xmalloc ((n + 2) * sizeof (char *));
+ p = *ext;
+ *p = (char *) xmalloc(5);
+ strcpy(*p, ".dll");
+ p++;
+ q = v;
+ while ((r = strchr (q, ';')) != 0) {
+ *r = '\0';
+ *p = (char *) xmalloc (strlen (q) + 1);
+ strcpy (*p, q);
+ *r = ';';
+ r++;
+ q = r;
+ p++;
+ }
+ if (*q) {
+ *p = (char *) xmalloc (strlen (q) + 1);
+ strcpy (*p, q);
+ p++;
+ *p = NULL;
+ } else
+ *p = NULL;
+ free (v);
+}
+
+static void
+free_suffixlist (char ***ext)
+{
+ char **p;
+
+ if (*ext) {
+ p = *ext;
+ while (*p) {
+ free (*p);
+ p++;
+ }
+ free (*ext);
+ }
+}
+
+static boolean
+executable_filep (kpathsea kpse, const_string fname)
+{
+ string p, q, base;
+ string *pp;
+ char **suffixlist = NULL;
+
+/* check openout_any */
+ p = kpathsea_var_value (kpse, "openout_any");
+ if (p && *p == 'p') {
+ free (p);
+ mk_suffixlist (&suffixlist);
+/* get base name
+ we cannot use xbasename() for abnormal names.
+*/
+ base = xstrdup (fname);
+ p = strrchr (fname, '/');
+ if (p) {
+ p++;
+ strcpy (base, p);
+ }
+ p = strrchr (base, '\\');
+ if(p) {
+ p++;
+ strcpy (base, p);
+ }
+#if defined(__CYGWIN__)
+ for (p = base; *p; p++)
+ *p = TOLOWER (*p);
+ p = base;
+#else
+ p = (char *) strlwr (base);
+#endif
+ for (q = p + strlen (p) - 1;
+ (q >= p) && ((*q == '.') || (Isspace (*q))); q--) {
+ *q = '\0'; /* remove trailing '.' , ' ' and '\t' */
+ }
+ q = strrchr (p, '.'); /* get extension part */
+ pp = suffixlist;
+ if (pp && q) {
+ while (*pp) {
+ if (strchr (fname, ':') || !strcmp (q, *pp)) {
+ fprintf (stderr, "\nThe name %s is forbidden to open for writing.\n",
+ fname);
+ free (base);
+ free_suffixlist (&suffixlist);
+ return true;
+ }
+ pp++;
+ }
+ }
+ free (base);
+ free_suffixlist (&suffixlist);
+ } else if (p) {
+ free (p);
+ }
+ return false;
+}
+#endif /* WIN32 || __MINGW32__ || __CYGWIN__ */
+
boolean
kpathsea_out_name_ok (kpathsea kpse, const_string fname)
{
+#if defined(WIN32) || defined(__MINGW32__) || defined(__CYGWIN__)
+ /* Output of an executable file is restricted on Windows */
+ if (executable_filep (kpse, fname))
+ return false;
+#endif /* WIN32 || __MINGW32__ || __CYGWIN__ */
/* For output, default to paranoid. */
return kpathsea_name_ok (kpse, fname, "openout_any", "p", ok_writing);
}