dlugolecki.net.pl
Dziennik
Polecane
Software
projects
/
gedcom-parse.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Improved context handling, to allow elements out of context.
[gedcom-parse.git]
/
gedcom
/
gedcom_lex_common.c
diff --git
a/gedcom/gedcom_lex_common.c
b/gedcom/gedcom_lex_common.c
index 4949346bb9b903a5f891e887b87ebd74aa1a18fe..06c1f77a8a5fefb51696d6fb7ac63e9b1c7f917c 100644
(file)
--- a/
gedcom/gedcom_lex_common.c
+++ b/
gedcom/gedcom_lex_common.c
@@
-26,14
+26,17
@@
#include "gedcom_internal.h"
#include "multilex.h"
#include "encoding.h"
#include "gedcom_internal.h"
#include "multilex.h"
#include "encoding.h"
+#include "encoding_state.h"
#include "gedcom.h"
#include "gedcom.tabgen.h"
#include "compat.h"
static size_t encoding_width;
static int current_level = -1;
#include "gedcom.h"
#include "gedcom.tabgen.h"
#include "compat.h"
static size_t encoding_width;
static int current_level = -1;
-static int level_diff
=
MAXGEDCLEVEL;
+static int level_diff
=
MAXGEDCLEVEL;
static size_t line_len = 0;
static size_t line_len = 0;
+static int tab_space = 0;
+static int current_tag = -1;
static struct conv_buffer* ptr_buffer = NULL;
static struct conv_buffer* tag_buffer = NULL;
static struct conv_buffer* ptr_buffer = NULL;
static struct conv_buffer* tag_buffer = NULL;
@@
-91,10
+94,10
@@
int test_loop(ENCODING enc, const char* code)
/* These are defined as functions here, because xgettext has trouble
extracting the strings out of long pre-processor defined */
/* These are defined as functions here, because xgettext has trouble
extracting the strings out of long pre-processor defined */
-static void error_line_too_long(
const char *line
)
+static void error_line_too_long()
{
{
- gedcom_error(_("Line too long, max %d characters allowed
: %s
"),
- MAXGEDCLINELEN
, line
);
+ gedcom_error(_("Line too long, max %d characters allowed"),
+ MAXGEDCLINELEN);
}
static void error_level_leading_zero()
}
static void error_level_leading_zero()
@@
-135,6
+138,11
@@
static void error_at_character()
gedcom_error(_("'@' character should be written as '@@' in values"));
}
gedcom_error(_("'@' character should be written as '@@' in values"));
}
+static void error_tab_character()
+{
+ gedcom_error(_("Tab character is not allowed in values"));
+}
+
static void error_unexpected_character(const char* str, char ch)
{
gedcom_error(_("Unexpected character: '%s' (0x%02x)"), str, ch);
static void error_unexpected_character(const char* str, char ch)
{
gedcom_error(_("Unexpected character: '%s' (0x%02x)"), str, ch);
@@
-155,21
+163,29
@@
static int dummy_conv = 0;
#define CHECK_LINE_LEN \
{ if (line_len != (size_t)-1) { \
line_len += strlen(yytext); \
#define CHECK_LINE_LEN \
{ if (line_len != (size_t)-1) { \
line_len += strlen(yytext); \
- if (line_len > MAXGEDCLINELEN * encoding_width) { \
- error_line_too_long(yytext); \
+ if (line_len > MAXGEDCLINELEN * encoding_width \
+ && ! compat_long_line(current_level, current_tag)) { \
+ error_line_too_long(); \
line_len = (size_t)-1; \
return BADTOKEN; \
} \
} \
}
line_len = (size_t)-1; \
return BADTOKEN; \
} \
} \
}
+#define GENERATE_TAB_SPACE \
+ { gedcom_lval.string = " "; \
+ tab_space--; \
+ return DELIM; \
+ }
+
#define MKTAGACTION(THETAG) \
{ CHECK_LINE_LEN; \
gedcom_lval.tag.string = TO_INTERNAL(yytext, tag_buffer); \
#define MKTAGACTION(THETAG) \
{ CHECK_LINE_LEN; \
gedcom_lval.tag.string = TO_INTERNAL(yytext, tag_buffer); \
- gedcom_lval.tag.value = TAG_##THETAG; \
+ current_tag = TAG_##THETAG; \
+ gedcom_lval.tag.value = current_tag; \
BEGIN(NORMAL); \
line_no++; \
BEGIN(NORMAL); \
line_no++; \
- return
TAG_##THETAG;
\
+ return
current_tag;
\
}
/* The GEDCOM level number is converted into a sequence of opening
}
/* The GEDCOM level number is converted into a sequence of opening
@@
-205,10
+221,16
@@
static int dummy_conv = 0;
But because this means that one token is converted into a series
of tokens, there is some initial code following immediately here
But because this means that one token is converted into a series
of tokens, there is some initial code following immediately here
- that returns "pending" tokens. */
+ that returns "pending" tokens.
+
+ Also, for compatibility tabs are converted into spaces, which is
+ also handled here */
#define ACTION_BEFORE_REGEXPS \
#define ACTION_BEFORE_REGEXPS \
- { if (level_diff < 1) { \
+ { if (compat_mode(C_TAB_CHARACTER) && tab_space-- > 0) { \
+ GENERATE_TAB_SPACE; \
+ } \
+ else if (level_diff < 1) { \
level_diff++; \
return CLOSE; \
} \
level_diff++; \
return CLOSE; \
} \
@@
-336,6
+358,8
@@
static int dummy_conv = 0;
#define ACTION_TERMINATOR \
{ CHECK_LINE_LEN; \
INIT_LINE_LEN; \
#define ACTION_TERMINATOR \
{ CHECK_LINE_LEN; \
INIT_LINE_LEN; \
+ if (line_no == 1) \
+ set_read_encoding_terminator(TO_INTERNAL(yytext, str_buffer)); \
BEGIN(INITIAL); \
}
BEGIN(INITIAL); \
}
@@
-380,6
+404,17
@@
static int dummy_conv = 0;
} \
}
} \
}
+#define ACTION_TAB \
+ { if (compat_mode(C_TAB_CHARACTER)) { \
+ tab_space = 8; \
+ GENERATE_TAB_SPACE; \
+ } \
+ else { \
+ error_tab_character(); \
+ return BADTOKEN; \
+ } \
+ }
+
#define ACTION_UNEXPECTED \
{ error_unexpected_character(yytext, yytext[0]); \
return BADTOKEN; \
#define ACTION_UNEXPECTED \
{ error_unexpected_character(yytext, yytext[0]); \
return BADTOKEN; \