diff --git a/examples/example2 b/examples/example2 index 594842f..155367f 100755 Binary files a/examples/example2 and b/examples/example2 differ diff --git a/examples/example2.cpp b/examples/example2.cpp index 8faa824..661a6d7 100644 --- a/examples/example2.cpp +++ b/examples/example2.cpp @@ -5,10 +5,12 @@ using namespace pipecolors; int main(void) { - + char * buffer; int num = 5; const char* str = "My number is"; int len = pcprintf("|01%s |41|09%d|39\n", str, num); - pcprintf("|10Length of String is : |15|30%d\n", len); + pcprintf("|10Length of Len is : |15|30%d\n|07", len); + int len2 = pcsprintf(buffer, "%s %d\n", str, num); + printf("%s\n", buffer); return 0; } \ No newline at end of file diff --git a/libpipecolors.cpp b/libpipecolors.cpp index 89f00e1..34ad857 100644 --- a/libpipecolors.cpp +++ b/libpipecolors.cpp @@ -82,7 +82,7 @@ namespace pipecolors { start = s.begin(); end = s.end(); std::string len(s); - int reallen; + colors = getColors(); while(regex_search(start, end, match, re, flags)) @@ -103,8 +103,8 @@ namespace pipecolors { flags |= boost::match_prev_avail | boost::match_not_bob; } - return std::make_pair(s, len.find("\n") ? len.length() - 1 : len.length()); - + return std::make_pair(s, len.length()); + } int pcprintf( const char * fmt, ...) @@ -130,7 +130,24 @@ namespace pipecolors { return(result.second); } - int pcsprintf(char **strp, const char *fmt, va_list ap) { - return true; + int pcsprintf( char * str, const char * fmt, ... ) { + int ret; + + va_list args; + va_start(args, fmt); + ret = vasprintf(&str, fmt, args); + + if(ret == -1) { + free(str); + exit(EXIT_FAILURE); + } + + std::string s(str); + //free(buffer); + + //std::pair result = replace_colors(s); + //char* buffer = result.first; + + return s.length(); } } // namespace diff --git a/pipecolors.h b/pipecolors.h index 6b7a662..c571788 100644 --- a/pipecolors.h +++ b/pipecolors.h @@ -11,7 +11,7 @@ extern "C" { #endif int pcprintf( const char * format, ... ); -int pcsprintf(char **strp, const char *fmt, va_list ap); +int pcsprintf( char * str, const char * fmt, ... ); #ifdef __cplusplus }