[ragel-users] BUG while processing import directive

Denis Naumov alexander.me at gmail.com
Tue Jul 19 10:42:25 UTC 2011


Hi Adrian, Joseph.

I want to express some ideas about cross-platform ragel.
Joseph may add something, or offer the best solutions require minimal changes.

1. =========================================

ragel Windows specific code somewhere uses _WIN32 define, but
somewhere _MSC_VER.
IMHO it is better do not use _MSC_VER because _MSC_VER define is set
only for Microsoft VC compiler and contain it's version code.
_WIN32 define is used by all (as far as I know), compilers for Windows.

I myself often use this design:
somewhere in the general Include file that is included in all *. cpp files using

# Ifndef __WIN32__
# If defined (_WIN32) | | defined (WIN32)
# Define __WIN32__
# Endif
# Endif

and further where necessary

# Ifdef __WIN32__
   ...
# Else
   ...
# Endif

2. ==========================================

 I found that in the main.cpp include unistd.h twice.
 Also, there is no unistd.h header file in Windows, and I and Joseph
have to create empty file to compile the project.
 Could you move include unistd.h to use it only for unix-like systems.
 Something like

# Ifdef __WIN32__
   ...
# Else
   # Include <unistd.h>
# Endif

  Fix it - 3 seconds.

3. ==========================================

  About the problem with '\' and '/' in paths.
  I totally agree with Joseph. The first thing you may do - it does
not handle escape sequences in strings that can are the paths of
files.
  This is a strings in "include" and "import" directives.

  The situation on the one hand is simple - if _WIN32 use '\' in a way
or another, '/', but the other is
  some exotics. As I understand it when running under Windows in
Minwig-cigwin-... and other shells, we sometimes get
  that even so we should strictly be used '/'-unix separator.

  Possible ways how to solve the problem:
     - Solution 1.
       all strings that are paths - copy in a separate buffer, and
always use '\' to '/' replacement for them.
       when concatenating paths with '/' always.
       because '/' path work on all systems (windows, * nix, mac). We
simply adjust the path if the user uses the '\'.

     - Solution 2
       you can create a global variable that will contain the correct
path separator character.
       correct path separator character will detect at startup.
       For example you can try using argv [0] (first argument - the
name of the program)
       to create path like ".\ragel" - and try opening the file read-only.
       if this is possible - then the system in which we started using
'\' as path separator.
       save it in a global variable and use later .
       Or you can get an environment variable using the getenv (eg
PATH), which will always contain the path to search.
       scan the resulting string and find it '/' or '\' - this is the
path separator.

     - Maybe even some ideas:)))

Best regards.
Denis.

_______________________________________________
ragel-users mailing list
ragel-users at complang.org
http://www.complang.org/mailman/listinfo/ragel-users



More information about the ragel-users mailing list