Example #1
0
static int cursor_fetch(lua_State* L)
{
    Cursor* cur = check_cursor(L);
    luaL_argcheck(L, cur && cur->my_res, 1, "invalid Cursor object");
    int alpha_idx = 0;
    const char* opt = lua_tostring(L, 2);
    if (opt && strcmp(opt, "a") == 0) // alphabetic table index
    {
        alpha_idx = 1;
    }

    MYSQL_RES* res = cur->my_res;
    MYSQL_ROW row = mysql_fetch_row(res);
    if (row == NULL) // no more results
    {
        return 0;
    }
    unsigned long* lengths = mysql_fetch_lengths(res);
    if (cur->fields == NULL)
    {
        cur->fields = mysql_fetch_fields(res);
    }
    luaL_argcheck(L, lengths && cur->fields, 1, "fetch fields failed");
    luaL_checkstack(L, cur->numcols, "too many columns");
    result_to_table(L, cur, row, lengths, alpha_idx);
    return 1;
}
Example #2
0
void M_BufferWriteString(buf_t *buf, const char *string, size_t length) {
  M_BufferEnsureCapacity(buf, length + 1);
  strncpy(buf->data + buf->cursor, string, length + 1);
  buf->cursor += (length + 1);

  check_cursor(buf);
}
Example #3
0
void M_BufferWrite(buf_t *buf, const void *data, size_t size) {
  M_BufferEnsureCapacity(buf, size);
  memcpy(buf->data + buf->cursor, data, size);
  buf->cursor += size;

  check_cursor(buf);
}
Example #4
0
static int cursor_numrows(lua_State *L)
{
    Cursor* cur = check_cursor(L);
    luaL_argcheck(L, cur && cur->my_res, 1, "invalid Cursor object");
    my_ulonglong rows = mysql_num_rows(cur->my_res);
    lua_pushinteger(L, (lua_Integer)rows);
    return 1;
}
Example #5
0
static int cursor_gc(lua_State *L)
{
    Cursor* cur = check_cursor(L);
    if (cur)
    {
        cursor_nullify(L, cur);
    }
    return 0;
}
Example #6
0
void M_BufferWriteZeros(buf_t *buf, size_t count) {
  int i;

  M_BufferEnsureCapacity(buf, count);

  for (i = 0; i < count; i++)
    buf->data[buf->cursor++] = 0;

  check_cursor(buf);
}
Example #7
0
// Get indent level from 'indentexpr'.
int get_expr_indent(void)
{
  int indent;
  pos_T save_pos;
  colnr_T save_curswant;
  int save_set_curswant;
  int save_State;
  int use_sandbox = was_set_insecurely((char_u *)"indentexpr", OPT_LOCAL);

  // Save and restore cursor position and curswant, in case it was changed
  // * via :normal commands.
  save_pos = curwin->w_cursor;
  save_curswant = curwin->w_curswant;
  save_set_curswant = curwin->w_set_curswant;
  set_vim_var_nr(VV_LNUM, curwin->w_cursor.lnum);

  if (use_sandbox) {
    sandbox++;
  }
  textlock++;
  indent = eval_to_number(curbuf->b_p_inde);

  if (use_sandbox) {
    sandbox--;
  }
  textlock--;

  // Restore the cursor position so that 'indentexpr' doesn't need to.
  // Pretend to be in Insert mode, allow cursor past end of line for "o"
  // command.
  save_State = State;
  State = INSERT;
  curwin->w_cursor = save_pos;
  curwin->w_curswant = save_curswant;
  curwin->w_set_curswant = save_set_curswant;
  check_cursor();
  State = save_State;

  // If there is an error, just keep the current indent.
  if (indent < 0) {
    indent = get_indent();
  }

  return indent;
}
Example #8
0
void ex_rubydo(exarg_T *eap)
{
    int state;
    linenr_T i;

    if (ensure_ruby_initialized())
    {
	if (u_save(eap->line1 - 1, eap->line2 + 1) != OK)
	    return;
	for (i = eap->line1; i <= eap->line2; i++)
	{
	    VALUE line;

	    line = vim_str2rb_enc_str((char *)ml_get(i));
	    rb_lastline_set(line);
	    eval_enc_string_protect((char *) eap->arg, &state);
	    if (state)
	    {
		error_print(state);
		break;
	    }
	    line = rb_lastline_get();
	    if (!NIL_P(line))
	    {
		if (TYPE(line) != T_STRING)
		{
		    EMSG(_("E265: $_ must be an instance of String"));
		    return;
		}
		ml_replace(i, (char_u *) StringValuePtr(line), 1);
		changed();
#ifdef SYNTAX_HL
		syn_changed(i); /* recompute syntax hl. for this line */
#endif
	    }
	}
	check_cursor();
	update_curbuf(NOT_VALID);
    }
}
Example #9
0
static int cursor_fetch_all(lua_State* L)
{
    Cursor* cur = check_cursor(L);
    luaL_argcheck(L, cur && cur->my_res, 1, "invalid Cursor object");
    luaL_argcheck(L, cur->fetch_all, 1, "not compatible with execute()");

    int alpha_idx = 0;
    const char* opt = lua_tostring(L, 2);
    if (opt && strcmp(opt, "a") == 0) // alphabetic table index
    {
        alpha_idx = 1;
    }

    MYSQL_RES* res = cur->my_res;
    MYSQL_ROW row = mysql_fetch_row(res);
    if (row == NULL || cur->numcols == 0) // no results
    {
        cursor_nullify(L, cur);
        return 0;
    }
    if (cur->fields == NULL)
    {
        cur->fields = mysql_fetch_fields(res);
    }
    unsigned long* lengths = mysql_fetch_lengths(res);
    luaL_argcheck(L, lengths && cur->fields, 1, "fetch fields failed");
    int num_rows = (int)mysql_num_rows(cur->my_res);
    lua_createtable(L, num_rows, 0);
    int rownum = 1;
    while (row)
    {
        result_to_table(L, cur, row, lengths, alpha_idx);
        lua_rawseti(L, -2, rownum++);
        row = mysql_fetch_row(res);
    }
    cursor_nullify(L, cur);
    return 1;
}
Example #10
0
/*
 * Given a menu descriptor, e.g. "File.New", find it in the menu hierarchy and
 * execute it.
 */
void ex_emenu(exarg_T *eap)
{
  vimmenu_T   *menu;
  char_u      *name;
  char_u      *saved_name;
  char_u      *p;
  int idx;
  char_u      *mode;

  saved_name = vim_strsave(eap->arg);

  menu = root_menu;
  name = saved_name;
  while (*name) {
    /* Find in the menu hierarchy */
    p = menu_name_skip(name);

    while (menu != NULL) {
      if (menu_name_equal(name, menu)) {
        if (*p == NUL && menu->children != NULL) {
          EMSG(_("E333: Menu path must lead to a menu item"));
          menu = NULL;
        } else if (*p != NUL && menu->children == NULL) {
          EMSG(_(e_notsubmenu));
          menu = NULL;
        }
        break;
      }
      menu = menu->next;
    }
    if (menu == NULL || *p == NUL)
      break;
    menu = menu->children;
    name = p;
  }
  free(saved_name);
  if (menu == NULL) {
    EMSG2(_("E334: Menu not found: %s"), eap->arg);
    return;
  }

  /* Found the menu, so execute.
   * Use the Insert mode entry when returning to Insert mode. */
  if (restart_edit
      && !current_SID
      ) {
    mode = (char_u *)"Insert";
    idx = MENU_INDEX_INSERT;
  } else if (eap->addr_count) {
    pos_T tpos;

    mode = (char_u *)"Visual";
    idx = MENU_INDEX_VISUAL;

    /* GEDDES: This is not perfect - but it is a
     * quick way of detecting whether we are doing this from a
     * selection - see if the range matches up with the visual
     * select start and end.  */
    if ((curbuf->b_visual.vi_start.lnum == eap->line1)
        && (curbuf->b_visual.vi_end.lnum) == eap->line2) {
      /* Set it up for visual mode - equivalent to gv.  */
      VIsual_mode = curbuf->b_visual.vi_mode;
      tpos = curbuf->b_visual.vi_end;
      curwin->w_cursor = curbuf->b_visual.vi_start;
      curwin->w_curswant = curbuf->b_visual.vi_curswant;
    } else {
      /* Set it up for line-wise visual mode */
      VIsual_mode = 'V';
      curwin->w_cursor.lnum = eap->line1;
      curwin->w_cursor.col = 1;
      tpos.lnum = eap->line2;
      tpos.col = MAXCOL;
      tpos.coladd = 0;
    }

    /* Activate visual mode */
    VIsual_active = TRUE;
    VIsual_reselect = TRUE;
    check_cursor();
    VIsual = curwin->w_cursor;
    curwin->w_cursor = tpos;

    check_cursor();

    /* Adjust the cursor to make sure it is in the correct pos
     * for exclusive mode */
    if (*p_sel == 'e' && gchar_cursor() != NUL)
      ++curwin->w_cursor.col;
  } else {
    mode = (char_u *)"Normal";
    idx = MENU_INDEX_NORMAL;
  }

  if (idx != MENU_INDEX_INVALID && menu->strings[idx] != NULL) {
    /* When executing a script or function execute the commands right now.
     * Otherwise put them in the typeahead buffer. */
    if (current_SID != 0)
      exec_normal_cmd(menu->strings[idx], menu->noremap[idx],
          menu->silent[idx]);
    else
      ins_typebuf(menu->strings[idx], menu->noremap[idx], 0,
          TRUE, menu->silent[idx]);
  } else
    EMSG2(_("E335: Menu not defined for %s mode"), mode);
}
Example #11
0
File: if_lua.c Project: LeonB/vim
    static int
luaV_buffer_newindex(lua_State *L)
{
    buf_T *b = (buf_T *) luaV_checkvalid(L, luaV_Buffer, 1);
    linenr_T n = (linenr_T) luaL_checkinteger(L, 2);
#ifdef HAVE_SANDBOX
    luaV_checksandbox(L);
#endif
    if (n < 1 || n > b->b_ml.ml_line_count)
	luaL_error(L, "invalid line number");
    if (lua_isnil(L, 3)) /* delete line */
    {
	buf_T *buf = curbuf;
	curbuf = b;
	if (u_savedel(n, 1L) == FAIL)
	{
	    curbuf = buf;
	    luaL_error(L, "cannot save undo information");
	}
	else if (ml_delete(n, FALSE) == FAIL)
	{
	    curbuf = buf;
	    luaL_error(L, "cannot delete line");
	}
	else {
	    deleted_lines_mark(n, 1L);
	    if (b == curwin->w_buffer) /* fix cursor in current window? */
	    {
		if (curwin->w_cursor.lnum >= n)
		{
		    if (curwin->w_cursor.lnum > n)
		    {
			curwin->w_cursor.lnum -= 1;
			check_cursor_col();
		    }
		    else check_cursor();
		    changed_cline_bef_curs();
		}
		invalidate_botline();
	    }
	}
	curbuf = buf;
    }
    else if (lua_isstring(L, 3)) /* update line */
    {
	buf_T *buf = curbuf;
	curbuf = b;
	if (u_savesub(n) == FAIL)
	{
	    curbuf = buf;
	    luaL_error(L, "cannot save undo information");
	}
	else if (ml_replace(n, luaV_toline(L, 3), TRUE) == FAIL)
	{
	    curbuf = buf;
	    luaL_error(L, "cannot replace line");
	}
	else changed_bytes(n, 0);
	curbuf = buf;
	if (b == curwin->w_buffer)
	    check_cursor_col();
    }
    else
	luaL_error(L, "wrong argument to change line");
    return 0;
}