Guardtime Parameter and Task Handling SDK libparamset
Functions
strn.h File Reference
#include <stddef.h>
#include <stdarg.h>

Go to the source code of this file.

Functions

size_t PST_snprintf (char *buf, size_t n, const char *format,...)
 
char * PST_strncpy (char *destination, const char *source, size_t n)
 
size_t PST_snhiprintf (char *buf, size_t buf_len, int indent, int nxtLnIndnt, int headerLen, int rowLen, const char *paramName, const char delimiter, const char *desc,...)
 

Function Documentation

◆ PST_snhiprintf()

size_t PST_snhiprintf ( char *  buf,
size_t  buf_len,
int  indent,
int  nxtLnIndnt,
int  headerLen,
int  rowLen,
const char *  paramName,
const char  delimiter,
const char *  desc,
  ... 
)

Similar to the PST_snprintf but is used to print text for command-line help. Formatter can:

  • Print formatted text (desc) with maximum length (including indention) of rowLen.
  • Print indented text (desc) with indention of indent. See Example 1.
  • Print indented text (desc) where next line has extra indention of nxtLnIndnt. See Example 2.
  • Print a header with length of headerLen. It is composed of paramName and delimiter (including indent). If real header is larger than headerLen, it is printed without delimiter on the first line. In that case delimiter is printed on the next row followed by description (desc). See Example 3 and Example 4.

Usage and examples:

[ maximum row size ]
Regular text with indention:
[ indent ][ text line 1 ]
[ indent ][ text line N ]
Example 1. (indent = 2, headerLen = 0, delimiter = '\0', nxtLnIndnt = 0, paramName = NULL, rowLen = 10):
"1234567890"
" this is "
" sample"
Regular text with extra indention from next row:
[indent][ text line 1 ]
[indent][eint][ text line 2 ]
[indent][eint][ text line N ]
Example 2. (indent = 2, headerLen = 0, delimiter = '\0', nxtLnIndnt = 2, paramName = NULL, rowLen = 10):
"1234567890"
" this is "
" sample"
" text "
Parameter description with indention:
[header][delimiter][ desc. line 1 ]
[ indent ][ desc. line N ]
Example 3. (indent = 2, headerLen = 8, delimiter = '-', nxtLnIndnt = 0, paramName = "-a", rowLen = 20):
"123456789_1234567890"
" -a - this is my "
" description "
Parameter description with indention where header is larger than expected:
[ too large header]
[indent][delimiter][ desc. line 1 ]
[indent ][ desc. line N ]
Example 4. (indent = 2, headerLen = 8, delimiter = '-', nxtLnIndnt = 0, paramName = "-a", rowLen = 20):
"123456789_1234567890"
" --long "
" - this is long"
" description "
Parameters
bufPointer to buffer.
buf_lenThe size of the buffer.
indentThe size of regular indention. Can be 0.
nxtLnIndntThe amount of extra indention beginning from the next line. Can be 0.
headerLenThe size of the header. Can be 0.
rowLenThe overall size of the line.
paramNameParameter name used to compose header.
delimiterDelimiter character used for delimiter that separates parameter name from description.
descFormat string, parameter description.
...Extra parameters for formatting.
Returns
The number of characters written, not including terminating NULL character. On error 0 is returned.

◆ PST_snprintf()

size_t PST_snprintf ( char *  buf,
size_t  n,
const char *  format,
  ... 
)

Platform independent version of snprintf.

Parameters
bufPointer to buffer.
nMaximum number of bytes to be written into buffer. Includes terminating NULL character.
formatFormat string.
...Extra parameters for formatting.
Returns
The number of characters written, not including terminating NULL character. On error 0 is returned.

◆ PST_strncpy()

char* PST_strncpy ( char *  destination,
const char *  source,
size_t  n 
)

Platform independent version of strncpy that guarantees NULL terminated destination. To copy N characters from source to destination n and size of destination must be N + 1.

Parameters
destinationPointer to destination.
sourcePointer to source.
nMaximum number of characters to be copied including terminating NULL.
Returns
The pointer to destination. On error NULL is returned.