Small library of generic text parsing functions enough to parse simple grammars, like in config files.
For such grammars, it may be easier to implement parsing rules by hand, over than using parser generator like Bison.
To use these functions, source text should be available as a read-only raw array of bytes in utf-8 or other ascii-based encoding (for example latin1 or cp1251).
Large text files may be mmap()'ed to a memory region before parsing.
- Generic text functions
- Source text iterator API
- Handy functions for use with source text iterator
- Helpers for composing error message
- Installing
- digit_value
- is_digit
- _is_first_name
- _is_next_name
- _hex_char_value
- is_first_name (table lookup-based)
- is_next_name (table lookup-based)
- hex_char_value (table lookup-based)
- gt_scan_name
- gt_scan_uint
- gt_scan_uint64
- gt_scan_hex
- gt_scan_hex64
- is_space
Source text iterator API (gtparser/parser_base.h)
- src_iter_init
- src_iter_step
- src_iter_eof
- src_iter_next
- src_iter_process_tab
- src_iter_check_tab
- src_iter_inc_line
- src_iter_check
- src_iter_current_char
- src_iter_char_or_eof
- src_iter_get_column
- src_iter_get_pos
- src_iter_return_pos
- src_iter_save_pos
- src_iter_return_save_pos
- src_iter_restore_pos
- gt_skip_rest_of_line
- _skip_comment
- read_non_space_skip_comments
- read_non_space_stop_eol
- read_name
- read_uint
- read_uint64
- read_hex
- read_hex64
- gt_parse_cstring
- gt_copy_cstring
- parser_err_reserve
- parser_err_reserve_
- parser_err_prepend_at
- parser_err_prepend_at_
- parser_err_prepend_at_line
- parser_err_prepend_at_line_
- parser_err_prepend_at_char
- parser_err_prepend_at_char_
- parser_err_print_char
- parser_err_print_chars
- parser_err_print_string_constant
- parser_err_print_string
- parser_err_print
- parser_err_finish
unsigned digit_value(char c);
Parameters:
c
- char to check
Returns: value <= 9
if c
is matched by regexp [0-9]
Declared in: gtparser/char_func.h
int is_digit(char c);
Parameters:
c
- char to check
Returns: non-zero if c
is matched by regexp [0-9]
Declared in: gtparser/char_func.h
int _is_first_name(char c);
Parameters:
c
- char to check
Returns: non-zero if c
is matched by regexp: [_a-zA-Z]
Declared in: gtparser/char_func.h
Note: table lookup-based is_first_name()
may be slightly faster than this header-only inline _is_first_name()
int _is_next_name(char c);
Parameters:
c
- char to check
Returns: non-zero if c
is matched by regexp: [_a-zA-Z0-9]
Declared in: gtparser/char_func.h
Note: table lookup-based is_next_name()
may be slightly faster than this header-only inline _is_next_name()
unsigned _hex_char_value(char c);
Parameters:
c
- char to check
Returns: value <= 15
if c
is matched by regexp: [0-9a-fA-F]
Declared in: gtparser/char_func.h
Note: table lookup-based hex_char_value()
may be slightly faster than this header-only inline _hex_char_value()
int is_first_name(char c);
Parameters:
c
- char to check
Returns: non-zero if c
is matched by regexp: [_a-zA-Z]
Declared in: gtparser/name_scanner.h
int is_next_name(char c);
Parameters:
c
- char to check
Returns: non-zero if c
is matched by regexp: [_a-zA-Z0-9]
Declared in: gtparser/name_scanner.h
unsigned hex_char_value(char c);
Parameters:
c
- char to check
Returns: value <= 15
if c
is matched by regexp: [0-9a-fA-F]
Declared in: gtparser/name_scanner.h
const char *gt_scan_name(const char *s/*<end*/, const char *const end);
Parameters:
s
- points to first char of a name in a buffer (likely a char matched by regexp:[_a-zA-Z]
)end
- points one char beyond the buffer containing a name
Note: s < end
Returns: pointer beyond the last char of scanned name (pointer to char not matched by regexp: [_a-zA-Z0-9]
) or end
Declared in: gtparser/name_scanner.h
const char *gt_scan_uint(const char *s/*<end*/, const char *const end, unsigned *number/*out*/);
const char *gt_scan_uint64(const char *s/*<end*/, const char *const end, unsigned INT64_TYPE *number/*out*/);
Parameters:
s
- points to first char of unsigned decimal integer printed in a buffer (char matched by regexp:[0-9]
)end
- points one char beyond the buffer containing printed unsigned decimal integernumber
- (output) scanned unsigned (64-bit) integer value
Notes:
s < end
INT64_TYPE
- 64-bit integer type, by default defined aslong long
Returns: pointer beyond the last char of scanned unsigned decimal integer (pointer to char not matched by regexp: [0-9]
) or end
Note: on unsigned integer overflow, if printed number is too big, returns NULL
Declared in: gtparser/int_scanner.h
const char *gt_scan_hex(const char *s/*<end*/, const char *const end, unsigned *number/*out*/);
const char *gt_scan_hex64(const char *s/*<end*/, const char *const end, unsigned INT64_TYPE *number/*out*/);
Parameters:
s
- points to first char of unsigned hexadecimal integer printed in a buffer (char matched by regexp:[0-9a-fA-F]
)end
- points one char beyond the buffer containing printed unsigned hexadecimal integernumber
- (output) scanned unsigned (64-bit) integer value
Notes:
s < end
INT64_TYPE
- 64-bit integer type, by default defined aslong long
Returns: pointer beyond the last char of scanned unsigned hexadecimal integer (pointer to char not matched by regexp: [0-9a-fA-F]
) or end
Note: on unsigned integer overflow, if printed number is too big, returns NULL
Declared in: gtparser/int_scanner.h
int is_space(char c);
Parameters:
c
- checked char
Returns: non-zero if c
is a space - character with value in ASCII range [0..32]
Note: this fast and simple function is usable to skip all space characters, like tabulations, new lines, form feeds, bells and so on
Declared in: gtparser/parser_base.h
void src_iter_init(struct src_iter *it, const char *input, size_t size);
Parameters:
it
- iterator structure to initializeinput
- read-only text buffer to parsesize
- number of chars to parse in text buffer
Note: Iterator line and column numbers are set to 1
Example:
extern const char *input;
extern size_t size;
struct src_iter it;
src_iter_init(&it, input, size);
Declared in: gtparser/parser_base.h
void src_iter_step(struct src_iter *it);
Parameters:
it
- text iterator structure
Iterator column number incremented by 1
Notes:
- assume current char was checked for
<TAB>
(horizontal tabulate character'\t'
) or<EOL>
(end-of-line indicator character'\n'
) - iterator must not point to
<EOF>
(end-of-file indicator)
Declared in: gtparser/parser_base.h
int src_iter_eof(const struct src_iter *it);
Parameters:
it
- text iterator structure
Returns: non-zero if iterator points to <EOF>
, 0
- if not
Example of simple parsing loop:
extern struct src_iter *it;
while (!src_iter_eof(it)) {
/* process current character */
src_iter_step(it);
}
Declared in: gtparser/parser_base.h
int src_iter_next(struct src_iter *it);
Parameters:
it
- text iterator structure
Returns: non-zero if current character is not <EOF>
, may continue parsing
Iterator column number incremented by 1
Notes:
- assume current char was checked for
<TAB>
or<EOL>
- iterator must not point to
<EOF>
Example of simple parsing loop:
extern struct src_iter *it;
if (!src_iter_eof(it)) {
do {
/* process current character */
} while (src_iter_next(it));
}
Declared in: gtparser/parser_base.h
void src_iter_process_tab(struct src_iter *it);
Parameters:
it
- text iterator structure
Iterator column number incremented by some value in range [1..GTPARSER_TAB_SIZE]
, depending on current column number value
Notes:
- iterator must point to
<TAB>
character - horizontal tabulate width equals to
GTPARSER_TAB_SIZE
spaces,4
by default
Declared in: gtparser/parser_base.h
void src_iter_check_tab(struct src_iter *it);
Parameters:
it
- text iterator structure
Check if current character is a <TAB>
and account it by src_iter_process_tab()
if it is
Note: iterator must not point to <EOF>
Declared in: gtparser/parser_base.h
void src_iter_inc_line(struct src_iter *it);
Parameters:
it
- text iterator structure
Increment iterator line number, set column number to zero
Note: iterator must point to <EOL>
character
Declared in: gtparser/parser_base.h
void src_iter_check(struct src_iter *it);
Parameters:
it
- text iterator structure
Check if current character is a <TAB>
or <EOL>
, then account it appropriately by src_iter_process_tab()
or src_iter_inc_line()
Note: iterator must not point to <EOF>
Example of simple parsing loop:
extern struct src_iter *it;
if (!src_iter_eof(it)) {
do {
/* process current character */
/* account <TAB> or <EOL> */
src_iter_check(it);
} while (src_iter_next(it));
}
Declared in: gtparser/parser_base.h
char src_iter_current_char(const struct src_iter *it);
Parameters:
it
- text iterator structure
Returns: current character iterator points to
Note: iterator must not point to <EOF>
Example of simple parsing loop:
extern struct src_iter *it;
if (!src_iter_eof(it)) {
do {
/* get current character to process */
char c = src_iter_current_char(it);
/* process current character */
/* account <TAB> or <EOL> */
src_iter_check(it);
} while (src_iter_next(it));
}
Declared in: gtparser/parser_base.h
char src_iter_char_or_eof(const struct src_iter *it);
Parameters:
it
- text iterator structure
Returns: current non-zero character if iterator points to non-<EOF>
, else returns '\0'
Note: this function may be usable for parsing texts where characters with zero value are not expected
Example of simple parsing loop:
extern struct src_iter *it;
for (;;) {
/* get current character to process */
char c = src_iter_char_or_eof(it);
if (!c)
break; /* iterator points to <EOF> */
/* process current character */
/* account <TAB> or <EOL> */
src_iter_check(it);
}
Declared in: gtparser/parser_base.h
unsigned src_iter_get_column(const struct src_iter *it);
Parameters:
it
- text iterator structure
Returns: current iterator column number
Note: column number may overflow for large texts, but it is not fatal for parsing
Declared in: gtparser/parser_base.h
void src_iter_get_pos(const struct src_iter *it, struct src_pos *pos/*out*/);
Parameters:
it
- text iterator structurepos
- (output) current iterator text position
Declared in: gtparser/parser_base.h
struct src_pos src_iter_return_pos(const struct src_iter *it);
Parameters:
it
- text iterator structure
Returns: current iterator text position
Declared in: gtparser/parser_base.h
void src_iter_save_pos(const struct src_iter *it, struct src_save_pos *save_pos/*out*/);
Parameters:
it
- text iterator structuresave_pos
- (output) current iterator state
save_pos
may be used to restore iterator state - unparse characters processed after save_pos
was taken
Declared in: gtparser/parser_base.h
struct src_save_pos src_iter_return_save_pos(const struct src_iter *it);
Parameters:
it
- text iterator structure
Returns: current iterator state
Returned state value may be used to restore iterator state - unparse characters processed after state was taken
Declared in: gtparser/parser_base.h
void src_iter_restore_pos(struct src_iter *it, const struct src_save_pos *save_pos);
Parameters:
it
- text iterator structuresave_pos
- saved iterator state
Note: save_pos
may be obtained either by src_iter_save_pos()
or src_iter_return_save_pos()
Declared in: gtparser/parser_base.h
void gt_skip_rest_of_line(struct src_iter *it);
Parameters:
it
- text iterator structure
Skip current character, then next characters until <EOL>
, then skip <EOL>
On return, iterator points to beginning of next line or to <EOF>
Notes:
- this function is usable to skip one-line comment
- before the call, iterator must not point to
<EOF>
(assume iterator points to char indicating start of a comment)
Declared in: gtparser/parser_base.h
void _skip_comment(struct src_iter *it);
Just another name of gt_skip_rest_of_line()
function
Declared in: gtparser/parser_base.h
char read_non_space_skip_comments(struct src_iter *it, char comment);
Parameters:
it
- text iterator structurecomment
- char indicating start of one-line comment
Returns: current non-space char or '\0'
, if non-space char was not found and iterator points to <EOF>
Notes:
- checks all characters, starting from current one by
is_space()
function - skips one-line comments by
_skip_comment()
function - iterator may point to
<EOF>
Declared in: gtparser/parser_base.h
char read_non_space_stop_eol(struct src_iter *it);
Parameters:
it
- text iterator structure
Returns: current non-space char or <EOL>
or '\0'
, if non-space char or <EOL>
was not found and iterator points to <EOF>
Declared in: gtparser/parser_base.h
const char *read_name(struct src_iter *it);
Parameters:
it
- source text iterator structure
Returns: pointer to first char of read name
Notes:
- before the call,
it
must point to first char of a name (src_iter_current_char()
returns likely a char matched by regexp:[_a-zA-Z]
) - by return,
it
will point to non-name char (not matched by regexp[_a-zA-Z0-9]
) or to<EOF>
Declared in: gtparser/name_parser.h
int read_uint(struct src_iter *it, unsigned *number/*out*/);
int read_uint64(struct src_iter *it, unsigned INT64_TYPE *number/*out*/);
Parameters:
it
- source text iterator structurenumber
- (output) parsed unsigned (64-bit) integer value
Returns: 1
if number was successfully read, 0
- on unsigned integer overflow, if printed number is too big
Notes:
- before the call,
it
must point to first char of unsigned decimal integer (src_iter_current_char()
must return a char matched by regexp:[0-9]
) - by successful return,
it
will point beyond the last char of scanned unsigned decimal integer (points to a char not matched by regexp:[0-9]
or to<EOF>
) - on integer overflow,
it
not changed INT64_TYPE
- 64-bit integer type, by default defined aslong long
Declared in: gtparser/int_parser.h
int read_hex(struct src_iter *it, unsigned *number/*out*/);
int read_hex64(struct src_iter *it, unsigned INT64_TYPE *number/*out*/);
Parameters:
it
- source text iterator structurenumber
- (output) parsed unsigned (64-bit) integer value
Returns: 1
if number was successfully read, 0
- on unsigned integer overflow, if printed number is too big
Notes:
- before the call,
it
must point to first char of unsigned hexadecimal integer (src_iter_current_char()
must return a char matched by regexp:[0-9a-fA-F]
) - by successful return,
it
will point beyond the last char of scanned unsigned hexadecimal integer (points to a char not matched by regexp:[0-9a-fA-F]
or to<EOF>
) - on integer overflow,
it
not changed INT64_TYPE
- 64-bit integer type, by default defined aslong long
Declared in: gtparser/int_parser.h
enum PARSE_CSTRING_ERR {
PARSE_CSTRING_OK = 0, /* C-string successfully parsed */
PARSE_CSTRING_UNESCAPED_NEWLINE, /* unescaped line-feed '\n' or carriage-return '\r' */
PARSE_CSTRING_EXPECTING_LINE_FEED, /* expecting line-feed '\n' after carriage-return '\r' */
PARSE_CSTRING_EXPECTING_HEX_DIGIT, /* expecting hexadecimal digit in hex escape sequence after '\x' */
PARSE_CSTRING_TOO_BIG_OCTAL, /* too big octal character value > 255 in string, maximum allowed is '\377' */
PARSE_CSTRING_NULL_INSIDE_CSTRING, /* null character '\0' inside C-string is not allowed */
PARSE_CSTRING_UNTERMINATED /* unterminated string */
};
enum PARSE_CSTRING_ERR gt_parse_cstring(struct src_iter *it, size_t *removed/*out*/);
Parameters:
it
- source text iterator structureremoved
- (output) number of meta-characters to be removed bygt_copy_cstring()
Returns: one of enum PARSE_CSTRING_ERR
values
Notes:
- before the call,
it
must point to first (opening) quote of source C-string (src_iter_current_char()
returns'"'
) - by successful return,
it
will point to last (closing) quote of source C-string - on error,
it
will point to error position
Meta-characters removed by gt_copy_cstring()
:
- each line continuation-split (consists of two chars:
\<EOL>
) is removed - each
'\'
is removed and next char after it is unescaped (likely converted to some to non-printable char) - list of recognized escape sequences (a character after
'\'
will be replaced with byte value in{}
):\a{0x07} \b{0x08} \t{0x09} \n{0x0a} \v{0x0b} \f{0x0c} \r{0x0d}
- encoded characters in octadecimal (
\377
) or hexadecimal (\xff
) encoding are unencoded - octadecimal-encoded chars (max 3 octadecimal digits after
'\'
):\0..\7, \00..\77, \000..\377
- hexadecimal-encoded chars (max 2 hexadecimal digits after
'\x'
):\x0..\xf, \x00..\xff
Example: see gt_copy_cstring()
Declared in: gtparser/cstring_parser.h
void gt_copy_cstring(char dst[]/*out*/, const char *begin, const char *end, size_t removed);
Parameters:
dst
- destination buffer to copy and unescape C-string tobegin
- points to next char after first (opening) quote in source C-stringend
- points to the last (closing) quote in source C-stringremoved
- number of meta-characters to be removed (determined bygt_parse_cstring()
)
Note: dst
buffer must be large enough to read unescaped source C-string into it: dst
buffer length must be >= (end - begin - removed)
Example:
extern struct src_iter *it;
extern char dst[];
extern size_t dst_size;
size_t removed;
const char *first = it->current; /* assume it points to first (opening) quote */
enum PARSE_CSTRING_ERR err = gt_parse_cstring(it, &removed/*out*/);
if (PARSE_CSTRING_OK == err) {
const char *last = it->current; /* now it points to last (closing) quote */
size_t need_size = (size_t)(last - first) - removed; /* size of buffer to hold unescaped C-string + terminating '\0' */
if (dst_size >= need_size) {
gt_copy_cstring(dst, first + 1/*quote*/, last, removed);
dst[need_size - 1] = '\0';
}
}
Declared in: gtparser/cstring_parser.h
char *parser_err_reserve(char err_buf[], size_t err_buf_size, size_t filename_reserve);
char *parser_err_reserve_(char err_buf[], size_t err_buf_size);
Parameters:
err_buf
- buffer where to compose error messageerr_buf_size
- size oferr_buf
filename_reserve
- how much space to reserve inerr_buf
for file name passed toparser_err_prepend_at()
Returns: pointer to a space inside err_buf
to print error message details to, or returns err_buf
, if err_buf
is too small
parser_err_reserve_()
- just calls parser_err_reserve()
with zero filename_reserve
value
Note: if err_buf
is big enough, then parser_err_prepend_at()
will prepend resulting error message with something like "filename: parse error at (4294967295:4294967295):"
Example: see parser_err_prepend_at()
Declared in: gtparser/parser_err.h
const char *parser_err_prepend_at(
char err_buf,
size_t err_buf_size,
size_t filename_reserve/*0?*/,
const char *filename/*NULL?*/,
const char *err,
unsigned line/*0?*/,
unsigned column/*0?*/);
const char *parser_err_prepend_at_line(
char err_buf,
size_t err_buf_size,
size_t filename_reserve/*0?*/,
const char *filename/*NULL?*/,
const char *err,
unsigned line/*!=0*/);
const char *parser_err_prepend_at_char(
char err_buf,
size_t err_buf_size,
size_t filename_reserve/*0?*/,
const char *filename/*NULL?*/,
const char *err,
unsigned column/*!=0*/);
const char *parser_err_prepend_at_(
char err_buf,
size_t err_buf_size,
const char *err,
unsigned line/*0?*/,
unsigned column/*0?*/);
const char *parser_err_prepend_at_line_(
char err_buf,
size_t err_buf_size,
const char *err,
unsigned line/*!=0*/);
const char *parser_err_prepend_at_char_(
char err_buf,
size_t err_buf_size,
const char *err,
unsigned column/*!=0*/);
Parameters:
err_buf
- buffer where to compose error messageerr_buf_size
- size oferr_buf
filename_reserve
- how much space to reserve inerr_buf
for file namefilename
-'\0'
-terminated source file name where an error was encountered, may beNULL
err
-'\0'
-terminated error messageline
- source line number where a parsing error was encountered, if zero, then only column number is printedcolumn
- source column number where a parsing error was encountered, if zero, then only line number is printed
Returns: pointer to composed error message with prepended location info in err_buf
or err
, if err_buf
is too small
parser_err_prepend_at_line()
- just callsparser_err_prepend_at()
with zerocolumn
valueparser_err_prepend_at_char()
- just callsparser_err_prepend_at()
with zeroline
valueparser_err_prepend_at_()
- just callsparser_err_prepend_at()
with zerofilename_reserve
andNULL
filename
valuesparser_err_prepend_at_line_()
- just callsparser_err_prepend_at_line()
with zerofilename_reserve
andNULL
filename
valuesparser_err_prepend_at_char_()
- just callsparser_err_prepend_at_line()
with zerofilename_reserve
andNULL
filename
values
Note: if error message was printed to err_buf
(i.e. err
is the value returned by parser_err_reserve()
), then err_buf
, err_buf_size
and filename_reserve
must be the same that were passed to parser_err_reserve()
Example:
extern char err_buf[];
extern size_t err_buf_size;
extern size_t filename_reserve;
const char *err = parser_err_reserve(err_buf, err_buf_size, filename_reserve);
size_t err_space = (size_t)(err_buf + err_buf_size - err);
...
snprintf((char*)err, err_space, "some parameterized error message: %d", 100);
/* or */
err = "some error message without parameters";
...
extern const char *filename;
extern unsigned line;
extern unsigned column;
const char *err_msg = parser_err_prepend_at(
err_buf,
err_buf_size,
filename_reserve,
filename,
err,
line,
column);
Declared in: gtparser/parser_err.h
char *parser_err_print_char(char *buf/*<=end*/, const char *const end, char c);
Parameters:
buf
- position in destination buffer where to append characterend
- points one char beyond destination bufferc
- character to append to destination buffer
Returns: buffer position <= end
after appended character
Note: character added only if there is a place for it in destination buffer
Example:
extern char *buf;
extern char *end;
if (error)
buf = parser_err_print_char(buf, end, '.');
...
Declared in: gtparser/parser_err.h
char *parser_err_print_chars(char *buf/*<=end*/, const char *const end, const char chars[], size_t count);
Parameters:
buf
- position in destination buffer where to append charsend
- points one char beyond destination bufferchars
- characters array to append to destination buffercount
- number of characters to append to destination buffer
Returns: buffer position <= end
after appended characters
Note: characters array tail may be trimmed if it's too long to fit in buffer
Example:
extern char *buf;
extern char *end;
extern int error;
if (error)
buf = parser_err_print_chars(buf, end, "some error", 10);
...
Declared in: gtparser/parser_err.h
char *parser_err_print_string_constant(char *buf/*<=end*/, const char *const end, const char s[]);
Parameters:
buf
- position in destination buffer where to append string constantend
- points one char beyond destination buffers
- string constant to append to destination buffer
Returns: buffer position <= end
after appended string constant
Note: string constant tail may be trimmed if it's too long to fit in buffer
Note: implemented as a macro calling parser_err_print_chars()
Example:
extern char *buf;
extern char *end;
extern int error;
if (error)
buf = parser_err_print_string_constant(buf, end, "some error");
...
Declared in: gtparser/parser_err.h
char *parser_err_print_string(char *buf/*<=end*/, const char *const end, const char *string/*'\0'-terminated*/);
Parameters:
buf
- position in destination buffer where to append stringend
- points one char beyond destination bufferstring
- string to append to destination buffer
Returns: buffer position <= end
after appended string
Note: string tail may be trimmed if it's too long to fit in buffer
Example:
extern char *buf;
extern char *end;
extern int error;
extern const char *err_message1;
if (error)
buf = parser_err_print_string(buf, end, err_message1);
...
Declared in: gtparser/parser_err.h
char *parser_err_print(char *buf/*<=end*/, const char *const end, const char *format, ...);
Parameters:
buf
- position in destination buffer where to append formatted messageend
- points one char beyond destination bufferformat
-printf()
-like format string of parametrized message to append to destination buffer...
- parameters of parametrized message
Returns: buffer position <= end
after appended formatted message
Note: formatted message tail may be trimmed if it's too long to fit in buffer
Example:
extern char *buf;
extern char *end;
extern int error;
if (error)
buf = parser_err_print(buf, end, "an error occurred: %d", error);
...
Declared in: gtparser/parser_err.h
void parser_err_finish(char *buf/*<=end*/, const char *const end, size_t err_space);
Parameters:
buf
- position in destination buffer where to append'\0'
end
- points one char beyond destination buffererr_space
- total destination buffer size
Notes:
- if
err_space
is zero, nothing is appended - if
buf == end
, then last char in buffer is replaced with'\0'
Example:
extern char err[];
extern size_t err_space;
{
const char *buf = err;
const char *const end = err + err_space;
buf = parser_err_print(buf, end, "some message: %d", 100);
buf = parser_err_print(buf, end, "some message: %d", 101);
buf = parser_err_print(buf, end, "some message: %d", 102);
parser_err_finish(buf, end, err_space);
}
/* err - '\0'-terminated error message */
Declared in: gtparser/parser_err.h
-
Get clean-build build system:
-
For windows, get Gnu Make executable:
-
Build library
3.1 On Linux (example):
$ make MTOP=/home/user/clean-build OS=LINUX CPU=x86_64
3.2 On Windows (example):
C:\tools\gnumake-4.2.1.exe MTOP=C:\tools\clean-build OS=WINXX CPU=x86_64 WINVARIANT=WIN7 VS="C:\Program Files (x86)\Microsoft Visual Studio 14.0" WDK="C:\Program Files (x86)\Windows Kits\10" WDK_TARGET="10.0.14393.0"
Tips:
- specify
NO_STATIC=1
to not build static library archive - specify
NO_SHARED=1
to not build shared library (dll) - specify
TARGET=DEBUG
to build debug versions of libraries - to view other possible values of
OS
,CPU
orTARGET
variables, define them as?
- specify
V=1
for verbose build, to print executed commands
If make target is not specified, default target
all
(compile the library) will be builtBy default, all variants of libraries are built:
- for static library -
GTPARSER_LIB_VARIANTS="R P D S"
- for dynamic library -
GTPARSER_DLL_VARIANTS="R S"
Notes:
- if some variant is unsupported under target platform, variant is filtered-out from list of variants
- if variants list is empty, default variant
R
is built
Variants of static library for LINUX:
R
- default, position-dependent code for linking executablesP
- position-independent code for linking executables (-fpie
compiler option)D
- position-independent code for linking shared objects (-fpic
compiler option)
Variants of static library for WINDOWS:
R
- default, dynamically linked multi-threaded C runtime library (/MD
compiler option)S
- statically linked multi-threaded C runtime library (/MT
compiler option)
Variants of dynamic library for LINUX:
R
- default, position-independent code (-fpic
compiler option)
Variants of dynamic library for WINDOWS:
R
- default, dynamically linked multi-threaded C runtime library (/MD
compiler option)S
- statically linked multi-threaded C runtime library (/MT
compiler option)
Tip: there are predefined targets:
tests
- to build library and testscheck
- to build library and tests, then run testsclean
- to delete built artifacts, except created directoriesdistclean
- to delete all artifacts, including created directories
- specify
-
Install library and interface headers
Note: make command should be the same as for building, except the target should be
install
oruninstall
4.1 On Linux (example):
possibly as root, do
$ make MTOP=/home/user/clean-build OS=LINUX CPU=x86_64 install
4.2 On Windows (example):
C:\tools\gnumake-4.2.1.exe MTOP=C:\tools\clean-build OS=WINXX CPU=x86_64 WINVARIANT=WIN7 VS="C:\Program Files (x86)\Microsoft Visual Studio 14.0" WDK="C:\Program Files (x86)\Windows Kits\10" WDK_TARGET="10.0.14393.0" PREFIX=C:\dst install
Note: Headers are installed in
$(INCLUDEDIR)
, libraries - in$(LIBDIR)
Tips:
- define variable
PREFIX
to override default install location -/usr/local
(for UNIX) orartifacts
(for WINDOWS) - define variable
INCLUDEDIR
to override default headers install location -$(PREFIX)/include
- define variable
LIBDIR
to override default libraries install location -$(PREFIX)/lib
- define variable
DESTDIR
to add prefix to$(PREFIX)
- to make path to temporary install location - specify
NO_INSTALL_HEADERS=1
to not install development library interface header files - specify
NO_INSTALL_LA=1
to not install development libtool library files (for UNIX) - specify
NO_INSTALL_PC=1
to not install development pkg-config library files (for UNIX) - specify
NO_INSTALL_IMPS=1
to not install development dll import libraries (for WINDOWS) - specify
NO_DEVEL=1
to not install all above development files (headers, .la, .pc, import libraries)
Tip: there is one more predefined target:
uninstall
- to delete installed files. Note: some installed directories may not be deleted.
- define variable