CoMD
A Mini-app for Co-Design of Classical Molecular Dynamics.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cmdLineParser.c File Reference

A parser for command line arguments. More...

#include "cmdLineParser.h"
#include <stdio.h>
#include <getopt.h>
#include <string.h>
#include "mytype.h"
#include "memUtils.h"
Include dependency graph for cmdLineParser.c:

Go to the source code of this file.

Data Structures

struct  MyOptionSt
 

Macros

#define nextOption(o)   ((MyOption*) o->next)
 

Typedefs

typedef struct MyOptionSt MyOption
 

Functions

static char * dupString (const char *s)
 
static MyOptionmyOptionAlloc (const char *longOption, const char shortOption, int has_arg, const char type, void *dataPtr, int dataSize, const char *help)
 
static MyOptionmyOptionFree (MyOption *o)
 
static MyOptionlastOption (MyOption *o)
 
static MyOptionfindOption (MyOption *o, unsigned char shortArg)
 
int addArg (const char *longOption, const char shortOption, int has_arg, const char type, void *dataPtr, int dataSize, const char *help)
 Specifies a command line argument that should be accepted by the program. More...
 
void freeArgs ()
 
void printArgs ()
 Prints the arguments to the stdout stream. More...
 
void processArgs (int argc, char **argv)
 Call this to process your arguments. More...
 

Variables

static int longest = 1
 
static MyOptionmyargs =NULL
 

Detailed Description

A parser for command line arguments.

A general purpose command line parser that uses getopt_long() to parse the command line.

Author
Sriram Swaminarayan
Date
July 24, 2007

Definition in file cmdLineParser.c.

Macro Definition Documentation

#define nextOption (   o)    ((MyOption*) o->next)

Definition at line 19 of file cmdLineParser.c.

Typedef Documentation

typedef struct MyOptionSt MyOption

Function Documentation

int addArg ( const char *  longOption,
const char  shortOption,
int  has_arg,
const char  type,
void *  dataPtr,
int  dataSize,
const char *  help 
)

Specifies a command line argument that should be accepted by the program.

Parameters
[in]longOptionThe long name of option i.e., –optionname
[in]shortOptionThe short name of option i.e., -o
[in]has_argWhether this option has an argument i.e., -o value. If has_arg is 0, then dataPtr must be an integer pointer.
[in]typeThe type of the argument. Valid values are:
  • i integer
  • f float
  • d double
  • s string
  • c character
[in]dataPtrA pointer to where the value will be stored.
[in]dataSizeThe length of dataPtr, only useful for character strings.
[in]helpA short help string, preferably a single line or less.

Definition at line 96 of file cmdLineParser.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static char* dupString ( const char *  s)
static

Definition at line 36 of file cmdLineParser.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static MyOption* findOption ( MyOption o,
unsigned char  shortArg 
)
static

Definition at line 85 of file cmdLineParser.c.

Here is the caller graph for this function:

void freeArgs ( void  )

Definition at line 114 of file cmdLineParser.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static MyOption* lastOption ( MyOption o)
static

Definition at line 78 of file cmdLineParser.c.

Here is the caller graph for this function:

static MyOption* myOptionAlloc ( const char *  longOption,
const char  shortOption,
int  has_arg,
const char  type,
void *  dataPtr,
int  dataSize,
const char *  help 
)
static

Definition at line 45 of file cmdLineParser.c.

Here is the call graph for this function:

Here is the caller graph for this function:

static MyOption* myOptionFree ( MyOption o)
static

Definition at line 67 of file cmdLineParser.c.

Here is the caller graph for this function:

void printArgs ( void  )

Prints the arguments to the stdout stream.

Definition at line 123 of file cmdLineParser.c.

Here is the caller graph for this function:

void processArgs ( int  argc,
char **  argv 
)

Call this to process your arguments.

Definition at line 144 of file cmdLineParser.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

int longest = 1
static

Definition at line 33 of file cmdLineParser.c.

MyOption* myargs =NULL
static

Definition at line 34 of file cmdLineParser.c.