Esempio n. 1
0
int
XML_ProcessFile(XML_Parser parser,
                const XML_Char *filename,
                unsigned flags)
{
  int result;

  if (!XML_SetBase(parser, filename)) {
    ftprintf(stderr, T("%s: out of memory"), filename);
    exit(1);
  }

  if (flags & XML_EXTERNAL_ENTITIES)
      XML_SetExternalEntityRefHandler(parser,
                                      (flags & XML_MAP_FILE)
                                      ? externalEntityRefFilemap
                                      : externalEntityRefStream);
  if (flags & XML_MAP_FILE) {
    PROCESS_ARGS args;
    args.retPtr = &result;
    args.parser = parser;
    if (!filemap(filename, processFile, &args))
      result = 0;
  }
  else
    result = processStream(filename, parser);
  return result;
}
Esempio n. 2
0
File: sync.c Progetto: atikinn/db165
static
void restore_col_data(struct column *col) {
    char *tname = col->table->name;
    char buf[PATHLEN];
    char *path = vbsnprintf(buf, sizeof buf, "%s/%s.%s.bin", DBPATH, tname, col->name);

    char *data;
    off_t sz = filemap(path, &data, PROT_READ);
    vector_init(&col->data, col->table->length);
    memcpy(col->data.vals, data, sz);
    col->data.sz = sz / sizeof (int);
    col->data.capacity = col->data.sz;
    col->status = INMEMORY;
    cs165_log(stdout, "col capacity %d, %d\n", col->data.sz, col->data.vals[col->data.sz-1]);
    fileunmap(data, sz);
}
Esempio n. 3
0
static int
externalEntityRefFilemap(XML_Parser parser,
                         const XML_Char *context,
                         const XML_Char *base,
                         const XML_Char *systemId,
                         const XML_Char *publicId)
{
  int result;
  XML_Char *s;
  const XML_Char *filename;
  XML_Parser entParser = XML_ExternalEntityParserCreate(parser, context, 0);
  PROCESS_ARGS args;
  args.retPtr = &result;
  args.parser = entParser;
  filename = resolveSystemId(base, systemId, &s);
  XML_SetBase(entParser, filename);
  if (!filemap(filename, processFile, &args))
    result = 0;
  free(s);
  XML_ParserFree(entParser);
  return result;
}
Esempio n. 4
0
File: sync.c Progetto: atikinn/db165
static
struct column restore_col(char *record, struct table *tbl) {
    struct col_record *rec = (struct col_record *) record;
    bool clustered = tbl->clustered == tbl->col_count;
    struct column col = { .name = strdup(rec->name), .table = tbl, .index = NULL,
			  .clustered = clustered, .status = ONDISK, .data = { 0, 0, NULL } };
    cs165_log(stderr, "clustered = %d\n", col.clustered);
    enum index_type idx_type = rec->idx_type - '0';
    switch(idx_type) {
	case IDX_INVALID: break;
	case SORTED:
	case BTREE:
	    col.index = malloc(sizeof(struct column_index));
	    col.index->type = idx_type;
	    col.index->index = NULL;
	    break;
    }
    return col;
}

static
struct table restore_tbl(char *record, size_t *col_count) {
    struct tbl_record *rec = (struct tbl_record *) record;
    struct table tbl = { .name = strdup(rec->name), .length = rec->length,
		         .clustered = rec->clustered, .col_count = 0 };
    tbl.col = malloc(sizeof(struct column) * rec->col_count);
    *col_count = rec->col_count;
    return tbl;
}

static
struct db *restore_db(char *record) {
    struct db_record *rec = (struct db_record *) record;
    struct db *db = malloc(sizeof *db);
    assert (db);
    db->table_count = 0;
    db->capacity = rec->capacity;
    db->tables = malloc(sizeof(struct table) * db->capacity);
    assert(db->tables);
    db->name = strdup(rec->name);
    return db;
}

static
struct db *restore(char *meta, size_t sz) {
    enum meta_state state = DB_RECORD;
    struct db *db;
    struct table *tbl;
    struct column *col;
    char *rec;
    size_t col_count = 0, prev = 0;
    char varbuf[VARNAME_SIZE];
    for (size_t j = 0; j < sz; j++) {
	if (meta[j] == '|') {
	    meta[j] = '\0';
	    rec = &meta[prev];
	    prev = j + 1;

	    switch(state) {
		case DB_RECORD:
		    db = restore_db(rec);
		    //map_insert(db->name, db, ENTITY);
		    state = TBL_RECORD;
		    break;
		case TBL_RECORD:
		    db->tables[db->table_count] = restore_tbl(rec, &col_count);
		    tbl = &db->tables[db->table_count++];
		    snprintf(varbuf, sizeof varbuf, "%s.%s", db->name, tbl->name);
		    map_insert(strdup(varbuf), tbl, ENTITY);
		    state = COL_RECORD;
		    break;
		case COL_RECORD:
		    tbl->col[tbl->col_count] = restore_col(rec, tbl);
		    col = &tbl->col[tbl->col_count++];
		    snprintf(varbuf, sizeof varbuf, "%s.%s.%s", db->name, tbl->name, col->name);
		    map_insert(strdup(varbuf), col, ENTITY);
		    if (col_count == tbl->col_count) state = TBL_RECORD;
		    break;
	    }
	}
    }

    assert(state == TBL_RECORD);
    assert(db->table_count <= db->capacity);
    return db;
}

static
struct db *restore_meta(void) {
    char buf[PATHLEN];
    char *path = vbsnprintf(buf, sizeof buf, "%s/%s.bin", DBPATH, METAFILE);

    char *meta;
    off_t sz = filemap(path, &meta, PROT_READ | PROT_WRITE);
    struct db *db = restore(meta, sz);
    fileunmap(meta, sz);
    return db;
}

//////////////////////////////////////////////////////////////////////////////

static
void restore_sindex(struct column *col) {
    char *tname = col->table->name;
    char buf[PATHLEN];
    char *path = vbsnprintf(buf, sizeof buf, "%s/%s.%s.sorted.bin", DBPATH, tname, col->name);
    char *data;
    off_t sz = filemap(path, &data, PROT_READ);
    col->index->index = sindex_alloc(col->data.sz);
    memcpy(col->index->index, data, sz);
    assert(is_sorted(col->index->index, col->data.sz) == true);
    fileunmap(data, sz);
}