diff options
| author | Tony Finch <dot@dotat.at> | 2009-11-27 10:50:30 -0500 |
|---|---|---|
| committer | Michal Marek <mmarek@suse.cz> | 2009-12-12 07:08:16 -0500 |
| commit | d8379ab1dde371f13d7fdddf05346840a82c2b61 (patch) | |
| tree | 73b0efd874b60918169169391372d10036929b5d /scripts | |
| parent | eb8f844c0a41c4529a7d06b7801296eca9ae67aa (diff) | |
unifdef: update to upstream revision 1.190
Fix handling of input files (e.g. with no newline at EOF) that could
make unifdef get into an unexpected state and call abort().
The new -B option compresses blank lines around a deleted section
so that blank lines around "paragraphs" of code don't get doubled.
The evaluator can now handle macros with arguments, and unbracketed
arguments to the "defined" operator.
Add myself to MAINTAINERS for unifdef.
Signed-off-by: Tony Finch <dot@dotat.at>
Acked-by: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Michal Marek <mmarek@suse.cz>
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/unifdef.c | 341 |
1 files changed, 207 insertions, 134 deletions
diff --git a/scripts/unifdef.c b/scripts/unifdef.c index 30d459fb0709..44d39785e50d 100644 --- a/scripts/unifdef.c +++ b/scripts/unifdef.c | |||
| @@ -1,13 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | * Copyright (c) 2002 - 2005 Tony Finch <dot@dotat.at>. All rights reserved. | 2 | * Copyright (c) 2002 - 2009 Tony Finch <dot@dotat.at> |
| 3 | * | ||
| 4 | * This code is derived from software contributed to Berkeley by Dave Yost. | ||
| 5 | * It was rewritten to support ANSI C by Tony Finch. The original version of | ||
| 6 | * unifdef carried the following copyright notice. None of its code remains | ||
| 7 | * in this version (though some of the names remain). | ||
| 8 | * | ||
| 9 | * Copyright (c) 1985, 1993 | ||
| 10 | * The Regents of the University of California. All rights reserved. | ||
| 11 | * | 3 | * |
| 12 | * Redistribution and use in source and binary forms, with or without | 4 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions | 5 | * modification, are permitted provided that the following conditions |
| @@ -31,23 +23,20 @@ | |||
| 31 | * SUCH DAMAGE. | 23 | * SUCH DAMAGE. |
| 32 | */ | 24 | */ |
| 33 | 25 | ||
| 34 | #include <sys/cdefs.h> | 26 | /* |
| 27 | * This code was derived from software contributed to Berkeley by Dave Yost. | ||
| 28 | * It was rewritten to support ANSI C by Tony Finch. The original version | ||
| 29 | * of unifdef carried the 4-clause BSD copyright licence. None of its code | ||
| 30 | * remains in this version (though some of the names remain) so it now | ||
| 31 | * carries a more liberal licence. | ||
| 32 | * | ||
| 33 | * The latest version is available from http://dotat.at/prog/unifdef | ||
| 34 | */ | ||
| 35 | 35 | ||
| 36 | #ifndef lint | 36 | static const char * const copyright[] = { |
| 37 | #if 0 | 37 | "@(#) Copyright (c) 2002 - 2009 Tony Finch <dot@dotat.at>\n", |
| 38 | static const char copyright[] = | 38 | "$dotat: unifdef/unifdef.c,v 1.190 2009/11/27 17:21:26 fanf2 Exp $", |
| 39 | "@(#) Copyright (c) 1985, 1993\n\ | 39 | }; |
| 40 | The Regents of the University of California. All rights reserved.\n"; | ||
| 41 | #endif | ||
| 42 | #ifdef __IDSTRING | ||
| 43 | __IDSTRING(Berkeley, "@(#)unifdef.c 8.1 (Berkeley) 6/6/93"); | ||
| 44 | __IDSTRING(NetBSD, "$NetBSD: unifdef.c,v 1.8 2000/07/03 02:51:36 matt Exp $"); | ||
| 45 | __IDSTRING(dotat, "$dotat: things/unifdef.c,v 1.171 2005/03/08 12:38:48 fanf2 Exp $"); | ||
| 46 | #endif | ||
| 47 | #endif /* not lint */ | ||
| 48 | #ifdef __FBSDID | ||
| 49 | __FBSDID("$FreeBSD: /repoman/r/ncvs/src/usr.bin/unifdef/unifdef.c,v 1.20 2005/05/21 09:55:09 ru Exp $"); | ||
| 50 | #endif | ||
| 51 | 40 | ||
| 52 | /* | 41 | /* |
| 53 | * unifdef - remove ifdef'ed lines | 42 | * unifdef - remove ifdef'ed lines |
| @@ -72,8 +61,6 @@ __FBSDID("$FreeBSD: /repoman/r/ncvs/src/usr.bin/unifdef/unifdef.c,v 1.20 2005/05 | |||
| 72 | #include <string.h> | 61 | #include <string.h> |
| 73 | #include <unistd.h> | 62 | #include <unistd.h> |
| 74 | 63 | ||
| 75 | size_t strlcpy(char *dst, const char *src, size_t siz); | ||
| 76 | |||
| 77 | /* types of input lines: */ | 64 | /* types of input lines: */ |
| 78 | typedef enum { | 65 | typedef enum { |
| 79 | LT_TRUEI, /* a true #if with ignore flag */ | 66 | LT_TRUEI, /* a true #if with ignore flag */ |
| @@ -90,6 +77,7 @@ typedef enum { | |||
| 90 | LT_DODGY_LAST = LT_DODGY + LT_ENDIF, | 77 | LT_DODGY_LAST = LT_DODGY + LT_ENDIF, |
| 91 | LT_PLAIN, /* ordinary line */ | 78 | LT_PLAIN, /* ordinary line */ |
| 92 | LT_EOF, /* end of file */ | 79 | LT_EOF, /* end of file */ |
| 80 | LT_ERROR, /* unevaluable #if */ | ||
| 93 | LT_COUNT | 81 | LT_COUNT |
| 94 | } Linetype; | 82 | } Linetype; |
| 95 | 83 | ||
| @@ -100,7 +88,7 @@ static char const * const linetype_name[] = { | |||
| 100 | "DODGY IF", "DODGY TRUE", "DODGY FALSE", | 88 | "DODGY IF", "DODGY TRUE", "DODGY FALSE", |
| 101 | "DODGY ELIF", "DODGY ELTRUE", "DODGY ELFALSE", | 89 | "DODGY ELIF", "DODGY ELTRUE", "DODGY ELFALSE", |
| 102 | "DODGY ELSE", "DODGY ENDIF", | 90 | "DODGY ELSE", "DODGY ENDIF", |
| 103 | "PLAIN", "EOF" | 91 | "PLAIN", "EOF", "ERROR" |
| 104 | }; | 92 | }; |
| 105 | 93 | ||
| 106 | /* state of #if processing */ | 94 | /* state of #if processing */ |
| @@ -168,11 +156,13 @@ static char const * const linestate_name[] = { | |||
| 168 | * Globals. | 156 | * Globals. |
| 169 | */ | 157 | */ |
| 170 | 158 | ||
| 159 | static bool compblank; /* -B: compress blank lines */ | ||
| 160 | static bool lnblank; /* -b: blank deleted lines */ | ||
| 171 | static bool complement; /* -c: do the complement */ | 161 | static bool complement; /* -c: do the complement */ |
| 172 | static bool debugging; /* -d: debugging reports */ | 162 | static bool debugging; /* -d: debugging reports */ |
| 173 | static bool iocccok; /* -e: fewer IOCCC errors */ | 163 | static bool iocccok; /* -e: fewer IOCCC errors */ |
| 164 | static bool strictlogic; /* -K: keep ambiguous #ifs */ | ||
| 174 | static bool killconsts; /* -k: eval constant #ifs */ | 165 | static bool killconsts; /* -k: eval constant #ifs */ |
| 175 | static bool lnblank; /* -l: blank deleted lines */ | ||
| 176 | static bool lnnum; /* -n: add #line directives */ | 166 | static bool lnnum; /* -n: add #line directives */ |
| 177 | static bool symlist; /* -s: output symbol list */ | 167 | static bool symlist; /* -s: output symbol list */ |
| 178 | static bool text; /* -t: this is a text file */ | 168 | static bool text; /* -t: this is a text file */ |
| @@ -196,7 +186,9 @@ static bool ignoring[MAXDEPTH]; /* ignore comments state */ | |||
| 196 | static int stifline[MAXDEPTH]; /* start of current #if */ | 186 | static int stifline[MAXDEPTH]; /* start of current #if */ |
| 197 | static int depth; /* current #if nesting */ | 187 | static int depth; /* current #if nesting */ |
| 198 | static int delcount; /* count of deleted lines */ | 188 | static int delcount; /* count of deleted lines */ |
| 199 | static bool keepthis; /* don't delete constant #if */ | 189 | static unsigned blankcount; /* count of blank lines */ |
| 190 | static unsigned blankmax; /* maximum recent blankcount */ | ||
| 191 | static bool constexpr; /* constant #if expression */ | ||
| 200 | 192 | ||
| 201 | static int exitstat; /* program exit status */ | 193 | static int exitstat; /* program exit status */ |
| 202 | 194 | ||
| @@ -206,13 +198,14 @@ static void done(void); | |||
| 206 | static void error(const char *); | 198 | static void error(const char *); |
| 207 | static int findsym(const char *); | 199 | static int findsym(const char *); |
| 208 | static void flushline(bool); | 200 | static void flushline(bool); |
| 209 | static Linetype get_line(void); | 201 | static Linetype parseline(void); |
| 210 | static Linetype ifeval(const char **); | 202 | static Linetype ifeval(const char **); |
| 211 | static void ignoreoff(void); | 203 | static void ignoreoff(void); |
| 212 | static void ignoreon(void); | 204 | static void ignoreon(void); |
| 213 | static void keywordedit(const char *); | 205 | static void keywordedit(const char *); |
| 214 | static void nest(void); | 206 | static void nest(void); |
| 215 | static void process(void); | 207 | static void process(void); |
| 208 | static const char *skipargs(const char *); | ||
| 216 | static const char *skipcomment(const char *); | 209 | static const char *skipcomment(const char *); |
| 217 | static const char *skipsym(const char *); | 210 | static const char *skipsym(const char *); |
| 218 | static void state(Ifstate); | 211 | static void state(Ifstate); |
| @@ -220,7 +213,7 @@ static int strlcmp(const char *, const char *, size_t); | |||
| 220 | static void unnest(void); | 213 | static void unnest(void); |
| 221 | static void usage(void); | 214 | static void usage(void); |
| 222 | 215 | ||
| 223 | #define endsym(c) (!isalpha((unsigned char)c) && !isdigit((unsigned char)c) && c != '_') | 216 | #define endsym(c) (!isalnum((unsigned char)c) && c != '_') |
| 224 | 217 | ||
| 225 | /* | 218 | /* |
| 226 | * The main program. | 219 | * The main program. |
| @@ -230,7 +223,7 @@ main(int argc, char *argv[]) | |||
| 230 | { | 223 | { |
| 231 | int opt; | 224 | int opt; |
| 232 | 225 | ||
| 233 | while ((opt = getopt(argc, argv, "i:D:U:I:cdeklnst")) != -1) | 226 | while ((opt = getopt(argc, argv, "i:D:U:I:BbcdeKklnst")) != -1) |
| 234 | switch (opt) { | 227 | switch (opt) { |
| 235 | case 'i': /* treat stuff controlled by these symbols as text */ | 228 | case 'i': /* treat stuff controlled by these symbols as text */ |
| 236 | /* | 229 | /* |
| @@ -255,6 +248,13 @@ main(int argc, char *argv[]) | |||
| 255 | case 'I': | 248 | case 'I': |
| 256 | /* no-op for compatibility with cpp */ | 249 | /* no-op for compatibility with cpp */ |
| 257 | break; | 250 | break; |
| 251 | case 'B': /* compress blank lines around removed section */ | ||
| 252 | compblank = true; | ||
| 253 | break; | ||
| 254 | case 'b': /* blank deleted lines instead of omitting them */ | ||
| 255 | case 'l': /* backwards compatibility */ | ||
| 256 | lnblank = true; | ||
| 257 | break; | ||
| 258 | case 'c': /* treat -D as -U and vice versa */ | 258 | case 'c': /* treat -D as -U and vice versa */ |
| 259 | complement = true; | 259 | complement = true; |
| 260 | break; | 260 | break; |
| @@ -264,12 +264,12 @@ main(int argc, char *argv[]) | |||
| 264 | case 'e': /* fewer errors from dodgy lines */ | 264 | case 'e': /* fewer errors from dodgy lines */ |
| 265 | iocccok = true; | 265 | iocccok = true; |
| 266 | break; | 266 | break; |
| 267 | case 'K': /* keep ambiguous #ifs */ | ||
| 268 | strictlogic = true; | ||
| 269 | break; | ||
| 267 | case 'k': /* process constant #ifs */ | 270 | case 'k': /* process constant #ifs */ |
| 268 | killconsts = true; | 271 | killconsts = true; |
| 269 | break; | ||
