Hello community, here is the log from the commit of package unifdef for openSUSE:Factory checked in at 2015-12-06 07:41:36 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/unifdef (Old) and /work/SRC/openSUSE:Factory/.unifdef.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "unifdef" Changes: -------- --- /work/SRC/openSUSE:Factory/unifdef/unifdef.changes 2014-02-28 16:22:32.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.unifdef.new/unifdef.changes 2015-12-06 07:41:37.000000000 +0100 @@ -1,0 +2,8 @@ +Fri Dec 4 09:58:25 UTC 2015 - sweet_...@gmx.de + +- Update to 2.11: + * bug fixes + * add support for additional #if/#elif operators + * improve portability to Windows + +------------------------------------------------------------------- Old: ---- unifdef-2.10.tar.xz New: ---- unifdef-2.11.tar.xz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ unifdef.spec ++++++ --- /var/tmp/diff_new_pack.NzYjsr/_old 2015-12-06 07:41:37.000000000 +0100 +++ /var/tmp/diff_new_pack.NzYjsr/_new 2015-12-06 07:41:37.000000000 +0100 @@ -20,7 +20,7 @@ Summary: Removes ifdefs from C files License: BSD-2-Clause Group: Development/Libraries/C and C++ -Version: 2.10 +Version: 2.11 Release: 0 Url: http://dotat.at/prog/unifdef/ Source: http://dotat.at/prog/unifdef/unifdef-%{version}.tar.xz ++++++ unifdef-2.10.tar.xz -> unifdef-2.11.tar.xz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/.travis.yml new/unifdef-2.11/.travis.yml --- old/unifdef-2.10/.travis.yml 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/.travis.yml 2015-12-03 13:12:04.000000000 +0100 @@ -4,9 +4,6 @@ - gcc - clang -git: - depth: 0 - matrix: include: - compiler: i586-mingw32msvc-gcc @@ -28,8 +25,7 @@ echo -e '#!/bin/bash\nexec wine $0.exe "$@"' > unifdef; chmod ugo+x unifdef; make version.h && - make -f win32/Makefile.mingw && - make test; + make -f win32/Makefile.mingw test; fi ## whitelist diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/COPYING new/unifdef-2.11/COPYING --- old/unifdef-2.10/COPYING 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/COPYING 2015-12-03 13:12:04.000000000 +0100 @@ -14,7 +14,7 @@ Unless otherwise stated, the files in this package are: - Copyright (c) 2002 - 2014 Tony Finch <d...@dotat.at> + Copyright (c) 2002 - 2015 Tony Finch <d...@dotat.at> unifdefall.sh is: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/Changelog new/unifdef-2.11/Changelog --- old/unifdef-2.10/Changelog 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/Changelog 2015-12-03 13:12:04.000000000 +0100 @@ -1,6 +1,385 @@ --------------------------------------------------- -2014-01-07 19:16:02 +0000 Tony Finch <d...@dotat.at> (HEAD, tag: unifdef-2.10, -master) +2015-12-03 12:10:08 +0000 Tony Finch <d...@dotat.at> (HEAD -> master, tag: +unifdef-2.11) + +Bump copyright dates + + COPYING | 2 +- + unifdef.1 | 4 ++-- + unifdef.c | 2 +- + 3 files changed, 4 insertions(+), 4 deletions(-) + +--------------------------------------------------- +2015-12-03 12:06:33 +0000 Tony Finch <d...@dotat.at> + +unifdef-2.11 + + README | 3 +++ + web/index.html | 6 +++--- + 2 files changed, 6 insertions(+), 3 deletions(-) + +--------------------------------------------------- +2015-12-03 11:50:46 +0000 Tony Finch <d...@dotat.at> (github/master) + +Fix uninitialized variable in evaluator. + +Inner expressions typically return LT_IF without setting their +value pointer when they encounter an unknown value. Binary +operators then blindly use these inner values before checking if +they are unknown - before checking for LT_IF. This is undefined +behaviour, but we usually dodge the bullet - except division can +cause things to explode and expose the bug. + +Initializing the value to zero avoids undefined behaviour. But this +means that instead of avoiding division when the denominator is +definitely zero (because it might be unknown and zero) we now only +divide if it is definitely non-zero. + + unifdef.c | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +--------------------------------------------------- +2015-12-03 11:42:04 +0000 Tony Finch <d...@dotat.at> + +test: unexpected /0 exception happening in another part of the test + + tests/div.sh | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +--------------------------------------------------- +2015-12-03 11:37:56 +0000 Tony Finch <d...@dotat.at> + +travis: clone deeply, so version tags are included + + .travis.yml | 3 --- + 1 file changed, 3 deletions(-) + +--------------------------------------------------- +2015-12-03 11:37:23 +0000 Tony Finch <d...@dotat.at> + +test: clearer div test, and try to diagnose unexpected /0 exception + + tests/div.expout | 5 ++++- + tests/div.sh | 9 +++++++-- + 2 files changed, 11 insertions(+), 3 deletions(-) + +--------------------------------------------------- +2015-12-03 11:17:20 +0000 Tony Finch <d...@dotat.at> + +win32: suppress warnings about POSIX functions + + win32/unifdef.h | 5 +++++ + 1 file changed, 5 insertions(+) + +--------------------------------------------------- +2015-12-03 11:15:29 +0000 Tony Finch <d...@dotat.at> + +travis: clone with a nonzero depth + + .travis.yml | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--------------------------------------------------- +2015-12-03 11:08:24 +0000 Tony Finch <d...@dotat.at> + +Document the buggy effect of the dumb lexer on the -f option. + + unifdef.1 | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +--------------------------------------------------- +2015-12-03 10:59:28 +0000 Tony Finch <d...@dotat.at> + +Avoid redundant renames with a -M '' empty backup suffix. + +Submitted-by: Michael McConville <mm...@mykolab.com> + + unifdef.1 | 5 +++++ + unifdef.c | 3 ++- + 2 files changed, 7 insertions(+), 1 deletion(-) + +--------------------------------------------------- +2015-12-03 10:50:49 +0000 Tony Finch <d...@dotat.at> + +Handle division by zero gracefully. + +Reported-by: Michael McConville <mm...@mykolab.com> + + tests/div.c | 3 +++ + tests/div.experr | 0 + tests/div.expout | 7 +++++++ + tests/div.exprc | 1 + + tests/div.sh | 3 +++ + unifdef.1 | 1 + + unifdef.c | 4 ++++ + 7 files changed, 19 insertions(+) + +--------------------------------------------------- +2014-10-24 16:43:51 +0100 Tony Finch <d...@dotat.at> + +Replace hardcoded operator lexing with table-driven code. + + unifdef.c | 31 +++++++++++++++---------------- + 1 file changed, 15 insertions(+), 16 deletions(-) + +--------------------------------------------------- +2014-10-24 15:02:53 +0000 Brian Ginsbach <ginsb...@netbsd.org> + +Add support for additional #if/#elif operators + +Add support for additional operators in a #if/#elif statement. + - unary bitwise NOT (one's complement): ~ + - unary negative: - + - left shift: << + - right shift: >> + - bitwise AND: & + - bitwise exclusive OR: ^ + - bitwise inclusive OR: | + - addition: + + - subtraction: - + - multiplcation: * + - division: / + - modulo: % + + tests/if7.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++ + tests/if7.experr | 0 + tests/if7.expout | 46 ++++++++++++++++++++++++ + tests/if7.exprc | 1 + + tests/if7.sh | 1 + + tests/recursive.experr | 24 +++++++++++-- + unifdef.1 | 6 ++-- + unifdef.c | 81 ++++++++++++++++++++++++++++++++++++++++--- + 8 files changed, 244 insertions(+), 9 deletions(-) + +--------------------------------------------------- +2014-10-24 15:01:11 +0000 Brian Ginsbach <ginsb...@netbsd.org> + +Add all comparisons to tests + +Add tests for <, <=, >, and >= comparisons. + + tests/if5-a.expout | 12 ++++++++++++ + tests/if5.c | 28 ++++++++++++++++++++++++++++ + tests/if5.expout | 12 ++++++++++++ + 3 files changed, 52 insertions(+) + +--------------------------------------------------- +2014-10-20 21:45:20 +0100 Tony Finch <d...@dotat.at> + +Ensure that newlines change the linestate when skipping junk. + +Sometimes skipline() would skip meaningful characters without +letting skipcomment() look at them. + +Reported-By: Christoph Schied <christoph.sch...@kit.edu> + + tests/error.c | 4 ++++ + tests/error.experr | 0 + tests/error.expout | 2 ++ + tests/error.exprc | 1 + + tests/error.sh | 1 + + unifdef.c | 8 ++++++-- + 6 files changed, 14 insertions(+), 2 deletions(-) + +--------------------------------------------------- +2014-10-20 21:29:13 +0100 Tony Finch <d...@dotat.at> + +tests: update for capitalized diagnostics + + tests/defundef-broken2.experr | 4 ++-- + tests/defundef-broken3.experr | 4 ++-- + tests/defundef-broken4.experr | 2 +- + tests/whitespace-1.experr | 2 +- + 4 files changed, 6 insertions(+), 6 deletions(-) + +--------------------------------------------------- +2014-10-20 21:24:35 +0100 Tony Finch <d...@dotat.at> + +DIAGNOSTICS do not have full stops. + + unifdef.1 | 10 +++++----- + 1 file changed, 5 insertions(+), 5 deletions(-) + +--------------------------------------------------- +2014-10-20 21:23:50 +0100 Tony Finch <d...@dotat.at> + +Add some missing DIAGNOSTICS + + unifdef.1 | 6 ++++++ + 1 file changed, 6 insertions(+) + +--------------------------------------------------- +2014-10-20 21:21:00 +0100 Tony Finch <d...@dotat.at> + +Capitalize error messages + + unifdef.c | 12 ++++++------ + 1 file changed, 6 insertions(+), 6 deletions(-) + +--------------------------------------------------- +2014-10-20 21:19:37 +0100 Tony Finch <d...@dotat.at> + +Alphabetize DIAGNOSTICS + + unifdef.1 | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +--------------------------------------------------- +2014-10-20 21:16:34 +0100 Tony Finch <d...@dotat.at> + +Check there is a filename argument for inplace editing. + +Reported-by: Philip Guenther <guent...@openbsd.org> +Submitted-By: Stuart Henderson <st...@openbsd.org> + + unifdef.c | 2 ++ + 1 file changed, 2 insertions(+) + +--------------------------------------------------- +2014-01-08 15:03:36 +0000 Tony Finch <d...@dotat.at> + +travis: restore missing semicolon + + .travis.yml | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--------------------------------------------------- +2014-01-08 14:59:46 +0000 Tony Finch <d...@dotat.at> + +win32: do not use Unix Makefile for testing on MinGW + + .travis.yml | 3 +-- + win32/Makefile.mingw | 3 +++ + 2 files changed, 4 insertions(+), 2 deletions(-) + +--------------------------------------------------- +2014-01-08 14:16:13 +0000 Tony Finch <d...@dotat.at> + +win32: avoid deprecated -I- compiler option in MinGW build + + win32/Makefile.mingw | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +--------------------------------------------------- +2014-01-08 14:15:39 +0000 Tony Finch <d...@dotat.at> + +win32: need prototype for snprintf() + + win32/unifdef.h | 1 + + 1 file changed, 1 insertion(+) + +--------------------------------------------------- +2014-01-08 13:51:53 +0000 Tony Finch <d...@dotat.at> + +unifdef: typo in comment + +Reported-by: Bernhard Reutner-Fischer <rep.dot....@gmail.com> + + unifdef.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--------------------------------------------------- +2014-01-08 13:39:10 +0000 Tony Finch <d...@dotat.at> + +win32: avoid "secure" string functions - troublesome on MinGW + + win32/win32.c | 54 ++++++++++++++++++++++++++---------------------------- + 1 file changed, 26 insertions(+), 28 deletions(-) + +--------------------------------------------------- +2014-01-08 00:15:18 +0000 Tony Finch <d...@dotat.at> + +win32: or maybe stdint.h? MinGW seems to disagree with Windows :-( + + win32/unifdef.h | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--------------------------------------------------- +2014-01-08 00:06:22 +0000 Tony Finch <d...@dotat.at> + +win32: need stddef.h + + win32/unifdef.h | 1 + + 1 file changed, 1 insertion(+) + +--------------------------------------------------- +2014-01-07 23:57:36 +0000 Tony Finch <d...@dotat.at> + +win32: another try at working around lack of _TRUNCATE + + win32/unifdef.h | 2 -- + win32/win32.c | 16 +++++++++++++++- + 2 files changed, 15 insertions(+), 3 deletions(-) + +--------------------------------------------------- +2014-01-07 23:42:00 +0000 Tony Finch <d...@dotat.at> + +win32: need crtdefs.h? + + win32/unifdef.h | 2 ++ + 1 file changed, 2 insertions(+) + +--------------------------------------------------- +2014-01-07 22:45:47 +0000 Tony Finch <d...@dotat.at> + +win32: correct variable name in snprintf() + + win32/win32.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--------------------------------------------------- +2014-01-07 22:32:21 +0000 Tony Finch <d...@dotat.at> + +unifdef: cleaner exit status handling + + unifdef.c | 16 ++++++---------- + 1 file changed, 6 insertions(+), 10 deletions(-) + +--------------------------------------------------- +2014-01-07 20:41:07 +0000 Tony Finch <d...@dotat.at> + +unifdef: do not needlessly modify files when updating in place + +If unifdef made no changes, leave the original input file +in place and delete the temporary working copy. + +Inspired by http://trac.webkit.org/changeset/156877 + + tests/overunchanged.experr | 0 + tests/overunchanged.expout | 0 + tests/overunchanged.exprc | 1 + + tests/overunchanged.sh | 8 ++++++++ + unifdef.1 | 2 ++ + unifdef.c | 13 ++++++++++++- + 6 files changed, 23 insertions(+), 1 deletion(-) + +--------------------------------------------------- +2014-01-07 20:24:11 +0000 Tony Finch <d...@dotat.at> + +unifdef: correct exit status when lines are modified but not deleted + + tests/exitstat.c | 3 +++ + tests/exitstat.experr | 0 + tests/exitstat.expout | 3 +++ + tests/exitstat.exprc | 1 + + tests/exitstat.sh | 1 + + unifdef.c | 1 + + 6 files changed, 9 insertions(+) + +--------------------------------------------------- +2014-01-07 20:02:18 +0000 Tony Finch <d...@dotat.at> + +tests: NetBSD pr#47068 + + tests/NetBSD-47068.c | 2 ++ + tests/NetBSD-47068.experr | 0 + tests/NetBSD-47068.expout | 2 ++ + tests/NetBSD-47068.exprc | 1 + + tests/NetBSD-47068.sh | 1 + + 5 files changed, 6 insertions(+) + +--------------------------------------------------- +2014-01-07 19:16:02 +0000 Tony Finch <d...@dotat.at> (tag: unifdef-2.10) web: update for unifdef-2.10 release @@ -40,7 +419,7 @@ 6 files changed, 7 insertions(+), 3 deletions(-) --------------------------------------------------- -2014-01-06 10:51:56 +0000 Tony Finch <d...@dotat.at> (github/master) +2014-01-06 10:51:56 +0000 Tony Finch <d...@dotat.at> scripts: make release more verbose @@ -196,7 +575,8 @@ 1 file changed, 5 insertions(+), 5 deletions(-) --------------------------------------------------- -2013-05-10 00:16:01 +0200 Ruediger Meier <ruediger.me...@ga-group.nl> +2013-05-10 00:16:01 +0200 Ruediger Meier <ruediger.me...@ga-group.nl> +(github/pull/4) travis-ci: fix release traget by git cloning with infinite depth diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/README new/unifdef-2.11/README --- old/unifdef-2.10/README 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/README 2015-12-03 13:12:04.000000000 +0100 @@ -44,6 +44,9 @@ Steve Underwood <ste...@coppice.org> - read #define and #undef directives from a file +Brian Ginsbach <ginsb...@netbsd.org> + - improved expression evaluator + Other contributions are listed in the Changelog. - end - diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/NetBSD-47068.c new/unifdef-2.11/tests/NetBSD-47068.c --- old/unifdef-2.10/tests/NetBSD-47068.c 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/NetBSD-47068.c 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,2 @@ +#ifdef foo +#endif \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/NetBSD-47068.expout new/unifdef-2.11/tests/NetBSD-47068.expout --- old/unifdef-2.10/tests/NetBSD-47068.expout 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/NetBSD-47068.expout 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,2 @@ +#ifdef foo +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/NetBSD-47068.exprc new/unifdef-2.11/tests/NetBSD-47068.exprc --- old/unifdef-2.10/tests/NetBSD-47068.exprc 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/NetBSD-47068.exprc 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/NetBSD-47068.sh new/unifdef-2.11/tests/NetBSD-47068.sh --- old/unifdef-2.10/tests/NetBSD-47068.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/NetBSD-47068.sh 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +unifdef -Ubar NetBSD-47068.c diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/defundef-broken2.experr new/unifdef-2.11/tests/defundef-broken2.experr --- old/unifdef-2.10/tests/defundef-broken2.experr 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/tests/defundef-broken2.experr 2015-12-03 13:12:04.000000000 +0100 @@ -1,2 +1,2 @@ -unifdef: broken2.h: 1: missing macro name in #define -unifdef: output may be truncated +unifdef: broken2.h: 1: Missing macro name in #define +unifdef: Output may be truncated diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/defundef-broken3.experr new/unifdef-2.11/tests/defundef-broken3.experr --- old/unifdef-2.10/tests/defundef-broken3.experr 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/tests/defundef-broken3.experr 2015-12-03 13:12:04.000000000 +0100 @@ -1,2 +1,2 @@ -unifdef: broken3.h: 1: missing macro name in #undef -unifdef: output may be truncated +unifdef: broken3.h: 1: Missing macro name in #undef +unifdef: Output may be truncated diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/defundef-broken4.experr new/unifdef-2.11/tests/defundef-broken4.experr --- old/unifdef-2.10/tests/defundef-broken4.experr 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/tests/defundef-broken4.experr 2015-12-03 13:12:04.000000000 +0100 @@ -1,2 +1,2 @@ unifdef: broken4.h: 1: Obfuscated preprocessor control line -unifdef: output may be truncated +unifdef: Output may be truncated diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/div.c new/unifdef-2.11/tests/div.c --- old/unifdef-2.10/tests/div.c 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/div.c 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,3 @@ +#if 10 / DENOM +DIVISION +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/div.expout new/unifdef-2.11/tests/div.expout --- old/unifdef-2.10/tests/div.expout 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/div.expout 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,10 @@ +undef +#if 10 / DENOM +DIVISION +#endif +one +DIVISION +zero +#if 10 / DENOM +DIVISION +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/div.exprc new/unifdef-2.11/tests/div.exprc --- old/unifdef-2.10/tests/div.exprc 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/div.exprc 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/div.sh new/unifdef-2.11/tests/div.sh --- old/unifdef-2.10/tests/div.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/div.sh 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,10 @@ +echo undef +if ! unifdef div.c +then unifdef -d div.c +fi +echo one +unifdef -DDENOM div.c +echo zero +if ! unifdef -UDENOM div.c +then unifdef -d -UDENOM div.c +fi diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/error.c new/unifdef-2.11/tests/error.c --- old/unifdef-2.10/tests/error.c 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/error.c 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,4 @@ +#if FOO != 5 +#error +#endif +bar diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/error.expout new/unifdef-2.11/tests/error.expout --- old/unifdef-2.10/tests/error.expout 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/error.expout 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,2 @@ +#error +bar diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/error.exprc new/unifdef-2.11/tests/error.exprc --- old/unifdef-2.10/tests/error.exprc 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/error.exprc 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/error.sh new/unifdef-2.11/tests/error.sh --- old/unifdef-2.10/tests/error.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/error.sh 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +unifdef -DFOO=1 error.c diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/exitstat.c new/unifdef-2.11/tests/exitstat.c --- old/unifdef-2.10/tests/exitstat.c 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/exitstat.c 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,3 @@ +#if FALSE +#elif TRUE +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/exitstat.expout new/unifdef-2.11/tests/exitstat.expout --- old/unifdef-2.10/tests/exitstat.expout 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/exitstat.expout 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,3 @@ +#if FALSE +#else +#endif diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/exitstat.exprc new/unifdef-2.11/tests/exitstat.exprc --- old/unifdef-2.10/tests/exitstat.exprc 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/exitstat.exprc 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/exitstat.sh new/unifdef-2.11/tests/exitstat.sh --- old/unifdef-2.10/tests/exitstat.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/exitstat.sh 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +unifdef -DTRUE=1 exitstat.c diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/if5-a.expout new/unifdef-2.11/tests/if5-a.expout --- old/unifdef-2.10/tests/if5-a.expout 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/tests/if5-a.expout 2015-12-03 13:12:04.000000000 +0100 @@ -17,6 +17,14 @@ int foo6() { return 0; } +int foo7() { return 0; } + +int foo8() { return 0; } + +int foo9() { return 0; } + +int foo10() { return 0; } + int main() { foo1(); @@ -25,4 +33,8 @@ foo4(); foo5(); foo6(); + foo7(); + foo8(); + foo9(); + foo10(); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/if5.c new/unifdef-2.11/tests/if5.c --- old/unifdef-2.10/tests/if5.c 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/tests/if5.c 2015-12-03 13:12:04.000000000 +0100 @@ -41,6 +41,30 @@ int foo6() { return 0; } #endif +#if FOO > FOOB +#error FOO is greater than FOOB +#else +int foo7() { return 0; } +#endif + +#if FOOB < FOO +#error FOOB is less than FOO +#else +int foo8() { return 0; } +#endif + +#if FOO >= FOOB +#error FOO is greater than or equal FOOB +#else +int foo9() { return 0; } +#endif + +#if FOOB <= FOO +#error FOOB is less than or equal FOO +#else +int foo10() { return 0; } +#endif + int main() { foo1(); @@ -49,4 +73,8 @@ foo4(); foo5(); foo6(); + foo7(); + foo8(); + foo9(); + foo10(); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/if5.expout new/unifdef-2.11/tests/if5.expout --- old/unifdef-2.10/tests/if5.expout 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/tests/if5.expout 2015-12-03 13:12:04.000000000 +0100 @@ -17,6 +17,14 @@ int foo6() { return 0; } +int foo7() { return 0; } + +int foo8() { return 0; } + +int foo9() { return 0; } + +int foo10() { return 0; } + int main() { foo1(); @@ -25,4 +33,8 @@ foo4(); foo5(); foo6(); + foo7(); + foo8(); + foo9(); + foo10(); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/if7.c new/unifdef-2.11/tests/if7.c --- old/unifdef-2.10/tests/if7.c 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/if7.c 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,94 @@ +/* +Distributed under the two-clause BSD licence; +see the COPYING file for details. */ + +#include <stdio.h> +#include <stdlib.h> + +#if (FOOB | FOO) == 43 +int foo1() { return 0; } +#else +#error FOOB bitwise-or FOO is not 43 +#endif + +#if (FOO ^ FOO) == 0 +int foo2() { return 0; } +#else +#error FOO bitwise-xor FOO is not 0 +#endif + +#if (FOOB & 2) == 2 +int foo3() { return 0; } +#else +#error FOOB bitwise-and 2 is not 2 +#endif + +#if (FOO << 1) == 2 +int foo4() { return 0; } +#else +#error FOO left-shift 2 is not 2 +#endif + +#if (FOOB >> 4) == 2 +int foo5() { return 0; } +#else +#error FOOB right-shift 2 is not 2 +#endif + +#if (FOOB + FOO) == 43 +int foo6() { return 0; } +#else +#error FOOB add FOO is not 43 +#endif + +#if (FOOB - FOO) == 41 +int foo7() { return 0; } +#else +#error FOOB subtract FOO is not 41 +#endif + +#if (FOOB * 2) == 84 +int foo8() { return 0; } +#else +#error FOOB multiply 2 is not 84 +#endif + +#if (FOOB / 2) == 21 +int foo9() { return 0; } +#else +#error FOOB divided 2 is not 21 +#endif + +#if (FOOB % FOO) == 0 +int foo10() { return 0; } +#else +#error FOOB modulo FOO is not 0 +#endif + +#if ~(FOOB) == -43 +int foo11() { return 0; } +#else +#error bitwise-not FOOB is not -43 +#endif + +#if -(FOOB) == -42 +int foo12() { return 0; } +#else +#error negate FOOB is not -42 +#endif + +int main() +{ + foo1(); + foo2(); + foo3(); + foo4(); + foo5(); + foo6(); + foo7(); + foo8(); + foo9(); + foo10(); + foo11(); + foo12(); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/if7.expout new/unifdef-2.11/tests/if7.expout --- old/unifdef-2.10/tests/if7.expout 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/if7.expout 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,46 @@ +/* +Distributed under the two-clause BSD licence; +see the COPYING file for details. */ + +#include <stdio.h> +#include <stdlib.h> + +int foo1() { return 0; } + +int foo2() { return 0; } + +int foo3() { return 0; } + +int foo4() { return 0; } + +int foo5() { return 0; } + +int foo6() { return 0; } + +int foo7() { return 0; } + +int foo8() { return 0; } + +int foo9() { return 0; } + +int foo10() { return 0; } + +int foo11() { return 0; } + +int foo12() { return 0; } + +int main() +{ + foo1(); + foo2(); + foo3(); + foo4(); + foo5(); + foo6(); + foo7(); + foo8(); + foo9(); + foo10(); + foo11(); + foo12(); +} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/if7.exprc new/unifdef-2.11/tests/if7.exprc --- old/unifdef-2.10/tests/if7.exprc 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/if7.exprc 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/if7.sh new/unifdef-2.11/tests/if7.sh --- old/unifdef-2.10/tests/if7.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/if7.sh 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +unifdef -DFOO=1 -DFOOB=42 -UBAR if7.c diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/overunchanged.exprc new/unifdef-2.11/tests/overunchanged.exprc --- old/unifdef-2.10/tests/overunchanged.exprc 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/overunchanged.exprc 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1 @@ +0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/overunchanged.sh new/unifdef-2.11/tests/overunchanged.sh --- old/unifdef-2.10/tests/overunchanged.sh 1970-01-01 01:00:00.000000000 +0100 +++ new/unifdef-2.11/tests/overunchanged.sh 2015-12-03 13:12:04.000000000 +0100 @@ -0,0 +1,8 @@ +cp if1.c overunchanged.c +ls -i overunchanged.c >overunchanged-before +unifdef -DWEASEL=1 -ooverunchanged.c overunchanged.c +e=$? +ls -i overunchanged.c >overunchanged-after +diff overunchanged-before overunchanged-after +rm -f overunchanged-before overunchanged-after overunchanged.c +exit $e diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/recursive.experr new/unifdef-2.11/tests/recursive.experr --- old/unifdef-2.10/tests/recursive.experr 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/tests/recursive.experr 2015-12-03 13:12:04.000000000 +0100 @@ -40,7 +40,13 @@ unifdef: eval1 unifdef: eval2 unifdef: eval3 -unifdef: eval4 symbol +unifdef: eval4 +unifdef: eval5 +unifdef: eval6 +unifdef: eval7 +unifdef: eval8 +unifdef: eval9 +unifdef: eval10 symbol unifdef: findsym FOO=BAR unifdef: eval = 0 unifdef: parser line 8 state NO comment START line @@ -61,7 +67,13 @@ unifdef: eval1 unifdef: eval2 unifdef: eval3 -unifdef: eval4 symbol +unifdef: eval4 +unifdef: eval5 +unifdef: eval6 +unifdef: eval7 +unifdef: eval8 +unifdef: eval9 +unifdef: eval10 symbol unifdef: findsym BAR=BAR unifdef: eval = 0 unifdef: parser line 14 state NO comment START line @@ -74,7 +86,13 @@ unifdef: eval1 unifdef: eval2 unifdef: eval3 -unifdef: eval4 symbol +unifdef: eval4 +unifdef: eval5 +unifdef: eval6 +unifdef: eval7 +unifdef: eval8 +unifdef: eval9 +unifdef: eval10 symbol unifdef: findsym FOO=BAR unifdef: eval = 0 unifdef: parser line 16 state NO comment START line diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/tests/whitespace-1.experr new/unifdef-2.11/tests/whitespace-1.experr --- old/unifdef-2.10/tests/whitespace-1.experr 2014-01-07 20:18:31.000000000 +0100 +++ new/unifdef-2.11/tests/whitespace-1.experr 2015-12-03 13:12:04.000000000 +0100 @@ -1,2 +1,2 @@ unifdef: whitespace.c: 3: Obfuscated preprocessor control line (#if line 1 depth 1) -unifdef: output may be truncated +unifdef: Output may be truncated diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/unifdef.1 new/unifdef-2.11/unifdef.1 --- old/unifdef-2.10/unifdef.1 2014-01-07 20:18:31.000000000 +0100 +++ new/unifdef-2.11/unifdef.1 2015-12-03 13:12:04.000000000 +0100 @@ -1,6 +1,6 @@ .\" Copyright (c) 1985, 1991, 1993 .\" The Regents of the University of California. All rights reserved. -.\" Copyright (c) 2002 - 2013 Tony Finch <d...@dotat.at>. All rights reserved. +.\" Copyright (c) 2002 - 2015 Tony Finch <d...@dotat.at>. All rights reserved. .\" .\" This code is derived from software contributed to Berkeley by .\" Dave Yost. It was rewritten to support ANSI C by Tony Finch. @@ -29,7 +29,7 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd January 7, 2014 +.Dd December 3, 2015 .Dt UNIFDEF 1 PRM .Os " " .Sh NAME @@ -120,10 +120,13 @@ .Fn defined operator, the operators -.Ic \&! , < , > , -.Ic <= , >= , == , != , +.Ic \&! , ~ , - +(unary), +.Ic * , / , % , + , - , +.Ic < , <= , > , >= , == , != , & , ^ , \&| , .Ic && , || , and parenthesized expressions. +Division by zero is treated as an unknown value. A kind of .Dq "short circuit" evaluation is used for the @@ -251,6 +254,11 @@ Function-like macro definitions (with arguments) are treated as if they are set to 1. .Pp +.Em Warning: +string literals and character constants are not parsed correctly in +.Fl f +files. +.Pp .It Fl b Replace removed lines with blank lines instead of deleting them. @@ -323,12 +331,19 @@ .Pp .It Fl m Modify one or more input files in place. +If an input file is not modified, +the original is preserved instead of being overwritten with an identical copy. .Pp .It Fl M Ar backext Modify input files in place, and keep backups of the original files by appending the .Ar backext to the input filenames. +A zero length +.Ar backext +behaves the same as the +.Fl m +option. .Pp .It Fl n Add @@ -431,23 +446,29 @@ .Sh DIAGNOSTICS .Bl -item .It -Too many levels of nesting. +.Tn EOF +in comment .It Inappropriate .Ic #elif , .Ic #else or -.Ic #endif . +.Ic #endif +.It +Missing macro name in #define or #undef .It -Obfuscated preprocessor control line. +Obfuscated preprocessor control line .It Premature .Tn EOF (with the line number of the most recent unterminated -.Ic #if ) . +.Ic #if ) .It -.Tn EOF -in comment. +Too many levels of nesting +.It +Unrecognized preprocessor directive +.It +Unterminated char or string literal .El .Sh SEE ALSO .Xr cpp 1 , @@ -472,6 +493,12 @@ .Sh BUGS Expression evaluation is very limited. .Pp +Character constants are not evaluated. +String literals and character constants in +.Fl f +definition files are ignored rather than parsed as +part of a macro's replacement tokens. +.Pp Handling one line at a time means preprocessor directives split across more than one physical line (because of comments or backslash-newline) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/unifdef.c new/unifdef-2.11/unifdef.c --- old/unifdef-2.10/unifdef.c 2014-01-07 20:18:31.000000000 +0100 +++ new/unifdef-2.11/unifdef.c 2015-12-03 13:12:04.000000000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002 - 2014 Tony Finch <d...@dotat.at> + * Copyright (c) 2002 - 2015 Tony Finch <d...@dotat.at> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -207,6 +207,7 @@ static int exitmode; /* exit status mode */ static int exitstat; /* program exit status */ +static bool altered; /* was this file modified? */ static void addsym1(bool, bool, char *); static void addsym2(bool, const char *, const char *); @@ -311,7 +312,8 @@ break; case 'M': /* modify in place and keep backup */ inplace = true; - backext = optarg; + if (strlen(optarg) > 0) + backext = optarg; break; case 'n': /* add #line directive after deleted lines */ lnnum = true; @@ -349,6 +351,8 @@ errx(2, "-o cannot be used with multiple input files"); if (argc > 1 && !inplace) errx(2, "multiple input files require -m or -M"); + if (argc == 0 && inplace) + errx(2, "-m requires an input file"); if (argc == 0) argc = 1; if (argc == 1 && !inplace && ofilename == NULL) @@ -415,7 +419,11 @@ err(2, "can't rename \"%s\" to \"%s\"", ofn, backname); free(backname); } - if (replace(tempname, ofn) < 0) + /* leave file unmodified if unifdef made no changes */ + if (!altered && backext == NULL) { + if (remove(tempname) < 0) + warn("can't remove \"%s\"", tempname); + } else if (replace(tempname, ofn) < 0) err(2, "can't rename \"%s\" to \"%s\"", tempname, ofn); free(tempname); tempname = NULL; @@ -637,6 +645,7 @@ { snprintf(keyword, tline + sizeof(tline) - keyword, "%s%s", replacement, newline); + altered = true; print(); } static void @@ -699,7 +708,7 @@ } else { if (lnblank && fputs(newline, output) == EOF) closeio(); - exitstat = 1; + altered = true; delcount += 1; blankcount = 0; } @@ -751,6 +760,7 @@ zerosyms = true; newline = NULL; linenum = 0; + altered = false; while (lineval != LT_EOF) { lineval = parseline(); trans_table[ifstate[depth]][lineval](); @@ -758,6 +768,7 @@ linenum, linetype_name[lineval], ifstate_name[ifstate[depth]], depth); } + exitstat |= altered; } /* @@ -891,6 +902,40 @@ return (*p = 0, LT_FALSE); return op_strict(p, a && b, at, bt); } +static Linetype op_blsh(long *p, Linetype at, long a, Linetype bt, long b) { + return op_strict(p, a << b, at, bt); +} +static Linetype op_brsh(long *p, Linetype at, long a, Linetype bt, long b) { + return op_strict(p, a >> b, at, bt); +} +static Linetype op_add(long *p, Linetype at, long a, Linetype bt, long b) { + return op_strict(p, a + b, at, bt); +} +static Linetype op_sub(long *p, Linetype at, long a, Linetype bt, long b) { + return op_strict(p, a - b, at, bt); +} +static Linetype op_mul(long *p, Linetype at, long a, Linetype bt, long b) { + return op_strict(p, a * b, at, bt); +} +static Linetype op_div(long *p, Linetype at, long a, Linetype bt, long b) { + if (bt != LT_TRUE) { + debug("eval division by zero"); + return (LT_ERROR); + } + return op_strict(p, a / b, at, bt); +} +static Linetype op_mod(long *p, Linetype at, long a, Linetype bt, long b) { + return op_strict(p, a % b, at, bt); +} +static Linetype op_bor(long *p, Linetype at, long a, Linetype bt, long b) { + return op_strict(p, a | b, at, bt); +} +static Linetype op_bxor(long *p, Linetype at, long a, Linetype bt, long b) { + return op_strict(p, a ^ b, at, bt); +} +static Linetype op_band(long *p, Linetype at, long a, Linetype bt, long b) { + return op_strict(p, a & b, at, bt); +} /* * An evaluation function takes three arguments, as follows: (1) a pointer to @@ -914,10 +959,15 @@ * calls the inner function with its first argument pointing to the next * element of the table. Innermost expressions have special non-table-driven * handling. + * + * The stop characters help with lexical analysis: an operator is not + * recognized if it is followed by one of the stop characters because + * that would make it a different operator. */ struct op { const char *str; Linetype (*fn)(long *, Linetype, long, Linetype, long); + const char *stop; }; struct ops { eval_fn *inner; @@ -926,12 +976,22 @@ static const struct ops eval_ops[] = { { eval_table, { { "||", op_or } } }, { eval_table, { { "&&", op_and } } }, + { eval_table, { { "|", op_bor, "|" } } }, + { eval_table, { { "^", op_bxor } } }, + { eval_table, { { "&", op_band, "&" } } }, { eval_table, { { "==", op_eq }, { "!=", op_ne } } }, - { eval_unary, { { "<=", op_le }, + { eval_table, { { "<=", op_le }, { ">=", op_ge }, - { "<", op_lt }, - { ">", op_gt } } } + { "<", op_lt, "<=" }, + { ">", op_gt, ">=" } } }, + { eval_table, { { "<<", op_blsh }, + { ">>", op_brsh } } }, + { eval_table, { { "+", op_add }, + { "-", op_sub } } }, + { eval_unary, { { "*", op_mul }, + { "/", op_div }, + { "%", op_mod } } }, }; /* Current operator precedence level */ @@ -965,6 +1025,26 @@ *valp = !*valp; lt = *valp ? LT_TRUE : LT_FALSE; } + } else if (*cp == '~') { + debug("eval%d ~", prec(ops)); + cp++; + lt = eval_unary(ops, valp, &cp); + if (lt == LT_ERROR) + return (LT_ERROR); + if (lt != LT_IF) { + *valp = ~(*valp); + lt = *valp ? LT_TRUE : LT_FALSE; + } + } else if (*cp == '-') { + debug("eval%d -", prec(ops)); + cp++; + lt = eval_unary(ops, valp, &cp); + if (lt == LT_ERROR) + return (LT_ERROR); + if (lt != LT_IF) { + *valp = -(*valp); + lt = *valp ? LT_TRUE : LT_FALSE; + } } else if (*cp == '(') { cp++; debug("eval%d (", prec(ops)); @@ -1039,7 +1119,7 @@ { const struct op *op; const char *cp; - long val; + long val = 0; Linetype lt, rt; debug("eval%d", prec(ops)); @@ -1049,9 +1129,16 @@ return (LT_ERROR); for (;;) { cp = skipcomment(cp); - for (op = ops->op; op->str != NULL; op++) - if (strncmp(cp, op->str, strlen(op->str)) == 0) - break; + for (op = ops->op; op->str != NULL; op++) { + if (strncmp(cp, op->str, strlen(op->str)) == 0) { + /* assume only one-char operators have stop chars */ + if (op->stop != NULL && cp[1] != '\0' && + strchr(op->stop, cp[1]) != NULL) + continue; + else + break; + } + } if (op->str == NULL) break; cp += strlen(op->str); @@ -1122,10 +1209,14 @@ static const char * skipline(const char *cp) { + const char *pcp; if (*cp != '\0') linestate = LS_DIRTY; - while (*cp != '\0') - cp = skipcomment(cp + 1); + while (*cp != '\0') { + cp = skipcomment(pcp = cp); + if (pcp == cp) + cp++; + } return (cp); } @@ -1201,9 +1292,9 @@ cp += 2; } else if (strncmp(cp, "\n", 1) == 0) { if (incomment == CHAR_LITERAL) - error("unterminated char literal"); + error("Unterminated char literal"); else - error("unterminated string literal"); + error("Unterminated string literal"); } else cp += 1; continue; @@ -1477,7 +1568,7 @@ if ((cp = matchsym("define", kw)) != NULL) { sym = getsym(&cp); if (sym == NULL) - error("missing macro name in #define"); + error("Missing macro name in #define"); if (*cp == '(') { val = "1"; } else { @@ -1489,12 +1580,12 @@ } else if ((cp = matchsym("undef", kw)) != NULL) { sym = getsym(&cp); if (sym == NULL) - error("missing macro name in #undef"); + error("Missing macro name in #undef"); cp = skipcomment(cp); debug("#undef"); addsym2(false, sym, NULL); } else { - error("unrecognized preprocessor directive"); + error("Unrecognized preprocessor directive"); } skipline(cp); done: @@ -1566,5 +1657,5 @@ warnx("%s: %d: %s (#if line %d depth %d)", filename, linenum, msg, stifline[depth], depth); closeio(); - errx(2, "output may be truncated"); + errx(2, "Output may be truncated"); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/unifdef.h new/unifdef-2.11/unifdef.h --- old/unifdef-2.10/unifdef.h 2014-01-07 20:18:31.000000000 +0100 +++ new/unifdef-2.11/unifdef.h 2015-12-03 13:12:04.000000000 +0100 @@ -34,7 +34,7 @@ #include <string.h> #include <unistd.h> -/* portabiity stubs */ +/* portability stubs */ #define fbinmode(fp) (fp) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/unifdef.txt new/unifdef-2.11/unifdef.txt --- old/unifdef-2.10/unifdef.txt 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/unifdef.txt 2015-12-03 13:12:04.000000000 +0100 @@ -28,12 +28,13 @@ It understands a commonly-used subset of the expression syntax for #if and #elif lines: integer constants, integer values of macros defined on - the command line, the defined() operator, the operators !, <, >, <=, >=, - ==, !=, &&, ||, and parenthesized expressions. A kind of ``short - circuit'' evaluation is used for the && operator: if either operand is - definitely false then the result is false, even if the value of the other - operand is unknown. Similarly, if either operand of || is definitely - true then the result is true. + the command line, the defined() operator, the operators !, ~, - (unary), + *, /, %, +, -, <, <=, >, >=, ==, !=, &, ^, |, &&, ||, and parenthesized + expressions. Division by zero is treated as an unknown value. A kind of + ``short circuit'' evaluation is used for the && operator: if either oper- + and is definitely false then the result is false, even if the value of + the other operand is unknown. Similarly, if either operand of || is def- + initely true then the result is true. When evaluating an expression, unifdef does not expand macros first. The value of a macro must be a simple number, not an expression. A limited @@ -87,6 +88,9 @@ tion-like macro definitions (with arguments) are treated as if they are set to 1. + Warning: string literals and character constants are not parsed + correctly in -f files. + -b Replace removed lines with blank lines instead of deleting them. Mutually exclusive with the -B option. @@ -121,11 +125,14 @@ would be rude to strip them out, just as it would be for normal comments. - -m Modify one or more input files in place. + -m Modify one or more input files in place. If an input file is not + modified, the original is preserved instead of being overwritten + with an identical copy. -M backext Modify input files in place, and keep backups of the original - files by appending the backext to the input filenames. + files by appending the backext to the input filenames. A zero + length backext behaves the same as the -m option. -n Add #line directives to the output following any deleted lines, so that errors produced when compiling the output file correspond @@ -177,15 +184,21 @@ The exit status is 0 if the -h or -V command line options are given. DIAGNOSTICS - Too many levels of nesting. + EOF in comment + + Inappropriate #elif, #else or #endif + + Missing macro name in #define or #undef - Inappropriate #elif, #else or #endif. + Obfuscated preprocessor control line - Obfuscated preprocessor control line. + Premature EOF (with the line number of the most recent unterminated #if) - Premature EOF (with the line number of the most recent unterminated #if). + Too many levels of nesting - EOF in comment. + Unrecognized preprocessor directive + + Unterminated char or string literal SEE ALSO cpp(1), diff(1) @@ -203,6 +216,10 @@ BUGS Expression evaluation is very limited. + Character constants are not evaluated. String literals and character + constants in -f definition files are ignored rather than parsed as part + of a macro's replacement tokens. + Handling one line at a time means preprocessor directives split across more than one physical line (because of comments or backslash-newline) cannot be handled in every situation. @@ -215,4 +232,4 @@ The text-mode and ignore functionality does not correspond to modern cpp(1) behaviour. - January 7, 2014 + December 3, 2015 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/version.h new/unifdef-2.11/version.h --- old/unifdef-2.10/version.h 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/version.h 2015-12-03 13:12:04.000000000 +0100 @@ -1,2 +1,2 @@ -"@(#) $Version: unifdef-2.10 $\n" -"@(#) $Date: 2014-01-07 19:16:02 +0000 $\n" +"@(#) $Version: unifdef-2.11 $\n" +"@(#) $Date: 2015-12-03 12:10:08 +0000 $\n" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/version.sh new/unifdef-2.11/version.sh --- old/unifdef-2.10/version.sh 2014-01-07 20:18:30.000000000 +0100 +++ new/unifdef-2.11/version.sh 2015-12-03 13:12:04.000000000 +0100 @@ -1,2 +1,2 @@ -V="unifdef-2.10" -D="2014-01-07 19:16:02 +0000" +V="unifdef-2.11" +D="2015-12-03 12:10:08 +0000" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/win32/Makefile.mingw new/unifdef-2.11/win32/Makefile.mingw --- old/unifdef-2.10/win32/Makefile.mingw 2014-01-07 20:18:31.000000000 +0100 +++ new/unifdef-2.11/win32/Makefile.mingw 2015-12-03 13:12:04.000000000 +0100 @@ -4,4 +4,11 @@ all: unifdef.exe unifdef.exe: unifdef.c win32/win32.c FreeBSD/getopt.c FreeBSD/err.c - $(CC) $(CFLAGS) -Iwin32 -I. -I- -o $@ $^ + cd win32 && \ + cp ../unifdef.c ../version.h . && \ + $(CC) $(CFLAGS) $(LDFLAGS) -I. -o ../unifdef.exe unifdef.c \ + win32.c ../FreeBSD/getopt.c ../FreeBSD/err.c && \ + rm -f unifdef.c version.h + +test: unifdef.exe + scripts/runtests.sh tests diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/win32/unifdef.h new/unifdef-2.11/win32/unifdef.h --- old/unifdef-2.10/win32/unifdef.h 2014-01-07 20:18:31.000000000 +0100 +++ new/unifdef-2.11/win32/unifdef.h 2015-12-03 13:12:04.000000000 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 - 2014 Tony Finch <d...@dotat.at> + * Copyright (c) 2012 - 2015 Tony Finch <d...@dotat.at> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,10 +23,16 @@ * SUCH DAMAGE. */ +/* Stop being stupid about POSIX functions */ +#define _CRT_SECURE_NO_WARNINGS +#define _SCL_SECURE_NO_WARNINGS +#define _CRT_NONSTDC_NO_WARNINGS + #include <ctype.h> #include <errno.h> #include <stdarg.h> #include <stdio.h> +#include <stdint.h> #include <stdlib.h> #include <string.h> @@ -50,6 +56,7 @@ int replace(const char *old, const char *new); FILE *mktempmode(char *tmp, int mode); FILE *fbinmode(FILE *fp); +int snprintf(char *buf, size_t buflen, const char *format, ...); /* err.c */ void err(int, const char *, ...); diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/unifdef-2.10/win32/win32.c new/unifdef-2.11/win32/win32.c --- old/unifdef-2.10/win32/win32.c 2014-01-07 20:18:31.000000000 +0100 +++ new/unifdef-2.11/win32/win32.c 2015-12-03 13:12:04.000000000 +0100 @@ -53,23 +53,35 @@ } /* - * While Windows has _snprintf() it does not work like real snprintf(). + * Windows has _snprintf() but it does not work like real snprintf(). */ -int snprintf(char *buf, size_t size, const char *format, ...) +int snprintf(char *buf, size_t buflen, const char *format, ...) { va_list ap; - int count = -1; + int outlen, cpylen, tmplen; + char *tmp; - if (size > 0) { - va_start(ap, format); - count = _vsnprintf_s(str, size, _TRUNCATE, format, ap); - va_end(ap); - } - if (count < 0) { - va_start(ap, format); - count = _vscprintf(format, ap); - va_end(ap); - } + va_start(ap, format); + outlen = _vscprintf(format, ap); + va_end(ap); + if (buflen == 0 || outlen < 0) + return outlen; + if (buflen > outlen) + cpylen = outlen; + else + cpylen = buflen - 1; + /* Paranoia about off-by-one errors in _snprintf() */ + tmplen = outlen + 2; - return count; + tmp = malloc(tmplen); + if (tmp == NULL) + err(2, "malloc"); + va_start(ap, format); + _vsnprintf(tmp, tmplen, format, ap); + va_end(ap); + memcpy(buf, tmp, cpylen); + buf[cpylen] = '\0'; + free(tmp); + + return outlen; }