mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-20 18:29:33 -06:00
writePGF now allows to select list of languages
This commit is contained in:
@@ -244,6 +244,7 @@ void pgf_merge_pgf(PgfDB *db, PgfRevision revision,
|
||||
PGF_API
|
||||
void pgf_write_pgf(const char* fpath,
|
||||
PgfDB *db, PgfRevision revision,
|
||||
PgfText **langs,
|
||||
PgfExn* err)
|
||||
{
|
||||
FILE *out = NULL;
|
||||
@@ -258,7 +259,7 @@ void pgf_write_pgf(const char* fpath,
|
||||
DB_scope scope(db, READER_SCOPE);
|
||||
ref<PgfPGF> pgf = db->revision2pgf(revision);
|
||||
|
||||
PgfWriter wtr(out);
|
||||
PgfWriter wtr(langs, out);
|
||||
wtr.write_pgf(pgf);
|
||||
}
|
||||
} PGF_API_END
|
||||
|
||||
@@ -287,6 +287,7 @@ void pgf_merge_pgf(PgfDB *db, PgfRevision revision,
|
||||
PGF_API_DECL
|
||||
void pgf_write_pgf(const char* fpath,
|
||||
PgfDB *db, PgfRevision revision,
|
||||
PgfText **langs, // null terminated list or null
|
||||
PgfExn* err);
|
||||
|
||||
PGF_API_DECL
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
#include "data.h"
|
||||
#include "writer.h"
|
||||
|
||||
PgfWriter::PgfWriter(FILE *out)
|
||||
PgfWriter::PgfWriter(PgfText **langs, FILE *out)
|
||||
{
|
||||
this->out = out;
|
||||
this->langs = langs;
|
||||
this->abstract = 0;
|
||||
}
|
||||
|
||||
@@ -411,6 +412,22 @@ void PgfWriter::write_printname(ref<PgfConcrPrintname> printname)
|
||||
|
||||
void PgfWriter::write_concrete(ref<PgfConcr> concr)
|
||||
{
|
||||
if (langs != NULL) {
|
||||
bool found = false;
|
||||
PgfText** p = langs;
|
||||
while (*p) {
|
||||
if (textcmp(*p, &concr->name) == 0) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
seq_ids.start(concr);
|
||||
|
||||
write_name(&concr->name);
|
||||
@@ -431,5 +448,16 @@ void PgfWriter::write_pgf(ref<PgfPGF> pgf)
|
||||
write_namespace<PgfFlag>(pgf->gflags, &PgfWriter::write_flag);
|
||||
|
||||
write_abstract(ref<PgfAbstr>::from_ptr(&pgf->abstract));
|
||||
write_namespace<PgfConcr>(pgf->concretes, &PgfWriter::write_concrete);
|
||||
|
||||
if (langs == NULL)
|
||||
write_len(namespace_size(pgf->concretes));
|
||||
else {
|
||||
size_t len = 0;
|
||||
PgfText** p = langs;
|
||||
while (*p) {
|
||||
len++; p++;
|
||||
}
|
||||
write_len(len);
|
||||
}
|
||||
write_namespace_helper<PgfConcr>(pgf->concretes, &PgfWriter::write_concrete);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
class PGF_INTERNAL_DECL PgfWriter
|
||||
{
|
||||
public:
|
||||
PgfWriter(FILE *out);
|
||||
PgfWriter(PgfText **langs, FILE *out);
|
||||
|
||||
void write_uint8(uint8_t b);
|
||||
void write_u16be(uint16_t u);
|
||||
@@ -66,6 +66,7 @@ private:
|
||||
void write_presult(ref<ref<PgfPResult>> r) { write_presult(*r); };
|
||||
|
||||
FILE *out;
|
||||
PgfText **langs;
|
||||
|
||||
ref<PgfAbstr> abstract;
|
||||
PgfPhrasetableIds seq_ids;
|
||||
|
||||
Reference in New Issue
Block a user