mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-04 08:42:50 -06:00
manually copy the "c-runtime" branch from the old repository.
This commit is contained in:
@@ -87,14 +87,13 @@ libpgf_la_SOURCES = \
|
||||
pgf/graphviz.c \
|
||||
pgf/aligner.c \
|
||||
pgf/pgf.c \
|
||||
pgf/pgf.h
|
||||
libpgf_la_LDFLAGS = -no-undefined
|
||||
pgf/pgf.h \
|
||||
libpgf_la_LDFLAGS = "-no-undefined"
|
||||
libpgf_la_LIBADD = libgu.la
|
||||
|
||||
libsg_la_SOURCES = \
|
||||
sg/sqlite3Btree.c \
|
||||
sg/sg.c
|
||||
libsg_la_LDFLAGS = -no-undefined
|
||||
libsg_la_LIBADD = libgu.la libpgf.la
|
||||
|
||||
bin_PROGRAMS =
|
||||
|
||||
@@ -23,14 +23,6 @@
|
||||
|
||||
#define restrict __restrict
|
||||
|
||||
#elif defined(__MINGW32__)
|
||||
|
||||
#define GU_API_DECL
|
||||
#define GU_API
|
||||
|
||||
#define GU_INTERNAL_DECL
|
||||
#define GU_INTERNAL
|
||||
|
||||
#else
|
||||
|
||||
#define GU_API_DECL
|
||||
@@ -38,9 +30,7 @@
|
||||
|
||||
#define GU_INTERNAL_DECL __attribute__ ((visibility ("hidden")))
|
||||
#define GU_INTERNAL __attribute__ ((visibility ("hidden")))
|
||||
|
||||
#endif
|
||||
|
||||
// end MSVC workaround
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -30,8 +30,8 @@ pgf_expr_unwrap(PgfExpr expr)
|
||||
}
|
||||
}
|
||||
|
||||
PGF_API int
|
||||
pgf_expr_arity(PgfExpr expr)
|
||||
static PgfExprTag
|
||||
pgf_expr_arity(PgfExpr expr, int *arity)
|
||||
{
|
||||
int n = 0;
|
||||
while (true) {
|
||||
@@ -44,10 +44,9 @@ pgf_expr_arity(PgfExpr expr)
|
||||
n = n + 1;
|
||||
break;
|
||||
}
|
||||
case PGF_EXPR_FUN:
|
||||
return n;
|
||||
default:
|
||||
return -1;
|
||||
*arity = n;
|
||||
return i.tag;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,8 +54,8 @@ pgf_expr_arity(PgfExpr expr)
|
||||
PGF_API PgfApplication*
|
||||
pgf_expr_unapply(PgfExpr expr, GuPool* pool)
|
||||
{
|
||||
int arity = pgf_expr_arity(expr);
|
||||
if (arity < 0) {
|
||||
int arity;
|
||||
if (pgf_expr_arity(expr, &arity) != PGF_EXPR_FUN) {
|
||||
return NULL;
|
||||
}
|
||||
PgfApplication* appl = gu_new_flex(pool, PgfApplication, args, arity);
|
||||
@@ -68,13 +67,38 @@ pgf_expr_unapply(PgfExpr expr, GuPool* pool)
|
||||
appl->args[n] = app->arg;
|
||||
expr = app->fun;
|
||||
}
|
||||
PgfExpr e = pgf_expr_unwrap(expr);
|
||||
gu_assert(gu_variant_tag(e) == PGF_EXPR_FUN);
|
||||
PgfExprFun* fun = gu_variant_data(e);
|
||||
appl->efun = pgf_expr_unwrap(expr);
|
||||
gu_assert(gu_variant_tag(appl->efun) == PGF_EXPR_FUN);
|
||||
PgfExprFun* fun = gu_variant_data(appl->efun);
|
||||
appl->fun = fun->fun;
|
||||
return appl;
|
||||
}
|
||||
|
||||
PGF_API PgfApplication*
|
||||
pgf_expr_unapply_ex(PgfExpr expr, GuPool* pool)
|
||||
{
|
||||
int arity;
|
||||
pgf_expr_arity(expr, &arity);
|
||||
|
||||
PgfApplication* appl = gu_new_flex(pool, PgfApplication, args, arity);
|
||||
appl->n_args = arity;
|
||||
for (int n = arity - 1; n >= 0; n--) {
|
||||
PgfExpr e = pgf_expr_unwrap(expr);
|
||||
gu_assert(gu_variant_tag(e) == PGF_EXPR_APP);
|
||||
PgfExprApp* app = gu_variant_data(e);
|
||||
appl->args[n] = app->arg;
|
||||
expr = app->fun;
|
||||
}
|
||||
appl->efun = pgf_expr_unwrap(expr);
|
||||
if (gu_variant_tag(appl->efun) == PGF_EXPR_FUN) {
|
||||
PgfExprFun* fun = gu_variant_data(appl->efun);
|
||||
appl->fun = fun->fun;
|
||||
} else {
|
||||
appl->fun = NULL;
|
||||
}
|
||||
return appl;
|
||||
}
|
||||
|
||||
PGF_API PgfExpr
|
||||
pgf_expr_apply(PgfApplication* app, GuPool* pool)
|
||||
{
|
||||
@@ -675,6 +699,17 @@ pgf_expr_parser_binds(PgfExprParser* parser)
|
||||
return binds;
|
||||
}
|
||||
|
||||
PGF_API GuString
|
||||
pgf_expr_parser_ident(PgfExprParser* parser)
|
||||
{
|
||||
GuString ident = NULL;
|
||||
if (parser->token_tag == PGF_TOKEN_IDENT) {
|
||||
ident = gu_string_copy(gu_string_buf_data(parser->token_value), parser->expr_pool);
|
||||
pgf_expr_parser_token(parser, true);
|
||||
}
|
||||
return ident;
|
||||
}
|
||||
|
||||
PGF_API PgfExpr
|
||||
pgf_expr_parser_expr(PgfExprParser* parser, bool mark)
|
||||
{
|
||||
|
||||
@@ -126,12 +126,10 @@ typedef struct {
|
||||
PgfExpr expr;
|
||||
} PgfExprProb;
|
||||
|
||||
PGF_API_DECL int
|
||||
pgf_expr_arity(PgfExpr expr);
|
||||
|
||||
typedef struct PgfApplication PgfApplication;
|
||||
|
||||
struct PgfApplication {
|
||||
PgfExpr efun;
|
||||
PgfCId fun;
|
||||
int n_args;
|
||||
PgfExpr args[];
|
||||
@@ -140,6 +138,9 @@ struct PgfApplication {
|
||||
PGF_API_DECL PgfApplication*
|
||||
pgf_expr_unapply(PgfExpr expr, GuPool* pool);
|
||||
|
||||
PGF_API_DECL PgfApplication*
|
||||
pgf_expr_unapply_ex(PgfExpr expr, GuPool* pool);
|
||||
|
||||
PGF_API_DECL PgfExpr
|
||||
pgf_expr_apply(PgfApplication*, GuPool* pool);
|
||||
|
||||
|
||||
@@ -175,9 +175,8 @@ redo:;
|
||||
gu_buf_get(buf, PgfProductionApply*, index);
|
||||
gu_assert(n_args == gu_seq_length(papply->args));
|
||||
|
||||
capp->abs_id = papply->fun->absfun->name;
|
||||
capp->fun = papply->fun;
|
||||
capp->fid = 0;
|
||||
capp->fun = papply->fun;
|
||||
capp->fid = 0;
|
||||
capp->n_args = n_args;
|
||||
|
||||
for (size_t i = 0; i < n_args; i++) {
|
||||
@@ -223,10 +222,10 @@ redo:;
|
||||
static PgfCncTree
|
||||
pgf_cnc_resolve_def(PgfCnc* cnc,
|
||||
size_t n_vars, PgfPrintContext* context,
|
||||
PgfCId abs_id, PgfCCat* ccat, GuString s, GuPool* pool)
|
||||
PgfCCat* ccat, GuString s, GuPool* pool)
|
||||
{
|
||||
PgfCncTree ret = gu_null_variant;
|
||||
PgfCncTree lit = gu_null_variant;
|
||||
PgfCncTree ret = gu_null_variant;
|
||||
|
||||
PgfCncTreeLit* clit =
|
||||
gu_new_variant(PGF_CNC_TREE_LIT,
|
||||
@@ -234,7 +233,7 @@ pgf_cnc_resolve_def(PgfCnc* cnc,
|
||||
&lit, pool);
|
||||
clit->n_vars = 0;
|
||||
clit->context = context;
|
||||
clit->fid = -1; // don't report the literal in the bracket
|
||||
clit->fid = cnc->fid++;
|
||||
PgfLiteralStr* lit_str =
|
||||
gu_new_flex_variant(PGF_LITERAL_STR,
|
||||
PgfLiteralStr,
|
||||
@@ -242,7 +241,7 @@ pgf_cnc_resolve_def(PgfCnc* cnc,
|
||||
&clit->lit, pool);
|
||||
strcpy((char*) lit_str->val, (char*) s);
|
||||
|
||||
if (ccat == NULL || ccat->lindefs == NULL)
|
||||
if (ccat->lindefs == NULL)
|
||||
return lit;
|
||||
|
||||
int index =
|
||||
@@ -254,10 +253,9 @@ pgf_cnc_resolve_def(PgfCnc* cnc,
|
||||
gu_new_flex_variant(PGF_CNC_TREE_APP,
|
||||
PgfCncTreeApp,
|
||||
args, 1, &ret, pool);
|
||||
capp->ccat = ccat;
|
||||
capp->abs_id= abs_id;
|
||||
capp->fun = gu_seq_get(ccat->lindefs, PgfCncFun*, index);
|
||||
capp->fid = cnc->fid++;
|
||||
capp->ccat = ccat;
|
||||
capp->fun = gu_seq_get(ccat->lindefs, PgfCncFun*, index);
|
||||
capp->fid = cnc->fid++;
|
||||
capp->n_vars = n_vars;
|
||||
capp->context = context;
|
||||
capp->n_args = 1;
|
||||
@@ -297,7 +295,7 @@ pgf_lzr_wrap_linref(PgfCncTree ctree, GuPool* pool)
|
||||
PgfCncTreeApp* capp = cti.data;
|
||||
|
||||
assert(gu_seq_length(capp->ccat->linrefs) > 0);
|
||||
|
||||
|
||||
// here we must apply the linref function
|
||||
PgfCncTree new_ctree;
|
||||
PgfCncTreeApp* new_capp =
|
||||
@@ -305,7 +303,6 @@ pgf_lzr_wrap_linref(PgfCncTree ctree, GuPool* pool)
|
||||
PgfCncTreeApp,
|
||||
args, 1, &new_ctree, pool);
|
||||
new_capp->ccat = NULL;
|
||||
new_capp->abs_id = NULL;
|
||||
new_capp->fun = gu_seq_get(capp->ccat->linrefs, PgfCncFun*, 0);
|
||||
new_capp->fid = -1;
|
||||
new_capp->n_vars = 0;
|
||||
@@ -317,7 +314,7 @@ pgf_lzr_wrap_linref(PgfCncTree ctree, GuPool* pool)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ctree;
|
||||
}
|
||||
|
||||
@@ -399,17 +396,6 @@ pgf_cnc_resolve(PgfCnc* cnc,
|
||||
goto done;
|
||||
}
|
||||
|
||||
PgfCId abs_id = "?";
|
||||
if (emeta->id > 0) {
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
GuExn* err = gu_new_exn(tmp_pool);
|
||||
GuStringBuf* sbuf = gu_new_string_buf(tmp_pool);
|
||||
GuOut* out = gu_string_buf_out(sbuf);
|
||||
|
||||
gu_printf(out, err, "?%d", emeta->id);
|
||||
abs_id = gu_string_buf_freeze(sbuf, pool);
|
||||
}
|
||||
|
||||
int index =
|
||||
gu_choice_next(cnc->ch, gu_seq_length(ccat->lindefs));
|
||||
if (index < 0) {
|
||||
@@ -420,7 +406,6 @@ pgf_cnc_resolve(PgfCnc* cnc,
|
||||
PgfCncTreeApp,
|
||||
args, 1, &ret, pool);
|
||||
capp->ccat = ccat;
|
||||
capp->abs_id = abs_id;
|
||||
capp->fun = gu_seq_get(ccat->lindefs, PgfCncFun*, index);
|
||||
capp->fid = cnc->fid++;
|
||||
capp->n_vars = 0;
|
||||
@@ -450,7 +435,23 @@ pgf_cnc_resolve(PgfCnc* cnc,
|
||||
gu_putc(']', out, err);
|
||||
GuString s = gu_string_buf_freeze(sbuf, tmp_pool);
|
||||
|
||||
ret = pgf_cnc_resolve_def(cnc, n_vars, context, efun->fun, ccat, s, pool);
|
||||
if (ccat != NULL) {
|
||||
ret = pgf_cnc_resolve_def(cnc, n_vars, context, ccat, s, pool);
|
||||
} else {
|
||||
PgfCncTreeLit* clit =
|
||||
gu_new_variant(PGF_CNC_TREE_LIT,
|
||||
PgfCncTreeLit,
|
||||
&ret, pool);
|
||||
clit->n_vars = 0;
|
||||
clit->context = context;
|
||||
clit->fid = cnc->fid++;
|
||||
PgfLiteralStr* lit =
|
||||
gu_new_flex_variant(PGF_LITERAL_STR,
|
||||
PgfLiteralStr,
|
||||
val, strlen(s)+1,
|
||||
&clit->lit, pool);
|
||||
strcpy(lit->val, s);
|
||||
}
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
goto done;
|
||||
@@ -498,7 +499,28 @@ redo:;
|
||||
index--;
|
||||
}
|
||||
|
||||
ret = pgf_cnc_resolve_def(cnc, n_vars, context, ctxt->name, ccat, ctxt->name, pool);
|
||||
if (ccat != NULL && ccat->lindefs == NULL) {
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (ccat != NULL) {
|
||||
ret = pgf_cnc_resolve_def(cnc, n_vars, context, ccat, ctxt->name, pool);
|
||||
} else {
|
||||
PgfCncTreeLit* clit =
|
||||
gu_new_variant(PGF_CNC_TREE_LIT,
|
||||
PgfCncTreeLit,
|
||||
&ret, pool);
|
||||
clit->n_vars = 0;
|
||||
clit->context = context;
|
||||
clit->fid = cnc->fid++;
|
||||
PgfLiteralStr* lit =
|
||||
gu_new_flex_variant(PGF_LITERAL_STR,
|
||||
PgfLiteralStr,
|
||||
val, strlen(ctxt->name)+1,
|
||||
&clit->lit, pool);
|
||||
strcpy(lit->val, ctxt->name);
|
||||
}
|
||||
|
||||
goto done;
|
||||
}
|
||||
case PGF_EXPR_TYPED: {
|
||||
@@ -917,9 +939,9 @@ pgf_lzr_linearize_tree(PgfLzr* lzr, PgfCncTree ctree, size_t lin_idx)
|
||||
|
||||
if ((*lzr->funcs)->begin_phrase && fapp->ccat != NULL) {
|
||||
(*lzr->funcs)->begin_phrase(lzr->funcs,
|
||||
fapp->ccat->cnccat->abscat->name,
|
||||
fun->absfun->type->cid,
|
||||
fapp->fid, lin_idx,
|
||||
fapp->abs_id);
|
||||
fun->absfun->name);
|
||||
}
|
||||
|
||||
gu_require(lin_idx < fun->n_lins);
|
||||
@@ -927,9 +949,9 @@ pgf_lzr_linearize_tree(PgfLzr* lzr, PgfCncTree ctree, size_t lin_idx)
|
||||
|
||||
if ((*lzr->funcs)->end_phrase && fapp->ccat != NULL) {
|
||||
(*lzr->funcs)->end_phrase(lzr->funcs,
|
||||
fapp->ccat->cnccat->abscat->name,
|
||||
fun->absfun->type->cid,
|
||||
fapp->fid, lin_idx,
|
||||
fapp->abs_id);
|
||||
fun->absfun->name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -955,7 +977,7 @@ pgf_lzr_linearize_tree(PgfLzr* lzr, PgfCncTree ctree, size_t lin_idx)
|
||||
PgfCId cat =
|
||||
pgf_literal_cat(lzr->concr, flit->lit)->cnccat->abscat->name;
|
||||
|
||||
if ((*lzr->funcs)->begin_phrase && flit->fid >= 0) {
|
||||
if ((*lzr->funcs)->begin_phrase) {
|
||||
(*lzr->funcs)->begin_phrase(lzr->funcs,
|
||||
cat, flit->fid, 0,
|
||||
"");
|
||||
@@ -987,7 +1009,7 @@ pgf_lzr_linearize_tree(PgfLzr* lzr, PgfCncTree ctree, size_t lin_idx)
|
||||
(*lzr->funcs)->symbol_token(lzr->funcs, tok);
|
||||
}
|
||||
|
||||
if ((*lzr->funcs)->end_phrase && flit->fid >= 0) {
|
||||
if ((*lzr->funcs)->end_phrase) {
|
||||
(*lzr->funcs)->end_phrase(lzr->funcs,
|
||||
cat, flit->fid, 0,
|
||||
"");
|
||||
|
||||
@@ -22,7 +22,6 @@ typedef enum {
|
||||
|
||||
typedef struct {
|
||||
PgfCCat* ccat;
|
||||
PgfCId abs_id;
|
||||
PgfCncFun* fun;
|
||||
int fid;
|
||||
|
||||
|
||||
@@ -9,9 +9,6 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#if defined(__MINGW32__) || defined(_MSC_VER)
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
//#define PGF_LOOKUP_DEBUG
|
||||
//#define PGF_LINEARIZER_DEBUG
|
||||
@@ -119,7 +116,7 @@ typedef struct {
|
||||
static PgfAbsProduction*
|
||||
pgf_lookup_new_production(PgfAbsFun* fun, GuPool *pool)
|
||||
{
|
||||
size_t n_hypos = fun->type->hypos ? gu_seq_length(fun->type->hypos) : 0;
|
||||
size_t n_hypos = gu_seq_length(fun->type->hypos);
|
||||
PgfAbsProduction* prod = gu_new_flex(pool, PgfAbsProduction, args, n_hypos);
|
||||
prod->fun = fun;
|
||||
prod->count = 0;
|
||||
@@ -699,12 +696,8 @@ pgf_lookup_tokenize(GuMap* lexicon_idx, GuString sentence, GuPool* pool)
|
||||
break;
|
||||
|
||||
const uint8_t* start = p-1;
|
||||
if (strchr(".!?,:",c) != NULL)
|
||||
while (c != 0 && !gu_ucs_is_space(c)) {
|
||||
c = gu_utf8_decode(&p);
|
||||
else {
|
||||
while (c != 0 && strchr(".!?,:",c) == NULL && !gu_ucs_is_space(c)) {
|
||||
c = gu_utf8_decode(&p);
|
||||
}
|
||||
}
|
||||
const uint8_t* end = p-1;
|
||||
|
||||
|
||||
@@ -65,7 +65,6 @@ typedef enum { BIND_NONE, BIND_HARD, BIND_SOFT } BIND_TYPE;
|
||||
typedef struct {
|
||||
PgfProductionIdx* idx;
|
||||
size_t offset;
|
||||
size_t sym_idx;
|
||||
} PgfLexiconIdxEntry;
|
||||
|
||||
typedef GuBuf PgfLexiconIdx;
|
||||
@@ -1061,13 +1060,13 @@ pgf_parsing_complete(PgfParsing* ps, PgfItem* item, PgfExprProb *ep)
|
||||
}
|
||||
|
||||
static int
|
||||
pgf_symbols_cmp(GuString* psent, PgfSymbols* syms, size_t* sym_idx, bool case_sensitive)
|
||||
pgf_symbols_cmp(GuString* psent, PgfSymbols* syms, bool case_sensitive)
|
||||
{
|
||||
size_t n_syms = gu_seq_length(syms);
|
||||
while (*sym_idx < n_syms) {
|
||||
PgfSymbol sym = gu_seq_get(syms, PgfSymbol, *sym_idx);
|
||||
for (size_t i = 0; i < n_syms; i++) {
|
||||
PgfSymbol sym = gu_seq_get(syms, PgfSymbol, i);
|
||||
|
||||
if (*sym_idx > 0) {
|
||||
if (i > 0) {
|
||||
if (!skip_space(psent)) {
|
||||
if (**psent == 0)
|
||||
return -1;
|
||||
@@ -1111,8 +1110,6 @@ pgf_symbols_cmp(GuString* psent, PgfSymbols* syms, size_t* sym_idx, bool case_se
|
||||
default:
|
||||
gu_impossible();
|
||||
}
|
||||
|
||||
(*sym_idx)++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -1133,8 +1130,7 @@ pgf_parsing_lookahead(PgfParsing *ps, PgfParseState* state,
|
||||
|
||||
GuString start = ps->sentence + state->end_offset;
|
||||
GuString current = start;
|
||||
size_t sym_idx = 0;
|
||||
int cmp = pgf_symbols_cmp(¤t, seq->syms, &sym_idx, ps->case_sensitive);
|
||||
int cmp = pgf_symbols_cmp(¤t, seq->syms, ps->case_sensitive);
|
||||
if (cmp < 0) {
|
||||
j = k-1;
|
||||
} else if (cmp > 0) {
|
||||
@@ -1155,9 +1151,8 @@ pgf_parsing_lookahead(PgfParsing *ps, PgfParseState* state,
|
||||
|
||||
if (seq->idx != NULL) {
|
||||
PgfLexiconIdxEntry* entry = gu_buf_extend(state->lexicon_idx);
|
||||
entry->idx = seq->idx;
|
||||
entry->offset = (size_t) (current - ps->sentence);
|
||||
entry->sym_idx = sym_idx;
|
||||
entry->idx = seq->idx;
|
||||
entry->offset = (size_t) (current - ps->sentence);
|
||||
}
|
||||
|
||||
if (len+1 <= max)
|
||||
@@ -1236,7 +1231,6 @@ pgf_new_parse_state(PgfParsing* ps, size_t start_offset,
|
||||
PgfLexiconIdxEntry* entry = gu_buf_extend(state->lexicon_idx);
|
||||
entry->idx = seq->idx;
|
||||
entry->offset = state->start_offset;
|
||||
entry->sym_idx= 0;
|
||||
}
|
||||
|
||||
// Add non-epsilon lexical rules to the bottom up index
|
||||
@@ -1284,15 +1278,14 @@ pgf_parsing_add_transition(PgfParsing* ps, PgfToken tok, PgfItem* item)
|
||||
static void
|
||||
pgf_parsing_predict_lexeme(PgfParsing* ps, PgfItemConts* conts,
|
||||
PgfProductionIdxEntry* entry,
|
||||
size_t offset, size_t sym_idx)
|
||||
size_t offset)
|
||||
{
|
||||
GuVariantInfo i = { PGF_PRODUCTION_APPLY, entry->papp };
|
||||
PgfProduction prod = gu_variant_close(i);
|
||||
PgfItem* item =
|
||||
pgf_new_item(ps, conts, prod);
|
||||
PgfSymbols* syms = entry->papp->fun->lins[conts->lin_idx]->syms;
|
||||
item->sym_idx = sym_idx;
|
||||
pgf_item_set_curr_symbol(item, ps->pool);
|
||||
item->sym_idx = gu_seq_length(syms);
|
||||
prob_t prob = item->inside_prob+item->conts->outside_prob;
|
||||
PgfParseState* state =
|
||||
pgf_new_parse_state(ps, offset, BIND_NONE, prob);
|
||||
@@ -1365,7 +1358,7 @@ pgf_parsing_td_predict(PgfParsing* ps,
|
||||
PgfProductionIdxEntry, &key);
|
||||
|
||||
if (value != NULL) {
|
||||
pgf_parsing_predict_lexeme(ps, conts, value, lentry->offset, lentry->sym_idx);
|
||||
pgf_parsing_predict_lexeme(ps, conts, value, lentry->offset);
|
||||
|
||||
PgfProductionIdxEntry* start =
|
||||
gu_buf_data(lentry->idx);
|
||||
@@ -1376,7 +1369,7 @@ pgf_parsing_td_predict(PgfParsing* ps,
|
||||
while (left >= start &&
|
||||
value->ccat->fid == left->ccat->fid &&
|
||||
value->lin_idx == left->lin_idx) {
|
||||
pgf_parsing_predict_lexeme(ps, conts, left, lentry->offset, lentry->sym_idx);
|
||||
pgf_parsing_predict_lexeme(ps, conts, left, lentry->offset);
|
||||
left--;
|
||||
}
|
||||
|
||||
@@ -1384,7 +1377,7 @@ pgf_parsing_td_predict(PgfParsing* ps,
|
||||
while (right <= end &&
|
||||
value->ccat->fid == right->ccat->fid &&
|
||||
value->lin_idx == right->lin_idx) {
|
||||
pgf_parsing_predict_lexeme(ps, conts, right, lentry->offset, lentry->sym_idx);
|
||||
pgf_parsing_predict_lexeme(ps, conts, right, lentry->offset);
|
||||
right++;
|
||||
}
|
||||
}
|
||||
@@ -1957,6 +1950,8 @@ pgf_parsing_init(PgfConcr* concr, PgfCId cat,
|
||||
start_ccat->prods = NULL;
|
||||
start_ccat->n_synprods = 0;
|
||||
|
||||
gu_assert(start_ccat->cnccat != NULL);
|
||||
|
||||
#ifdef PGF_COUNTS_DEBUG
|
||||
state->ps->ccat_full_count++;
|
||||
#endif
|
||||
@@ -2300,7 +2295,7 @@ pgf_parser_completions_next(GuEnum* self, void* to, GuPool* pool)
|
||||
}
|
||||
|
||||
PGF_API GuEnum*
|
||||
pgf_complete(PgfConcr* concr, PgfType* type, GuString sentence,
|
||||
pgf_complete(PgfConcr* concr, PgfType* type, GuString sentence,
|
||||
GuString prefix, GuExn *err, GuPool* pool)
|
||||
{
|
||||
if (concr->sequences == NULL ||
|
||||
@@ -2379,9 +2374,8 @@ pgf_sequence_cmp_fn(GuOrder* order, const void* p1, const void* p2)
|
||||
GuString sent = (GuString) p1;
|
||||
const PgfSequence* sp2 = p2;
|
||||
|
||||
size_t sym_idx = 0;
|
||||
int res = pgf_symbols_cmp(&sent, sp2->syms, &sym_idx, self->case_sensitive);
|
||||
if (res == 0 && (*sent != 0 || sym_idx != gu_seq_length(sp2->syms))) {
|
||||
int res = pgf_symbols_cmp(&sent, sp2->syms, self->case_sensitive);
|
||||
if (res == 0 && *sent != 0) {
|
||||
res = 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ pgf_read_in(GuIn* in,
|
||||
}
|
||||
|
||||
PGF_API_DECL void
|
||||
pgf_write(PgfPGF* pgf, const char* fpath, GuExn* err)
|
||||
pgf_write(PgfPGF* pgf, size_t n_concrs, PgfConcr** concrs, const char* fpath, GuExn* err)
|
||||
{
|
||||
FILE* outfile = fopen(fpath, "wb");
|
||||
if (outfile == NULL) {
|
||||
@@ -60,13 +60,70 @@ pgf_write(PgfPGF* pgf, const char* fpath, GuExn* err)
|
||||
GuOut* out = gu_file_out(outfile, tmp_pool);
|
||||
|
||||
PgfWriter* wtr = pgf_new_writer(out, tmp_pool, err);
|
||||
pgf_write_pgf(pgf, wtr);
|
||||
pgf_write_pgf(pgf, n_concrs, concrs, wtr);
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
fclose(outfile);
|
||||
}
|
||||
|
||||
PGF_API void
|
||||
pgf_concrete_save(PgfConcr* concr, const char* fpath, GuExn* err)
|
||||
{
|
||||
FILE* outfile = fopen(fpath, "wb");
|
||||
if (outfile == NULL) {
|
||||
gu_raise_errno(err);
|
||||
return;
|
||||
}
|
||||
|
||||
GuPool* tmp_pool = gu_local_pool();
|
||||
|
||||
// Create an input stream from the input file
|
||||
GuOut* out = gu_file_out(outfile, tmp_pool);
|
||||
|
||||
PgfWriter* wtr = pgf_new_writer(out, tmp_pool, err);
|
||||
pgf_write_concrete(concr, wtr, true);
|
||||
|
||||
gu_pool_free(tmp_pool);
|
||||
|
||||
fclose(outfile);
|
||||
}
|
||||
|
||||
PGF_API bool
|
||||
pgf_have_same_abstract(PgfPGF *one, PgfPGF *two)
|
||||
{
|
||||
if (strcmp(one->abstract.name, two->abstract.name) != 0)
|
||||
return false;
|
||||
|
||||
size_t n_cats = gu_seq_length(one->abstract.cats);
|
||||
if (n_cats != gu_seq_length(two->abstract.cats))
|
||||
return false;
|
||||
size_t n_funs = gu_seq_length(one->abstract.funs);
|
||||
if (n_funs != gu_seq_length(two->abstract.funs))
|
||||
return false;
|
||||
|
||||
for (size_t i = 0; i < n_cats; i++) {
|
||||
PgfAbsCat* cat1 = gu_seq_index(one->abstract.cats, PgfAbsCat, i);
|
||||
PgfAbsCat* cat2 = gu_seq_index(two->abstract.cats, PgfAbsCat, i);
|
||||
|
||||
if (strcmp(cat1->name, cat2->name) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < n_funs; i++) {
|
||||
PgfAbsFun* fun1 = gu_seq_index(one->abstract.funs, PgfAbsFun, i);
|
||||
PgfAbsFun* fun2 = gu_seq_index(two->abstract.funs, PgfAbsFun, i);
|
||||
|
||||
if (strcmp(fun1->name, fun2->name) != 0)
|
||||
return false;
|
||||
|
||||
if (!pgf_type_eq(fun1->type, fun2->type))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
PGF_API GuString
|
||||
pgf_abstract_name(PgfPGF* pgf)
|
||||
{
|
||||
|
||||
@@ -19,14 +19,6 @@
|
||||
#define PGF_INTERNAL_DECL
|
||||
#define PGF_INTERNAL
|
||||
|
||||
#elif defined(__MINGW32__)
|
||||
|
||||
#define PGF_API_DECL
|
||||
#define PGF_API
|
||||
|
||||
#define PGF_INTERNAL_DECL
|
||||
#define PGF_INTERNAL
|
||||
|
||||
#else
|
||||
|
||||
#define PGF_API_DECL
|
||||
@@ -66,7 +58,10 @@ PGF_API_DECL void
|
||||
pgf_concrete_unload(PgfConcr* concr);
|
||||
|
||||
PGF_API_DECL void
|
||||
pgf_write(PgfPGF* pgf, const char* fpath, GuExn* err);
|
||||
pgf_write(PgfPGF* pgf, size_t n_concrs, PgfConcr** concrs, const char* fpath, GuExn* err);
|
||||
|
||||
PGF_API_DECL bool
|
||||
pgf_have_same_abstract(PgfPGF *one, PgfPGF *two);
|
||||
|
||||
PGF_API_DECL GuString
|
||||
pgf_abstract_name(PgfPGF*);
|
||||
@@ -249,7 +244,8 @@ pgf_callbacks_map_add_literal(PgfConcr* concr, PgfCallbacksMap* callbacks,
|
||||
PgfCId cat, PgfLiteralCallback* callback);
|
||||
|
||||
PGF_API_DECL void
|
||||
pgf_print(PgfPGF* pgf, GuOut* out, GuExn* err);
|
||||
pgf_print(PgfPGF* pgf, size_t n_concrs, PgfConcr** concrs,
|
||||
GuOut* out, GuExn* err);
|
||||
|
||||
PGF_API_DECL void
|
||||
pgf_check_expr(PgfPGF* gr, PgfExpr* pe, PgfType* ty,
|
||||
|
||||
@@ -7,13 +7,17 @@ typedef struct {
|
||||
} PgfPrintFn;
|
||||
|
||||
static void
|
||||
pgf_print_flags(PgfFlags* flags, GuOut *out, GuExn* err)
|
||||
pgf_print_flags(PgfFlags* flags, int indent, GuOut *out, GuExn* err)
|
||||
{
|
||||
size_t n_flags = gu_seq_length(flags);
|
||||
for (size_t i = 0; i < n_flags; i++) {
|
||||
PgfFlag* flag = gu_seq_index(flags, PgfFlag, i);
|
||||
|
||||
gu_puts(" flag ", out, err);
|
||||
|
||||
for (int k = 0; k < indent; k++) {
|
||||
gu_putc(' ', out, err);
|
||||
}
|
||||
|
||||
gu_puts("flag ", out, err);
|
||||
pgf_print_cid(flag->name, out, err);
|
||||
gu_puts(" = ", out, err);
|
||||
pgf_print_literal(flag->value, out, err);
|
||||
@@ -70,7 +74,7 @@ pgf_print_abstract(PgfAbstr* abstr, GuOut* out, GuExn* err)
|
||||
pgf_print_cid(abstr->name, out, err);
|
||||
gu_puts(" {\n", out, err);
|
||||
|
||||
pgf_print_flags(abstr->aflags, out, err);
|
||||
pgf_print_flags(abstr->aflags, 2, out, err);
|
||||
pgf_print_abscats(abstr->cats, out, err);
|
||||
pgf_print_absfuns(abstr->funs, out, err);
|
||||
|
||||
@@ -358,7 +362,7 @@ pgf_print_concrete(PgfConcr* concr, GuOut* out, GuExn* err)
|
||||
pgf_print_cid(concr->name, out, err);
|
||||
gu_puts(" {\n", out, err);
|
||||
|
||||
pgf_print_flags(concr->cflags, out, err);
|
||||
pgf_print_flags(concr->cflags, 2, out, err);
|
||||
|
||||
gu_puts(" productions\n", out, err);
|
||||
PgfPrintFn clo2 = { { pgf_print_productions }, out };
|
||||
@@ -396,13 +400,12 @@ pgf_print_concrete(PgfConcr* concr, GuOut* out, GuExn* err)
|
||||
}
|
||||
|
||||
PGF_API void
|
||||
pgf_print(PgfPGF* pgf, GuOut* out, GuExn* err)
|
||||
pgf_print(PgfPGF* pgf, size_t n_concrs, PgfConcr** concrs, GuOut* out, GuExn* err)
|
||||
{
|
||||
pgf_print_flags(pgf->gflags, 0, out, err);
|
||||
pgf_print_abstract(&pgf->abstract, out, err);
|
||||
|
||||
size_t n_concrs = gu_seq_length(pgf->concretes);
|
||||
|
||||
for (size_t i = 0; i < n_concrs; i++) {
|
||||
PgfConcr* concr = gu_seq_index(pgf->concretes, PgfConcr, i);
|
||||
pgf_print_concrete(concr, out, err);
|
||||
pgf_print_concrete(concrs[i], out, err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -937,7 +937,7 @@ pgf_read_pargs(PgfReader* rdr, PgfConcr* concr)
|
||||
}
|
||||
|
||||
PGF_API bool
|
||||
pgf_production_is_lexical(PgfProductionApply *papp,
|
||||
pgf_production_is_lexical(PgfProductionApply *papp,
|
||||
GuBuf* non_lexical_buf, GuPool* pool)
|
||||
{
|
||||
if (gu_seq_length(papp->args) > 0)
|
||||
@@ -1168,6 +1168,14 @@ pgf_read_ccat_cb(GuMapItor* fn, const void* key, void* value, GuExn* err)
|
||||
// pgf_ccat_set_viterbi_prob(ccat);
|
||||
}
|
||||
|
||||
// The GF compiler needs to call this function when building in memory grammars.
|
||||
PGF_API void
|
||||
pgf_concrete_fix_internals(PgfConcr* concr)
|
||||
{
|
||||
GuMapItor clo1 = { pgf_read_ccat_cb };
|
||||
gu_map_iter(concr->ccats, &clo1, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
pgf_read_concrete_content(PgfReader* rdr, PgfConcr* concr)
|
||||
{
|
||||
@@ -1193,8 +1201,7 @@ pgf_read_concrete_content(PgfReader* rdr, PgfConcr* concr)
|
||||
concr->cnccats = pgf_read_cnccats(rdr, concr->abstr, concr);
|
||||
concr->total_cats = pgf_read_int(rdr);
|
||||
|
||||
GuMapItor clo1 = { pgf_read_ccat_cb };
|
||||
gu_map_iter(concr->ccats, &clo1, NULL);
|
||||
pgf_concrete_fix_internals(concr);
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -72,10 +72,15 @@ pgf_write_cid(PgfCId id, PgfWriter* wtr)
|
||||
PGF_INTERNAL void
|
||||
pgf_write_string(GuString val, PgfWriter* wtr)
|
||||
{
|
||||
size_t len = strlen(val);
|
||||
size_t len = 0;
|
||||
const uint8_t* buf = (const uint8_t*) val;
|
||||
const uint8_t* p = buf;
|
||||
while (gu_utf8_decode(&p) != 0)
|
||||
len++;
|
||||
|
||||
pgf_write_len(len, wtr);
|
||||
gu_return_on_exn(wtr->err, );
|
||||
gu_out_bytes(wtr->out, (uint8_t*) val, len, wtr->err);
|
||||
gu_out_bytes(wtr->out, (uint8_t*) val, (p-buf)-1, wtr->err);
|
||||
}
|
||||
|
||||
PGF_INTERNAL void
|
||||
@@ -843,7 +848,7 @@ pgf_write_concrete_content(PgfConcr* concr, PgfWriter* wtr)
|
||||
pgf_write_int(concr->total_cats, wtr);
|
||||
}
|
||||
|
||||
static void
|
||||
PGF_INTERNAL void
|
||||
pgf_write_concrete(PgfConcr* concr, PgfWriter* wtr, bool with_content)
|
||||
{
|
||||
if (with_content &&
|
||||
@@ -865,34 +870,20 @@ pgf_write_concrete(PgfConcr* concr, PgfWriter* wtr, bool with_content)
|
||||
gu_return_on_exn(wtr->err, );
|
||||
}
|
||||
|
||||
PGF_API void
|
||||
pgf_concrete_save(PgfConcr* concr, GuOut* out, GuExn* err)
|
||||
{
|
||||
GuPool* pool = gu_new_pool();
|
||||
|
||||
PgfWriter* wtr = pgf_new_writer(out, pool, err);
|
||||
|
||||
pgf_write_concrete(concr, wtr, true);
|
||||
|
||||
gu_pool_free(pool);
|
||||
}
|
||||
|
||||
static void
|
||||
pgf_write_concretes(PgfConcrs* concretes, PgfWriter* wtr, bool with_content)
|
||||
pgf_write_concretes(size_t n_concrs, PgfConcr** concrs, PgfWriter* wtr, bool with_content)
|
||||
{
|
||||
size_t n_concrs = gu_seq_length(concretes);
|
||||
pgf_write_len(n_concrs, wtr);
|
||||
gu_return_on_exn(wtr->err, );
|
||||
|
||||
for (size_t i = 0; i < n_concrs; i++) {
|
||||
PgfConcr* concr = gu_seq_index(concretes, PgfConcr, i);
|
||||
pgf_write_concrete(concr, wtr, with_content);
|
||||
pgf_write_concrete(concrs[i], wtr, with_content);
|
||||
gu_return_on_exn(wtr->err, );
|
||||
}
|
||||
}
|
||||
|
||||
PGF_INTERNAL void
|
||||
pgf_write_pgf(PgfPGF* pgf, PgfWriter* wtr) {
|
||||
pgf_write_pgf(PgfPGF* pgf, size_t n_concrs, PgfConcr** concrs, PgfWriter* wtr) {
|
||||
gu_out_u16be(wtr->out, pgf->major_version, wtr->err);
|
||||
gu_return_on_exn(wtr->err, );
|
||||
|
||||
@@ -907,7 +898,7 @@ pgf_write_pgf(PgfPGF* pgf, PgfWriter* wtr) {
|
||||
|
||||
bool with_content =
|
||||
(gu_seq_binsearch(pgf->gflags, pgf_flag_order, PgfFlag, "split") == NULL);
|
||||
pgf_write_concretes(pgf->concretes, wtr, with_content);
|
||||
pgf_write_concretes(n_concrs, concrs, wtr, with_content);
|
||||
gu_return_on_exn(wtr->err, );
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,10 @@ pgf_write_len(size_t len, PgfWriter* wtr);
|
||||
PGF_INTERNAL_DECL void
|
||||
pgf_write_cid(PgfCId id, PgfWriter* wtr);
|
||||
|
||||
PGF_INTERNAL void
|
||||
pgf_write_concrete(PgfConcr* concr, PgfWriter* wtr, bool with_content);
|
||||
|
||||
PGF_INTERNAL_DECL void
|
||||
pgf_write_pgf(PgfPGF* pgf, PgfWriter* wtr);
|
||||
pgf_write_pgf(PgfPGF* pgf, size_t n_concrs, PgfConcr** concrs, PgfWriter* wtr);
|
||||
|
||||
#endif // WRITER_H_
|
||||
|
||||
@@ -4918,7 +4918,6 @@ SQLITE_PRIVATE int sqlite3PendingByte;
|
||||
# define SQLITE_UTF16NATIVE SQLITE_UTF16BE
|
||||
#endif
|
||||
#if !defined(SQLITE_BYTEORDER)
|
||||
const int sqlite3one = 1;
|
||||
# define SQLITE_BYTEORDER 0 /* 0 means "unknown at compile-time" */
|
||||
# define SQLITE_BIGENDIAN (*(char *)(&sqlite3one)==0)
|
||||
# define SQLITE_LITTLEENDIAN (*(char *)(&sqlite3one)==1)
|
||||
@@ -5041,30 +5040,6 @@ SQLITE_PRIVATE int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedR
|
||||
*/
|
||||
/* #include "sqliteInt.h" */
|
||||
|
||||
/* An array to map all upper-case characters into their corresponding
|
||||
** lower-case character.
|
||||
**
|
||||
** SQLite only considers US-ASCII (or EBCDIC) characters. We do not
|
||||
** handle case conversions for the UTF character set since the tables
|
||||
** involved are nearly as big or bigger than SQLite itself.
|
||||
*/
|
||||
const unsigned char sqlite3UpperToLower[] = {
|
||||
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
|
||||
18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
|
||||
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
|
||||
54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 97, 98, 99,100,101,102,103,
|
||||
104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,
|
||||
122, 91, 92, 93, 94, 95, 96, 97, 98, 99,100,101,102,103,104,105,106,107,
|
||||
108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,124,125,
|
||||
126,127,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,
|
||||
144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159,160,161,
|
||||
162,163,164,165,166,167,168,169,170,171,172,173,174,175,176,177,178,179,
|
||||
180,181,182,183,184,185,186,187,188,189,190,191,192,193,194,195,196,197,
|
||||
198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
|
||||
216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
|
||||
234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
|
||||
252,253,254,255
|
||||
};
|
||||
/* EVIDENCE-OF: R-02982-34736 In order to maintain full backwards
|
||||
** compatibility for legacy applications, the URI filename capability is
|
||||
** disabled by default.
|
||||
@@ -9088,22 +9063,6 @@ SQLITE_PRIVATE int sqlite3Strlen30(const char *z){
|
||||
return 0x3fffffff & (int)strlen(z);
|
||||
}
|
||||
|
||||
/* Convenient short-hand */
|
||||
#define UpperToLower sqlite3UpperToLower
|
||||
|
||||
int sqlite3StrICmp(const char *zLeft, const char *zRight){
|
||||
unsigned char *a, *b;
|
||||
int c;
|
||||
a = (unsigned char *)zLeft;
|
||||
b = (unsigned char *)zRight;
|
||||
for(;;){
|
||||
c = (int)UpperToLower[*a] - (int)UpperToLower[*b];
|
||||
if( c || *a==0 ) break;
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
/*
|
||||
** The string z[] is an text representation of a real number.
|
||||
** Convert this string to a double and write it into *pResult.
|
||||
@@ -17871,6 +17830,13 @@ struct winFile {
|
||||
#define WINFILE_PERSIST_WAL 0x04 /* Persistent WAL mode */
|
||||
#define WINFILE_PSOW 0x10 /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
|
||||
|
||||
/*
|
||||
* The size of the buffer used by sqlite3_win32_write_debug().
|
||||
*/
|
||||
#ifndef SQLITE_WIN32_DBG_BUF_SIZE
|
||||
# define SQLITE_WIN32_DBG_BUF_SIZE ((int)(4096-sizeof(DWORD)))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* The value used with sqlite3_win32_set_directory() to specify that
|
||||
* the temporary directory should be changed.
|
||||
@@ -18819,6 +18785,43 @@ SQLITE_PRIVATE int sqlite3_win32_reset_heap(){
|
||||
}
|
||||
#endif /* SQLITE_WIN32_MALLOC */
|
||||
|
||||
/*
|
||||
** This function outputs the specified (ANSI) string to the Win32 debugger
|
||||
** (if available).
|
||||
*/
|
||||
|
||||
SQLITE_PRIVATE void sqlite3_win32_write_debug(const char *zBuf, int nBuf){
|
||||
char zDbgBuf[SQLITE_WIN32_DBG_BUF_SIZE];
|
||||
int nMin = MIN(nBuf, (SQLITE_WIN32_DBG_BUF_SIZE - 1)); /* may be negative. */
|
||||
if( nMin<-1 ) nMin = -1; /* all negative values become -1. */
|
||||
assert( nMin==-1 || nMin==0 || nMin<SQLITE_WIN32_DBG_BUF_SIZE );
|
||||
#if defined(SQLITE_WIN32_HAS_ANSI)
|
||||
if( nMin>0 ){
|
||||
memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
|
||||
memcpy(zDbgBuf, zBuf, nMin);
|
||||
osOutputDebugStringA(zDbgBuf);
|
||||
}else{
|
||||
osOutputDebugStringA(zBuf);
|
||||
}
|
||||
#elif defined(SQLITE_WIN32_HAS_WIDE)
|
||||
memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
|
||||
if ( osMultiByteToWideChar(
|
||||
osAreFileApisANSI() ? CP_ACP : CP_OEMCP, 0, zBuf,
|
||||
nMin, (LPWSTR)zDbgBuf, SQLITE_WIN32_DBG_BUF_SIZE/sizeof(WCHAR))<=0 ){
|
||||
return;
|
||||
}
|
||||
osOutputDebugStringW((LPCWSTR)zDbgBuf);
|
||||
#else
|
||||
if( nMin>0 ){
|
||||
memset(zDbgBuf, 0, SQLITE_WIN32_DBG_BUF_SIZE);
|
||||
memcpy(zDbgBuf, zBuf, nMin);
|
||||
fprintf(stderr, "%s", zDbgBuf);
|
||||
}else{
|
||||
fprintf(stderr, "%s", zBuf);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
** The following routine suspends the current thread for at least ms
|
||||
** milliseconds. This is equivalent to the Win32 Sleep() interface.
|
||||
@@ -19260,6 +19263,40 @@ SQLITE_PRIVATE char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){
|
||||
return zFilenameMbcs;
|
||||
}
|
||||
|
||||
/*
|
||||
** This function sets the data directory or the temporary directory based on
|
||||
** the provided arguments. The type argument must be 1 in order to set the
|
||||
** data directory or 2 in order to set the temporary directory. The zValue
|
||||
** argument is the name of the directory to use. The return value will be
|
||||
** SQLITE_OK if successful.
|
||||
*/
|
||||
SQLITE_PRIVATE int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){
|
||||
char **ppDirectory = 0;
|
||||
#ifndef SQLITE_OMIT_AUTOINIT
|
||||
int rc = sqlite3BtreeInitialize();
|
||||
if( rc ) return rc;
|
||||
#endif
|
||||
if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){
|
||||
ppDirectory = &sqlite3_temp_directory;
|
||||
}
|
||||
assert( !ppDirectory || type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE
|
||||
);
|
||||
assert( !ppDirectory || sqlite3MemdebugHasType(*ppDirectory, MEMTYPE_HEAP) );
|
||||
if( ppDirectory ){
|
||||
char *zValueUtf8 = 0;
|
||||
if( zValue && zValue[0] ){
|
||||
zValueUtf8 = winUnicodeToUtf8(zValue);
|
||||
if ( zValueUtf8==0 ){
|
||||
return SQLITE_NOMEM;
|
||||
}
|
||||
}
|
||||
sqlite3_free(*ppDirectory);
|
||||
*ppDirectory = zValueUtf8;
|
||||
return SQLITE_OK;
|
||||
}
|
||||
return SQLITE_ERROR;
|
||||
}
|
||||
|
||||
/*
|
||||
** The return value of winGetLastErrorMsg
|
||||
** is zero if the error message fits in the buffer, or non-zero
|
||||
@@ -22331,6 +22368,9 @@ static int winOpen(
|
||||
if( isReadonly ){
|
||||
pFile->ctrlFlags |= WINFILE_RDONLY;
|
||||
}
|
||||
if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
|
||||
pFile->ctrlFlags |= WINFILE_PSOW;
|
||||
}
|
||||
pFile->lastErrno = NO_ERROR;
|
||||
pFile->zPath = zName;
|
||||
#if SQLITE_MAX_MMAP_SIZE>0
|
||||
@@ -22549,6 +22589,43 @@ static BOOL winIsDriveLetterAndColon(
|
||||
return ( sqlite3Isalpha(zPathname[0]) && zPathname[1]==':' );
|
||||
}
|
||||
|
||||
/*
|
||||
** Returns non-zero if the specified path name should be used verbatim. If
|
||||
** non-zero is returned from this function, the calling function must simply
|
||||
** use the provided path name verbatim -OR- resolve it into a full path name
|
||||
** using the GetFullPathName Win32 API function (if available).
|
||||
*/
|
||||
static BOOL winIsVerbatimPathname(
|
||||
const char *zPathname
|
||||
){
|
||||
/*
|
||||
** If the path name starts with a forward slash or a backslash, it is either
|
||||
** a legal UNC name, a volume relative path, or an absolute path name in the
|
||||
** "Unix" format on Windows. There is no easy way to differentiate between
|
||||
** the final two cases; therefore, we return the safer return value of TRUE
|
||||
** so that callers of this function will simply use it verbatim.
|
||||
*/
|
||||
if ( winIsDirSep(zPathname[0]) ){
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
** If the path name starts with a letter and a colon it is either a volume
|
||||
** relative path or an absolute path. Callers of this function must not
|
||||
** attempt to treat it as a relative path name (i.e. they should simply use
|
||||
** it verbatim).
|
||||
*/
|
||||
if ( winIsDriveLetterAndColon(zPathname) ){
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
** If we get to this point, the path name should almost certainly be a purely
|
||||
** relative one (i.e. not a UNC name, not absolute, and not volume relative).
|
||||
*/
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
** Turn a relative pathname into a full pathname. Write the full
|
||||
** pathname into zOut[]. zOut[] will be at least pVfs->mxPathname
|
||||
|
||||
Reference in New Issue
Block a user