summaryrefslogtreecommitdiff
path: root/libdiskfs
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-06-26 02:06:25 +0000
committerMiles Bader <miles@gnu.org>1996-06-26 02:06:25 +0000
commit8f27c97d12ae4091b78444c9b2dc54a9d2a2bfce (patch)
tree3837185f7297e9493d0c72dee6772dd2e68bc36e /libdiskfs
parenteb2654f4f861bded25d52002846eb59787d8da3e (diff)
(parse_opt): Add hair to share arg parsing state between two parsers that use
the same parse_opt function at the same time.
Diffstat (limited to 'libdiskfs')
-rw-r--r--libdiskfs/opts-std-runtime.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/libdiskfs/opts-std-runtime.c b/libdiskfs/opts-std-runtime.c
index 90e5fe9c..9a3ee80a 100644
--- a/libdiskfs/opts-std-runtime.c
+++ b/libdiskfs/opts-std-runtime.c
@@ -92,20 +92,32 @@ parse_opt (int opt, char *arg, struct argp_state *state)
break;
case ARGP_KEY_INIT:
- h = state->hook = malloc (sizeof (struct parse_hook));
- if (! h)
- return ENOMEM;
- h->readonly = diskfs_readonly;
- h->sync = diskfs_synchronous;
- h->sync_interval = -1;
- h->remount = 0;
+ if (state->input)
+ state->hook = state->input; /* Share hook with parent. */
+ else
+ {
+ h = state->hook = malloc (sizeof (struct parse_hook));
+ if (! h)
+ return ENOMEM;
+ h->readonly = diskfs_readonly;
+ h->sync = diskfs_synchronous;
+ h->sync_interval = -1;
+ h->remount = 0;
+
+ /* We know that we have one child, with which we share our hook. */
+ state->child_inputs[0] = h;
+ }
break;
case ARGP_KEY_ERROR:
- free (h); break;
+ if (! state->input)
+ free (h);
+ break;
case ARGP_KEY_SUCCESS:
- return set_opts (h);
+ if (! state->input)
+ return set_opts (h);
+ break;
default:
return ARGP_ERR_UNKNOWN;
@@ -114,8 +126,8 @@ parse_opt (int opt, char *arg, struct argp_state *state)
}
static const struct argp common_argp = { diskfs_common_options, parse_opt };
-static const struct argp *parents[] = { &common_argp, 0 };
+static const struct argp *parents[] = { &common_argp, 0 };
const struct argp diskfs_std_runtime_argp =
{
std_runtime_options, parse_opt, 0, 0, parents