diff options
author | Vitaliy Batichko <[email protected]> | 2010-11-23 17:08:01 +0200 |
---|---|---|
committer | Vitaliy Batichko <[email protected]> | 2010-12-08 20:15:50 +0200 |
commit | ad5b84bd154e27d9e4db3af12b8b4326c564b2bf (patch) | |
tree | c71a2607537d15259ec4cb2fd8224bd02af34c71 /lib/erl_interface | |
parent | 1d82ce2e4466980e5c360b54722952a30bc3ae50 (diff) | |
download | otp-ad5b84bd154e27d9e4db3af12b8b4326c564b2bf.tar.gz otp-ad5b84bd154e27d9e4db3af12b8b4326c564b2bf.tar.bz2 otp-ad5b84bd154e27d9e4db3af12b8b4326c564b2bf.zip |
Add char (~c) type parameters to ei_format
Diffstat (limited to 'lib/erl_interface')
-rw-r--r-- | lib/erl_interface/doc/src/ei.xml | 1 | ||||
-rw-r--r-- | lib/erl_interface/src/misc/ei_format.c | 9 | ||||
-rw-r--r-- | lib/erl_interface/test/ei_format_SUITE.erl | 2 | ||||
-rw-r--r-- | lib/erl_interface/test/ei_format_SUITE_data/ei_format_test.c | 2 |
4 files changed, 12 insertions, 2 deletions
diff --git a/lib/erl_interface/doc/src/ei.xml b/lib/erl_interface/doc/src/ei.xml index d7af7a1b67..be5d7ebef8 100644 --- a/lib/erl_interface/doc/src/ei.xml +++ b/lib/erl_interface/doc/src/ei.xml @@ -641,6 +641,7 @@ ei_x_encode_empty_list(&x); <p></p> <pre> ~a - an atom, char* +~c - a character, char ~s - a string, char* ~i - an integer, int ~l - a long integer, long int diff --git a/lib/erl_interface/src/misc/ei_format.c b/lib/erl_interface/src/misc/ei_format.c index b35421d4b2..96203a0d15 100644 --- a/lib/erl_interface/src/misc/ei_format.c +++ b/lib/erl_interface/src/misc/ei_format.c @@ -47,6 +47,7 @@ * array of unions. */ union arg { + char c; char* s; long l; unsigned long u; @@ -224,6 +225,7 @@ static int pquotedatom(const char** fmt, ei_x_buff* x) /* * The format letters are: * a - An atom + * c - A character * s - A string * i - An integer * l - A long integer @@ -240,6 +242,10 @@ static int pformat(const char** fmt, union arg** args, ei_x_buff* x) res = ei_x_encode_atom(x, (*args)->s); (*args)++; break; + case 'c': + res = ei_x_encode_char(x, (*args)->c); + (*args)++; + break; case 's': res = ei_x_encode_string(x, (*args)->s); (*args)++; @@ -396,6 +402,9 @@ static int read_args(const char* fmt, va_list ap, union arg **argp) return -1; /* Error, string not complete */ } switch (*p++) { + case 'c': + args[i++].c = (char) va_arg(ap, int); + break; case 'a': case 's': args[i++].s = va_arg(ap, char*); diff --git a/lib/erl_interface/test/ei_format_SUITE.erl b/lib/erl_interface/test/ei_format_SUITE.erl index cbe9fa52d7..6d44e0adf3 100644 --- a/lib/erl_interface/test/ei_format_SUITE.erl +++ b/lib/erl_interface/test/ei_format_SUITE.erl @@ -155,7 +155,7 @@ format_wo_ver(suite) -> []; format_wo_ver(Config) when is_list(Config) -> ?line P = runner:start(?format_wo_ver), - ?line {term, [-1, 2, {a, "b"}, {c, 10}]} = get_term(P), + ?line {term, [-1, 2, $c, {a, "b"}, {c, 10}]} = get_term(P), ?line runner:recv_eot(P), ok. diff --git a/lib/erl_interface/test/ei_format_SUITE_data/ei_format_test.c b/lib/erl_interface/test/ei_format_SUITE_data/ei_format_test.c index ecdce402f5..a6eeb25abc 100644 --- a/lib/erl_interface/test/ei_format_SUITE_data/ei_format_test.c +++ b/lib/erl_interface/test/ei_format_SUITE_data/ei_format_test.c @@ -176,7 +176,7 @@ TESTCASE(format_wo_ver) { ei_x_buff x; ei_x_new (&x); - ei_x_format(&x, "[-1, +2, {~a,~s},{~a,~i}]", "a", "b", "c", 10); + ei_x_format(&x, "[-1, +2, ~c, {~a,~s},{~a,~i}]", 'c', "a", "b", "c", 10); send_bin_term(&x); free(x.buff); |