示例#1
0
文件: p_s_lr.c 项目: po-connor/42sh
int	p_s_lr(
		t_list **stack,
		t_list **lexed,
		t_ast_tree **tree)
{
	static t_pt_token	prod[] = {e_pt_linerep, e_pt_str, 0};

	if (change_stack(stack, prod) < 0)
		return (-1);
	if (!(*tree = new_leaf(e_ast_line)))
		return (-1);
	if (recursive_parse(stack, lexed, &(*tree)->left) < 0)
		return (del_leaf(tree));
	if (recursive_parse(stack, lexed, &(*tree)->right) < 0)
		return (del_leaf(tree));
	return (0);
}
示例#2
0
static struct DB *db_load(const char *const meta_dir,
                          struct ContainerMapConf *const cm_conf) {
    const double sec0 = debug_time_sec();
    char path_meta[2048];

    // test files
    sprintf(path_meta, "%s/%s", meta_dir, DB_META_MAIN);
    if (0 != access(path_meta, F_OK))
        return NULL;
    assert(cm_conf);
    // test cmaps
    for (int i = 0; (i < 6) && cm_conf->raw_fn[i]; i++) {
        char path_cm[2048];
        sprintf(path_cm, "%s/%s-%01d", meta_dir, DB_META_CMAP_PREFIX, i);
        if (0 != access(path_cm, F_OK))
            return NULL;
    }

    // alloc db and load ContainerMap
    struct DB *const db = (typeof(db))malloc(sizeof(*db));
    assert(db);
    bzero(db, sizeof(*db));

    // load ContainerMaps
    for (int i = 0; (i < 6) && cm_conf->raw_fn[i]; i++) {
        char path_cm[2048];
        sprintf(path_cm, "%s/%s-%01d", meta_dir, DB_META_CMAP_PREFIX, i);
        struct ContainerMap *const cm =
            containermap_load(path_cm, cm_conf->raw_fn[i]);
        assert(cm);
        db->cms_dump[i] = cm;
    }

    db_initial(db, meta_dir, cm_conf);

    //// LOAD META
    // parse vc
    FILE *const meta_in = fopen(path_meta, "r");
    struct VirtualContainer *const vcroot = recursive_parse(meta_in, 0, db);
    assert(vcroot);
    db->vcroot = vcroot;

    // read mtid
    char buf_mtid[32];
    fgets(buf_mtid, 30, meta_in);
    const uint64_t mtid = strtoull(buf_mtid, NULL, 10);
    assert(mtid > 0);
    db->next_mtid = mtid;
    fclose(meta_in);

    // initial anything
    db_log_diff(db, sec0, "Loaded Metadata Done");
    return db;
}
示例#3
0
int			parser(t_list *lexed, t_ast_tree **tree)
{
	t_list	*stack;

	if (!(stack = init_stack()))
		return (-1);
	if (recursive_parse(&stack, &lexed, tree) < 0)
	{
		ft_lstdelproper(&stack);
		return (-1);
	}
	return (0);
}
示例#4
0
static struct VirtualContainer *recursive_parse(FILE *const in,
                                                uint64_t start_bit,
                                                struct DB *const db) {
    char buf[128];
    fgets(buf, 120, in);
    assert(buf[0] == '[');
    if (buf[1] == ']') {
        return NULL;
    }
    struct VirtualContainer *vc = vc_create(start_bit);
    fgets(buf, 28, in);
    assert(buf[0] == '<');
    // '<!' : bloomcontainer
    // '<'  : bloomtable
    const bool load_bf = (buf[1] != '!');
    for (uint64_t j = 0; j < DB_CONTAINER_NR; j++) {
        fgets(buf, 28, in);
        if (buf[0] == '>')
            break;

        const uint64_t mtid = strtoull(buf, NULL, 16);
        assert(db->cms[start_bit / 3]);
        const int raw_fd = db->cms[start_bit / 3]->raw_fd;
        struct MetaTable *const mt =
            db_load_metatable(db, mtid, raw_fd, load_bf);
        assert(mt);
        vc->cc.count++;
        vc->cc.metatables[j] = mt;
    }
    if (buf[0] != '>') {  // read 8 in loop, eat '>'
        fgets(buf, 28, in);
        assert(buf[0] == '>');
    }
    if (!load_bf) {  // no bf, load bc
        assert(buf[1] == '!');
        // load bloomcontainer
        assert(buf[2] != '\0');
        const uint64_t mtid_bc = strtoull(buf + 2, NULL, 16);
        struct BloomContainer *const bc =
            db_load_bloomcontainer_meta(db, mtid_bc);
        vc->cc.bc = bc;
    }
    for (uint64_t i = 0; i < 8; i++) {
        vc->sub_vc[i] = recursive_parse(in, start_bit + 3, db);
    }
    fgets(buf, 28, in);
    assert(buf[0] == ']');
    return vc;
}