warning.c 2.3 KB

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