The outage for Sunday 24th November has been cancelled.
Bioplib
Protein Structure C Library
 All Data Structures Files Functions Variables Typedefs Macros Pages
Macros | Functions
parse.c File Reference

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)
 

Detailed Description

A keyword command parser.

Version
V1.11
Date
07.07.14
Author
Dr. Andrew C. R. Martin
Institute of Structural & Molecular Biology, University College London, Gower Street, London. WC1E 6BT.
andre.nosp@m.w@bi.nosp@m.oinf..nosp@m.org..nosp@m.uk andre.nosp@m.w.ma.nosp@m.rtin@.nosp@m.ucl..nosp@m.ac.uk

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.

Description:

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:

KeyWd keywords[NCOMM];
char *strparam[MAXSTRPARAM];

The returned REAL parameters are defined thus:

REAL floatparam[MAXFLOATPARAM];

Space for the returned strings must be allocated thus:

strparam[n] = (char *)malloc(MAXSTRLEN * sizeof(char));

and repeated for each parameter.

The keyword list with type and numbers of returned parameters is constructed using the MAKEKEY macros:

MAKEKEY(keywords[0],"RANGE",NUMBER,2);
MAKEKEY(keywords[1],"STRING",STRING,1);

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:

MAKEMKEY(keywords[0],"RANGE",NUMBER,2,2);
MAKEMKEY(keywords[1],"STRING",STRING,1,3);

Usage:

blParse(comline,nkeys,keywords,floatparam,strparam)
Parameters
[in]*comlineA command line string to parse
[in]nkeysNumber of keywords
[in]*keywordsArray of keyword structures
[out]*floatparamArray of returned strings
[out]**strparamArray of pointers to returned strings
Returns
Index of found command or error flag
blMparse(comline,nkeys,keywords,floatparam,strparam,nparam)
Parameters
[in]*comlineA command line string to parse
[in]nkeysNumber of keywords
[in]*keywordsArray of keyword structures
[out]*floatparamArray of returned strings
[out]**strparamArray of pointers to returned strings
[out]*nparamNumber of parameters found
Returns
Index of found command or error flag

Revision History:

Definition in file parse.c.

Macro Definition Documentation

#define CR   13

Definition at line 176 of file parse.c.

#define DIC   34 /* Double inverted commas */

Definition at line 177 of file parse.c.

#define LF   10

Definition at line 175 of file parse.c.

Function Documentation

int blGetParam ( char *  command,
REAL value,
int *  nletters 
)
Parameters
[in]*commandA character string
[out]*valueReturned float value
[out]*nlettersNumber of charcters pulled out of the command string
Returns
0 If error 1 If OK

Extracts the first space-delimited number from the `command' character string.

  • 11.07.90 Original By: ACRM
  • 22.04.93 Tidied comments, etc. Corrected NULL to 0
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 412 of file parse.c.

int blGetString ( char *  command,
char *  strparam 
)
Parameters
[in]*commandA character string
[out]*strparamReturned character string
Returns
Number of characters pulled out of the command string

Returns the first space-delimited group of characters from character string `command'

  • 11.07.90 Original By: ACRM
  • 22.04.93 Tidied comments, etc. Changed toggle method
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 358 of file parse.c.

int blMatch ( char *  comstring,
char *  string2,
int *  nletters 
)
Parameters
[in]*comstringA character string
[in]*string2A second string
[out]*nlettersNumber of letters matched
Returns
0 String mismatch 1 First string finished first 2 Second string finished first

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.

  • 11.07.90 Original By: ACRM
  • 22.04.93 Tidied comments, etc. Added check on malloc and corrected calls to free()
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 304 of file parse.c.

int blMparse ( char *  comline,
int  nkeys,
MKeyWd keywords,
REAL floatparam,
char **  strparam,
int *  nparam 
)
Parameters
[in]*comlineA command line string to parse
[in]nkeysNumber of keywords
[in]*keywordsArray of keyword structures
[out]*floatparamArray of returned strings
[out]**strparamArray of pointers to returned strings
[out]*nparamNumber of parameters found
Returns
Index of found command or error flag

As blParse(), but allows variable number of parameters to each keyword.

  • 23.02.94 Original based on parse() By: ACRM
  • 11.03.94 Added $ line handling
  • 08.10.99 Initialise nlett to 0
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 447 of file parse.c.

int blParse ( char *  comline,
int  nkeys,
KeyWd keywords,
REAL floatparam,
char **  strparam 
)
Parameters
[in]*comlineA command line string to parse
[in]nkeysNumber of keywords
[in]*keywordsArray of keyword structures
[out]*floatparamArray of returned strings
[out]**strparamArray of pointers to returned strings
Returns
Index of found command or error flag

Keyword-based command parser using a fixed number of parameters per command

  • 11.07.90 Original By: ACRM
  • 22.04.93 Tidied comments, etc. Corrected NULL to 0.
  • 11.03.94 Added $ line handling
  • 08.10.99 Initialise nlett
  • 28.02.11 Added # for comments
  • 07.07.14 Use bl prefix for functions By: CTP

Definition at line 202 of file parse.c.