[Xorp-cvs] XORP cvs commit: xorp/rtrmgr

Pavlin Radoslavov pavlin@icir.org
Tue, 11 Oct 2005 16:08:17 -0700


> On Sun, Oct 02, 2005 at 10:10:23PM +0000, Pavlin Radoslavov wrote:
> > 	* Regenerate lex.opcmd.cc
> > 	  Note that this regeneration removes manually added Windows-related
> > 	  modifications like the following, so this may break the Windows
> > 	  compilation:
> > 	
> > 	#ifdef HOST_OS_WINDOWS
> > 	#define isatty(x) _isatty(x)
> > 	#define fileno(x) _fileno(x)
> > 	#endif
> > 	
> > 	  It is impossible to maintain such modifications in auto-generated
> > 	  files, and they should be added somewhere else (e.g., somewhere
> > 	  in libxorp).
> %%%
> 
> This is ugly.
> 
> We need to decide what we're more comfortable with -- the cost of possibly
> misusing emulation functions, or making lexer regens slightly more complex.
> 
> We could remove -D_NO_OLDNAMES from Windows compilation, but this creates a
> situation where MSVCRT.DLL library functions which imitate UNIX syscalls may
> be used without explicit reference, perhaps in error.
> 
> During the porting process I made a deliberate decision to use -D_NO_OLDNAMES,
> to weed out cases where we might be doing things the UNIX way, when they
> needed to be done the Windows way.
> 
> On the other hand, we could use modified lex templates when regenerating
> the lexer, but this has additional maintenance cost.
> 
> These particular two functions have very specific actions, and fileno()'s
> use is quite different from the UNIX world because of the 3-tier
> file descriptor dance which is happening in MSVCRT.DLL (stdio,
> 'file descriptor', and underlying Win32 file handle).
> 
> isatty() in the Windows case actually ends up calling into the console
> mode subsystem to determine if a given file handle points to a
> console window.

If the above #define is a working (and acceptable) solution, then
what is the issue with moving them to some header file inside
libxorp?


BTW, in this particular case if we add "%option never-interactive"
to the *.ll file, then the code that uses isatty() and fileno()
inside the auto-generated *.cc file is commented out:

#if YY_NEVER_INTERACTIVE
        b->yy_is_interactive = 0;
#else
        b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) :
        0;
#endif

Hence, in case of all *.ll files we can use
"%option never-interactive" and we don't have to redefine isatty()
and fileno().

Pavlin