+
+/* Return 1 if OPTION is enabled, 0 if it is disabled, or -1 if it isn't
+ a simple on-off switch. */
+
+int
+option_enabled (int opt_idx)
+{
+ const struct cl_option *option = &(cl_options[opt_idx]);
+ if (option->flag_var)
+ switch (option->var_type)
+ {
+ case CLVC_BOOLEAN:
+ return *(int *) option->flag_var != 0;
+
+ case CLVC_EQUAL:
+ return *(int *) option->flag_var == option->var_value;
+
+ case CLVC_BIT_CLEAR:
+ return (*(int *) option->flag_var & option->var_value) == 0;
+
+ case CLVC_BIT_SET:
+ return (*(int *) option->flag_var & option->var_value) != 0;
+
+ case CLVC_STRING:
+ break;
+ }
+ return -1;
+}
+
+/* Fill STATE with the current state of option OPTION. Return true if
+ there is some state to store. */
+
+bool
+get_option_state (int option, struct cl_option_state *state)
+{
+ if (cl_options[option].flag_var == 0)
+ return false;
+
+ switch (cl_options[option].var_type)
+ {
+ case CLVC_BOOLEAN:
+ case CLVC_EQUAL:
+ state->data = cl_options[option].flag_var;
+ state->size = sizeof (int);
+ break;
+
+ case CLVC_BIT_CLEAR:
+ case CLVC_BIT_SET:
+ state->ch = option_enabled (option);
+ state->data = &state->ch;
+ state->size = 1;
+ break;
+
+ case CLVC_STRING:
+ state->data = *(const char **) cl_options[option].flag_var;
+ if (state->data == 0)
+ state->data = "";
+ state->size = strlen (state->data) + 1;
+ break;
+ }
+ return true;
+}