[comp.windows.x] Lex and X11/Xutil.h conflict

phils@athena.mit.EDU (03/27/91)

Hi,

I'm having trouble getting Lex and <X11/Xutil.h> to coexist.
I need to include <X11/Xutil.h> in my lex file, but I'm having
trouble with lex wanting to do something like 
#define input() ...  while X11/Xutil.h has a record called "input"
in its XWMHints struct.

Have others had this problem?  What's the work-around?

Thank you,

Philip Thompson
Dept. of Architecture and Urban Planning, MIT

frank@giza.cis.ohio-state.edu (Frank Adelstein) (04/02/91)

In article <9103270244.AA02490@pelli> phils@athena.mit.EDU writes:

>I'm having trouble getting Lex and <X11/Xutil.h> to coexist.
>I need to include <X11/Xutil.h> in my lex file, but I'm having
>trouble with lex wanting to do something like 
>#define input() ...  while X11/Xutil.h has a record called "input"
>in its XWMHints struct.
>
>Have others had this problem?  What's the work-around?
>
>Philip Thompson
>Dept. of Architecture and Urban Planning, MIT

I had the same problem (though it was with X11/Intrinsic.h).  The
work-around we used (and there must be a better way) was to manually
include the specific things that we needed from X11/Intrinsic.h
(which in our case was Boolean, String and Widget).  Here's what 
the top of our lex file looks like:

%{
typedef char *String;
typedef int   Boolean;
typedef void *Widget;
/*
#include <stdio.h>
#include <X11/Intrinsic.h>
*/
#include "types.h"    /* types and stuff used by our program */
#include "y.tab.h"
%}

I don't know what the "correct" way to do it would be (I think this
would qualify as 'quick and dirty').  And the less that is defined,
the less likely it'll break if the includes change.  Hope this helps.

--Frank Adelstein
  frank@cis.ohio-state.edu

cjmchale@cs.tcd.ie (Ciaran McHale) (04/02/91)

In <102367@tut.cis.ohio-state.edu>
frank@giza.cis.ohio-state.edu (Frank Adelstein) writes:

>In article <9103270244.AA02490@pelli> phils@athena.mit.EDU writes:
>>I need to include <X11/Xutil.h> in my lex file, but I'm having
>>trouble with lex wanting to do something like 
>>#define input() ...  while X11/Xutil.h has a record called "input"
>>in its XWMHints struct.
>>
>
>The work-around we used (and there must be a better way) was to manually
>include the specific things that we needed from X11/Intrinsic.h
>(which in our case was Boolean, String and Widget).  Here's what 
>the top of our lex file looks like:
>
>%{
>typedef char *String;
>typedef int   Boolean;
>typedef void *Widget;
>/*
>#include <stdio.h>
>#include <X11/Intrinsic.h>
>*/
>#include "types.h"    /* types and stuff used by our program */
>#include "y.tab.h"
>%}
>
>I don't know what the "correct" way to do it would be (I think this
>would qualify as 'quick and dirty').  And the less that is defined,
>the less likely it'll break if the includes change.  Hope this helps.

Another approach would be to to run lex and munge the output file with
sed to change all occurances of output() to, say, lex_output(). This
should remove the name conflicts. Such munging can be automated nicely
if you're using make to manage recompilations. And you _are_
using make, aren't you :-)


Ciaran.
-- 
Ciaran McHale           "There's a lot to be said for verbosity."     ----
Department of Computer Science, Trinity College, Dublin 2, Ireland.   \  /
Telephone: +353-1-772941 ext 1538       FAX: +353-1-772204             \/
Telex: 93782 TCD EI                     email: cjmchale@cs.tcd.ie