#line 416 "../grecs/build-aux/getopt.m4"
/* -*- buffer-read-only: t -*- vi: set ro:
   THIS FILE IS GENERATED AUTOMATICALLY.  PLEASE DO NOT EDIT.
*/
#line 1 "cmdline.opt"
/* This file is part of GNU Pies. -*- c -*-
   Copyright (C) 2008-2016 Sergey Poznyakoff

   GNU Pies is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   GNU Pies is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with GNU Pies.  If not, see <http://www.gnu.org/licenses/>. */

#line 208 "cmdline.opt"

#line 208

#line 208
#ifdef HAVE_CONFIG_H
#line 208
# include <config.h>
#line 208
#endif
#line 208
#ifdef HAVE_GETOPT_H
#line 208
# include <getopt.h>
#line 208
#endif
#line 208
#include <unistd.h>
#line 208

#line 208
#include <grecs.h>
#line 208
#include <grecs/opt.h>
#line 208
/* Option codes */
#line 208
enum {
#line 208
	_OPTION_INIT=255,
#line 208
	#line 32 "cmdline.opt"

#line 32
	OPTION_CONFIG_HELP,
#line 45 "cmdline.opt"

#line 45
	OPTION_FORCE,
#line 51 "cmdline.opt"

#line 51
	OPTION_FOREGROUND,
#line 67 "cmdline.opt"

#line 67
	OPTION_INSTANCE,
#line 73 "cmdline.opt"

#line 73
	OPTION_RATE,
#line 85 "cmdline.opt"

#line 85
	OPTION_STDERR,
#line 91 "cmdline.opt"

#line 91
	OPTION_SYNTAX,
#line 102 "cmdline.opt"

#line 102
	OPTION_SYSLOG,
#line 146 "cmdline.opt"

#line 146
	OPTION_HUP,
#line 175 "cmdline.opt"

#line 175
	OPTION_DUMP_DEPMAP,
#line 182 "cmdline.opt"

#line 182
	OPTION_TRACE_DEPEND,
#line 189 "cmdline.opt"

#line 189
	OPTION_TRACE_PREREQ,
#line 196 "cmdline.opt"

#line 196
	OPTION_SOURCE_INFO,
#line 208 "cmdline.opt"

#line 208
	OPTION_USAGE,

#line 208 "cmdline.opt"
	MAX_OPTION
#line 208
};
#line 208
#ifdef HAVE_GETOPT_LONG
#line 208
static struct option long_options[] = {
#line 208
	#line 26 "cmdline.opt"

#line 26
	{ "config-file", required_argument, 0, 'c' },
#line 32 "cmdline.opt"

#line 32
	{ "config-help", no_argument, 0, OPTION_CONFIG_HELP },
#line 45 "cmdline.opt"

#line 45
	{ "force", no_argument, 0, OPTION_FORCE },
#line 51 "cmdline.opt"

#line 51
	{ "foreground", no_argument, 0, OPTION_FOREGROUND },
#line 58 "cmdline.opt"

#line 58
	{ "inetd", no_argument, 0, 'i' },
#line 67 "cmdline.opt"

#line 67
	{ "instance", required_argument, 0, OPTION_INSTANCE },
#line 73 "cmdline.opt"

#line 73
	{ "rate", required_argument, 0, OPTION_RATE },
#line 85 "cmdline.opt"

#line 85
	{ "stderr", no_argument, 0, OPTION_STDERR },
#line 91 "cmdline.opt"

#line 91
	{ "syntax", required_argument, 0, OPTION_SYNTAX },
#line 102 "cmdline.opt"

#line 102
	{ "syslog", no_argument, 0, OPTION_SYSLOG },
#line 108 "cmdline.opt"

#line 108
	{ "lint", no_argument, 0, 't' },
#line 115 "cmdline.opt"

#line 115
	{ "telinit", no_argument, 0, 'T' },
#line 124 "cmdline.opt"

#line 124
	{ "include-directory", required_argument, 0, 'I' },
#line 130 "cmdline.opt"

#line 130
	{ "define", required_argument, 0, 'D' },
#line 136 "cmdline.opt"

#line 136
	{ "undefine", required_argument, 0, 'U' },
#line 144 "cmdline.opt"

#line 144
	{ "reload", no_argument, 0, 'r' },
#line 146 "cmdline.opt"

#line 146
	{ "hup", no_argument, 0, OPTION_HUP },
#line 152 "cmdline.opt"

#line 152
	{ "restart-component", no_argument, 0, 'R' },
#line 159 "cmdline.opt"

#line 159
	{ "status", no_argument, 0, 's' },
#line 166 "cmdline.opt"

#line 166
	{ "stop", no_argument, 0, 'S' },
#line 175 "cmdline.opt"

#line 175
	{ "dump-depmap", no_argument, 0, OPTION_DUMP_DEPMAP },
#line 182 "cmdline.opt"

#line 182
	{ "trace-depend", no_argument, 0, OPTION_TRACE_DEPEND },
#line 189 "cmdline.opt"

#line 189
	{ "trace-prereq", no_argument, 0, OPTION_TRACE_PREREQ },
#line 196 "cmdline.opt"

#line 196
	{ "source-info", no_argument, 0, OPTION_SOURCE_INFO },
#line 202 "cmdline.opt"

#line 202
	{ "debug", required_argument, 0, 'x' },
#line 208 "cmdline.opt"

#line 208
	{ "help", no_argument, 0, 'h' },
#line 208 "cmdline.opt"

#line 208
	{ "usage", no_argument, 0, OPTION_USAGE },
#line 208 "cmdline.opt"

#line 208
	{ "version", no_argument, 0, 'V' },

#line 208 "cmdline.opt"
	{0, 0, 0, 0}
#line 208
};
#line 208
#endif
#line 208
static struct grecs_opthelp opthelp[] = {
#line 208
	#line 24 "cmdline.opt"

#line 24
	{ NULL, NULL, 0, N_("Operation Mode") },
#line 28 "cmdline.opt"

#line 28
	{
#line 28
#ifdef HAVE_GETOPT_LONG
#line 28
	  "-c, --config-file",
#line 28
#else
#line 28
	  "-c",
#line 28
#endif
#line 28
				   N_("FILE"), 0, N_("use FILE instead of the default configuration") },
#line 34 "cmdline.opt"

#line 34
	{
#line 34
#ifdef HAVE_GETOPT_LONG
#line 34
	  "--config-help",
#line 34
#else
#line 34
	  "",
#line 34
#endif
#line 34
				   NULL, 0, N_("show configuration file summary") },
#line 41 "cmdline.opt"

#line 41
	{
#line 41
#ifdef HAVE_GETOPT_LONG
#line 41
	  "-E",
#line 41
#else
#line 41
	  "-E",
#line 41
#endif
#line 41
				   NULL, 0, N_("preprocess config and exit") },
#line 47 "cmdline.opt"

#line 47
	{
#line 47
#ifdef HAVE_GETOPT_LONG
#line 47
	  "--force",
#line 47
#else
#line 47
	  "",
#line 47
#endif
#line 47
				   NULL, 0, N_("force startup even if another instance may be running") },
#line 53 "cmdline.opt"

#line 53
	{
#line 53
#ifdef HAVE_GETOPT_LONG
#line 53
	  "--foreground",
#line 53
#else
#line 53
	  "",
#line 53
#endif
#line 53
				   NULL, 0, N_("remain in foreground") },
#line 60 "cmdline.opt"

#line 60
	{
#line 60
#ifdef HAVE_GETOPT_LONG
#line 60
	  "-i, --inetd",
#line 60
#else
#line 60
	  "-i",
#line 60
#endif
#line 60
				   NULL, 0, N_("run in inetd mode") },
#line 69 "cmdline.opt"

#line 69
	{
#line 69
#ifdef HAVE_GETOPT_LONG
#line 69
	  "--instance",
#line 69
#else
#line 69
	  "",
#line 69
#endif
#line 69
				   N_("NAME"), 0, N_("set instance name") },
#line 75 "cmdline.opt"

#line 75
	{
#line 75
#ifdef HAVE_GETOPT_LONG
#line 75
	  "--rate",
#line 75
#else
#line 75
	  "",
#line 75
#endif
#line 75
				   N_("NUMBER"), 0, N_("set default maximum rate for inetd-style components") },
#line 87 "cmdline.opt"

#line 87
	{
#line 87
#ifdef HAVE_GETOPT_LONG
#line 87
	  "--stderr",
#line 87
#else
#line 87
	  "",
#line 87
#endif
#line 87
				   NULL, 0, N_("log to stderr") },
#line 93 "cmdline.opt"

#line 93
	{
#line 93
#ifdef HAVE_GETOPT_LONG
#line 93
	  "--syntax",
#line 93
#else
#line 93
	  "",
#line 93
#endif
#line 93
				   N_("{pies|meta1|inetd|inittab}"), 0, N_("expect configuration files in the given syntax") },
#line 104 "cmdline.opt"

#line 104
	{
#line 104
#ifdef HAVE_GETOPT_LONG
#line 104
	  "--syslog",
#line 104
#else
#line 104
	  "",
#line 104
#endif
#line 104
				   NULL, 0, N_("log to syslog") },
#line 110 "cmdline.opt"

#line 110
	{
#line 110
#ifdef HAVE_GETOPT_LONG
#line 110
	  "-t, --lint",
#line 110
#else
#line 110
	  "-t",
#line 110
#endif
#line 110
				   NULL, 0, N_("parse configuration file and exit") },
#line 117 "cmdline.opt"

#line 117
	{
#line 117
#ifdef HAVE_GETOPT_LONG
#line 117
	  "-T, --telinit",
#line 117
#else
#line 117
	  "-T",
#line 117
#endif
#line 117
				   NULL, 0, N_("telinit command: run \"pies -T --help\" for help") },
#line 122 "cmdline.opt"

#line 122
	{ NULL, NULL, 0, N_("Preprocessor") },
#line 126 "cmdline.opt"

#line 126
	{
#line 126
#ifdef HAVE_GETOPT_LONG
#line 126
	  "-I, --include-directory",
#line 126
#else
#line 126
	  "-I",
#line 126
#endif
#line 126
				   N_("DIR"), 0, N_("add include directory") },
#line 132 "cmdline.opt"

#line 132
	{
#line 132
#ifdef HAVE_GETOPT_LONG
#line 132
	  "-D, --define",
#line 132
#else
#line 132
	  "-D",
#line 132
#endif
#line 132
				   N_("NAME[=VALUE]"), 0, N_("define a preprocessor symbol NAME as having VALUE or empty") },
#line 138 "cmdline.opt"

#line 138
	{
#line 138
#ifdef HAVE_GETOPT_LONG
#line 138
	  "-U, --undefine",
#line 138
#else
#line 138
	  "-U",
#line 138
#endif
#line 138
				   N_("NAME"), 0, N_("undefine a preprocessor symbol NAME") },
#line 142 "cmdline.opt"

#line 142
	{ NULL, NULL, 0, N_("Component Management") },
#line 147 "cmdline.opt"

#line 147
	{
#line 147
#ifdef HAVE_GETOPT_LONG
#line 147
	  "-r, --reload, --hup",
#line 147
#else
#line 147
	  "-r",
#line 147
#endif
#line 147
				   NULL, 0, N_("reload the running instance of pies") },
#line 154 "cmdline.opt"

#line 154
	{
#line 154
#ifdef HAVE_GETOPT_LONG
#line 154
	  "-R, --restart-component",
#line 154
#else
#line 154
	  "-R",
#line 154
#endif
#line 154
				   NULL, 0, N_("restart components named in the command line") },
#line 161 "cmdline.opt"

#line 161
	{
#line 161
#ifdef HAVE_GETOPT_LONG
#line 161
	  "-s, --status",
#line 161
#else
#line 161
	  "-s",
#line 161
#endif
#line 161
				   NULL, 0, N_("display info about the running instance") },
#line 168 "cmdline.opt"

#line 168
	{
#line 168
#ifdef HAVE_GETOPT_LONG
#line 168
	  "-S, --stop",
#line 168
#else
#line 168
	  "-S",
#line 168
#endif
#line 168
				   NULL, 0, N_("stop the running instance") },
#line 173 "cmdline.opt"

#line 173
	{ NULL, NULL, 0, N_("Debugging and Additional Diagnostics") },
#line 177 "cmdline.opt"

#line 177
	{
#line 177
#ifdef HAVE_GETOPT_LONG
#line 177
	  "--dump-depmap",
#line 177
#else
#line 177
	  "",
#line 177
#endif
#line 177
				   NULL, 0, N_("dump dependency map") },
#line 184 "cmdline.opt"

#line 184
	{
#line 184
#ifdef HAVE_GETOPT_LONG
#line 184
	  "--trace-depend",
#line 184
#else
#line 184
	  "",
#line 184
#endif
#line 184
				   NULL, 0, N_("trace dependencies") },
#line 191 "cmdline.opt"

#line 191
	{
#line 191
#ifdef HAVE_GETOPT_LONG
#line 191
	  "--trace-prereq",
#line 191
#else
#line 191
	  "",
#line 191
#endif
#line 191
				   NULL, 0, N_("trace prerequisites") },
#line 198 "cmdline.opt"

#line 198
	{
#line 198
#ifdef HAVE_GETOPT_LONG
#line 198
	  "--source-info",
#line 198
#else
#line 198
	  "",
#line 198
#endif
#line 198
				   NULL, 0, N_("show source info with debugging messages") },
#line 204 "cmdline.opt"

#line 204
	{
#line 204
#ifdef HAVE_GETOPT_LONG
#line 204
	  "-x, --debug",
#line 204
#else
#line 204
	  "-x",
#line 204
#endif
#line 204
				   N_("LEVEL"), 0, N_("set debug verbosity level") },
#line 208 "cmdline.opt"

#line 208
	{ NULL, NULL, 0, N_("Other options") },
#line 208 "cmdline.opt"

#line 208
	{
#line 208
#ifdef HAVE_GETOPT_LONG
#line 208
	  "-h, --help",
#line 208
#else
#line 208
	  "-h",
#line 208
#endif
#line 208
				   NULL, 0, N_("Give this help list") },
#line 208 "cmdline.opt"

#line 208
	{
#line 208
#ifdef HAVE_GETOPT_LONG
#line 208
	  "--usage",
#line 208
#else
#line 208
	  "",
#line 208
#endif
#line 208
				   NULL, 0, N_("Give a short usage message") },
#line 208 "cmdline.opt"

#line 208
	{
#line 208
#ifdef HAVE_GETOPT_LONG
#line 208
	  "-V, --version",
#line 208
#else
#line 208
	  "-V",
#line 208
#endif
#line 208
				   NULL, 0, N_("Print program version") },

#line 208 "cmdline.opt"
};
#line 17 "cmdline.opt"

#line 17

#line 17
static struct grecs_proginfo proginfo = {
#line 17
	"pies", /* progname */
#line 17
	NULL, /* subcommands */
#line 17
	N_("process invocation and execution supervisor"), /* docstring */
#line 17
	"", /* args_doc */
#line 17
	opthelp, /* opthelp */
#line 17
	sizeof(opthelp)/sizeof(opthelp[0]), /* optcount */
#line 17
	NULL, /* print_help_hook */
#line 17
	NULL, /* print_version_hook */
#line 17
	PACKAGE_NAME,    /* package */
#line 17
	PACKAGE_VERSION, /* version */
#line 17
	NULL, /* license */
#line 17
	"2008-2016",/* copyright_year */
#line 17
	"Sergey Poznyakoff", /* copyright_holder */
#line 17
	NULL, /* *authors */
#line 17
	"<" PACKAGE_BUGREPORT ">", /* bug_address */
#line 17
	PACKAGE_URL, /* url */
#line 17
	NULL  /* epilogue */
#line 17
};
#line 17
static struct grecs_node *cmdline_tree;
#line 17

#line 17

#line 208 "cmdline.opt"

#line 208


void
parse_options (int *pargc, char ***pargv)
{
  int argc = *pargc;
  char **argv = *pargv;
  int index;
  
  if (init_process)
    {
      sysvinit_parse_argv (argc, argv);
      index = argc;
    }
  else
    {
      
#line 224
 {
#line 224
  int c;
#line 224

#line 224
  optind = 0;
#line 224
#ifdef HAVE_GETOPT_LONG
#line 224
  while ((c = getopt_long(argc, argv, "c:EitTI:D:U:rRsSx:hV",
#line 224
			  long_options, NULL)) != EOF)
#line 224
#else
#line 224
  while ((c = getopt(argc, argv, "c:EitTI:D:U:rRsSx:hV")) != EOF)
#line 224
#endif
#line 224
    {
#line 224
      switch (c)
#line 224
	{
#line 224
	default:
#line 224
	   	   exit(EX_USAGE);
#line 224
	#line 28 "cmdline.opt"
	 case 'c':
#line 28
	  {
#line 28

  config_file_add (current_syntax, optarg);

#line 30
	     break;
#line 30
	  }
#line 34 "cmdline.opt"
	 case OPTION_CONFIG_HELP:
#line 34
	  {
#line 34

  config_help ();
  exit (0);

#line 37
	     break;
#line 37
	  }
#line 41 "cmdline.opt"
	 case 'E':
#line 41
	  {
#line 41

  preprocess_only = 1;

#line 43
	     break;
#line 43
	  }
#line 47 "cmdline.opt"
	 case OPTION_FORCE:
#line 47
	  {
#line 47

  force_option = 1;

#line 49
	     break;
#line 49
	  }
#line 53 "cmdline.opt"
	 case OPTION_FOREGROUND:
#line 53
	  {
#line 53

  log_to_stderr_only = 1;
  foreground = 1;

#line 56
	     break;
#line 56
	  }
#line 60 "cmdline.opt"
	 case 'i':
#line 60
	  {
#line 60

  if (!instance)
    instance = "inetd";
  current_syntax = &config_syntax_tab[CONF_INETD];
  inetd_mode = 1;

#line 65
	     break;
#line 65
	  }
#line 69 "cmdline.opt"
	 case OPTION_INSTANCE:
#line 69
	  {
#line 69

  instance = optarg;

#line 71
	     break;
#line 71
	  }
#line 75 "cmdline.opt"
	 case OPTION_RATE:
#line 75
	  {
#line 75

  char *p;
  default_max_rate = strtoul (optarg, &p, 10);
  if (*p)
    {
      logmsg (LOG_ERR, _("not a number: %s"), optarg);
      exit (EX_USAGE);
    }

#line 83
	     break;
#line 83
	  }
#line 87 "cmdline.opt"
	 case OPTION_STDERR:
#line 87
	  {
#line 87

  log_to_stderr_only = 1;

#line 89
	     break;
#line 89
	  }
#line 93 "cmdline.opt"
	 case OPTION_SYNTAX:
#line 93
	  {
#line 93

  current_syntax = str_to_config_syntax (optarg);
  if (!current_syntax)
    {
      logmsg (LOG_ERR, _("unknown syntax type: %s"), optarg);
      exit (EX_USAGE);
    }

#line 100
	     break;
#line 100
	  }
#line 104 "cmdline.opt"
	 case OPTION_SYSLOG:
#line 104
	  {
#line 104

  log_to_stderr_only = 0;

#line 106
	     break;
#line 106
	  }
#line 110 "cmdline.opt"
	 case 't':
#line 110
	  {
#line 110

  log_to_stderr_only = 1;
  lint_mode = 1;

#line 113
	     break;
#line 113
	  }
#line 117 "cmdline.opt"
	 case 'T':
#line 117
	  {
#line 117

  log_to_stderr_only = 1;
  exit (telinit (argc - (optind - 1), argv + (optind - 1)));

#line 120
	     break;
#line 120
	  }
#line 126 "cmdline.opt"
	 case 'I':
#line 126
	  {
#line 126

  grecs_preproc_add_include_dir(optarg);

#line 128
	     break;
#line 128
	  }
#line 132 "cmdline.opt"
	 case 'D':
#line 132
	  {
#line 132

  pp_add_option ("-D", optarg);

#line 134
	     break;
#line 134
	  }
#line 138 "cmdline.opt"
	 case 'U':
#line 138
	  {
#line 138

  pp_add_option ("-U", optarg);

#line 140
	     break;
#line 140
	  }
#line 147 "cmdline.opt"
	 case 'r': case OPTION_HUP:
#line 147
	  {
#line 147

  log_to_stderr_only = 1;
  command = COM_RELOAD;

#line 150
	     break;
#line 150
	  }
#line 154 "cmdline.opt"
	 case 'R':
#line 154
	  {
#line 154

  log_to_stderr_only = 1;
  command = COM_RESTART_COMPONENT;

#line 157
	     break;
#line 157
	  }
#line 161 "cmdline.opt"
	 case 's':
#line 161
	  {
#line 161

  log_to_stderr_only = 1;
  command = COM_STATUS;

#line 164
	     break;
#line 164
	  }
#line 168 "cmdline.opt"
	 case 'S':
#line 168
	  {
#line 168

  log_to_stderr_only = 1;
  command = COM_STOP;

#line 171
	     break;
#line 171
	  }
#line 177 "cmdline.opt"
	 case OPTION_DUMP_DEPMAP:
#line 177
	  {
#line 177

  log_to_stderr_only = 1;
  command = COM_DUMP_DEPMAP;

#line 180
	     break;
#line 180
	  }
#line 184 "cmdline.opt"
	 case OPTION_TRACE_DEPEND:
#line 184
	  {
#line 184

  log_to_stderr_only = 1;
  command = COM_TRACE_DEPEND;  

#line 187
	     break;
#line 187
	  }
#line 191 "cmdline.opt"
	 case OPTION_TRACE_PREREQ:
#line 191
	  {
#line 191

  log_to_stderr_only = 1;
  command = COM_TRACE_PREREQ;  

#line 194
	     break;
#line 194
	  }
#line 198 "cmdline.opt"
	 case OPTION_SOURCE_INFO:
#line 198
	  {
#line 198

  source_info_option = 1;

#line 200
	     break;
#line 200
	  }
#line 204 "cmdline.opt"
	 case 'x':
#line 204
	  {
#line 204

  debug_level = strtoul (optarg, NULL, 0);

#line 206
	     break;
#line 206
	  }
#line 208 "cmdline.opt"
	 case 'h':
#line 208
	  {
#line 208

#line 208
		grecs_print_help(&proginfo);
#line 208
		exit(0);
#line 208
	 
#line 208
	     break;
#line 208
	  }
#line 208 "cmdline.opt"
	 case OPTION_USAGE:
#line 208
	  {
#line 208

#line 208
		grecs_print_usage(&proginfo);
#line 208
		exit(0);
#line 208
	 
#line 208
	     break;
#line 208
	  }
#line 208 "cmdline.opt"
	 case 'V':
#line 208
	  {
#line 208

#line 208
		/* Give version */
#line 208
		grecs_print_version(&proginfo, stdout);
#line 208
		exit(0);
#line 208
	 
#line 208
	     break;
#line 208
	  }

#line 224 "cmdline.opt"
	}
#line 224
    }
#line 224
  index = optind;
#line 224
  if (cmdline_tree)
#line 224
    {
#line 224
      struct grecs_node *rn = grecs_node_create(grecs_node_root, NULL);
#line 224
      rn->down = cmdline_tree;
#line 224
      cmdline_tree = rn;
#line 224
    }
#line 224
 }
#line 224
;
    }
  *pargc -= index;
  *pargv += index;
}
