> -----Original Message----- > From: Stefan Sperling [mailto:s...@elego.de] > Sent: dinsdag 18 december 2012 10:46 > To: Peter Samuelson; dev@subversion.apache.org > Subject: Re: svn commit: r1422706 - in /subversion/trunk/subversion: > libsvn_subr/opt.c tests/cmdline/svntest/main.py > > On Mon, Dec 17, 2012 at 09:39:49PM +0100, Stefan Sperling wrote: > > The simple patch below implements it with the isatty() on *nix and > > _isatty() on Windows (untested -- thanks for the hint Bert!). > > Updated version that adds --force-interactive for users who require > the previous behaviour for whatever purposes. > > [[[ > Add a new function to the cmdline library to determine whether standard > input is connected to a terminal device. Set the --non-interactive flag > by default if standard input is not a terminal device. > Add a new --force-interactive option to force previous behaviour. > > * subversion/include/svn_cmdline.h > (svn_cmdline__stdin_isatty): Declare. > > * subversion/libsvn_subr/cmdline.c: Include io.h on Windows. > (svn_cmdline__stdin_isatty): New. > > * subversion/svn/cl.h > (svn_cl__opt_state_t): Add force_interactive option. > > * subversion/svn/svn.c > (svn_cl__longopt_t): Add opt_force_interactive. > (sub_main): Set the --non-interactive option based on whether stdin is a > tty, > unless interactive mode has been forced with --force-interactive. > Enforce mutual exclusion of --non-interactive and --force-interactive. > ]]] > > Index: subversion/include/svn_cmdline.h > ========================================================== > ========= > --- subversion/include/svn_cmdline.h (revision 1423113) > +++ subversion/include/svn_cmdline.h (working copy) > @@ -381,6 +381,11 @@ svn_cmdline__getopt_init(apr_getopt_t **os, > const char *argv[], > apr_pool_t *pool); > > +/* Determine whether standard input is associated with a terminal. > + * @since New in 1.8. */ > +svn_boolean_t > +svn_cmdline__stdin_isatty(void); > + > #ifdef __cplusplus > } > #endif /* __cplusplus */ > Index: subversion/libsvn_subr/cmdline.c > ========================================================== > ========= > --- subversion/libsvn_subr/cmdline.c (revision 1423113) > +++ subversion/libsvn_subr/cmdline.c (working copy) > @@ -33,6 +33,7 @@ > #include <unistd.h> > #else > #include <crtdbg.h> > +#include <io.h> > #endif > > #include <apr_errno.h> /* for apr_strerror */ > @@ -923,3 +924,13 @@ > svn_cmdline__print_xml_prop_hash(svn_stringbuf_t * > > return SVN_NO_ERROR; > } > + > +svn_boolean_t > +svn_cmdline__stdin_isatty(void) > +{ > +#ifdef WIN32 > + return (_isatty(0) != 0); > +#else > + return (isatty(STDIN_FILENO) != 0); > +#endif
apr.h defines STDIN_FILENO (and friends) on Windows, so you can just use that macro on Windows. Bert