Skip to content

Commit

Permalink
Enable command options at build time
Browse files Browse the repository at this point in the history
  • Loading branch information
mturk committed Oct 3, 2024
1 parent 39b627c commit e6632a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ In case the `PROGRAM` name is `.` character, the
Cygwrun will print the evaluated arguments to the
stdout.

The command line usage is as follows:
In case the first argument is **-v**, Cygwrun will
print version information and exit.

In case the Cygwrun was compiled with command options
enabled, the command line usage is as follows:

```
cygwrun [OPTIONS]... PROGRAM [ARGUMENTS]...
Expand All @@ -56,6 +60,10 @@ Options are:
```

The command options can be enabled by setting
`#define CYGWRUN_HAVE_CMDOPTS 1` inside
[cygwrun.c](./cygwrun.c) file.


## Global configuration

Expand All @@ -77,18 +85,13 @@ Cygwrun uses for each instance:

The names of the environment variables are comma separated.


* **CYGWRUN_UNSET**

This variable allows to set which environment variables
Cygwrun will not pass to the `PROGRAM`.

The names of the environment variables are comma separated.

In case the **-u** command option was also defined, it's
argument(s) will be added to the list of variables that will
not be set for the `PROGRAM`.


## Posix root

Expand Down Expand Up @@ -197,7 +200,6 @@ by Cygwrun in case of failure.

Return value `126` is returned in case the `PROGRAM`
cannot be executed.

Return value `127` is returned in case the `PROGRAM`
cannot be found.

Expand Down
14 changes: 12 additions & 2 deletions cygwrun.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
* Set this value to 1 for dev versions
*/
#define CYGWRUN_USE_MEMFREE 0
/**
* Use -s and -u command options
*/
#define CYGWRUN_HAVE_CMDOPTS 0

#define CYGWRUN_ERRMAX 110
#define CYGWRUN_FAILED 126
Expand Down Expand Up @@ -1989,9 +1993,10 @@ int main(int argc, const char **argv, const char **envp)
wchar_t *eparam;
char *sparam;
const char *optarg;
#if CYGWRUN_HAVE_CMDOPTS
const char *scmdopt = NULL;
const char *ucmdopt = NULL;

#endif
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX | SEM_NOGPFAULTERRORBOX);
if (argc < 2)
return CYGWRUN_ENOEXEC;
Expand All @@ -2016,7 +2021,7 @@ int main(int argc, const char **argv, const char **envp)
if ((configvals[CCYGWIN_TEMP] == NULL) ||
(configvals[CCYGWIN_TMP] == NULL))
return CYGWRUN_EBADPATH;

#if CYGWRUN_HAVE_CMDOPTS
while (*optarg == '-') {
int opt = *++optarg;

Expand All @@ -2042,10 +2047,13 @@ int main(int argc, const char **argv, const char **envp)
}
__NEXT_ARG();
}
#endif
if (argc < 1)
return CYGWRUN_ENOEXEC;
sparam = xstrdup(configvals[CYGWRUN_SKIP]);
#if CYGWRUN_HAVE_CMDOPTS
sparam = xstrappend(sparam, scmdopt, ',');
#endif
sparam = xstrappend(sparam, sskipenv, ',');
wparam = xmbstowcs(sparam);
askipenv = wcstoarray(wparam, L',');
Expand All @@ -2054,7 +2062,9 @@ int main(int argc, const char **argv, const char **envp)
xmfree(sparam);
#endif
sparam = xstrdup(configvals[CYGWRUN_UNSET]);
#if CYGWRUN_HAVE_CMDOPTS
sparam = xstrappend(sparam, ucmdopt, ',');
#endif
adelenvv = strtoarray(sparam, ',');
#if CYGWRUN_USE_MEMFREE
xmfree(sparam);
Expand Down
5 changes: 3 additions & 2 deletions runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,10 @@ rv="`$_cygwrun $_dumpenvp FOO`"
test "x$rv" = "xFOO=$tmpdir;$vardir;..\\d" || xbexit 1 "Failed #6.2: \`$rv'"
export FOO="c*"
export CYGWRUN_SKIP=BAR
rv="`$_cygwrun -u=FOO $_dumpenvp BAR`"
rv="`$_cygwrun $_dumpenvp BAR`"
test "x$rv" = "xBAR=/tmp/bin" || xbexit 1 "Failed #6.3: \`$rv'"
rv="`$_cygwrun -s=FOO $_dumpenvp FOO`"
export CYGWRUN_SKIP=FOO,BAR
rv="`$_cygwrun $_dumpenvp FOO`"
test "x$rv" = "xFOO=c*" || xbexit 1 "Failed #6.4: \`$rv'"
echo "All tests passed!"
Expand Down

0 comments on commit e6632a2

Please sign in to comment.