示例#1
0
文件: m_sqlite.c 项目: x768/fox-lang
/*
 * 最初の行の最初の列だけ取得
 */
static int conn_single(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_ref(*v);
    sqlite3 *conn = Value_ptr(r->v[INDEX_SQLITE_CONN]);

    sqlite3_stmt *stmt = NULL;
    if (!conn_prepare_sub(&stmt, conn, v)) {
        return FALSE;
    }

    if (stmt != NULL) {
        int result = sqlite3_step(stmt);
        if (result == SQLITE_ROW) {
            *vret = cursor_get_sub(stmt, 0);
            sqlite3_finalize(stmt);
        } else if (result == SQLITE_ERROR_USER) {
            fs->throw_errorf(mod_sqlite, "SQLiteError", "%s", sqlite3_errmsg(conn));
            return FALSE;
        } else {
            sqlite3_finalize(stmt);
        }
    }

    return TRUE;
}
示例#2
0
文件: m_sqlite.c 项目: x768/fox-lang
static int conn_exec(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_ref(*v);
    sqlite3 *conn = Value_ptr(r->v[INDEX_SQLITE_CONN]);
    int result;
    int count;

    sqlite3_stmt *stmt = NULL;
    if (!conn_prepare_sub(&stmt, conn, v)) {
        return FALSE;
    }

    result = sqlite3_step(stmt);
    if (result != SQLITE_DONE && result != SQLITE_ROW) {
        // ???
        if (result != SQLITE_ERROR_USER) {
            fs->throw_errorf(mod_sqlite, "SQLiteError", "%s", sqlite3_errmsg(conn));
            return FALSE;
        }
        //return FALSE;
    }
    count = sqlite3_changes(conn);
    sqlite3_finalize(stmt);

    *vret = int32_Value(count);

    return TRUE;
}
示例#3
0
static int markdown_dispose(Value *vret, Value *v, RefNode *node)
{
    Ref *ref = Value_ref(*v);
    Markdown *r = Value_ptr(ref->v[INDEX_MARKDOWN_MD]);
    fs->Mem_close(&r->mem);
    free(r);
    ref->v[INDEX_MARKDOWN_MD] = VALUE_NULL;

    return TRUE;
}
示例#4
0
static int markdown_enable_tex(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_vp(*v);
    Markdown *md = Value_ptr(r->v[INDEX_MARKDOWN_MD]);
    if (fg->stk_top > v + 1) {
        md->enable_tex = Value_bool(v[1]);
    } else {
        *vret = bool_Value(md->enable_tex);
    }
    return TRUE;
}
示例#5
0
文件: m_sqlite.c 项目: x768/fox-lang
static int conn_close(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_ref(*v);
    sqlite3 *conn = Value_ptr(r->v[INDEX_SQLITE_CONN]);

    if (conn != NULL) {
        sqlite3_close(conn);
        r->v[INDEX_SQLITE_CONN] = VALUE_NULL;
    }

    return TRUE;
}
示例#6
0
static int markdown_add_link(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_vp(*v);
    Markdown *md = Value_ptr(r->v[INDEX_MARKDOWN_MD]);
    RefStr *key = Value_vp(v[1]);
    RefStr *href = Value_vp(v[2]);

    MDNode *nd = MDNode_new(MD_TEXT, md);
    nd->cstr = fs->str_dup_p(href->c, href->size, &md->mem);
    SimpleHash_add_node(md->link_map, &md->mem, key->c, nd);

    return TRUE;
}
示例#7
0
static int markdown_compile(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_vp(*v);
    Markdown *md = Value_ptr(r->v[INDEX_MARKDOWN_MD]);

    if (!parse_markdown(md, Value_cstr(v[1]))) {
        return FALSE;
    }
    if (!link_markdown(r)) {
        return FALSE;
    }

    return TRUE;
}
示例#8
0
static int markdown_heading_level(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_vp(*v);
    Markdown *md = Value_ptr(r->v[INDEX_MARKDOWN_MD]);
    if (fg->stk_top > v + 1) {
        int64_t i64 = fs->Value_int64(v[1], NULL);
        if (i64 < 1 || i64 > 6) {
            fs->throw_errorf(fs->mod_lang, "ValueError", "Out of range (1 - 6)");
            return FALSE;
        }
        md->heading_level = (int)i64;
    } else {
        *vret = int32_Value(md->heading_level);
    }
    return TRUE;
}
示例#9
0
static int markdown_heading_list(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_vp(*v);
    Markdown *md = Value_ptr(r->v[INDEX_MARKDOWN_MD]);
    RefArray *ra = fs->refarray_new(0);
    MDNodeLink *link;

    *vret = vp_Value(ra);
    for (link = md->heading; link != NULL; link = link->next) {
        StrBuf sb;
        fs->StrBuf_init_refstr(&sb, 0);
        MDNode_tostr(&sb, link->node);
        *fs->refarray_push(ra) = fs->StrBuf_str_Value(&sb, fs->cls_str);
    }

    return TRUE;
}
示例#10
0
文件: monitor.c 项目: x768/fox-lang
void native_dirmonitor_remove(Ref *r)
{
    FileMonitor *fm = Value_ptr(r->v[INDEX_FILEMONITOR_STRUCT]);

    if (fm != NULL) {
        fm->valid = FALSE;
        CancelIo(fm->hDir);
        refresh_dirmonitor(fm, TRUE);

        if (!HasOverlappedIoCompleted(&fm->overlapped)) {
            SleepEx(5, TRUE);
        }
        CloseHandle(fm->hDir);
        CloseHandle(fm->overlapped.hEvent);

        FileMonitor_del(fm);
        r->v[INDEX_FILEMONITOR_STRUCT] = VALUE_NULL;
    }
}
示例#11
0
文件: m_sqlite.c 项目: x768/fox-lang
static int conn_query(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_ref(*v);
    sqlite3 *conn = Value_ptr(r->v[INDEX_SQLITE_CONN]);

    sqlite3_stmt *stmt = NULL;
    if (!conn_prepare_sub(&stmt, conn, v)) {
        return FALSE;
    }

    {
        RefCursor *rc = fs->buf_new(cls_cursor, sizeof(RefCursor));
        *vret = vp_Value(rc);
        rc->connect = fs->Value_cp(*v);
        rc->stmt = stmt;
        rc->is_map = FUNC_INT(node);
    }

    return TRUE;
}
示例#12
0
static int markdown_make_xml(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_vp(*v);
    Markdown *md = Value_ptr(r->v[INDEX_MARKDOWN_MD]);
    RefStr *root_name = Value_vp(v[1]);
    Ref *root;

    if (!xst->is_valid_elem_name(root_name->c, root_name->size)) {
        fs->throw_errorf(fs->mod_lang, "ValueError", "Invalid element name");
        return FALSE;
    }

    root = xmlelem_new(root_name->c);
    *vret = vp_Value(root);
    if (!xml_from_markdown(root, md, md->root)) {
        return FALSE;
    }

    return TRUE;
}
示例#13
0
文件: m_sqlite.c 项目: x768/fox-lang
/**
 * Function f : スカラ関数
 * Class c : 集約関数
 * c.new(), c#step(..), c#result() を実装する
 */
static int conn_create_function(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_ref(*v);
    sqlite3 *conn = Value_ptr(r->v[INDEX_SQLITE_CONN]);
    RefStr *name = Value_vp(v[1]);
    Value v2 = v[2];
    const RefNode *v2_type = fs->Value_type(v2);

    if (v2_type == fs->cls_fn) {
        Value *vf = conn_create_function_reg(r, v2);
        sqlite3_create_function_v2(conn, name->c, -1, SQLITE_UTF8, vf, sqlite_callback_func, NULL, NULL, NULL);
    } else if (v2_type == fs->cls_class) {
        RefNode *klass = Value_vp(v2);
        sqlite3_create_function_v2(conn, name->c, -1, SQLITE_UTF8, klass, NULL, sqlite_callback_step, sqlite_callback_final, NULL);
    } else {
        fs->throw_error_select(THROW_ARGMENT_TYPE2__NODE_NODE_NODE_INT, fs->cls_fn, fs->cls_class, v2_type, 2);
        return FALSE;
    }

    return TRUE;
}
示例#14
0
static int mapiter_next(Value *vret, Value *v, RefNode *node)
{
    Ref *r = Value_ref(*v);
    RefMap *map = Value_vp(r->v[INDEX_MAPITER_VAL]);
    int idx = Value_integral(r->v[INDEX_MAPITER_IDX]);
    HashValueEntry *ep = Value_ptr(r->v[INDEX_MAPITER_PTR]);

    if (ep != NULL) {
        ep = ep->next;
    }
    while (ep == NULL && idx < map->entry_num) {
        ep = map->entry[idx];
        idx++;
    }

    r->v[INDEX_MAPITER_IDX] = int32_Value(idx);
    r->v[INDEX_MAPITER_PTR] = ptr_Value(ep);

    if (ep != NULL) {
        switch (Value_integral(r->v[INDEX_MAPITER_TYPE])) {
        case ITERATOR_KEY:
            *vret = Value_cp(ep->key);
            break;
        case ITERATOR_VAL:
            *vret = Value_cp(ep->val);
            break;
        default: {
            Ref *r2 = ref_new(fv->cls_entry);
            *vret = vp_Value(r2);
            r2->v[INDEX_ENTRY_KEY] = Value_cp(ep->key);
            r2->v[INDEX_ENTRY_VAL] = Value_cp(ep->val);
            break;
        }
        }
    } else {
        throw_stopiter();
        return FALSE;
    }
    return TRUE;
}
示例#15
0
文件: m_gui_sub.c 项目: x768/fox-lang
void *Value_handle(Value v)
{
    return Value_ptr(v);
}