diff options
author | Peter Breitenlohner <peb@mppmu.mpg.de> | 2009-11-10 10:27:09 +0000 |
---|---|---|
committer | Peter Breitenlohner <peb@mppmu.mpg.de> | 2009-11-10 10:27:09 +0000 |
commit | 5e8e9500102800e68c9e7fcac9e85c1668b71a36 (patch) | |
tree | 81d79ac70ffbb127e8063f18c8f55475ca169ee1 /Build/source/texk/web2c/lib/texmfmp.c | |
parent | e6a9c88ada2f11dd61e4c4e39dff84944bed5787 (diff) |
towards TL2010: texk/web2c
git-svn-id: svn://tug.org/texlive/trunk@15964 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/lib/texmfmp.c')
-rw-r--r-- | Build/source/texk/web2c/lib/texmfmp.c | 189 |
1 files changed, 42 insertions, 147 deletions
diff --git a/Build/source/texk/web2c/lib/texmfmp.c b/Build/source/texk/web2c/lib/texmfmp.c index e4b63c3090b..063cdfcc621 100644 --- a/Build/source/texk/web2c/lib/texmfmp.c +++ b/Build/source/texk/web2c/lib/texmfmp.c @@ -263,22 +263,23 @@ free_shellcmdlist (void) what is checked against the shell_escape_commands list. */ int -shell_cmd_is_allowed (char **cmd, char **safecmd, char **cmdname) +shell_cmd_is_allowed (const char *cmd, char **safecmd, char **cmdname) { char **p; char *buf; - char *s, *d; + char *c, *d; + const char *s; int pre, spaces; int allow = 0; /* pre == 1 means that the previous character is a white space pre == 0 means that the previous character is not a white space */ - buf = (char *) xmalloc (strlen (*cmd) + 1); - strcpy (buf, *cmd); - s = buf; - while (Isspace (*s)) - s++; - d = s; + buf = (char *) xmalloc (strlen (cmd) + 1); + strcpy (buf, cmd); + c = buf; + while (Isspace (*c)) + c++; + d = c; while (!Isspace(*d) && *d) d++; *d = '\0'; @@ -287,7 +288,7 @@ shell_cmd_is_allowed (char **cmd, char **safecmd, char **cmdname) *cmdname == "kpsewhich" for \write18{kpsewhich --progname=dvipdfm --format="other text files" config} */ - *cmdname = xstrdup (s); + *cmdname = xstrdup (c); free (buf); /* Is *cmdname listed in a texmf.cnf vriable as @@ -306,20 +307,20 @@ shell_cmd_is_allowed (char **cmd, char **safecmd, char **cmdname) } if (allow == 2) { spaces = 0; - for (s = *cmd; *s; s++) { + for (s = cmd; *s; s++) { if (Isspace (*s)) spaces++; } /* allocate enough memory (too much?) */ #ifdef WIN32 - *safecmd = (char *) xmalloc (2 * strlen (*cmd) + 3 + 2 * spaces); + *safecmd = (char *) xmalloc (2 * strlen (cmd) + 3 + 2 * spaces); #else - *safecmd = (char *) xmalloc (strlen (*cmd) + 3 + 2 * spaces); + *safecmd = (char *) xmalloc (strlen (cmd) + 3 + 2 * spaces); #endif /* make a safe command line *safecmd */ - s = *cmd; + s = cmd; while (Isspace (*s)) s++; d = *safecmd; @@ -389,7 +390,7 @@ shell_cmd_is_allowed (char **cmd, char **safecmd, char **cmdname) *d++ = QUOTE; *d++ = *s++; } else { - /* Copy a character from *cmd to *safecmd. */ + /* Copy a character from cmd to *safecmd. */ #ifdef WIN32 if (char_needs_quote (*s)) *d++ = '^'; @@ -416,7 +417,7 @@ shell_cmd_is_allowed (char **cmd, char **safecmd, char **cmdname) 2 if shell escapes are restricted and CMD is allowed. */ int -runsystem (char *cmd) +runsystem (const char *cmd) { int allow = 0; char *safecmd = NULL; @@ -430,7 +431,7 @@ runsystem (char *cmd) if (restrictedshell == 0) allow = 1; else - allow = shell_cmd_is_allowed (&cmd, &safecmd, &cmdname); + allow = shell_cmd_is_allowed (cmd, &safecmd, &cmdname); if (allow == 1) (void) system (cmd); @@ -445,13 +446,14 @@ runsystem (char *cmd) return allow; } +#if defined(pdfTeX) || defined(luaTeX) /* Like runsystem(), the runpopen() function is called only when shellenabledp == 1. Unlike runsystem(), here we write errors to stderr, since we have nowhere better to use; and of course we return a file handle (or NULL) instead of a status indicator. */ static FILE * -runpopen (char *cmd, char *mode) +runpopen (const char *cmd, const char *mode) { FILE *f = NULL; char *safecmd = NULL; @@ -462,7 +464,7 @@ runpopen (char *cmd, char *mode) if (restrictedshell == 0) allow = 1; else - allow = shell_cmd_is_allowed (&cmd, &safecmd, &cmdname); + allow = shell_cmd_is_allowed (cmd, &safecmd, &cmdname); if (allow == 1) f = popen (cmd, mode); @@ -480,7 +482,8 @@ runpopen (char *cmd, char *mode) free (cmdname); return f; } -#endif +#endif /* pdfTeX || luaTeX */ +#endif /* TeX */ /* The main program, etc. */ @@ -516,11 +519,15 @@ extern string fullnameoffile; string translate_filename; string default_translate_filename; +#if defined(TeX) /* Needed for --src-specials option. */ MAYBE_STATIC char *last_source_name; -static int last_lineno; -MAYBE_STATIC boolean srcspecialsoption = false; -MAYBE_STATIC void parse_src_specials_option (const_string); +MAYBE_STATIC int last_lineno; +#if !defined (luaTeX) +static boolean srcspecialsoption = false; +static void parse_src_specials_option (const_string); +#endif +#endif /* The main body of the WEB is transformed into this procedure. */ extern TEXDLL void mainbody (void); @@ -541,10 +548,6 @@ static string get_input_file_name (void); static int eightbitp; #endif /* Aleph */ -#if defined(pdfTeX) || defined(luaTeX) -char *ptexbanner; -#endif - /* Get a true/false value for a variable from texmf.cnf and the environment. */ static boolean texmf_yesno(const_string var) @@ -577,6 +580,10 @@ texmf_yesno(const_string var) #define poolsize pool_size #endif +#if defined(pdfTeX) || defined(luaTeX) +const char *ptexbanner = BANNER; +#endif + /* The entry point: set up for reading the command line, which will happen in `topenin', then call the main body. */ @@ -613,10 +620,6 @@ maininit (int ac, string *av) # endif #endif -#if defined(pdfTeX) || defined(luaTeX) - ptexbanner = BANNER; -#endif - /* If the user says --help or --version, we need to notice early. And since we want the --ini option, have to do it before getting into the web (which would read the base file, etc.). */ @@ -1026,7 +1029,7 @@ ipcpage (int is_eof) { static boolean begun = false; unsigned len = 0; - string p = (string)""; + string p = NULL; if (!begun) { string name; /* Just the filename. */ @@ -1061,7 +1064,7 @@ ipcpage (int is_eof) } ipc_snd (len, is_eof, p); - if (len > 0) { + if (p) { free (p); } } @@ -1662,115 +1665,6 @@ parse_first_line (const_string filename) } } -/* Return true if FNAME is acceptable as a name for \openout, \openin, or - \input. */ - -typedef enum ok_type { - ok_reading, - ok_writing -} ok_type; - -static const_string ok_type_name[] = { - "reading", - "writing" -}; - -static boolean -opennameok (const_string fname, const_string check_var, - const_string default_choice, ok_type action) -{ - /* We distinguish three cases: - 'a' (any) allows any file to be opened. - 'r' (restricted) means disallowing special file names. - 'p' (paranoid) means being really paranoid: disallowing special file - names and restricting output files to be in or below - the working directory or $TEXMFOUTPUT, while input files - must be below the current directory, $TEXMFOUTPUT, or - (implicitly) in the system areas. - We default to "paranoid". The error messages from TeX will be somewhat - puzzling... - This function contains several return statements... */ - - const_string open_choice = kpse_var_value (check_var); - - if (!open_choice) open_choice = default_choice; - - if (*open_choice == 'a' || *open_choice == 'y' || *open_choice == '1') - return true; - -#if defined (unix) && !defined (MSDOS) - { - const_string base = xbasename (fname); - /* Disallow .rhosts, .login, etc. Allow .tex (for LaTeX). */ - if (base[0] == 0 || - (base[0] == '.' && !IS_DIR_SEP(base[1]) && !STREQ (base, ".tex"))) { - fprintf(stderr, "%s: Not %s to %s (%s = %s).\n", - program_invocation_name, ok_type_name[action], fname, - check_var, open_choice); - return false; - } - } -#else - /* Other OSs don't have special names? */ -#endif - - if (*open_choice == 'r' || *open_choice == 'n' || *open_choice == '0') - return true; - - /* Paranoia supplied by Charles Karney... */ - if (kpse_absolute_p (fname, false)) { - const_string texmfoutput = kpse_var_value ("TEXMFOUTPUT"); - /* Absolute pathname is only OK if TEXMFOUTPUT is set, it's not empty, - fname begins the TEXMFOUTPUT, and is followed by / */ - if (!texmfoutput || *texmfoutput == '\0' - || fname != strstr (fname, texmfoutput) - || !IS_DIR_SEP(fname[strlen(texmfoutput)])) { - fprintf(stderr, "%s: Not %s to %s (%s = %s).\n", - program_invocation_name, ok_type_name[action], fname, - check_var, open_choice); - return false; - } - } - /* For all pathnames, we disallow "../" at the beginning or "/../" - anywhere. */ - if (fname[0] == '.' && fname[1] == '.' && IS_DIR_SEP(fname[2])) { - fprintf(stderr, "%s: Not %s to %s (%s = %s).\n", - program_invocation_name, ok_type_name[action], fname, - check_var, open_choice); - return false; - } else { - /* Check for "/../". Since more than one characted can be matched - by IS_DIR_SEP, we cannot use "/../" itself. */ - const_string dotpair = strstr(fname, ".."); - while (dotpair) { - /* If dotpair[2] == DIR_SEP, then dotpair[-1] is well-defined, - because the "../" case was handled above. */ - if (IS_DIR_SEP(dotpair[2]) && IS_DIR_SEP(dotpair[-1])) { - fprintf(stderr, "%s: Not %s to %s (%s = %s).\n", - program_invocation_name, ok_type_name[action], fname, - check_var, open_choice); - return false; - } - /* Continue after the dotpair. */ - dotpair = strstr(dotpair+2, ".."); - } - } - - /* We passed all tests. */ - return true; -} - -boolean openinnameok (const_string fname) -{ - /* For input default to all. */ - return opennameok (fname, "openin_any", "a", ok_reading); -} - -boolean openoutnameok (const_string fname) -{ - /* For output, default to paranoid. */ - return opennameok (fname, "openout_any", "p", ok_writing); -} /* piped I/O */ @@ -1996,7 +1890,7 @@ get_seconds_and_micros (integer *seconds, integer *micros) Generating a better seed numbers */ integer -getrandomseed() +getrandomseed(void) { #if defined (HAVE_GETTIMEOFDAY) struct timeval tv; @@ -2350,7 +2244,7 @@ maketexstring(const_string s) size_t len; #ifdef XeTeX UInt32 rval; - unsigned char* cp = (unsigned char*)s; + const unsigned char* cp = (const unsigned char*)s; #endif assert (s != 0); len = strlen(s); @@ -2385,7 +2279,7 @@ maketexstring(const_string s) #endif /* !pdfTeX */ strnumber -makefullnamestring() +makefullnamestring(void) { return maketexstring(fullnameoffile); } @@ -2403,7 +2297,7 @@ getjobname(strnumber name) #endif #if defined(TeX) -int +static int compare_paths (const_string p1, const_string p2) { int ret; @@ -2824,7 +2718,7 @@ extern void mf_trap_paintrow (screenrow, pixelcolor, transspec, screencol); struct mfwin_sw { - char *mfwsw_type; /* Name of terminal a la TERMCAP. */ + const char *mfwsw_type; /* Name of terminal a la TERMCAP. */ int (*mfwsw_initscreen) (void); void (*mfwsw_updatescrn) (void); void (*mfwsw_blankrect) (screencol, screencol, screenrow, screenrow); @@ -2931,7 +2825,7 @@ initscreen (void) under Emacs, the first one. */ for (mfwp = mfwsw; mfwp->mfwsw_type != NULL; mfwp++) { if (!strncmp (mfwp->mfwsw_type, tty_type, strlen (mfwp->mfwsw_type)) - || STREQ (tty_type, "emacs")) + || STREQ (tty_type, "emacs")) { if (mfwp->mfwsw_initscreen) return ((*mfwp->mfwsw_initscreen) ()); else { @@ -2939,6 +2833,7 @@ initscreen (void) tty_type); break; } + } } /* We disable X support by default, since most sites don't use it, and |