Improved include and import file searching errors. Added documentation for
authorthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 7 Apr 2008 00:35:00 +0000 (00:35 +0000)
committerthurston <thurston@052ea7fc-9027-0410-9066-f65837a77df0>
Mon, 7 Apr 2008 00:35:00 +0000 (00:35 +0000)
include file searching and the -I option.

git-svn-id: http://svn.complang.org/ragel/trunk@425 052ea7fc-9027-0410-9066-f65837a77df0

CREDITS
doc/ragel-guide.tex
doc/ragel.1.in
ragel/main.cpp
ragel/rlscan.rl

diff --git a/CREDITS b/CREDITS
index 7ee8922..150b26f 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -33,4 +33,5 @@ missed.
     Carlos Antunes, Steve Horne, Matt Mower, Josef Goettgens, Zed Shaw,
     Marcus Rueckert, Jeremy Hinegardner, Aaron Campbell, Josh Purinton,
     Judson Lester, Barry Arthur, Tim Potter, Ryan Phelps, David Waite,
-    Kenny MacDermid, MenTaLguY, Manoj Rajagopalan, Tim Chklovski
+    Kenny MacDermid, MenTaLguY, Manoj Rajagopalan, Tim Chklovski,
+    Mikkel Fahnøe Jørgensen
index 682a5da..b1c3a73 100644 (file)
@@ -571,6 +571,10 @@ of the same name as the current specification. Without an input file the
 current file is searched for a machine of the given name. If both are present,
 the given input file is searched for a machine of the given name.
 
+Ragel searches for included files from the location of the current file.
+Additional directories can be added to the search path using the \verb|-I|
+option.
+
 \subsection{Importing Definitions}
 \label{import}
 
@@ -594,6 +598,9 @@ If the input file is a Ragel program then tokens inside any Ragel
 specifications are ignored. See Section \ref{export} for a description of
 exporting machine definitions.
 
+Ragel searches for imported files from the location of the current file.
+Additional directories can be added to the search path using the \verb|-I|
+option.
 
 \section{Lexical Analysis of a Ragel Block}
 \label{lexing}
index 8a7ef0a..6593701 100644 (file)
@@ -70,6 +70,9 @@ Print some statistics on standard error.
 .B \-d
 Do not remove duplicate actions from action lists.
 .TP
+.B \-I " dir"
+Add dir to the list of directories to search for included and imported files
+.TP
 .B \-n
 Do not perform state minimization.
 .TP
index bc80364..09c9060 100644 (file)
@@ -88,6 +88,8 @@ void usage()
 "   -o <file>            Write output to <file>\n"
 "   -s                   Print some statistics on stderr\n"
 "   -d                   Do not remove duplicates from action lists\n"
+"   -I <dir>             Add <dir> to the list of directories to search\n"
+"                        for included an imported files\n"
 "fsm minimization:\n"
 "   -n                   Do not perform minimization\n"
 "   -m                   Minimize at the end of the compilation\n"
index 39dd29b..c2e332c 100644 (file)
@@ -302,37 +302,41 @@ void Scanner::handleInclude()
 {
        if ( active() ) {
                char *inclSectionName = word;
-               char **inclFileName = 0;
+               char **includeChecks = 0;
 
                /* Implement defaults for the input file and section name. */
                if ( inclSectionName == 0 )
                        inclSectionName = parser->sectionName;
 
                if ( lit != 0 )
-                       inclFileName = makeIncludePathChecks( fileName, lit, lit_len );
+                       includeChecks = makeIncludePathChecks( fileName, lit, lit_len );
                else {
                        char *test = new char[strlen(fileName)+1];
                        strcpy( test, fileName );
 
-                       inclFileName = new char*[2];
+                       includeChecks = new char*[2];
 
-                       inclFileName[0] = test;
-                       inclFileName[1] = 0;
+                       includeChecks[0] = test;
+                       includeChecks[1] = 0;
                }
 
                long found = 0;
-               ifstream *inFile = tryOpenInclude( inclFileName, found );
-               if ( inFile == 0 )
+               ifstream *inFile = tryOpenInclude( includeChecks, found );
+               if ( inFile == 0 ) {
                        scan_error() << "include: failed to locate file" << endl;
+                       char **tried = includeChecks;
+                       while ( *tried != 0 )
+                               scan_error() << "include: attempted: \"" << *tried++ << '\"' << endl;
+               }
                else {
                        /* Check for a recursive include structure. Add the current file/section
                         * name then check if what we are including is already in the stack. */
                        includeStack.append( IncludeStackItem( fileName, parser->sectionName ) );
 
-                       if ( recursiveInclude( inclFileName[found], inclSectionName ) )
+                       if ( recursiveInclude( includeChecks[found], inclSectionName ) )
                                scan_error() << "include: this is a recursive include operation" << endl;
                        else {
-                               Scanner scanner( inclFileName[found], *inFile, output, parser,
+                               Scanner scanner( includeChecks[found], *inFile, output, parser,
                                                inclSectionName, includeDepth+1, false );
                                scanner.do_scan( );
                                delete inFile;
@@ -347,17 +351,20 @@ void Scanner::handleInclude()
 void Scanner::handleImport()
 {
        if ( active() ) {
-               char **importFileName = makeIncludePathChecks( fileName, lit, lit_len );
+               char **importChecks = makeIncludePathChecks( fileName, lit, lit_len );
 
                /* Open the input file for reading. */
                long found = 0;
-               ifstream *inFile = tryOpenInclude( importFileName, found );
+               ifstream *inFile = tryOpenInclude( importChecks, found );
                if ( inFile == 0 ) {
                        scan_error() << "import: could not open import file " <<
                                        "for reading" << endl;
+                       char **tried = importChecks;
+                       while ( *tried != 0 )
+                               scan_error() << "import: attempted: \"" << *tried++ << '\"' << endl;
                }
 
-               Scanner scanner( importFileName[found], *inFile, output, parser,
+               Scanner scanner( importChecks[found], *inFile, output, parser,
                                0, includeDepth+1, true );
                scanner.do_scan( );
                scanner.importToken( 0, 0, 0 );