NAME

catgen_getopt - Agent option handling

SYNOPSIS

#include <cat/gen.h>

int catgen_getopt(int argc, char **argv, const char *opts);

DESCRIPTION

This function handles all standard options for Agents, including the interaction with the Agent server, catd, as described in catgen. The argc, argv, and opts arguments are the same as for cat_getopt(), but the return values differ.

Standard Agent options are handled automatically and thus cannot be part of the opts argument.

This function is useful for a program that wants to use its own command line options in addition to the standard Agent options. If only standard Agent options are used, catgen_parseargs() should be used instead.

On error, the variable catgen_operrstring will be set to a descriptive error message.

RETURN VALUES

Zero (0)
No more options found, additional parameters start at cat_optind.

Negative (< 0)
CAT error codes.

Colon (:)
An option in variable cat_optopt requires an argument.

Question mark (?)
An option in variable cat_optopt is unknown.

Other positive values
Any other values are options

ERRORS

CAT_EINVAL
A ``generic'' option is specified in opts. The standard option string is defined in CATGEN_OPTS.

CAT_EOVERFLOW
Too many options in opts.

CAT_ECONFIG
The "-C" option received faulty data.

Sets the global variable catgen_opterrstring to an error message.

EXAMPLES

Arguments may be parsed with catgen_getopt prior to calling another catgen function that would parse arguments, such as catgen_server, thus:

  #include <cat/gen.h>
  #include <stdio.h>

  int
  main(int argc, char **argv)
  {
      int c;

      while ((c = catgen_getopt(argc, argv, "a:x")) > 0) {
          switch (c) {
            case 'a':
              handle_a_arg(cat_optarg);
              break;

            case 'x':
              x_flag++; /* Should be declared and used somewhere... */
              break;

            case ':':   /* Option requires an argument */
            case '?':   /* Unknown option */
            default:    /* Other error */
              fputs(catgen_opterrstring, stderr);
              exit(1);
          }
      }
      return catgen_server("agent-2.3", argc, argv, sesshandler, NULL);
}

NOTES

Uses cat_getopt().

May interfere with the standard input, so no data should be read from it.

SEE ALSO

cat, catgen

catgen_parseargs