Back to index

courier  0.68.2
Classes | Functions
argparse.h File Reference
#include "config.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  args

Functions

int argparse (int argc, char **, struct args *)

Function Documentation

int argparse ( int  argc,
char **  ,
struct args  
)

Definition at line 13 of file argparse.c.

{
int    argn=1;
int    i;

       while (argn < argc)
       {
       const char *p;
       int    l=0;

              if ( argv[argn][0] != '-')  break;
              if ( argv[argn][1] == 0)
              {
                     ++argn;
                     break;
              }
              for (i=0; s[i].name; i++)
              {
                     l=strlen(s[i].name);
                     if (strncmp(s[i].name, argv[argn]+1, l) == 0 &&
                            (argv[argn][l+1] == 0 ||
                            argv[argn][l+1] == '='))    break;
              }
              if (s[i].name == 0)
              {
                     fprintf(stderr, "%s: Invalid option: %s\n",
                            argv[0], argv[argn]);
                     exit(1);
              }
              p=argv[argn]+1+l;
              if (*p)       ++p;
              if (s[i].valuep)
                     *s[i].valuep=p;
              else
                     (*s[i].funcp)(p);
              ++argn;
       }
       return (argn);
}

Here is the caller graph for this function: