GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> CLI / V0-1-2 > cli / rhel6-64


Interface   Data Structures   File List   Data Fields   Globals  

CLI_parseValue.c File Reference

Parses a value (a parameter or the value of a qualifier). More...

#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <CLI/CLI_msgs.h>
#include <CLI/CLI_pubdefs.h>
#include <MDB/MDB_pubdefs.h>
#include <CLI_prvdefs.h>

Functions

static void clearValueList (CLI_Valu *head)
 Clear out a value list.
static unsigned int saveValue (char *tbeg, char *tend, unsigned short type, CLI_KeyList *keys, CLI_Valu **last)
 Save a parsed value.
static unsigned int validateKey (char *tbeg, char *tend, CLI_KeyList *list, CLI_KeyDef **key)
 Validate a value as a member of a keyword list.
static unsigned int validateTime (const char *tbeg, const char *tend, struct tm *bdt)
 Validate/parse a timestamp string.
unsigned int CLI_parseValue (char *tbeg, char *tend, unsigned short type, CLI_KeyList *keys, CLI_Valu **list)
 Parse a command line value.
time_t CLI_timeString2Unix (const char *text, CLI_Timezone zone)
 Parse a string timestamp into a unix calendar time.
void CLI_timeUnix2String (time_t time, char *text, CLI_Timezone zone)
 Parse a unix calendar time into a string timestamp.


Detailed Description

Parses a value (a parameter or the value of a qualifier).

CVS $Id: CLI_parseValue.c,v 1.7 2011/03/25 00:51:25 apw Exp $
Author:
A.P.Waite
CLI_parseValue.c parses the input line for a value. This might be a parameter of the value of a qualifier.

Function Documentation

static void clearValueList ( CLI_Valu head  )  [static]

Clear out a value list.

Parameters:
head Head of list of values

References _CLI_Valu::next, and _CLI_Valu::text.

Referenced by CLI_parseValue().

unsigned int CLI_parseValue ( char *  tbeg,
char *  tend,
unsigned short  type,
CLI_KeyList keys,
CLI_Valu **  list 
)

Parse a command line value.

Parameters:
tbeg First character
tend (One past) the last character
type Type constraints on value(s)
keys Keyword list (if needed)
list Location where the value list should be saved
Return values:
CLI_BADPAREN Unexpected/unbalanced parentheses
CLI_BADQUOTE Unexpected/unbalanced quotation marks
CLI_KEYAMBG Keyword is ambiguous
CLI_KEYUND Value is not a valid keyword
CLI_NOTALLOC Memory allocation failure
CLI_SUCCESS Success
CLI_VALEND Unexpected end of value
CLI_VALLIST Unexpected list of values
CLI_VALNTFLT Value is not a floating point number
CLI_VALNTINT Value is not an integer

References clearValueList(), and saveValue().

Referenced by savePval(), and saveQval().

time_t CLI_timeString2Unix ( const char *  text,
CLI_Timezone  zone 
)

Parse a string timestamp into a unix calendar time.

Parameters:
text String timestamp (presumably a token from CLI parsing)
zone Zone in which to perform the conversion
Returns:
0 Invalid timestamp string

x Unix calendar time

References CLI_K_TIMEZONE_UTC, and validateTime().

void CLI_timeUnix2String ( time_t  time,
char *  text,
CLI_Timezone  zone 
)

Parse a unix calendar time into a string timestamp.

Parameters:
time Unix calendar time
text String timestamp
zone Zone in which to perform the conversion
Returns:
0 Invalid timestamp string

x Unix calendar time

References CLI_K_TIMEZONE_UTC.

static unsigned int saveValue ( char *  tbeg,
char *  tend,
unsigned short  type,
CLI_KeyList keys,
CLI_Valu **  last 
) [static]

Save a parsed value.

Parameters:
tbeg Start of value to save (token begin)
tend End of value to save plus one (token end)
type Type constraints on value
keys Keyword list
last Last value structure in value list
Return values:
CLI_KEYAMBG Keyword is ambiguous
CLI_KEYUND Value is not a valid keyword
CLI_NOTALLOC Memory allocation failure
CLI_SUCCESS Success
CLI_VALNTFLT Value is not a floating point number
CLI_VALNTINT Value is not an integer

References _CLI_Valu::next, _CLI_Valu::text, _CLI_KeyDef::text, validateKey(), and validateTime().

Referenced by CLI_parseValue().

static unsigned int validateKey ( char *  tbeg,
char *  tend,
CLI_KeyList list,
CLI_KeyDef **  key 
) [static]

Validate a value as a member of a keyword list.

Parameters:
list Head of the list of keywords
tbeg Start of value to test (token begin)
tend End of value to test plus one (token end)
key Valid key definition (returned)
Warning:
Return values are not reported
Return values:
CLI_KEYAMBG Keyword is ambiguous
CLI_KEYUND Value is not a valid keyword
CLI_SUCCESS Success

References _CLI_KeyList::key, _CLI_KeyDef::next, _CLI_KeyDef::text, and _CLI_KeyDef::tlen.

Referenced by saveValue().

static unsigned int validateTime ( const char *  tbeg,
const char *  tend,
struct tm *  bdt 
) [static]

Validate/parse a timestamp string.

Parameters:
tbeg Start of value to test (token begin)
tend End of value to test plus one (token end)
bdt Caller provided "broken-down-time" structure
Warning:
Return values are not reported
Return values:
CLI_SUCCESS Success
CLI_VALNTTIM Value is not a valid timestamp
Parses a string as a date/time string. It only accepts one format. A plague on both U.S. and European formats, pick a format that sorts well (when all fields are correctly padded with leading zeros). Oh well, allow the leading zeros to be dropped. The format is basically:

"YYYY-MM-DD HH:MI:SS"

Or in regular expression speak:

"[\d]{4:4}-[\d]{1:2}-[\d]{1:2} [\d]{1:2}:[\d]{1:2}:[\d]{1:2}"

As a courtesy, allow the string to be truncated from the right, defaulting any missing fields to zero.

Referenced by CLI_timeString2Unix(), and saveValue().


Generated on Tue Nov 29 16:30:28 2011 by  doxygen 1.5.8