Repository: Konstantin8105/c4go
Pull request #420 (2019-04-22 20:01:40)

CSTD: stdio.h: add vprintf

codecov[bot]: # [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/420?src=pr&el=h1) Report
> Merging [#420](https://codecov.io/gh/Konstantin8105/c4go/pull/420?src=pr&el=desc) into [master](https://codecov.io/gh/Konstantin8105/c4go/commit/1dc5b3dcfb0d8a46f99552e8532c6435bbffbeb2?src=pr&el=desc) will **increase** coverage by `0.47%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Konstantin8105/c4go/pull/420/graphs/tree.svg?width=650&token=esH2rHXlZ2&height=150&src=pr)](https://codecov.io/gh/Konstantin8105/c4go/pull/420?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #420      +/-   ##
==========================================
+ Coverage   84.78%   85.26%   +0.47%     
==========================================
  Files         191      191              
  Lines       11595    12027     +432     
==========================================
+ Hits         9831    10255     +424     
- Misses       1282     1286       +4     
- Partials      482      486       +4
```


| [Impacted Files](https://codecov.io/gh/Konstantin8105/c4go/pull/420?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [program/definition\_function.go](https://codecov.io/gh/Konstantin8105/c4go/pull/420/diff?src=pr&el=tree#diff-cHJvZ3JhbS9kZWZpbml0aW9uX2Z1bmN0aW9uLmdv) | `91.97% <ø> (+3.19%)` | :arrow_up: |
| [noarch/stdio.go](https://codecov.io/gh/Konstantin8105/c4go/pull/420/diff?src=pr&el=tree#diff-bm9hcmNoL3N0ZGlvLmdv) | `79.72% <100%> (+0.97%)` | :arrow_up: |
| [noarch/string.go](https://codecov.io/gh/Konstantin8105/c4go/pull/420/diff?src=pr&el=tree#diff-bm9hcmNoL3N0cmluZy5nbw==) | `89.05% <0%> (+0.58%)` | :arrow_up: |
| [program/program.go](https://codecov.io/gh/Konstantin8105/c4go/pull/420/diff?src=pr&el=tree#diff-cHJvZ3JhbS9wcm9ncmFtLmdv) | `80.6% <0%> (+2.75%)` | :arrow_up: |
| [transpiler/transpiler.go](https://codecov.io/gh/Konstantin8105/c4go/pull/420/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci90cmFuc3BpbGVyLmdv) | `90.84% <0%> (+3.83%)` | :arrow_up: |
| [transpiler/call.go](https://codecov.io/gh/Konstantin8105/c4go/pull/420/diff?src=pr&el=tree#diff-dHJhbnNwaWxlci9jYWxsLmdv) | `83.41% <0%> (+5.44%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/420?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/Konstantin8105/c4go/pull/420?src=pr&el=footer). Last update [1dc5b3d...76280b9](https://codecov.io/gh/Konstantin8105/c4go/pull/420?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/README.md b/README.md
index 5931522..2c373f0 100644
--- a/README.md
+++ b/README.md
@@ -291,23 +291,23 @@ func c4goUnsafeConvert_int32(c4go_name *int32) []int32 {
 
 ```
             assert.h	       1/1	         100%
-             ctype.h	     14/14	         100%
+             ctype.h	     13/13	         100%
              errno.h	       0/1	           0%
              float.h	          	    undefined
             iso646.h	          	    undefined
             limits.h	          	    undefined
             locale.h	       3/3	         100%
-              math.h	     38/58	        65.5%
+              math.h	     22/23	        95.7%
             setjmp.h	       0/3	           0%
             signal.h	       3/3	         100%
             stdarg.h	       4/4	         100%
-            stddef.h	       2/6	        33.3%
-             stdio.h	     35/46	        76.1%
-            stdlib.h	     33/47	        70.2%
+            stddef.h	       3/4	          75%
+             stdio.h	     35/41	        85.4%
+            stdlib.h	     30/37	        81.1%
             string.h	     21/24	        87.5%
               time.h	     14/15	        93.3%
-             wchar.h	      3/68	        4.41%
-            wctype.h	      0/22	           0%
+             wchar.h	      3/60	           5%
+            wctype.h	      0/21	           0%
 ```
 
 # Contributing
diff --git a/noarch/stdio.go b/noarch/stdio.go
index 8eb81dc..3e6bade 100644
--- a/noarch/stdio.go
+++ b/noarch/stdio.go
@@ -743,12 +743,6 @@ func Sprintf(buffer, format []byte, args ...interface{}) int32 {
 // resulting string replacing their respective specifiers.
 func Vsprintf(buffer, format []byte, varList ...interface{}) int32 {
 	realArgs := []interface{}{}
-
-	if len(varList) > 1 {
-		// TODO : I don`t found the situation with more 1 size
-		return 0
-	}
-
 	realArgs = append(realArgs, convert(varList)...)
 
 	result := fmt.Sprintf(CStringToString(format), realArgs...)
@@ -761,6 +755,14 @@ func Vsprintf(buffer, format []byte, varList ...interface{}) int32 {
 	return n
 }
 
+func Vprintf(format []byte, varList ...interface{}) int32 {
+	buffer := make([]byte, 1000)
+	n := Vsprintf(buffer, format, varList...)
+	buf := CStringToString(buffer)
+	fmt.Fprintf(os.Stdout, "%s", buf)
+	return n
+}
+
 // Snprintf handles snprintf().
 //
 // Writes the C string pointed by format to the standard output (stdout). If
diff --git a/program/definition_function.go b/program/definition_function.go
index fb6fd11..b7cad9a 100644
--- a/program/definition_function.go
+++ b/program/definition_function.go
@@ -245,6 +245,7 @@ var builtInFunctionDefinitions = map[string][]string{
 		"int sprintf(char*, const char *, ...) -> noarch.Sprintf",
 		"int snprintf(char*, int, const char *, ...) -> noarch.Snprintf",
 		"int vsprintf(char*, const char *, ...) -> noarch.Vsprintf",
+		"int vprintf(const char *, ...) -> noarch.Vprintf",
 		"int vsnprintf(char*, int, const char *, ...) -> noarch.Vsnprintf",
 		"void perror( const char *) -> noarch.Perror",
 		"ssize_t getline(char **, size_t *, FILE *) -> noarch.Getline",


Test patch:
diff --git a/cstd_test.go b/cstd_test.go
index 8de79fc..23ea517 100644
--- a/cstd_test.go
+++ b/cstd_test.go
@@ -50,25 +50,25 @@ var cstd = map[string][]string{
 		"scanf",
 		"setbuf",
 		"setvbuf",
-		"snprintf",
+		// c++ "snprintf",
 		"sprintf",
 		"sscanf",
 		"tmpfile",
 		"tmpnam",
 		"ungetc",
 		"vfprintf",
-		"vfscanf",
+		// c++ "vfscanf",
 		"vprintf",
-		"vscanf",
-		"vsnprintf",
+		// c++ "vscanf",
+		// c++ "vsnprintf",
 		"vsprintf",
-		"vsscanf",
+		// c++ "vsscanf",
 	},
 	"assert.h": {"assert"},
 	"ctype.h": {
 		"isalnum",
 		"isalpha",
-		"isblank",
+		//c++ "isblank",
 		"iscntrl",
 		"isdigit",
 		"isgraph",
@@ -93,62 +93,62 @@ var cstd = map[string][]string{
 	"math.h": {
 		"abs",
 		"acos",
-		"acosh",
+		//c++ "acosh",
 		"asin",
-		"asinh",
+		//c++ "asinh",
 		"atan",
 		"atan2",
-		"atanh",
-		"cbrt",
+		//c++ "atanh",
+		//c++ "cbrt",
 		"ceil",
-		"copysign",
+		//c++ "copysign",
 		"cos",
 		"cosh",
-		"erf",
-		"erfc",
+		//c++ "erf",
+		//c++ "erfc",
 		"exp",
-		"exp2",
-		"expm1",
+		//c++ "exp2",
+		//c++ "expm1",
 		"fabs",
-		"fdim",
+		//c++ "fdim",
 		"floor",
-		"fma",
-		"fmax",
-		"fmin",
+		//c++ "fma",
+		//c++ "fmax",
+		//c++ "fmin",
 		"fmod",
 		"frexp",
-		"hypot",
-		"ilogb",
+		//c++ "hypot",
+		//c++ "ilogb",
 		"ldexp",
-		"lgamma",
-		"llrint",
-		"llround",
+		//c++ "lgamma",
+		//c++ "llrint",
+		//c++ "llround",
 		"log",
 		"log10",
-		"log1p",
-		"log2",
-		"logb",
-		"lrint",
-		"lround",
+		//c++ "log1p",
+		//c++ "log2",
+		//c++ "logb",
+		//c++ "lrint",
+		//c++ "lround",
 		"modf",
-		"nan",
-		"nearbyint",
-		"nextafter",
-		"nexttoward",
+		//c++ "nan",
+		//c++ "nearbyint",
+		//c++ "nextafter",
+		//c++ "nexttoward",
 		"pow",
-		"remainder",
-		"remquo",
-		"rint",
-		"round",
-		"scalbln",
-		"scalbn",
+		//c++ "remainder",
+		//c++ "remquo",
+		//c++ "rint",
+		//c++ "round",
+		//c++ "scalbln",
+		//c++ "scalbn",
 		"sin",
 		"sinh",
 		"sqrt",
 		"tan",
 		"tanh",
-		"tgamma",
-		"trunc",
+		//c++ "tgamma",
+		//c++ "trunc",
 	},
 	"setjmp.h": {
 		"jmp_buf",
@@ -163,13 +163,14 @@ var cstd = map[string][]string{
 	"stdarg.h": {
 		"va_arg",
 		"va_end",
+		//c++ "va_copy",
 		"va_list",
 		"va_start",
 	},
 	"stddef.h": {
 		"NULL",
-		"max_align_t",
-		"nullptr_t",
+		//c++ "max_align_t",
+		//c++ "nullptr_t",
 		"offsetof",
 		"ptrdiff_t",
 		"size_t",
@@ -180,15 +181,15 @@ var cstd = map[string][]string{
 		"MB_CUR_MAX",
 		"NULL",
 		"RAND_MAX",
-		"_Exit",
+		//c++ "_Exit",
 		"abort",
 		"abs",
-		"at_quick_exit",
 		"atexit",
 		"atof",
 		"atoi",
 		"atol",
-		"atoll",
+		//c++ "atoll",
+		//c++ "at_quick_exit",
 		"bsearch",
 		"calloc",
 		"div",
@@ -199,26 +200,26 @@ var cstd = map[string][]string{
 		"labs",
 		"ldiv",
 		"ldiv_t",
-		"llabs",
-		"lldiv",
+		//c++ "llabs",
+		//c++ "lldiv",
 		"lldiv_t",
 		"malloc",
 		"mblen",
 		"mbstowcs",
 		"mbtowc",
 		"qsort",
-		"quick_exit",
+		//c++ "quick_exit",
 		"rand",
 		"realloc",
 		"size_t",
 		"srand",
 		"strtod",
-		"strtof",
+		//c++ "strtof",
 		"strtol",
-		"strtold",
-		"strtoll",
+		//c++ "strtold",
+		//c++ "strtoll",
 		"strtoul",
-		"strtoull",
+		//c++ "strtoull",
 		"system",
 		"wcstombs",
 		"wctomb",
@@ -294,11 +295,11 @@ var cstd = map[string][]string{
 		"tm", // "struct tm",
 		"ungetwc",
 		"vfwprintf",
-		"vfwscanf",
-		"vswprintf",
-		"vswscanf",
+		//c++ "vfwscanf",
+		//c++ "vswprintf",
+		//c++ "vswscanf",
 		"vwprintf",
-		"vwscanf",
+		//c++ "vwscanf",
 		"wchar_t",
 		"wcrtomb",
 		"wcscat",
@@ -318,13 +319,13 @@ var cstd = map[string][]string{
 		"wcsspn",
 		"wcsstr",
 		"wcstod",
-		"wcstof",
+		//c++ "wcstof",
 		"wcstok",
 		"wcstol",
-		"wcstold",
-		"wcstoll",
+		//c++ "wcstold",
+		//c++ "wcstoll",
 		"wcstoul",
-		"wcstoull",
+		//c++ "wcstoull",
 		"wcsxfrm",
 		"wctob",
 		"wint_t",
@@ -340,7 +341,7 @@ var cstd = map[string][]string{
 		"WEOF",
 		"iswalnum",
 		"iswalpha",
-		"iswblank",
+		//c++ "iswblank",
 		"iswcntrl",
 		"iswctype",
 		"iswdigit",
diff --git a/tests/math.c b/tests/math.c
index 157f103..aede270 100644
--- a/tests/math.c
+++ b/tests/math.c
@@ -14,6 +14,14 @@ int main()
 {
     plan(488);
 
+	{
+		diag("modf");
+		double param, fractpart, intpart;
+		param = 3.14159265;
+		fractpart = modf (param , &intpart);
+		printf ("%f = %f + %f \n", param, intpart, fractpart);
+	}
+
     double w1 = 100;
     double w2 = 2;
     double x1 = 3;
diff --git a/tests/stddef.c b/tests/stddef.c
index 88d00c5..11dda9c 100644
--- a/tests/stddef.c
+++ b/tests/stddef.c
@@ -28,6 +28,9 @@ void test_ptrdiff_t()
         diag("ptrdiff_t : int");
         int numbers[100];
         int *p1 = &numbers[18], *p2 = &numbers[29];
+		if (p1 == NULL || p2 == NULL){
+			fail("NULL fail");
+		}
         ptrdiff_t diff = p2 - p1;
         is_eq(diff, 11);
     }
diff --git a/tests/stdio.c b/tests/stdio.c
index dac9560..d5983ad 100644
--- a/tests/stdio.c
+++ b/tests/stdio.c
@@ -606,6 +606,20 @@ void test_FILE()
     (void)p;
 }
 
+void WriteFormatted ( const char * format, ... )
+{
+  va_list args;
+  va_start (args, format);
+  vprintf (format, args);
+  va_end (args);
+}
+
+void test_vfprintf()
+{
+   WriteFormatted ("Call with %d variable argument.\n",1);
+   WriteFormatted ("Call with %d variable %s.\n",2,"arguments");
+}
+
 int main()
 {
     plan(71);
@@ -645,6 +659,7 @@ int main()
     START_TEST(getline)
     START_TEST(sscanf)
     START_TEST(FILE)
+    START_TEST(vfprintf)
 
     // that test must be last test
     START_TEST(perror)
diff --git a/tests/stdlib.c b/tests/stdlib.c
index 0a692e9..756c8ef 100644
--- a/tests/stdlib.c
+++ b/tests/stdlib.c
@@ -336,6 +336,47 @@ void test_atoi_post()
 //		is_null(p);
 //	}
 
+// TODO:
+// void printbuffer (const char* pt, size_t max)
+// {
+  // int length;
+  // wchar_t dest;
+// 
+  // mblen (NULL, 0);         /* reset mblen */
+  // mbtowc (NULL, NULL, 0);  /* reset mbtowc */
+// 
+  // while (max>0) {
+    // length = mblen (pt, max);
+    // if (length<1) break;
+    // mbtowc(&dest,pt,length);
+    // printf ("[%lc]",dest);
+    // pt+=length; max-=length;
+  // }
+// }
+// 
+// void test_mblen()
+// {
+  // const char str [] = "test string";
+  // printbuffer (str,sizeof(str));
+// }
+
+// TODO:
+// void test_wctomb()
+// {
+  // const wchar_t str[] = L"wctomb example";
+  // const wchar_t* pt;
+  // char buffer [MB_CUR_MAX];
+  // int i,length;
+// 
+  // pt = str;
+  // while (*pt) {
+    // length = wctomb(buffer,*pt);
+    // if (length<1) break;
+    // for (i=0;i<length;++i) printf ("[%c]",buffer[i]);
+    // ++pt;
+  // }
+// }
+
 int main()
 {
     plan(766);
@@ -628,6 +669,9 @@ int main()
     diag("q_sort");
     q_sort();
 
+	// test_mblen();
+	// test_wctomb();
+
     // TODO:
     // diag("my_memrchr");
     // test_my_memrchr();