summaryrefslogtreecommitdiff
path: root/Build/source/texk/kpathsea/mingw32.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2011-03-01 15:06:01 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2011-03-01 15:06:01 +0000
commit9f6cfe192c1dc17eb6c668e874fa5f1b0a469f3c (patch)
treee5685064f5061c2fcba852182ad8177652db73ad /Build/source/texk/kpathsea/mingw32.c
parentd14a599c4c5df86c60ebb1ac9000416c1177f4cd (diff)
remove unused code
git-svn-id: svn://tug.org/texlive/trunk@21568 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/kpathsea/mingw32.c')
-rw-r--r--Build/source/texk/kpathsea/mingw32.c376
1 files changed, 0 insertions, 376 deletions
diff --git a/Build/source/texk/kpathsea/mingw32.c b/Build/source/texk/kpathsea/mingw32.c
index 01d3eda5e1f..f9716834759 100644
--- a/Build/source/texk/kpathsea/mingw32.c
+++ b/Build/source/texk/kpathsea/mingw32.c
@@ -386,8 +386,6 @@ win32_get_long_filename (char * name, char * buf, int size)
This does make sense only under WIN32.
Functions:
- look_for_cmd() : locates an executable file
- - parse_cmdline() : splits a command with pipes and redirections
- - build_cmdline() : builds a command with pipes and redirections (useful ?)
*/
/*
@@ -485,378 +483,4 @@ look_for_cmd(const char *cmd, char **app)
}
-/*
- Command parser. Borrowed from DJGPP.
- */
-
-static BOOL __system_allow_multiple_cmds = FALSE;
-
-typedef enum {
- EMPTY,
- WORDARG,
- REDIR_INPUT,
- REDIR_APPEND,
- REDIR_OUTPUT,
- PIPE,
- SEMICOLON,
- UNMATCHED_QUOTE,
- EOL
-} cmd_sym_t;
-
-/* Return a copy of a word between BEG and (excluding) END with all
- quoting characters removed from it. */
-
-static char *
-__unquote (char *to, const char *beg, const char *end)
-{
- const char *s = beg;
- char *d = to;
- int quote = 0;
-
- while (s < end)
- {
- switch (*s)
- {
- case '"':
- case '\'':
- if (!quote)
- quote = *s;
- else if (quote == *s)
- quote = 0;
- s++;
- break;
- case '\\':
- if (s[1] == '"' || s[1] == '\''
- || (s[1] == ';'
- && (__system_allow_multiple_cmds)))
- s++;
- /* Fall-through. */
- default:
- *d++ = *s++;
- break;
- }
- }
-
- *d = 0;
- return to;
-}
-
-/* A poor-man's lexical analyzer for simplified command processing.
-
- It only knows about these:
-
- redirection and pipe symbols
- semi-colon `;' (that possibly ends a command)
- argument quoting rules with quotes and `\'
- whitespace delimiters of words (except in quoted args)
-
- Returns the type of next symbol and pointers to its first and (one
- after) the last characters.
-
- Only `get_sym' and `unquote' should know about quoting rules. */
-
-static cmd_sym_t
-get_sym (char *s, char **beg, char **end)
-{
- int in_a_word = 0;
-
- while (isspace (*s))
- s++;
-
- *beg = s;
-
- do {
- *end = s + 1;
-
- if (in_a_word
- && (!*s || strchr ("<>| \t\n", *s)
- || ((__system_allow_multiple_cmds) && *s == ';')))
- {
- --*end;
- return WORDARG;
- }
-
- switch (*s)
- {
- case '<':
- return REDIR_INPUT;
- case '>':
- if (**end == '>')
- {
- ++*end;
- return REDIR_APPEND;
- }
- return REDIR_OUTPUT;
- case '|':
- return PIPE;
- case ';':
- if (__system_allow_multiple_cmds)
- return SEMICOLON;
- else
- in_a_word = 1;
- break;
- case '\0':
- --*end;
- return EOL;
- case '\\':
- if (s[1] == '"' || s[1] == '\''
- || (s[1] == ';' && (__system_allow_multiple_cmds)))
- s++;
- in_a_word = 1;
- break;
- case '\'':
- case '"':
- {
- char quote = *s++;
-
- while (*s && *s != quote)
- {
- if (*s++ == '\\' && (*s == '"' || *s == '\''))
- s++;
- }
- *end = s;
- if (!*s)
- return UNMATCHED_QUOTE;
- in_a_word = 1;
- break;
- }
- default:
- in_a_word = 1;
- break;
- }
-
- s++;
-
- } while (1);
-}
-
-/*
- What we allow :
- [cmd] [arg1] ... [argn] < [redinput] | [cmd2] | ... | [cmdn] > [redoutput]
-*/
-static void *
-parse_cmdline(char *line, char **input, char **output)
-{
- BOOL again, needcmd = TRUE, bSuccess = TRUE, append_out = FALSE;
- char *beg = line, *end, *new_end;
- cmd_sym_t token = EMPTY, prev_token = EMPTY;
- int ncmd = 0, narg = 1;
- char **fp = NULL;
- char ***cmd;
- char *dummy_input; /* So that we could pass NULL */
- char *dummy_output; /* instead of a real ??put */
-
- if (input == NULL) input = &dummy_input;
- if (output == NULL) output = &dummy_output;
-
- *input = NULL;
- *output = NULL;
- cmd = xmalloc(MAX_PIPES*sizeof(char **));
- cmd[ncmd] = NULL;
-#ifdef TRACE
- fprintf(stderr, "line = %s\n", line);
-#endif
- do {
- again = FALSE;
- prev_token = token;
- token = get_sym (beg, &beg, &end); /* get next symbol */
-#ifdef TRACE
- fprintf(stderr, "token = %s\n", beg);
-#endif
- switch (token) {
- case WORDARG:
- if (prev_token == REDIR_INPUT
- || prev_token == REDIR_OUTPUT) {
- fprintf(stderr, "Ambigous input/output redirect.");
- bSuccess = FALSE;
- goto leave;
- }
- /* First word we see is the program to run. */
- if (needcmd) {
- narg = 1;
- cmd[ncmd] = xmalloc(narg * sizeof(char *));
- cmd[ncmd][narg - 1] = xmalloc(end - beg + 1);
- __unquote (cmd[ncmd][narg - 1], beg, end); /* unquote and copy to prog */
- if (cmd[ncmd][narg - 1][0] == '(') {
- fprintf(stderr, "parse_cmdline(%s): Parenthesized groups not allowed.\n", line);
- bSuccess = FALSE;
- goto leave;
- }
- needcmd = FALSE;
- }
- else {
- narg++;
- cmd[ncmd] = xrealloc(cmd[ncmd], narg * sizeof(char *));
- cmd[ncmd][narg - 1] = xmalloc(end - beg + 1);
- __unquote (cmd[ncmd][narg - 1], beg, end); /* unquote and copy to prog */
- }
- beg = end; /* go forward */
- again = TRUE;
- break;
-
- case REDIR_INPUT:
- case REDIR_OUTPUT:
- case REDIR_APPEND:
- if (token == REDIR_INPUT) {
- if (*input) {
- fprintf(stderr, "Ambiguous input redirect.");
- errno = EINVAL;
- bSuccess = FALSE;
- goto leave;
- }
- fp = input;
- }
- else if (token == REDIR_OUTPUT || token == REDIR_APPEND) {
- if (*output) {
- fprintf(stderr, "Ambiguous output redirect.");
- errno = EINVAL;
- bSuccess = FALSE;
- goto leave;
- }
- fp = output;
- if (token == REDIR_APPEND)
- append_out = TRUE;
- }
- if (get_sym (end, &end, &new_end) != WORDARG) {
- fprintf(stderr, "Target of redirect is not a filename.");
- errno = EINVAL;
- bSuccess = FALSE;
- goto leave;
- }
- *fp = (char *)xmalloc (new_end - end + 1);
- memcpy (*fp, end, new_end - end);
- (*fp)[new_end - end] = '\0';
- beg = new_end;
- again = TRUE;
- break;
- case PIPE:
- if (*output) {
- fprintf(stderr, "Ambiguous output redirect.");
- errno = EINVAL;
- bSuccess = FALSE;
- goto leave;
- }
- narg++;
- cmd[ncmd] = xrealloc(cmd[ncmd], narg * sizeof(char *));
- cmd[ncmd][narg - 1] = NULL;
- ncmd++;
- needcmd = TRUE;
- beg = end;
- again = TRUE;
- break;
- case SEMICOLON:
- case EOL:
- if (needcmd) {
- fprintf(stderr, "No command name seen.");
- errno = EINVAL;
- bSuccess = FALSE;
- goto leave;
- }
- narg++;
- cmd[ncmd] = xrealloc(cmd[ncmd], narg * sizeof(char *));
- cmd[ncmd][narg - 1] = NULL;
- ncmd++;
- cmd[ncmd] = NULL;
- again = FALSE;
- break;
-
- case UNMATCHED_QUOTE:
- fprintf(stderr, "Unmatched quote character.");
- errno = EINVAL;
- bSuccess = FALSE;
- goto leave;
- default:
- fprintf(stderr, "I cannot grok this.");
- errno = EINVAL;
- bSuccess = FALSE;
- goto leave;
-
- }
-
- } while (again);
-
- leave:
- if (!bSuccess) {
- int i;
- char **p;
- /* Need to free everything that was allocated */
- for (i = 0; i < ncmd; i++) {
- for (p = cmd[i]; *p; p++)
- free(*p);
- free(cmd[i]);
- }
- if (cmd[ncmd]) {
- for (i = 0; i < narg; i++)
- free(cmd[ncmd][i]);
- free(cmd[ncmd]);
- }
- free(cmd);
- *cmd = NULL;
- }
- return cmd;
-}
-
-static char *
-quote_elt(char *elt)
-{
- char *p;
- for (p = elt; *p; p++)
- if (isspace(*p))
- return concat3("\"", elt, "\"");
-
- return xstrdup(elt);
-}
-
-char *
-quote_args(char **argv)
-{
- int i;
- char *line = NULL, *new_line;
- char *new_argv;
-
- if (!argv)
- return line;
-
- line = quote_elt(argv[0]);
- for (i = 1; argv[i]; i++) {
- new_argv = quote_elt(argv[i]);
- new_line = concat3(line, " ", new_argv);
- free(line);
- free(new_argv);
- line = new_line;
- }
-
- return line;
-}
-
-static char *
-build_cmdline(char ***cmd, char *input, char *output)
-{
- int ncmd;
- char *line = NULL, *new_line;
-
- if (!cmd)
- return line;
-
- line = quote_args(cmd[0]);
- if (input) {
- new_line = concat3(line, " < ", quote_elt(input));
- free(line);
- line = new_line;
- }
- for(ncmd = 1; cmd[ncmd]; ncmd++) {
- new_line = concat3(line, " | ", quote_args(cmd[ncmd]));
- free(line);
- line = new_line;
- }
-
- if (output) {
- new_line = concat3(line, " > ", quote_elt(output));
- free(line);
- line = new_line;
- }
-
- return line;
-}
-
#endif /* __MINGW32__ */