diff --git a/examples/example b/examples/example deleted file mode 100755 index 7249736..0000000 Binary files a/examples/example and /dev/null differ diff --git a/examples/example2 b/examples/example2 deleted file mode 100755 index 155367f..0000000 Binary files a/examples/example2 and /dev/null differ diff --git a/examples/example2.cpp b/examples/example2.cpp index 661a6d7..654d0c5 100644 --- a/examples/example2.cpp +++ b/examples/example2.cpp @@ -5,12 +5,17 @@ using namespace pipecolors; int main(void) { - char * buffer; + + char buffer[128]; + char * buf; int num = 5; const char* str = "My number is"; + const char* str2 = "|10My number is|07"; int len = pcprintf("|01%s |41|09%d|39\n", str, num); pcprintf("|10Length of Len is : |15|30%d\n|07", len); - int len2 = pcsprintf(buffer, "%s %d\n", str, num); - printf("%s\n", buffer); + int len2 = pcsprintf(buffer, "%s %d\n", str2, num); + printf("\n%s %d\n", buffer, len2); + int len3 = asprintf(&buf, "%s %d\n", str2, num); + printf("\n%s %d\n", buf, len3); return 0; } \ No newline at end of file diff --git a/libpipecolors.cpp b/libpipecolors.cpp index 34ad857..7070522 100644 --- a/libpipecolors.cpp +++ b/libpipecolors.cpp @@ -104,17 +104,17 @@ namespace pipecolors { } return std::make_pair(s, len.length()); - + } - int pcprintf( const char * fmt, ...) + int pcprintf( const char * format, ...) { char * buffer; va_list args; int ret; - va_start(args, fmt); - ret = vasprintf(&buffer, fmt, args); + va_start(args, format); + ret = vasprintf(&buffer, format, args); va_end(args); if(ret == -1) { free(buffer); @@ -130,24 +130,29 @@ namespace pipecolors { return(result.second); } - int pcsprintf( char * str, const char * fmt, ... ) { + + + int pcsprintf( char * str, const char * format, ... ) { + int ret; - + std::cout << sizeof(str); + char** str1 = (char**)str; va_list args; - va_start(args, fmt); - ret = vasprintf(&str, fmt, args); - + + va_start(args, format); + ret = vasprintf(str1, format, args); + va_end(args); + if(ret == -1) { - free(str); + free(str1); exit(EXIT_FAILURE); } - std::string s(str); - //free(buffer); - - //std::pair result = replace_colors(s); - //char* buffer = result.first; - - return s.length(); + std::string s(*str1); + free(*str1); + std::pair result = replace_colors(s); + const char * s2 = (const char *)result.first.c_str(); + strcpy(str, s2); + return result.second; } } // namespace diff --git a/pcprintf.3 b/pcprintf.3 index 6650885..2679582 100644 --- a/pcprintf.3 +++ b/pcprintf.3 @@ -32,9 +32,9 @@ pcsprintf \- convert pipecode (|10) to ansi colors .sp .B using namespace pipecolors; .sp -.BI "int pcprintf(const char *" format ", ...);" +.BI "int pcprintf(const char * " format ", ...);" .br -.BI "int pcsprintf(char *" str ", const char *" format ", ...);" +.BI "int pcsprintf(char * " str ", const char * " format ", ...);" .sp .in -4n .ad diff --git a/pipecolors.h b/pipecolors.h index c571788..ddee655 100644 --- a/pipecolors.h +++ b/pipecolors.h @@ -11,7 +11,7 @@ extern "C" { #endif int pcprintf( const char * format, ... ); -int pcsprintf( char * str, const char * fmt, ... ); +int pcsprintf( char * str, const char * format, ... ); #ifdef __cplusplus }