Allow to store/extract '=' character in xattr keyword
[debian/tar] / src / warning.c
1 /* This file is part of GNU tar.
2
3    Copyright (C) 2009, 2012 Free Software Foundation, Inc.
4
5    This program is free software; you can redistribute it and/or modify it
6    under the terms of the GNU General Public License as published by the
7    Free Software Foundation; either version 3, or (at your option) any later
8    version.
9
10    This program is distributed in the hope that it will be useful, but
11    WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
13    Public License for more details.
14
15    You should have received a copy of the GNU General Public License along
16    with this program.  If not, see <http://www.gnu.org/licenses/>. */
17
18 #include <system.h>
19 #include <argmatch.h>
20
21 #include "common.h"
22
23 static char const *const warning_args[] = {
24   "all",
25   "alone-zero-block",
26   "bad-dumpdir",
27   "cachedir",
28   "contiguous-cast",
29   "file-changed",
30   "file-ignored",
31   "file-removed",
32   "file-shrank",
33   "file-unchanged",
34   "filename-with-nuls",
35   "ignore-archive",
36   "ignore-newer",
37   "new-directory",
38   "rename-directory",
39   "symlink-cast",
40   "timestamp",
41   "unknown-cast",
42   "unknown-keyword",
43   "xdev",
44   "decompress-program",
45   "existing-file",
46   "xattr-write",
47   NULL
48 };
49
50 static int warning_types[] = {
51   WARN_ALL,
52   WARN_ALONE_ZERO_BLOCK,
53   WARN_BAD_DUMPDIR,
54   WARN_CACHEDIR,
55   WARN_CONTIGUOUS_CAST,
56   WARN_FILE_CHANGED,
57   WARN_FILE_IGNORED,
58   WARN_FILE_REMOVED,
59   WARN_FILE_SHRANK,
60   WARN_FILE_UNCHANGED,
61   WARN_FILENAME_WITH_NULS,
62   WARN_IGNORE_ARCHIVE,
63   WARN_IGNORE_NEWER,
64   WARN_NEW_DIRECTORY,
65   WARN_RENAME_DIRECTORY,
66   WARN_SYMLINK_CAST,
67   WARN_TIMESTAMP,
68   WARN_UNKNOWN_CAST,
69   WARN_UNKNOWN_KEYWORD,
70   WARN_XDEV,
71   WARN_DECOMPRESS_PROGRAM,
72   WARN_EXISTING_FILE,
73   WARN_XATTR_WRITE
74 };
75
76 ARGMATCH_VERIFY (warning_args, warning_types);
77
78 int warning_option = WARN_ALL;
79
80 void
81 set_warning_option (const char *arg)
82 {
83   int negate = 0;
84   int option;
85
86   if (strcmp (arg, "none") == 0)
87     {
88       warning_option = 0;
89       return;
90     }
91   if (strlen (arg) > 2 && memcmp (arg, "no-", 3) == 0)
92     {
93       negate = 1;
94       arg += 3;
95     }
96
97   option = XARGMATCH ("--warning", arg,
98                       warning_args, warning_types);
99   if (negate)
100     warning_option &= ~option;
101   else
102     warning_option |= option;
103 }