diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-08-07 16:09:15 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-08-07 16:09:15 +0000 |
commit | dc4f80f3acfdc6a98a543b535a9cb31823ed2835 (patch) | |
tree | 6814fdb8337b2164e7a0667759731eeceffa9d44 | |
parent | 89b5cb358a13e7229487fe3c22785942d329b018 (diff) | |
download | build-dc4f80f3acfdc6a98a543b535a9cb31823ed2835.tar.gz build-dc4f80f3acfdc6a98a543b535a9cb31823ed2835.tar.bz2 build-dc4f80f3acfdc6a98a543b535a9cb31823ed2835.tar.xz build-dc4f80f3acfdc6a98a543b535a9cb31823ed2835.zip |
Added support for setting and adding the output of commands to variables.
-rw-r--r-- | src/build.y | 8 | ||||
-rw-r--r-- | src/builder.cpp | 24 | ||||
-rw-r--r-- | src/builder.h | 2 |
3 files changed, 34 insertions, 0 deletions
diff --git a/src/build.y b/src/build.y index d8cba53..d1f3945 100644 --- a/src/build.y +++ b/src/build.y | |||
@@ -212,6 +212,14 @@ setexpr: STRING '=' STRING | |||
212 | { | 212 | { |
213 | bld.varAddSet( $1, $3 ); | 213 | bld.varAddSet( $1, $3 ); |
214 | } | 214 | } |
215 | | STRING '=' TOK_FROM TOK_COMMAND STRING | ||
216 | { | ||
217 | bld.varSet( $1, bld.cmdToString( $5 ).c_str() ); | ||
218 | } | ||
219 | | STRING TOK_ADDSET TOK_FROM TOK_COMMAND STRING | ||
220 | { | ||
221 | bld.varSet( $1, bld.cmdToString( $5 ).c_str() ); | ||
222 | } | ||
215 | ; | 223 | ; |
216 | 224 | ||
217 | rule: TOK_RULE STRING | 225 | rule: TOK_RULE STRING |
diff --git a/src/builder.cpp b/src/builder.cpp index 8fd72bb..8c3bbbb 100644 --- a/src/builder.cpp +++ b/src/builder.cpp | |||
@@ -799,3 +799,27 @@ std::list<std::string> Builder::findTargets( const char *sRegex ) | |||
799 | return lTmp; | 799 | return lTmp; |
800 | } | 800 | } |
801 | 801 | ||
802 | std::string Builder::cmdToString( const char *sCmd ) | ||
803 | { | ||
804 | std::string buf; | ||
805 | FILE *pr = popen( sCmd, "r" ); | ||
806 | if( pr == NULL ) | ||
807 | throw BuildException("Couldn't execute program \"%s\"", sCmd ); | ||
808 | |||
809 | char cbuf[2048]; | ||
810 | |||
811 | for(;;) | ||
812 | { | ||
813 | int nRead = fread( cbuf, 1, 2048, pr ); | ||
814 | for( int j = 0; j < nRead; j++ ) | ||
815 | if( cbuf[j] != '\n' && cbuf[j] != '\r' ) | ||
816 | buf.append( cbuf+j, 1 ); | ||
817 | if( feof( pr ) ) | ||
818 | break; | ||
819 | } | ||
820 | |||
821 | pclose( pr ); | ||
822 | |||
823 | return buf; | ||
824 | } | ||
825 | |||
diff --git a/src/builder.h b/src/builder.h index 195296a..c570dbb 100644 --- a/src/builder.h +++ b/src/builder.h | |||
@@ -137,6 +137,8 @@ public: | |||
137 | void regexVars( RegExp *re, varmap &map ); | 137 | void regexVars( RegExp *re, varmap &map ); |
138 | std::string varRepl( const char *sSrc, const char *cont, varmap *mExtra ); | 138 | std::string varRepl( const char *sSrc, const char *cont, varmap *mExtra ); |
139 | 139 | ||
140 | std::string cmdToString( const char *sCmd ); | ||
141 | |||
140 | private: | 142 | private: |
141 | void requiresNormal( const char *sBase, const char *sReq ); | 143 | void requiresNormal( const char *sBase, const char *sReq ); |
142 | void requiresRegexp( const char *sBase, const char *sReq ); | 144 | void requiresRegexp( const char *sBase, const char *sReq ); |