From c688963d4ac433b61e5e0652e1e19f4265b3a002 Mon Sep 17 00:00:00 2001 From: thurston Date: Tue, 23 Oct 2007 02:17:07 +0000 Subject: [PATCH] Added name finding for backend executable. If any forward slash is found in argv0 then it is assumed that the path is explicit and the path to the backend executable should be derived from that. If no forward slash is found it is assumed the file is being run from the installed location. The PREFIX supplied during configuration is used. git-svn-id: http://svn.complang.org/ragel/trunk@314 052ea7fc-9027-0410-9066-f65837a77df0 --- common/Makefile.in | 2 ++ ragel/main.cpp | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/common/Makefile.in b/common/Makefile.in index c584dee..381b6c5 100644 --- a/common/Makefile.in +++ b/common/Makefile.in @@ -29,6 +29,7 @@ CC_SRCS = common.cpp GEN_SRC = version.h #************************************* +prefix = @prefix@ # Programs CXX = @CXX@ @@ -50,6 +51,7 @@ common.a: $(GEN_SRC) $(OBJS) version.h: ../version.mk echo '#define VERSION "$(VERSION)"' > version.h echo '#define PUBDATE "$(PUBDATE)"' >> version.h + echo '#define PREFIX "$(prefix)"' >> version.h %.o: %.cpp @$(CXX) -M $(DEFS) $(INCS) $< > .$*.d diff --git a/ragel/main.cpp b/ragel/main.cpp index 6f929c3..11b9659 100644 --- a/ragel/main.cpp +++ b/ragel/main.cpp @@ -127,6 +127,71 @@ void escapeLineDirectivePath( std::ostream &out, char *path ) } } +/* If any forward slash is found in argv0 then it is assumed that the path is + * explicit and the path to the backend executable should be derived from + * that. If no forward slash is found it is assumed the file is being run from + * the installed location. The PREFIX supplied during configuration is used. + * */ +char **makePathChecks( const char *argv0, const char *progName ) +{ + char **result = new char*[3]; + const char *lastSlash = strrchr( argv0, '/' ); + int numChecks = 0; + + if ( lastSlash != 0 ) { + char *path = strdup( argv0 ); + int givenPathLen = (lastSlash - argv0) + 1; + path[givenPathLen] = 0; + + int progNameLen = strlen(progName); + int length = givenPathLen + progNameLen + 1; + char *check = new char[length]; + sprintf( check, "%s%s", path, progName ); + result[numChecks++] = check; + + length = givenPathLen + 3 + progNameLen + 1 + progNameLen + 1; + check = new char[length]; + sprintf( check, "%s../%s/%s", path, progName, progName ); + result[numChecks++] = check; + } + else { + int prefixLen = strlen(PREFIX); + int progNameLen = strlen(progName); + int length = prefixLen + 5 + progNameLen + 1; + char *check = new char[length]; + + sprintf( check, PREFIX "/bin/%s", progName ); + result[numChecks++] = check; + } + + result[numChecks] = 0; + return result; +} + + +void execBackend( const char *argv0 ) +{ + /* Locate the backend program */ + const char *progName = 0; + switch ( hostLang->lang ) { + case HostLang::C: + case HostLang::D: + progName = "rlgen-cd"; + break; + case HostLang::Java: + progName = "rlgen-java"; + break; + case HostLang::Ruby: + progName = "rlgen-ruby"; + break; + } + + char **pathChecks = makePathChecks( argv0, progName ); + while ( *pathChecks != 0 ) { + pathChecks += 1; + } +} + /* Main, process args and call yyparse to start scanning input. */ int main(int argc, char **argv) { @@ -326,5 +391,7 @@ int main(int argc, char **argv) if ( outputFileName != 0 ) delete outputFile; + execBackend( argv[0] ); + return 0; } -- 2.7.4