NuSMV/code/nusmv/core/utils/ucmd.h File Reference

#include <stdlib.h>
#include "nusmv/core/utils/utils.h"
#include "nusmv/core/opt/opt.h"

Go to the source code of this file.

Data Structures

struct  SubstString
 SubstString is the structure passed to the function apply_string_macro_expansion. More...
struct  SubstValue
 SubstValue a service structure used by SubstString. Ignore. More...

Defines

#define SYMBOL_ASSIGN(_subst, _symbol, _type, _format, _value)
 SYMBOL_ASSIGN helps to fill the fields of the SubstString structure, previously allocated with the SYMBOL_CREATE macro.
#define SYMBOL_CREATE()   { "\0", {sv_undef, {NULL}}, "" }
 SYMBOL_CREATE helps the static allocation of a new symbol usable with the function apply_string_macro_expansion.

Enumerations

enum  SubstValueType {
  sv_string, sv_integer, sv_floating, sv_pointer,
  sv_undef
}
 

Header part of ucmd.c.

More...

Functions

void apply_string_macro_expansion (const SubstString *const subst, char *string, size_t buf_len)
 Searches for a symbol in the given string, and and substitutes all its occurences with the specified element, using the given format.
int util_is_string_null (const char *string)
 Checks if given string is NULL, "", or the converted string of NULL.
int util_str2int (const char *str, int *value)
 Converts a given string representing a number (base 10) to an integer with the same value.
int util_str2int_incr (const char *str, char **endptr, int *out)
 An abstraction over BSD strtol for integers.

Define Documentation

#define SYMBOL_ASSIGN ( _subst,
_symbol,
_type,
_format,
_value   ) 
Value:
_subst.symbol = _symbol; \
_subst.value.type = sv_##_type;    \
_subst.format = _format;  \
_subst.value.assign._type = _value

SYMBOL_ASSIGN helps to fill the fields of the SubstString structure, previously allocated with the SYMBOL_CREATE macro.

The first parameter is the variable assigned by SYMBOL_CREATE;
The third parameter is the type of the value that will substitute the symbol. Can be: string, integer, floating or pointer.
The fourth parameter is the format string (as the printf format string) used to convert the value in a string. The fifth parameter is the static value which will substitute all occurences of the symbol.

The structure passed as first parameter will change

See also:
SYMBOL_CREATE, apply_string_macro_expansion
 
#define SYMBOL_CREATE (  )     { "\0", {sv_undef, {NULL}}, "" }

SYMBOL_CREATE helps the static allocation of a new symbol usable with the function apply_string_macro_expansion.

The macro parameter is the symbol string which will be searched for substitution in the function apply_string_macro_expansion

See also:
SYMBOL_ASSIGN, apply_string_macro_expansion

Enumeration Type Documentation

Header part of ucmd.c.

Author:
Roberto Cavada This file contains useful structures, macros and functions to be used in command line processing
Todo:
Missing synopsis
Todo:
Missing description
Enumerator:
sv_string 
sv_integer 
sv_floating 
sv_pointer 
sv_undef 

Function Documentation

void apply_string_macro_expansion ( const SubstString *const   subst,
char *  string,
size_t  buf_len 
)

Searches for a symbol in the given string, and and substitutes all its occurences with the specified element, using the given format.

AutomaticStart

The first parameter subst contains information about the symbol to be checked and about the element which substitutes every occurence of the symbol, and the format (as in printf) used to convert the element in a string. The element has a type (integer, string, float, etc.) and a statically assigned value.
The second parameter string contains the string to be searched for, and the string finally returned too. So it is *very important* you supply a buffer large enought to contain the larger string between source and destination strings. Use the third parameter to fix the maximum buffer length.

The element can be built with a 2-passes procedure. The first pass consists in constructing the static instance of the element. Use the SYMBOL_CREATE macro to build it, and assign the result to a SubstString type variable. Then assign the substitution value to the created instance using the macro SYMBOL_ASSIGN.
Example of usage:

  {
    char szBuffer[256];
    SubstString sb = SYMBOL_CREATE("$D");
    SYMBOL_ASSIGN(sb, integer, "%d", 10);
    strncpy(szBuffer, "Every symbol $D will be substituted with $D",
            sizeof(szBuffer));
    apply_string_macro_expansion(&sb, szBuffer, sizeof(szBuffer));
  }
  

The given string will change

See also:
SYMBOL_CREATE, SYMBOL_ASSIGN, SubstString
int util_is_string_null ( const char *  string  ) 

Checks if given string is NULL, "", or the converted string of NULL.

Returns 1 if the string is equal to "", NULL or equal to the converted string of NULL (as sprintf does). Otherwise returns 0.

int util_str2int ( const char *  str,
int *  value 
)

Converts a given string representing a number (base 10) to an integer with the same value.

Returns zero (0) if conversion is carried out successfully, otherwise returns 1

'value' parameter might change

int util_str2int_incr ( const char *  str,
char **  endptr,
int *  out 
)

An abstraction over BSD strtol for integers.

Parses an integer value from a string, performing error-checking on the parsed value. This function can be used to parse incrementally a complex string made of numbers and separators.

Returns 0 iff no error was detected.

Remarks:

Empty strings are allowed as a corner case. They are interpreted as 0.

*endptr points to the next character in string, *out contains the integer value corresponding to the parsed string.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on 14 Oct 2015 for NuSMV Developers Manual by  doxygen 1.6.1