Defines | Functions | Variables

argparser.c File Reference

A simple argument parser, inspired by getopt. More...

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "argparser.h"
Include dependency graph for argparser.c:

Go to the source code of this file.

Functions

int _eurephia_getopt (const char *module, int *curarg, int argc, char **argv, e_options *argopts)
size_t eurephia_arraycp (int stidx, int inargc, char **inargv, char **outargv, size_t outsize)

Variables

char * optargs [64]

Detailed Description

A simple argument parser, inspired by getopt.

Author:
David Sommerseth <dazo@users.sourceforge.net>
Date:
2008-12-04

Definition in file argparser.c.


Function Documentation

int _eurephia_getopt ( const char *  module,
int *  curarg,
int  argc,
char **  argv,
e_options argopts 
)

Internal argument parser. Normally called via the eurephia_getopt(...) macro. Parses an argument and prepares the char **optargs array with parameters to the arguments.

Parameters:
module string (const char *) containing a descriptive module name, used in error situations.
curarg pointer to the argument index counter which gets updated during parsing.
argc Input argument counter
argv Input argument array (char **)
argopts e_options struct array containing valid argument
Returns:
returns the short arg value on success, or -1 on failure.

Definition at line 53 of file argparser.c.

size_t eurephia_arraycp ( int  stidx,
int  inargc,
char **  inargv,
char **  outargv,
size_t  outsize 
)

This function will take (argc,argv) and copy pointers over to (**outargv), starting from the index given in stidx (start index). The outargv array must have been allocated first by calloc(sizeof(char *), elmnts). The outsize must not exceed the number of elements you have allocated space for. The function returns number of elements copied (the new argc, kind of)

Parameters:
stidx start index of where to start the copy
inargc input argument counter (size of the input array)
inargv input argument array (char **)
outargv pointer to an array of where to put the values being copied.
outsize Size of the output array.
Returns:
Returns number of argument copied over to the output array.

Definition at line 97 of file argparser.c.

Here is the caller graph for this function:


Variable Documentation

char* optargs[64]

If an argument takes parameters, they will be put into this array

Definition at line 38 of file argparser.c.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines