git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 05/75] parse-options: add OPT_BITOP()

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Dec 27, 2018, 16:25 UTC
Message-ID
<20181227162536.15895-6-pclouds@gmail.com>
In-Reply-To
<20181227162536.15895-1-pclouds@gmail.com>
This is needed for diff_opt_parse() where we do
   value = (value & ~mask) | some_more;
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 parse-options.c | 7 +++++++
 parse-options.h | 5 +++++
 2 files changed, 12 insertions(+)
diff --git a/parse-options.c b/parse-options.c
index 81e66b9374..9e19d64cc9 100644
--- a/parse-options.c
+++ b/parse-options.c
@@ -110,6 +110,13 @@ static int get_value(struct parse_opt_ctx_t *p,
 			*(int *)opt->value &= ~opt->defval;
 		return 0;
 
+	case OPTION_BITOP:
+		if (unset)
+			BUG("BITOP can't have unset form");
+		*(int *)opt->value &= ~opt->extra;
+		*(int *)opt->value |= opt->defval;
+		return 0;
+
 	case OPTION_COUNTUP:
 		if (*(int *)opt->value < 0)
 			*(int *)opt->value = 0;
diff --git a/parse-options.h b/parse-options.h
index 043d296ea4..69afd0bce6 100644
--- a/parse-options.h
+++ b/parse-options.h
@@ -10,6 +10,7 @@ enum parse_opt_type {
 	/* options with no arguments */
 	OPTION_BIT,
 	OPTION_NEGBIT,
+	OPTION_BITOP,
 	OPTION_COUNTUP,
 	OPTION_SET_INT,
 	OPTION_CMDMODE,
@@ -118,6 +119,7 @@ struct option {
 	int flags;
 	parse_opt_cb *callback;
 	intptr_t defval;
+	intptr_t extra;
 };
 
 #define OPT_BIT_F(s, l, v, h, b, f) { OPTION_BIT, (s), (l), (v), NULL, (h), \
@@ -133,6 +135,9 @@ struct option {
 				      (h), PARSE_OPT_NOARG}
 #define OPT_GROUP(h)                { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
 #define OPT_BIT(s, l, v, h, b)      OPT_BIT_F(s, l, v, h, b, 0)
+#define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \
+					    PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, \
+					    (set), (clear) }
 #define OPT_NEGBIT(s, l, v, h, b)   { OPTION_NEGBIT, (s), (l), (v), NULL, \
 				      (h), PARSE_OPT_NOARG, NULL, (b) }
 #define OPT_COUNTUP(s, l, v, h)     OPT_COUNTUP_F(s, l, v, h, 0)
-- 
2.20.0.482.g66447595a7
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 6 of 18 in “Convert diff opt parser to parse_options()”
  1. 00/75 Convert diff opt parser to parse_options()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  2. 01/75 parse-options.h: remove extern on function prototypesNguyễn Thái Ngọc Duy, Dec 27, 2018
  3. 02/75 parse-options: add one-shot modeNguyễn Thái Ngọc Duy, Dec 27, 2018
  4. 04/75 parse-options: disable option abbreviation with PARSE_OPT_KEEP_UNKNOWNNguyễn Thái Ngọc Duy, Dec 27, 2018
  5. 03/75 parse-options: allow keep-unknown + stop-at-non-opt combinationNguyễn Thái Ngọc Duy, Dec 27, 2018
  6. 05/75 parse-options: add OPT_BITOP()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  7. 07/75 parse-options: avoid magic return codesNguyễn Thái Ngọc Duy, Dec 27, 2018
  8. 06/75 parse-options: stop abusing 'callback' for lowlevel callbacksNguyễn Thái Ngọc Duy, Dec 27, 2018
  9. 08/75 parse-options: allow ll_callback with OPTION_CALLBACKNguyễn Thái Ngọc Duy, Dec 27, 2018
  10. 11/75 diff.c: prepare to use parse_options() for parsingNguyễn Thái Ngọc Duy, Dec 27, 2018
  11. 74/75 diff --no-index: use parse_options() instead of diff_opt_parse()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  12. Eric SunshineDec 27, 2018
  13. 10/75 diff.h: avoid bit fields in struct diff_flagsNguyễn Thái Ngọc Duy, Dec 27, 2018
  14. Stefan BellerJan 9, 2019
  15. 75/75 am: avoid diff_opt_parse()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  16. 73/75 range-diff: use parse_options() instead of diff_opt_parse()Nguyễn Thái Ngọc Duy, Dec 27, 2018
  17. 09/75 diff.h: keep forward struct declarations sortedNguyễn Thái Ngọc Duy, Dec 27, 2018
  18. 12/75 diff.c: convert -u|-p|--patchNguyễn Thái Ngọc Duy, Dec 27, 2018

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.