Bioplib
Protein Structure C Library
|
A keyword command parser. More...
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include "MathType.h"
#include "SysDefs.h"
#include "macros.h"
#include "parse.h"
#include "general.h"
Go to the source code of this file.
Macros | |
#define | LF 10 |
#define | CR 13 |
#define | DIC 34 /* Double inverted commas */ |
Functions | |
int | blParse (char *comline, int nkeys, KeyWd *keywords, REAL *floatparam, char **strparam) |
int | blMatch (char *comstring, char *string2, int *nletters) |
int | blGetString (char *command, char *strparam) |
int | blGetParam (char *command, REAL *value, int *nletters) |
int | blMparse (char *comline, int nkeys, MKeyWd *keywords, REAL *floatparam, char **strparam, int *nparam) |
A keyword command parser.
This code is NOT IN THE PUBLIC DOMAIN, but it may be copied according to the conditions laid out in the accompanying file COPYING.DOC.
The code may be modified as required, but any modifications must be documented so that the person responsible can be identified.
The code may not be sold commercially or included as part of a commercial product except as described in the file COPYING.DOC.
blParse() is a command line parser which will accept upper or lower case commands and abbreviations. Comment lines may be indicated using a !. The keyword structure array and returned string array are defined thus:
The returned REAL parameters are defined thus:
Space for the returned strings must be allocated thus:
and repeated for each parameter.
The keyword list with type and numbers of returned parameters is constructed using the MAKEKEY macros:
Here, the keywords must be defined in upper case.
blMparse() is used in the same way, but allows a variable number of parameters for each keyword. Keywords are of type MKeyWd and are defined using the macro MAKEMKEY:
[in] | *comline | A command line string to parse |
[in] | nkeys | Number of keywords |
[in] | *keywords | Array of keyword structures |
[out] | *floatparam | Array of returned strings |
[out] | **strparam | Array of pointers to returned strings |
[in] | *comline | A command line string to parse |
[in] | nkeys | Number of keywords |
[in] | *keywords | Array of keyword structures |
[out] | *floatparam | Array of returned strings |
[out] | **strparam | Array of pointers to returned strings |
[out] | *nparam | Number of parameters found |
Definition in file parse.c.
int blGetParam | ( | char * | command, |
REAL * | value, | ||
int * | nletters | ||
) |
[in] | *command | A character string |
[out] | *value | Returned float value |
[out] | *nletters | Number of charcters pulled out of the command string |
Extracts the first space-delimited number from the `command' character string.
int blGetString | ( | char * | command, |
char * | strparam | ||
) |
[in] | *command | A character string |
[out] | *strparam | Returned character string |
Returns the first space-delimited group of characters from character string `command'
int blMatch | ( | char * | comstring, |
char * | string2, | ||
int * | nletters | ||
) |
[in] | *comstring | A character string |
[in] | *string2 | A second string |
[out] | *nletters | Number of letters matched |
Matches two strings, but stops the comparison as soon as a space or NULL is found in either string. The returned value indicates which string finished first or 0 if the letters before the space or NULL have a mismatch. The routine calls StringToUpper() on `comstring' before the comparison.
int blMparse | ( | char * | comline, |
int | nkeys, | ||
MKeyWd * | keywords, | ||
REAL * | floatparam, | ||
char ** | strparam, | ||
int * | nparam | ||
) |
[in] | *comline | A command line string to parse |
[in] | nkeys | Number of keywords |
[in] | *keywords | Array of keyword structures |
[out] | *floatparam | Array of returned strings |
[out] | **strparam | Array of pointers to returned strings |
[out] | *nparam | Number of parameters found |
As blParse(), but allows variable number of parameters to each keyword.
[in] | *comline | A command line string to parse |
[in] | nkeys | Number of keywords |
[in] | *keywords | Array of keyword structures |
[out] | *floatparam | Array of returned strings |
[out] | **strparam | Array of pointers to returned strings |
Keyword-based command parser using a fixed number of parameters per command