Commit b3c08e5a authored by Niels Möller's avatar Niels Möller
Browse files

* src/server.h (service_config): New class.

* src/server.c (init_service_config): New function.
(service_argp, service_argp_parser): New parser för --service {
... } argument.

Rev: src/server.c:1.82
Rev: src/server.h:1.24
parent 0caffdeb
......@@ -161,6 +161,7 @@ enum {
OPT_CONFIG_FILE = 0x200,
OPT_PRINT_EXAMPLE,
OPT_USE_EXAMPLE,
OPT_SERVICE
};
static const struct argp_option
......@@ -248,3 +249,76 @@ server_argp =
server_argp_children,
NULL, NULL
};
void
init_service_config(struct service_config *self)
{
self->name = NULL;
arglist_init (&self->args);
}
static const struct argp_option
service_options[] =
{
{ "service", OPT_SERVICE, "NAME { COMMAND LINE }", 0,
"Service to offer.", 0 },
{ NULL, 0, NULL, 0, NULL, 0 }
};
static error_t
service_argp_parser(int key, char *arg, struct argp_state *state)
{
CAST_SUBTYPE(service_config, self, state->input);
switch(key)
{
default:
return ARGP_ERR_UNKNOWN;
case OPT_SERVICE:
if (self->name)
argp_error (state, "Multiple --service options not supported.");
self->name = arg;
if (state->next >= state->argc
|| strcmp (state->argv[state->next], "{"))
argp_error (state,
"--service requires a name and a brace-delimited command line.");
else
{
unsigned level = 1;
for (state->next++; state->next < state->argc; )
{
const char *s = state->argv[state->next++];
if (!strcmp(s, "{"))
level++;
else if (!strcmp(s, "}"))
{
level--;
if (!level)
{
if (!self->args.argc)
argp_error (state, "Empty command line for --service.");
return 0;
}
}
arglist_push (&self->args, s);
}
argp_error (state, "Unexpected end of arguments while parsing --service command line.");
}
break;
}
return 0;
}
const struct argp
service_argp =
{
service_options,
service_argp_parser,
NULL, NULL,
NULL,
NULL, NULL
};
......@@ -24,6 +24,7 @@
#ifndef LSH_SERVER_H_INCLUDED
#define LSH_SERVER_H_INCLUDED
#include "arglist.h"
#include "server_config.h"
#include "werror.h"
......@@ -61,5 +62,20 @@ make_server_config(const struct config_parser *parser,
extern const struct argp server_argp;
/* GABA:
(struct
(name service_config)
(vars
; Pointers into the original command line
(name . "const char *")
(args indirect-special "struct arglist" #f arglist_clear)))
*/
void
init_service_config(struct service_config *self);
extern const struct argp service_argp;
#endif /* LSH_SERVER_H_INCLUDED */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment