diff --git a/indent-2.2.12-Recognize-binary-integer-literals.patch b/indent-2.2.12-Recognize-binary-integer-literals.patch new file mode 100644 index 0000000..e33d0a4 --- /dev/null +++ b/indent-2.2.12-Recognize-binary-integer-literals.patch @@ -0,0 +1,124 @@ +From 2b1d8978ea303e8da1bc8f672cdb82c76ef38c02 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= +Date: Mon, 3 Dec 2018 10:42:21 +0100 +Subject: [PATCH] Recognize binary integer literals +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Some compilers support binary constants written as 0b1 or 0B1. This is +the case of GCC +. + +This is based on a patch provided by Josef Kubin . + + + +Signed-off-by: Petr Písař +--- + regression/TEST | 2 +- + regression/input/binary-constant.c | 12 ++++++++++++ + regression/standard/binary-constant.c | 12 ++++++++++++ + src/lexi.c | 23 +++++++++++++++++------ + 4 files changed, 42 insertions(+), 7 deletions(-) + create mode 100644 regression/input/binary-constant.c + create mode 100644 regression/standard/binary-constant.c + +diff --git a/regression/TEST b/regression/TEST +index 56f41d9..64b9bce 100755 +--- a/regression/TEST ++++ b/regression/TEST +@@ -37,7 +37,7 @@ 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 \ + bug-gnu-33364.c float-constant-suffix.c block-comments.c \ +- no-forced-nl-in-block-init.c hexadecimal_float.c" ++ no-forced-nl-in-block-init.c hexadecimal_float.c binary-constant.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/binary-constant.c b/regression/input/binary-constant.c +new file mode 100644 +index 0000000..25f1624 +--- /dev/null ++++ b/regression/input/binary-constant.c +@@ -0,0 +1,12 @@ ++int foo = 0b1; ++long int foo = 0b1L; ++unsigned int foo = 0b1U; ++unsigned long int foo = 0b1LU; ++ ++int foo = 0B1; ++long int foo = 0B1L; ++unsigned int foo = 0B1U; ++unsigned long int foo = 0B1LU; ++ ++int foo = 0b01010101; ++int foo = 0B01010101; +diff --git a/regression/standard/binary-constant.c b/regression/standard/binary-constant.c +new file mode 100644 +index 0000000..25f1624 +--- /dev/null ++++ b/regression/standard/binary-constant.c +@@ -0,0 +1,12 @@ ++int foo = 0b1; ++long int foo = 0b1L; ++unsigned int foo = 0b1U; ++unsigned long int foo = 0b1LU; ++ ++int foo = 0B1; ++long int foo = 0B1L; ++unsigned int foo = 0B1U; ++unsigned long int foo = 0B1LU; ++ ++int foo = 0b01010101; ++int foo = 0B01010101; +diff --git a/src/lexi.c b/src/lexi.c +index 848ddc9..6eaba95 100644 +--- a/src/lexi.c ++++ b/src/lexi.c +@@ -286,15 +286,24 @@ extern codes_ty lexi(void) + if (parser_state_tos->last_rw == rw_return) + parser_state_tos->last_rw = rw_none; + ++ /* decimal, octal, hex, binary and floating point number format */ + if (isdigit (*buf_ptr) || + ((buf_ptr[0] == '.') && isdigit (buf_ptr[1]))) + { +- int seendot = 0, seenexp = 0, ishexa = 0; ++ int seendot = 0, seenexp = 0, ishexa = 0, isbinary = 0; + +- if ((*buf_ptr == '0') && ((buf_ptr[1] == 'x') || (buf_ptr[1] == 'X'))) ++ if (*buf_ptr == '0') + { +- ishexa = 1; +- buf_ptr += 1; ++ if ((buf_ptr[1] == 'x') || (buf_ptr[1] == 'X')) ++ { ++ ishexa = 1; ++ buf_ptr += 1; ++ } ++ else if ((buf_ptr[1] == 'b') || (buf_ptr[1] == 'B')) ++ { ++ isbinary = 1; ++ buf_ptr += 1; ++ } + } + while (1) + { +@@ -312,8 +321,10 @@ extern codes_ty lexi(void) + + buf_ptr++; + +- if (!(ishexa && !seenexp ? +- isxdigit (*buf_ptr) : isdigit (*buf_ptr) ++ if (!( ++ (ishexa && !seenexp && isxdigit (*buf_ptr)) || ++ (isbinary && !seenexp && (*buf_ptr == '0' || *buf_ptr == '1')) || ++ ((!(ishexa || isbinary) || seenexp) && isdigit (*buf_ptr)) + ) && *buf_ptr != '.') + { + if ((ishexa ? +-- +2.17.2 + diff --git a/indent.spec b/indent.spec index 41687e5..aee0be2 100644 --- a/indent.spec +++ b/indent.spec @@ -37,6 +37,9 @@ Patch1: indent-2.2.12-doc-Fix-dont-cuddle-else-short-option-and-index-remo.p # license is "GPLv3+ with exception", proposed to upstream # Patch2: indent-2.2.12-Add-m4-ax_cc_for_build.m4-for-CC_FOR_BUILD.patch +# Recognize binary integer literals, bug #1655319, submitted to the upstream +# +Patch3: indent-2.2.12-Recognize-binary-integer-literals.patch # Update config.sub to support aarch64, bug #925588 BuildRequires: autoconf BuildRequires: automake @@ -62,6 +65,7 @@ you want a program to format your code. %setup -q %patch1 -p1 %patch2 -p1 +%patch3 -p1 # Regenerate sources rm src/gperf.c src/gperf-cc.c # Update config.sub to support aarch64, bug #925588 @@ -93,6 +97,7 @@ make check %changelog * Fri Feb 01 2019 Petr Pisar - 2.2.12-3 - Correct invoking tests at build time +- Recognize binary integer literals (bug #1655319) * Fri Feb 01 2019 Fedora Release Engineering - 2.2.12-2 - Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild