On Sun, Mar 15, 2015 at 04:56:56AM -0400, Moshe Benezra wrote: > C can recognize float in hex float literals, for example: > > #include <stdio.h> > double pi = 0x1.921fb54442d18p+1; > int main() > { > printf("%17.15lf\n", pi); > return 0; > } > > However, when gnu-indent is applied to this program it replaces the hex > float with: > > double pi = 0x1 .921 fb54442d18p + 1; > Try attached patch.
-- Petr
From 6e810d57172a85ef6fe7847994e65530f6f0709a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppi...@redhat.com> Date: Wed, 18 Mar 2015 16:29:49 +0100 Subject: [PATCH] Support hexadecimal floats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Petr Písař <ppi...@redhat.com> --- regression/TEST | 3 +- regression/input/hexadecimal_float.c | 17 +++++++++ regression/standard/hexadecimal_float.c | 17 +++++++++ src/lexi.c | 63 ++++++++++++++++----------------- 4 files changed, 67 insertions(+), 33 deletions(-) create mode 100644 regression/input/hexadecimal_float.c create mode 100644 regression/standard/hexadecimal_float.c diff --git a/regression/TEST b/regression/TEST index c860ef2..e995ab9 100755 --- a/regression/TEST +++ b/regression/TEST @@ -35,7 +35,8 @@ EXAMPLES="do.c else.c for.c func-def.c lshift.c ncs.c \ BUGS="case-label.c one-line-1.c one-line-2.c one-line-3.c \ one-line-4.c struct-decl.c sizeof-in-while.c line-break-comment.c \ - macro.c enum.c elif.c nested.c wrapped-string.c minus_predecrement.c" + macro.c enum.c elif.c nested.c wrapped-string.c minus_predecrement.c + hexadecimal_float.c" INDENTSRC="args.c backup.h backup.c dirent_def.h globs.c indent.h \ indent.c indent_globs.h io.c lexi.c memcpy.c parse.c pr_comment.c \ diff --git a/regression/input/hexadecimal_float.c b/regression/input/hexadecimal_float.c new file mode 100644 index 0000000..34c52cd --- /dev/null +++ b/regression/input/hexadecimal_float.c @@ -0,0 +1,17 @@ +/* Hexadecimal */ +double xpi = 0x1.921fb54442d18p+1; +double xa = 0xe.fp-1; +double xb = 0xe.fP-1; +double xc = 0xf.P+1; +double xd = 0x.fP+1; +/* hexadecimal floats must have exponent part */ + +/* Decimal */ +double dpi = 3.141592653589793e+0; +double da = 1.2e-1; +double db = 1.2E-1; +double dc = 1.E+1; +double dd = .1E+1; +double de = 1.2; +double df = 1.; +double dg = .1; diff --git a/regression/standard/hexadecimal_float.c b/regression/standard/hexadecimal_float.c new file mode 100644 index 0000000..34c52cd --- /dev/null +++ b/regression/standard/hexadecimal_float.c @@ -0,0 +1,17 @@ +/* Hexadecimal */ +double xpi = 0x1.921fb54442d18p+1; +double xa = 0xe.fp-1; +double xb = 0xe.fP-1; +double xc = 0xf.P+1; +double xd = 0x.fP+1; +/* hexadecimal floats must have exponent part */ + +/* Decimal */ +double dpi = 3.141592653589793e+0; +double da = 1.2e-1; +double db = 1.2E-1; +double dc = 1.E+1; +double dd = .1E+1; +double de = 1.2; +double df = 1.; +double dg = .1; diff --git a/src/lexi.c b/src/lexi.c index abc2bfa..f5547c5 100644 --- a/src/lexi.c +++ b/src/lexi.c @@ -277,50 +277,49 @@ extern codes_ty lexi(void) if (isdigit (*buf_ptr) || ((buf_ptr[0] == '.') && isdigit (buf_ptr[1]))) { - int seendot = 0, seenexp = 0; + int seendot = 0, seenexp = 0, ishexa = 0; if ((*buf_ptr == '0') && ((buf_ptr[1] == 'x') || (buf_ptr[1] == 'X'))) { - buf_ptr += 2; - while (isxdigit (*buf_ptr)) - { - buf_ptr++; - } + ishexa = 1; + buf_ptr += 1; } - else + while (1) { - while (1) + if (*buf_ptr == '.') { - if (*buf_ptr == '.') + if (seendot) { - if (seendot) - { - break; - } - else - { - seendot++; - } + break; } + else + { + seendot++; + } + } - buf_ptr++; - - if (!isdigit (*buf_ptr) && *buf_ptr != '.') + buf_ptr++; + + if (!(ishexa && !seenexp ? + isxdigit (*buf_ptr) : isdigit (*buf_ptr) + ) && *buf_ptr != '.') + { + if ((ishexa ? + (*buf_ptr != 'P' && *buf_ptr != 'p') : + (*buf_ptr != 'E' && *buf_ptr != 'e') + ) || seenexp) { - if ((*buf_ptr != 'E' && *buf_ptr != 'e') || seenexp) - { - break; - } - else + break; + } + else + { + seenexp++; + seendot++; + buf_ptr++; + + if (*buf_ptr == '+' || *buf_ptr == '-') { - seenexp++; - seendot++; buf_ptr++; - - if (*buf_ptr == '+' || *buf_ptr == '-') - { - buf_ptr++; - } } } } -- 2.1.0
pgpLxV5coQmrj.pgp
Description: PGP signature
_______________________________________________ bug-indent mailing list bug-indent@gnu.org https://lists.gnu.org/mailman/listinfo/bug-indent