Exemplo n.º 1
0
void test15(void) {
  ElementNode_handle pE1=0,pE2=0,pE3=0;
  RowNode_handle pR=0; 
  int i;
  printf("\n====== INSERT ROWS MIDDLE =========================\n");
  for(i=0;i<5;++i) insert_element(&pE1,2*i,10*i-50);
  printf_elements(pE1,"%4d",10); printf("\n");

  for(i=0;i<20;++i) insert_element(&pE2,20-i,i);
  printf_elements(pE2,"%4d",10); printf("\n");
 
  for(i=0;i<10;++i) {
    if (i%2) insert_element(&pE3,i,i);
    else     insert_element(&pE3,10-i,-i);
  }
  
  insert_row(&pR,8,pE3);
  printf("after insert:\n"); printf_rows(pR,"%4i",10); printf("\n");
  insert_row(&pR,0,pE1);
  printf("after insert:\n"); printf_rows(pR,"%4i",10); printf("\n");
  insert_row(&pR,5,pE2);
  printf("after insert:\n"); printf_rows(pR,"%4i",10); printf("\n");

  free_rows(pR);
}
Exemplo n.º 2
0
void test_text_key() {
  // Create a table named "Table".
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");

  // Create a column named "Column".
  auto column = table->create_column("Column", GRNXX_TEXT);

  // Append three rows.
  grnxx::Int row_id = table->insert_row();
  column->set(row_id, grnxx::Text("1"));
  row_id = table->insert_row();
  column->set(row_id, grnxx::Text("12"));
  row_id = table->insert_row();
  column->set(row_id, grnxx::Text("123"));

  // Set key column.
  table->set_key_column("Column");
  assert(table->key_column() == column);

  // Duplicate keys must be rejected.
  bool inserted = true;
  row_id = table->find_or_insert_row(grnxx::Text("1"), &inserted);
  assert(row_id.raw() == 0);
  assert(!inserted);
  row_id = table->find_or_insert_row(grnxx::Text("12"), &inserted);
  assert(row_id.raw() == 1);
  assert(!inserted);
  row_id = table->find_or_insert_row(grnxx::Text("123"), &inserted);
  assert(row_id.raw() == 2);
  assert(!inserted);

  // Append new keys.
  grnxx::Datum datum;
  row_id = table->find_or_insert_row(grnxx::Text("A"), &inserted);
  assert(row_id.raw() == 3);
  assert(inserted);
  row_id = table->find_or_insert_row(grnxx::Text("AB"), &inserted);
  assert(row_id.raw() == 4);
  assert(inserted);
  row_id = table->find_or_insert_row(grnxx::Text("ABC"), &inserted);
  assert(row_id.raw() == 5);
  assert(inserted);

  // Find rows by key.
  assert(table->find_row(grnxx::Text("1")).raw() == 0);
  assert(table->find_row(grnxx::Text("12")).raw() == 1);
  assert(table->find_row(grnxx::Text("123")).raw() == 2);
  assert(table->find_row(grnxx::Text("A")).raw() == 3);
  assert(table->find_row(grnxx::Text("AB")).raw() == 4);
  assert(table->find_row(grnxx::Text("ABC")).raw() == 5);
  assert(table->find_row(grnxx::Text::na()).is_na());

  // Unset key column.
  table->unset_key_column();
  assert(!table->key_column());
}
Exemplo n.º 3
0
int
main(int argc, char **argv)
{
	LOGINREC *login;
	DBPROCESS *dbproc;

	read_login_info(argc, argv);
	printf("Starting %s\n", argv[0]);

	dbinit();

	printf("About to logon\n");

	login = dblogin();
	DBSETLPWD(login, PASSWORD);
	DBSETLUSER(login, USER);
	DBSETLAPP(login, "t0011");

	printf("About to open\n");

	dbproc = dbopen(login, SERVER);
	if (strlen(DATABASE))
		dbuse(dbproc, DATABASE);
	dbloginfree(login);

	printf("Dropping table\n");
	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}

	printf("creating table\n");
	sql_cmd(dbproc);
	dbsqlexec(dbproc);
	while (dbresults(dbproc) != NO_MORE_RESULTS) {
		/* nop */
	}

	printf("insert\n");

	insert_row(dbproc);
	insert_row(dbproc);
	insert_row(dbproc);

	failed = select_rows(dbproc, STRINGBIND);

	dbexit();

	printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
	return failed ? 1 : 0;
}
Exemplo n.º 4
0
void test_rows() {
  // Create a table named "Table".
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");

  // Append the first row.
  grnxx::Int row_id = table->insert_row();
  assert(row_id.raw() == 0);
  assert(table->num_rows() == 1);
  assert(table->max_row_id().match(row_id));
  assert(!table->test_row(grnxx::Int(-1)));
  assert(table->test_row(grnxx::Int(0)));
  assert(!table->test_row(grnxx::Int(1)));

  // Append two more rows.
  assert(table->insert_row().raw() == 1);
  assert(table->insert_row().raw() == 2);
  assert(table->num_rows() == 3);
  assert(table->max_row_id().raw() == 2);
  assert(table->test_row(grnxx::Int(0)));
  assert(table->test_row(grnxx::Int(1)));
  assert(table->test_row(grnxx::Int(2)));
  assert(!table->test_row(grnxx::Int(3)));

  // Remove the second row.
  table->remove_row(grnxx::Int(1));
  assert(table->num_rows() == 2);
  assert(table->max_row_id().raw() == 2);
  assert(table->test_row(grnxx::Int(0)));
  assert(!table->test_row(grnxx::Int(1)));
  assert(table->test_row(grnxx::Int(2)));
  assert(!table->test_row(grnxx::Int(3)));

  // Remove the first row.
  table->remove_row(grnxx::Int(0));
  assert(table->num_rows() == 1);
  assert(table->max_row_id().raw() == 2);
  assert(!table->test_row(grnxx::Int(0)));
  assert(!table->test_row(grnxx::Int(1)));
  assert(table->test_row(grnxx::Int(2)));
  assert(!table->test_row(grnxx::Int(3)));

  // Remove the third row.
  table->remove_row(grnxx::Int(2));
  assert(table->num_rows() == 0);
  assert(table->max_row_id().is_na());
  assert(!table->test_row(grnxx::Int(0)));
  assert(!table->test_row(grnxx::Int(1)));
  assert(!table->test_row(grnxx::Int(2)));
  assert(!table->test_row(grnxx::Int(3)));
}
Exemplo n.º 5
0
void test_find_one() {
  // Create a table and insert rows.
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");
  table->insert_row();
  table->insert_row();
  table->insert_row();

  auto column = table->create_column("Int", GRNXX_INT);
  assert(column->find_one(grnxx::Int(123)).is_na());
  assert(column->find_one(grnxx::Int(456)).is_na());
  assert(column->find_one(grnxx::Int(789)).is_na());
  assert(!column->find_one(grnxx::Int::na()).is_na());
  column->set(grnxx::Int(0), grnxx::Int(123));
  assert(!column->find_one(grnxx::Int(123)).is_na());
  assert(column->find_one(grnxx::Int(456)).is_na());
  assert(column->find_one(grnxx::Int(789)).is_na());
  assert(!column->find_one(grnxx::Int::na()).is_na());
  column->set(grnxx::Int(1), grnxx::Int(456));
  assert(!column->find_one(grnxx::Int(123)).is_na());
  assert(!column->find_one(grnxx::Int(456)).is_na());
  assert(column->find_one(grnxx::Int(789)).is_na());
  assert(!column->find_one(grnxx::Int::na()).is_na());
  column->set(grnxx::Int(2), grnxx::Int(789));
  assert(!column->find_one(grnxx::Int(123)).is_na());
  assert(!column->find_one(grnxx::Int(456)).is_na());
  assert(!column->find_one(grnxx::Int(789)).is_na());
  assert(column->find_one(grnxx::Int::na()).is_na());

  column->create_index("Index", GRNXX_TREE_INDEX);
  assert(!column->find_one(grnxx::Int(123)).is_na());
  assert(!column->find_one(grnxx::Int(456)).is_na());
  assert(!column->find_one(grnxx::Int(789)).is_na());
  assert(column->find_one(grnxx::Int::na()).is_na());
  column->set(grnxx::Int(2), grnxx::Int::na());
  assert(!column->find_one(grnxx::Int(123)).is_na());
  assert(!column->find_one(grnxx::Int(456)).is_na());
  assert(column->find_one(grnxx::Int(789)).is_na());
  assert(!column->find_one(grnxx::Int::na()).is_na());
  column->set(grnxx::Int(1), grnxx::Int::na());
  assert(!column->find_one(grnxx::Int(123)).is_na());
  assert(column->find_one(grnxx::Int(456)).is_na());
  assert(column->find_one(grnxx::Int(789)).is_na());
  assert(!column->find_one(grnxx::Int::na()).is_na());
  column->set(grnxx::Int(0), grnxx::Int::na());
  assert(column->find_one(grnxx::Int(123)).is_na());
  assert(column->find_one(grnxx::Int(456)).is_na());
  assert(column->find_one(grnxx::Int(789)).is_na());
  assert(!column->find_one(grnxx::Int::na()).is_na());
}
Exemplo n.º 6
0
void test_reference() {
  // Create tables.
  auto db = grnxx::open_db("");
  auto to_table = db->create_table("To");
  auto from_table = db->create_table("From");

  // Create a column named "Ref".
  grnxx::ColumnOptions options;
  options.reference_table_name = "To";
  auto ref_column = from_table->create_column("Ref", GRNXX_INT, options);

  // Append rows.
  to_table->insert_row();
  to_table->insert_row();
  to_table->insert_row();
  from_table->insert_row();
  from_table->insert_row();
  from_table->insert_row();

  ref_column->set(grnxx::Int(0), grnxx::Int(0));
  ref_column->set(grnxx::Int(1), grnxx::Int(1));
  ref_column->set(grnxx::Int(2), grnxx::Int(1));

  // TODO: "from_table" may be updated in "to_table->remove_row()".

  to_table->remove_row(grnxx::Int(0));

  grnxx::Datum datum;
  ref_column->get(grnxx::Int(0), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 0);
  ref_column->get(grnxx::Int(1), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 1);
  ref_column->get(grnxx::Int(2), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 1);

  to_table->remove_row(grnxx::Int(1));

  ref_column->get(grnxx::Int(0), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 0);
  ref_column->get(grnxx::Int(1), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 1);
  ref_column->get(grnxx::Int(2), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 1);
}
Exemplo n.º 7
0
void main_listctrl::gui_add_channel_wizard()
{
#if ( setupUSE_WIZARDS )
    plucker_controller::get()->set_is_new_update_execution_allowed( FALSE );
    
    bool        clicked_finish_button;
    wxString    generated_channel_section;
    bool        is_launch_channel_dialog_requested;
    
    clicked_finish_button = plucker_wizard_wrappers::run_add_channel_wizard( m_parent,
                &generated_channel_section, &is_launch_channel_dialog_requested );
    
    // If they clicked the finish button...
    if ( clicked_finish_button )
    {
        // ...and they want to launch a channel dialog...
        if ( is_launch_channel_dialog_requested )
        {
            // Launch a dialog for the new channel
            launch_dialog_for_new_channel( generated_channel_section );
        // ..or if they didn't want to launch a channel dialog...
        } 
        else
        {
            // ...just insert the row
            insert_row( generated_channel_section );
        }
    }    
        
    plucker_controller::get()->set_is_new_update_execution_allowed( TRUE );
#endif
}
Exemplo n.º 8
0
int main()
{
    char *a = "Petar";
    generate();
    write_tab(stdout);
    FILE *fout;
    fout = fopen("tab.txt", "w");
    
    write_tab(fout);
    fclose(fout);
    
    sort_tab_number();
    write_tab(stdout);
    
    sort_tab_name();
    write_tab(stdout);
    
    delete_row(96);
    write_tab(stdout);
    
    insert_row(a, 500, 20000);
    write_tab(stdout);
    
    return 0;
}
Exemplo n.º 9
0
void interpret ( int argc, char* argv[] )
{
  init_with_options (argc, argv);

  //test_rec_write("test");

  char token[30];
	
  while (!feof(in_s))
    {
      fscanf (in_s, "%s", token);
      put_msg (DEBUG, "current token is \"%s\".\n", token);
      if (strcmp(token, t_quit) == 0)
	{ quit(); break;}
      if (token[0] == '#')
	{ skip_line (); continue; }
      if (strcmp(token, t_help) == 0)
	{ show_help_info (); continue; }
      if (strcmp(token, t_database) == 0)
	{ set_database(); continue; }
      if (strcmp(token, t_show) == 0)
	{ show_database(); continue; }
      if (strcmp(token, t_print) == 0)
	{ print_str(); continue; }
      if (strcmp(token, t_create) == 0)
	{ create_tbl(); continue; }
      if (strcmp(token, t_drop) == 0)
	{ drop_tbl(); continue; }
      if (strcmp(token, t_insert) == 0)
	{ insert_row(); continue; }
      if (strcmp(token, t_select) == 0)
	{ select_rows(); continue; }
      syntax_error (token);
    }
}
// Only use this for newly created channels
void main_listctrl::launch_dialog_for_new_channel( const wxString& new_channel_section )
{
    if ( new_channel_section.IsEmpty() ) {
        wxLogError( "Error: can't open a channel dialog for an empty section." );
        return;
    }
    
    wxString channel_section = new_channel_section;
    
    // Show the configuration dialog, ready to edit the new channel.
    // Can't make them a child of this window (freezes) or parent (since an
    // XRC unknown container and says 2 things can't occupy it), so needs to be a 
    // child of the main_dialog (probably could be grandparent, but this is more 
    // readable).
    channel_dialog a_channel_dialog( m_parent, channel_section );
    
    // Show modal, and if clicked OK, then refresh the row, which will repaint as required.
    if ( a_channel_dialog.ShowModal() == wxID_OK ) {    
        insert_row( channel_section );
    } else {
        // Cancel button on channel dialog was clicked
        // Cancel button on channel dialog doesn't (and shouldn't, since a cancel) 
        // flush changes.
        // However, a flush is needed to cement the aborted section from memory 
        // into the written file so that a DeleteGroup() will find it in the file,
        // [called from within the plucker controller's delete channel function],
        // instead of the section existing in memory only, so won't see it until 
        // next flush, by which time we will have forgotten what it was. 
        the_configuration->Flush();
        // If didn't return OK, then must have clicked cancel to close the channel dialog
        // Since canceled before finished adding the chennel, delete the channel. No
        // gui delete needed, since never inserted the row.            
        the_plucker_controller->delete_channel( channel_section );       
    }               
}
Exemplo n.º 11
0
void test_basic_operations(const T &value) {
  constexpr grnxx::DataType data_type = T::type();

  // Create a table and insert the first row.
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");
  grnxx::Int row_id = table->insert_row();

  // Create a column named "Column".
  auto column = table->create_column("Column", data_type);
  assert(column->table() == table);
  assert(column->name() == "Column");
  assert(column->data_type() == data_type);
  assert(!column->reference_table());
  assert(!column->is_key());
  assert(column->num_indexes() == 0);

  // Check if N/A is stored or not.
  grnxx::Datum datum;
  T stored_value;
  column->get(row_id, &datum);
  assert(datum.type() == data_type);
  datum.force(&stored_value);
  assert(stored_value.is_na());

  // Set a value and get it.
  column->set(row_id, value);
  column->get(row_id, &datum);
  assert(datum.type() == data_type);
  datum.force(&stored_value);
  assert(stored_value.match(value));
}
Exemplo n.º 12
0
void test_set_and_get() {
  constexpr size_t NUM_ROWS = 1 << 16;

  // Create a table and insert the first row.
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");
  auto column = table->create_column("Column", T::type());
  grnxx::Array<T> values;
  values.resize(NUM_ROWS);
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    generate_random_value(&values[i]);
    grnxx::Int row_id = table->insert_row();
    column->set(row_id, values[i]);
    grnxx::Datum datum;
    column->get(row_id, &datum);

    T stored_value;
    datum.force(&stored_value);
    assert(stored_value.match(values[i]));
  }

  // Test all the values again.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int row_id = grnxx::Int(i);
    grnxx::Datum datum;
    column->get(row_id, &datum);
    T stored_value;
    datum.force(&stored_value);
    assert(stored_value.match(values[i]));
  }
}
Exemplo n.º 13
0
inline RC TPCCTxnManager::new_order_9(uint64_t w_id,uint64_t  d_id,bool remote, uint64_t ol_i_id, uint64_t ol_supply_w_id, uint64_t ol_quantity,uint64_t  ol_number, uint64_t ol_amount, uint64_t  o_id, row_t * r_stock_local) {
  assert(r_stock_local != NULL);
		// XXX s_dist_xx are not retrieved.
		UInt64 s_quantity;
		int64_t s_remote_cnt;
		s_quantity = *(int64_t *)r_stock_local->get_value(S_QUANTITY);
#if !TPCC_SMALL
		int64_t s_ytd;
		int64_t s_order_cnt;
		char * s_data __attribute__ ((unused));
		r_stock_local->get_value(S_YTD, s_ytd);
		r_stock_local->set_value(S_YTD, s_ytd + ol_quantity);
    // In Coordination Avoidance, this record must be protected!
		r_stock_local->get_value(S_ORDER_CNT, s_order_cnt);
		r_stock_local->set_value(S_ORDER_CNT, s_order_cnt + 1);
		s_data = r_stock_local->get_value(S_DATA);
#endif
		if (remote) {
			s_remote_cnt = *(int64_t*)r_stock_local->get_value(S_REMOTE_CNT);
			s_remote_cnt ++;
			r_stock_local->set_value(S_REMOTE_CNT, &s_remote_cnt);
		}
		uint64_t quantity;
		if (s_quantity > ol_quantity + 10) {
			quantity = s_quantity - ol_quantity;
		} else {
			quantity = s_quantity - ol_quantity + 91;
		}
		r_stock_local->set_value(S_QUANTITY, &quantity);

		/*====================================================+
		EXEC SQL INSERT
			INTO order_line(ol_o_id, ol_d_id, ol_w_id, ol_number,
				ol_i_id, ol_supply_w_id,
				ol_quantity, ol_amount, ol_dist_info)
			VALUES(:o_id, :d_id, :w_id, :ol_number,
				:ol_i_id, :ol_supply_w_id,
				:ol_quantity, :ol_amount, :ol_dist_info);
		+====================================================*/
		row_t * r_ol;
		uint64_t row_id;
		_wl->t_orderline->get_new_row(r_ol, wh_to_part(ol_supply_w_id), row_id);
		r_ol->set_value(OL_O_ID, &o_id);
		r_ol->set_value(OL_D_ID, &d_id);
		r_ol->set_value(OL_W_ID, &w_id);
		r_ol->set_value(OL_NUMBER, &ol_number);
		r_ol->set_value(OL_I_ID, &ol_i_id);
#if !TPCC_SMALL
		r_ol->set_value(OL_SUPPLY_W_ID, &ol_supply_w_id);
		r_ol->set_value(OL_QUANTITY, &ol_quantity);
		r_ol->set_value(OL_AMOUNT, &ol_amount);
#endif		
		insert_row(r_ol, _wl->t_orderline);

	return RCOK;
}
Exemplo n.º 14
0
inline void insert_node(int x,int y)
{
 s[y]++;
 addnode(node);
 row[node]=x;
 col[node]=y;
 insert_col(y,node);
 if(head[x]==-1) head[x]=node;
 else
  insert_row(head[x],node);
}
Exemplo n.º 15
0
/// Builds the truth table.
void MainWindow::build_table(FunctionParser* const parser)
{
    if(!parser || !parser->size())
        return;

    insert_columns();

    const unsigned int size = 1 << parser->size();
    for(unsigned int row = 0; row < size; ++row)
        if(!insert_row(row, parser))
            return;
}
Exemplo n.º 16
0
inline RC TPCCTxnManager::new_order_5(uint64_t w_id, uint64_t d_id, uint64_t c_id, bool remote, uint64_t  ol_cnt,uint64_t  o_entry_d, uint64_t * o_id, row_t * r_dist_local) {
  assert(r_dist_local != NULL);
	//double d_tax;
	//int64_t o_id;
	//d_tax = *(double *) r_dist_local->get_value(D_TAX);
	*o_id = *(int64_t *) r_dist_local->get_value(D_NEXT_O_ID);
	(*o_id) ++;
	r_dist_local->set_value(D_NEXT_O_ID, *o_id);

	// return o_id
	/*========================================================================================+
	EXEC SQL INSERT INTO ORDERS (o_id, o_d_id, o_w_id, o_c_id, o_entry_d, o_ol_cnt, o_all_local)
		VALUES (:o_id, :d_id, :w_id, :c_id, :datetime, :o_ol_cnt, :o_all_local);
	+========================================================================================*/
	row_t * r_order;
	uint64_t row_id;
	_wl->t_order->get_new_row(r_order, wh_to_part(w_id), row_id);
	r_order->set_value(O_ID, *o_id);
	r_order->set_value(O_C_ID, c_id);
	r_order->set_value(O_D_ID, d_id);
	r_order->set_value(O_W_ID, w_id);
	r_order->set_value(O_ENTRY_D, o_entry_d);
	r_order->set_value(O_OL_CNT, ol_cnt);
	int64_t all_local = (remote? 0 : 1);
	r_order->set_value(O_ALL_LOCAL, all_local);
	insert_row(r_order, _wl->t_order);
	/*=======================================================+
    EXEC SQL INSERT INTO NEW_ORDER (no_o_id, no_d_id, no_w_id)
        VALUES (:o_id, :d_id, :w_id);
    +=======================================================*/
	row_t * r_no;
	_wl->t_neworder->get_new_row(r_no, wh_to_part(w_id), row_id);
	r_no->set_value(NO_O_ID, *o_id);
	r_no->set_value(NO_D_ID, d_id);
	r_no->set_value(NO_W_ID, w_id);
	insert_row(r_no, _wl->t_neworder);

	return RCOK;
}
Exemplo n.º 17
0
void dlx_init(int col)
{
 memset(head,-1,sizeof(head));
 memset(res,0,sizeof(res));
 memset(o,0,sizeof(o));
 memset(s,0,sizeof(s));
 int i;
 node=-1;
 addnode(node);
 for(i=1;i<=col;i++)
 {
        addnode(node);
        insert_row(0, node);  
 }
}
Exemplo n.º 18
0
//-----------------------------------------------------------------
FillableVec*
FillableMat::getRow(int row, bool create_if_not_already_present)
{
  feipoolmat::iterator iter = matdata_.lower_bound(row);

  if (iter == matdata_.end() || iter->first != row) {
    if (create_if_not_already_present == false) {
      throw std::runtime_error("fei::FillableMat: row not found.");
    }
    else {
      iter = insert_row(matdata_, iter, row, vecpool_);
    }
  }

  return iter->second;
}
Exemplo n.º 19
0
void main_listctrl::launch_dialog_for_new_channel( const wxString& new_channel_section )
{
    if ( new_channel_section.IsEmpty() ) 
    {
        wxLogError( "Error: can't open a channel dialog for an empty section." );
        return;
    }
    
    wxString channel_section = new_channel_section;
    
    // Show the configuration dialog, ready to edit the new channel.
    // Can't make them a child of this window (freezes) or parent (since an
    // XRC unknown container and says 2 things can't occupy it), so needs to be a 
    // child of the main_frame (probably could be grandparent, but this is more 
    // readable).
    channel_dialog a_channel_dialog( m_parent, channel_section );
    
    // Show modal, and if clicked OK, then refresh the row, which will repaint as required.
    if ( a_channel_dialog.ShowModal() == wxID_OK ) 
    {    
        // insert_row also adds it to our array
        insert_row( channel_section );
    } 
    else
    {
        // Cancel button on channel dialog was clicked
        wxLogDebug( "main_listctrl::launch_dialog_for_new_channel != wxID_OK so flushing..." );
     
        // If didn't return OK, then must have clicked cancel to close the channel dialog
        // Since canceled before finished adding the chennel, delete the channel. No
        // gui delete needed, since never inserted the row.            
        plucker_controller::get()->delete_channel( channel_section );       
        wxLogDebug( "...and plucker_controller::delete_channel was called..." );        
        
        // Then flush again to write the new configuration with the section now removed.
        the_configuration->Flush();                
        wxLogDebug( ".. and finally Flush()'ed the configuration to write the deletion" );
    }               
}
Exemplo n.º 20
0
inline RC TPCCTxnManager::run_payment_5(uint64_t w_id, uint64_t d_id,uint64_t c_id,uint64_t c_w_id, uint64_t c_d_id, char * c_last, double h_amount, bool by_last_name, row_t * r_cust_local) { 
  assert(r_cust_local != NULL);
	double c_balance;
	double c_ytd_payment;
	double c_payment_cnt;

	r_cust_local->get_value(C_BALANCE, c_balance);
	r_cust_local->set_value(C_BALANCE, c_balance - h_amount);
	r_cust_local->get_value(C_YTD_PAYMENT, c_ytd_payment);
	r_cust_local->set_value(C_YTD_PAYMENT, c_ytd_payment + h_amount);
	r_cust_local->get_value(C_PAYMENT_CNT, c_payment_cnt);
	r_cust_local->set_value(C_PAYMENT_CNT, c_payment_cnt + 1);

	//char * c_credit = r_cust_local->get_value(C_CREDIT);

	/*=============================================================================+
	  EXEC SQL INSERT INTO
	  history (h_c_d_id, h_c_w_id, h_c_id, h_d_id, h_w_id, h_date, h_amount, h_data)
	  VALUES (:c_d_id, :c_w_id, :c_id, :d_id, :w_id, :datetime, :h_amount, :h_data);
	  +=============================================================================*/
	row_t * r_hist;
	uint64_t row_id;
	// Which partition should we be inserting into?
	_wl->t_history->get_new_row(r_hist, wh_to_part(c_w_id), row_id);
	r_hist->set_value(H_C_ID, c_id);
	r_hist->set_value(H_C_D_ID, c_d_id);
	r_hist->set_value(H_C_W_ID, c_w_id);
	r_hist->set_value(H_D_ID, d_id);
	r_hist->set_value(H_W_ID, w_id);
	int64_t date = 2013;		
	r_hist->set_value(H_DATE, date);
	r_hist->set_value(H_AMOUNT, h_amount);
	insert_row(r_hist, _wl->t_history);

	return RCOK;
}
Exemplo n.º 21
0
void
test (char* type, int c_type)
{
  int i, n;
  HSTMT hstmt;
  SQLRETURN rc;

  printf ("=====================================================\n");
  printf ("%s -> %s\n", type,
	  c_type == SQL_C_BINARY ? "SQL_C_BINARY" :
	  c_type == SQL_C_CHAR ? "SQL_C_CHAR" :
	  c_type == SQL_C_WCHAR ? "SQL_C_WCHAR" : "???");

  if (strstr (type, "LONG") != NULL || strstr (type, "IMAGE") != NULL || strstr (type, "TEXT") != NULL)
    n = 16;
  else
    n = 12;

  create_table (type);
  for (i = 0; i < n; i++)
    insert_row (type, i);

  rc = SQLAllocHandle (SQL_HANDLE_STMT, (SQLHANDLE) hdbc, (SQLHANDLE *) &hstmt);
  if (rc != SQL_SUCCESS)
    {
    	err_printf ("SQLAllocHandle() failed.\n");
	return;
    }

  rc = SQLExecDirect (hstmt, "select id, data from tab", SQL_NTS);
  if (rc != SQL_SUCCESS)
    {
    	err_printf ("select failed.\n");
        error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
	exit (1);
    }

  for (;;)
    {
      char buffer[1024];
      long id;
      SQLLEN offset, full_length, length;

      rc = SQLFetch (hstmt);
      if (rc != SQL_SUCCESS)
	{
	  if (rc == SQL_NO_DATA)
	    break;
	  err_printf ("SQLFetch() failed.\n");
	  error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
	  exit (1);
	}

      rc = SQLGetData (hstmt, 1, SQL_C_LONG, &id, sizeof id,  &length);
      if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
	{
	  err_printf ("SQLGetData failed.\n");
	  error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
	  exit (1);
	}

      printf ("--- id: %ld, size: %ld\n", id, 1L << id);

      if (SQL_C_WCHAR == c_type)
	full_length = (1 << id) * sizeof (wchar_t);
      else
	full_length = (1 << id);

      offset = 0;
      for (;;)
	{
	  int size_in_buffer;

	  rc = SQLGetData (hstmt, 2, c_type, buffer, sizeof buffer, (void*) &length);
	  if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO)
	    {
	      if (rc == SQL_NO_DATA)
		break;
	      err_printf ("SQLGetData failed.\n");
	      error (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
	      exit (1);
	    }

	  if (offset + length != full_length)
	    {
	      err_printf ("offset: %ld\n", (long) offset);
	      err_printf ("length: %ld (should be %ld)\n", (long) length, (long) (full_length - offset));
	      err_printf ("***FAILED: SQLGetData() returned wrong length.\n");
	      exit (1);
	    }

	  if (SQL_C_WCHAR == c_type)
	    size_in_buffer = sizeof buffer - sizeof (wchar_t);
	  else if (SQL_C_CHAR == c_type)
	    size_in_buffer = sizeof buffer - sizeof (char);
	  else
	    size_in_buffer = sizeof buffer;
	  if (size_in_buffer > length)
	    size_in_buffer = length;

	  if ((size_in_buffer < length) != (rc == SQL_SUCCESS_WITH_INFO))
	    {
	      err_printf ("offset: %ld\n", (long) offset);
	      err_printf ("length: %ld\n", (long) length);
	      err_printf ("rc: %s (should be %s)\n",
		rc != SQL_SUCCESS ? "SQL_SUCCESS_WITH_INFO" : "SQL_SUCCESS",
		size_in_buffer < length ? "SQL_SUCCESS_WITH_INFO" : "SQL_SUCCESS");
	      err_printf ("***FAILED: SQLGetData() returned wrong return code.\n");
	      exit (1);
	    }

	  n = SQL_C_WCHAR == c_type ? size_in_buffer / sizeof (wchar_t) : size_in_buffer;
	  for (i = 0; i < n; i++)
	    {
	      int index = SQL_C_WCHAR == c_type ? offset / sizeof (wchar_t) + i : offset + i;
	      int exp_c = 32 + index % (127 - 32);
	      int act_c = SQL_C_WCHAR == c_type ? ((wchar_t*)buffer)[i] : buffer[i];
	      if (act_c != exp_c)
		{
		  err_printf ("buffer index: %d, data index: %d, data: %d ", i, index, act_c);
		  if (index < (1 << id))
		    err_printf ("(should be %d)\n", exp_c);
		  else
		    err_printf ("(should be no data)\n");
		  err_printf ("***FAILED: SQLGetData() returned wrong data.\n");
		  exit (1);
		}
	    }

	  offset += size_in_buffer;
	}
    }

  SQLFreeHandle (SQL_HANDLE_STMT, (SQLHANDLE) hstmt);
  err_printf ("PASSED: %s -> %s\n", type,
	  c_type == SQL_C_BINARY ? "SQL_C_BINARY" :
	  c_type == SQL_C_CHAR ? "SQL_C_CHAR" :
	  c_type == SQL_C_WCHAR ? "SQL_C_WCHAR" : "???");

}
Exemplo n.º 22
0
void test_cursor() {
  // Create a table named "Table".
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");

  // Insert rows.
  constexpr size_t NUM_ROWS = 1 << 16;
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    table->insert_row();
  }

  // Test a cursor with the default options.
  auto cursor = table->create_cursor();
  grnxx::Array<grnxx::Record> records;
  assert(cursor->read(0, &records) == 0);
  assert(records.is_empty());
  assert(cursor->read(NUM_ROWS / 2, &records) == (NUM_ROWS / 2));
  assert(records.size() == (NUM_ROWS / 2));
  assert(cursor->read_all(&records) == (NUM_ROWS / 2));
  assert(records.size() == NUM_ROWS);
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int exptected_row_id(i);
    assert(records[i].row_id.match(exptected_row_id));
    assert(records[i].score.raw() == 0.0);
  }
  records.clear();

  // Test a cursor that scans a table in reverse order.
  grnxx::CursorOptions cursor_options;
  cursor_options.order_type = GRNXX_REVERSE_ORDER;
  cursor = table->create_cursor(cursor_options);
  assert(cursor->read_all(&records) == NUM_ROWS);
  assert(records.size() == NUM_ROWS);
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int exptected_row_id(NUM_ROWS - i - 1);
    assert(records[i].row_id.match(exptected_row_id));
    assert(records[i].score.raw() == 0.0);
  }
  records.clear();

  // Remove 98.4375% rows.
  std::mt19937 rng;
  std::vector<grnxx::Int> row_ids;
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int row_id(i);
    if ((rng() % 64) != 0) {
      table->remove_row(row_id);
    } else {
      row_ids.push_back(row_id);
    }
  }

  // Test a cursor with the default options.
  cursor = table->create_cursor();
  assert(cursor->read_all(&records) == row_ids.size());
  for (size_t i = 0; i < row_ids.size(); ++i) {
    assert(records[i].row_id.match(row_ids[i]));
  }
  records.clear();

  // Test a cursor that scans a table in reverse order.
  cursor = table->create_cursor(cursor_options);
  assert(cursor->read_all(&records) == row_ids.size());
  for (size_t i = 0; i < row_ids.size(); ++i) {
    assert(records[i].row_id.match(row_ids[row_ids.size() - i - 1]));
  }
  records.clear();
}
Exemplo n.º 23
0
void test_contains_and_find_one() {
  constexpr size_t NUM_ROWS = 1 << 10;

  // Create a table and insert the first row.
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");
  auto column = table->create_column("Column", T::type());
  grnxx::Array<T> values;
  values.resize(NUM_ROWS);
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    generate_random_value(&values[i]);
    grnxx::Int row_id = table->insert_row();
    column->set(row_id, values[i]);
  }

  // Test all the values.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    assert(column->contains(values[i]));
    grnxx::Int row_id = column->find_one(values[i]);
    assert(!row_id.is_na());
    assert(values[i].match(values[row_id.raw()]));
  }

  // Test all the values with index if available.
  try {
    column->create_index("Index", GRNXX_TREE_INDEX);
    for (size_t i = 0; i < NUM_ROWS; ++i) {
      assert(column->contains(values[i]));
      grnxx::Int row_id = column->find_one(values[i]);
      assert(!row_id.is_na());
      assert(values[i].match(values[row_id.raw()]));
    }
    column->remove_index("Index");
  } catch (...) {
  }

  // Remove N/A values.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    if (values[i].is_na()) {
      table->remove_row(grnxx::Int(i));
    }
  }

  // Test all the values.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    if (!values[i].is_na()) {
      assert(column->contains(values[i]));
      grnxx::Int row_id = column->find_one(values[i]);
      assert(!row_id.is_na());
      assert(values[i].match(values[row_id.raw()]));
    }
  }
  assert(!column->contains(T::na()));
  assert(column->find_one(T::na()).is_na());

  // Test all the values with index if available.
  try {
    column->create_index("Index", GRNXX_TREE_INDEX);
    for (size_t i = 0; i < NUM_ROWS; ++i) {
      if (!values[i].is_na()) {
        assert(column->contains(values[i]));
        grnxx::Int row_id = column->find_one(values[i]);
        assert(!row_id.is_na());
        assert(values[i].match(values[row_id.raw()]));
      }
    }
    assert(!column->contains(T::na()));
    assert(column->find_one(T::na()).is_na());
    column->remove_index("Index");
  } catch (...) {
  }

  // Insert a trailing N/A value.
  table->insert_row_at(grnxx::Int(NUM_ROWS));
  assert(column->contains(T::na()));
  assert(column->find_one(T::na()).match(grnxx::Int(NUM_ROWS)));
  try {
    column->create_index("Index", GRNXX_TREE_INDEX);
    assert(column->contains(T::na()));
    assert(column->find_one(T::na()).match(grnxx::Int(NUM_ROWS)));
    column->remove_index("Index");
  } catch (...) {
  }

  // Remove non-N/A values.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    if (!values[i].is_na()) {
      table->remove_row(grnxx::Int(i));
    }
  }

  // Test all the values.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    if (!values[i].is_na()) {
      assert(!column->contains(values[i]));
      assert(column->find_one(values[i]).is_na());
    }
  }
  assert(column->contains(T::na()));
  assert(column->find_one(T::na()).match(grnxx::Int(NUM_ROWS)));

  // Test all the values with index if available.
  try {
    column->create_index("Index", GRNXX_TREE_INDEX);
    for (size_t i = 0; i < NUM_ROWS; ++i) {
      if (!values[i].is_na()) {
        assert(!column->contains(values[i]));
        assert(column->find_one(values[i]).is_na());
      }
    }
    assert(column->contains(T::na()));
    assert(column->find_one(T::na()).match(grnxx::Int(NUM_ROWS)));
    column->remove_index("Index");
  } catch (...) {
  }
}
Exemplo n.º 24
0
int insert_element2( RowNode_handle *pp_r,int pos_row,int pos_col,int val )
{
  RowNode_handle pRow = *pp_r, pRowFind;
  
  int result;
  
    /* dummy element node pointer to use in insert row calls */
  ElementNode_handle pColumns = 0;
  
    /* if matrix doesnt exist */
  if(!pRow && val != 0)
  {
      /* make a row */
    *pp_r = make_row(pos_row);
    
      /* insert an element where desired  */
    result =  insert_element(&(*pp_r)->elements, pos_col, val);
  
      /* remove any rows that have been zero'd out */
    ZeroRowRemover(pp_r);
    
      /* return reuslt of insertion */
    return result;
  }  
  
    /* iterate through the rows */
  while(pRow && pRow->pos != pos_row)
    pRow = pRow->next;
  
    /* insert element in row if found */
  if(pRow && pRow->pos == pos_row)
  {
      /* insert element */
    result = insert_element(&pRow->elements, pos_col, val);
    
      /* remove any rows zero'd out */
    ZeroRowRemover(pp_r);
    
      /* return result of insertion */
    return result;
  }
  else /* if row not found, insert it */
  {
      /* dont create row if val desired in non-existent row is 0 */
    if(val == 0)
      return 0;
    
      /* insert a row into this matrix */
    insert_row(pp_r, pos_row, pColumns);
    
      /* get pointer to row inserted */
    pRowFind = find_row(pp_r, pos_row);
    
      /* insert element in row requested */
    result =  insert_element(&pRowFind->elements, pos_col, val);
    
      /* remove any rows that have been zero'd out */
    ZeroRowRemover(pp_r);
    
      /* return result of insertion */
    return result;
  }
}
Exemplo n.º 25
0
void test_int_key() {
  // Create a table named "Table".
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");

  // Create a column named "Column".
  auto column = table->create_column("Column", GRNXX_INT);

  // Append three rows.
  grnxx::Int row_id = table->insert_row();
  column->set(row_id, grnxx::Int(1));
  row_id = table->insert_row();
  column->set(row_id, grnxx::Int(10));
  row_id = table->insert_row();
  column->set(row_id, grnxx::Int(100));

  // Set key column.
  table->set_key_column("Column");
  assert(table->key_column() == column);

  // Duplicate keys must be rejected.
  bool inserted = true;
  row_id = table->find_or_insert_row(grnxx::Int(1), &inserted);
  assert(row_id.match(grnxx::Int(0)));
  assert(!inserted);
  row_id = table->find_or_insert_row(grnxx::Int(10), &inserted);
  assert(row_id.match(grnxx::Int(1)));
  assert(!inserted);
  row_id = table->find_or_insert_row(grnxx::Int(100), &inserted);
  assert(row_id.match(grnxx::Int(2)));
  assert(!inserted);

  // Append new keys.
  grnxx::Datum datum;
  row_id = table->find_or_insert_row(grnxx::Int(2), &inserted);
  assert(inserted);
  column->get(row_id, &datum);
  assert(datum.as_int().raw() == 2);
  row_id = table->find_or_insert_row(grnxx::Int(20), &inserted);
  column->get(row_id, &datum);
  assert(datum.as_int().raw() == 20);
  row_id = table->find_or_insert_row(grnxx::Int(200), &inserted);
  column->get(row_id, &datum);
  assert(datum.as_int().raw() == 200);
  row_id = table->find_or_insert_row(grnxx::Int(200000), &inserted);
  column->get(row_id, &datum);
  assert(datum.as_int().raw() == 200000);
  row_id = table->find_or_insert_row(grnxx::Int(20000000000L), &inserted);
  column->get(row_id, &datum);
  assert(datum.as_int().raw() == 20000000000L);

  // Find rows by key.
  assert(table->find_row(grnxx::Int(1)).raw() == 0);
  assert(table->find_row(grnxx::Int(10)).raw() == 1);
  assert(table->find_row(grnxx::Int(100)).raw() == 2);
  assert(table->find_row(grnxx::Int(2)).raw() == 3);
  assert(table->find_row(grnxx::Int(20)).raw() == 4);
  assert(table->find_row(grnxx::Int(200)).raw() == 5);
  assert(table->find_row(grnxx::Int(200000)).raw() == 6);
  assert(table->find_row(grnxx::Int(20000000000L)).raw() == 7);
  assert(table->find_row(grnxx::Int::na()).is_na());

  // Unset key column.
  table->unset_key_column();
  assert(!table->key_column());

  // Test an N/A value.
  column->set(grnxx::Int(0), grnxx::Int::na());
  try {
    table->set_key_column("Column");
    assert(false);
  } catch (...) {
  }

  // Test a trailing N/A value.
  table->insert_row();
  try {
    table->set_key_column("Column");
    assert(false);
  } catch (...) {
  }
}
Exemplo n.º 26
0
void test_bitmap() {
  constexpr size_t NUM_ROWS = 1 << 16;

  // Create a table named "Table".
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");

  // Insert rows.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int expected_row_id(i);
    assert(table->insert_row().match(expected_row_id));
  }
  assert(table->num_rows() == NUM_ROWS);
  assert(table->max_row_id().raw() == (NUM_ROWS - 1));

  // Remove all rows.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int row_id(i);
    table->remove_row(row_id);
  }
  assert(table->num_rows() == 0);
  assert(table->max_row_id().is_na());

  // Insert rows again.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int exptected_row_id(i);
    assert(table->insert_row().match(exptected_row_id));
  }
  assert(table->num_rows() == NUM_ROWS);
  assert(table->max_row_id().raw() == (NUM_ROWS - 1));

  // Remove rows with even IDs.
  for (size_t i = 0; i < NUM_ROWS; i += 2) {
    grnxx::Int row_id(i);
    table->remove_row(row_id);
  }
  assert(table->num_rows() == (NUM_ROWS / 2));
  assert(table->max_row_id().raw() == (NUM_ROWS - 1));

  // Insert rows again.
  for (size_t i = 0; i < NUM_ROWS; i += 2) {
    grnxx::Int exptected_row_id(i);
    assert(table->insert_row().match(exptected_row_id));
  }
  assert(table->num_rows() == NUM_ROWS);
  assert(table->max_row_id().raw() == (NUM_ROWS - 1));

  // Remove rows in reverse order.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int row_id(NUM_ROWS - i - 1);
    assert(table->max_row_id().match(row_id));
    table->remove_row(row_id);
  }
  assert(table->max_row_id().is_na());

  // Insert rows again.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int exptected_row_id(i);
    assert(table->insert_row().match(exptected_row_id));
  }
  assert(table->num_rows() == NUM_ROWS);
  assert(table->max_row_id().raw() == (NUM_ROWS - 1));
}
Exemplo n.º 27
0
Arquivo: FED.C Projeto: MegaGod/TW
void pan_down( void ) {
	insert_row( 0 );
}
Exemplo n.º 28
0
Arquivo: FED.C Projeto: MegaGod/TW
void edit( int ch ) {
	struct viewporttype tmp;
	char key, *buff;

	take_char( ( char ) ch );
	backup_char( );
	getviewsettings( &tmp );
	setviewport( 400, 30, getmaxx( ), getmaxy( ), 1 );
	buff = ( char* ) malloc( imagesize( 0 + align, 0, X*( 2 + WIDTH_X ) + align, Y*( 2 + WIDTH_Y ) ) );
	getimage( 0 + align, 0, X*( 2 + WIDTH_X ) + align, Y*( 2 + WIDTH_Y ), buff );
	draw_char( );
	start_clock( EDIT_FONT );

	while ( ( key = get_pos( &pos_x, &pos_y, X - 1, Y - 1, 1, 1 ) ) != 3 ) {
		switch ( tolower( key ) ) {
		case 1:
			xor_dot( pos_x, pos_y );
			continue;

		case '8':
			pan_up( );
			draw_char( );
			break;

		case '2':
			pan_down( );
			draw_char( );
			break;

		case '4':
			pan_left( );
			draw_char( );
			break;

		case '6':
			pan_right( );
			draw_char( );
			break;

		case 'r':
			insert_row( pos_y );
			draw_char( );
			break;

		case 'c':
			insert_col( pos_x );
			draw_char( );
			break;

		case 'e':
			del_row( pos_y );
			draw_char( );
			break;

		case 'd':
			del_col( pos_x );
			draw_char( );
			break;

		case 'i':
			invert( );
			draw_char( );
			break;

		case 'm':
			mirror( );
			draw_char( );
			break;

		case '.':
			++draw_mode;
			switch ( draw_mode ) {
			case 0:
				break;
			case 1:
				put_dot( pos_x, pos_y );
				edit_font[pos_x][pos_y] = ~0;
				break;
			case 2:
				square( pos_x, pos_y );
				edit_font[pos_x][pos_y] = 0;
				break;
			case 3:
				draw_mode = 0;
			}
			continue;

		case 'u':
			undo( );
			draw_char( );
			goto exit;

		case '?':
			help( );
			break;

		default:
			if ( draw_mode == 1 ) {
				put_dot( pos_x, pos_y );
				edit_font[pos_x][pos_y] = ~0;
			}
			if ( draw_mode == 2 ) {
				square( pos_x, pos_y );
				edit_font[pos_x][pos_y] = 0;
			}

		}
	}
	update_char( ( char ) ch );
exit:
	putimage( 0 + align, 0, buff, COPY_PUT );
	free( buff );
	stop_clock( );
	dispblank( 50, 16, strlen( "Move mode" ), 0 );
	setviewport( tmp.left, tmp.top, tmp.right, tmp.bottom, tmp.clip );
	print_table( which_page( ch ) );
}
Exemplo n.º 29
0
void do_normalmode(struct block * buf) {
    int bs = get_bufsize(buf);
    struct ent * e;

    switch (buf->value) {

        // Movement commands
        case 'j':
        case OKEY_DOWN:
            currow = forw_row(1)->row;
            unselect_ranges();
            update(TRUE);
            break;

        case 'k':
        case OKEY_UP:
            currow = back_row(1)->row;
            unselect_ranges();
            update(TRUE);
            break;

        case 'h':
        case OKEY_LEFT:
            curcol = back_col(1)->col;
            unselect_ranges();
            update(TRUE);
            break;

        case 'l':
        case OKEY_RIGHT:
            curcol = forw_col(1)->col;
            unselect_ranges();
            update(TRUE);
            break;

        case '0':
        case OKEY_HOME:
            curcol = left_limit()->col;
            unselect_ranges();
            update(TRUE);
            break;

        case '$':
        case OKEY_END:
            curcol = right_limit()->col;
            unselect_ranges();
            update(TRUE);
            break;

        case '^':
            currow = goto_top()->row;
            unselect_ranges();
            update(TRUE);
            break;

        case '#':
            currow = goto_bottom()->row;
            unselect_ranges();
            update(TRUE);
            break;

        // Tick
        case '\'':
            if (bs != 2) break;
            unselect_ranges();
            e = tick(buf->pnext->value);
            if (row_hidden[e->row]) {
                scerror("Cell row is hidden");
                break;
            }
            if (col_hidden[e->col]) {
                scerror("Cell column is hidden");
                break;
            }
            currow = e->row;
            curcol = e->col;
            update(TRUE);
            break;

        // CTRL j
        case ctl('j'):
            {
            int p, c = curcol, cf = curcol;
            if ( (p = is_range_selected()) != -1) {
                struct srange * sr = get_range_by_pos(p);
                c = sr->tlcol;
                cf = sr->brcol;
            }
            auto_justify(c, cf, DEFWIDTH);  // auto justificado de columnas
            update(TRUE);
            break;
            }

        // CTRL d
        case ctl('d'):                      // set date format using current locate D_FMT format
            {
        #ifdef USELOCALE
            #include <locale.h>
            #include <langinfo.h>
            char * loc = NULL;
            char * f = NULL;
            loc = setlocale(LC_TIME, "");
            if (loc != NULL) {
                f = nl_langinfo(D_FMT);
            } else {
                scerror("No locale set. Nothing changed");
            }
            int p, r = currow, c = curcol, rf = currow, cf = curcol;
            if ( (p = is_range_selected()) != -1) {
                struct srange * sr = get_range_by_pos(p);
                r = sr->tlrow;
                c = sr->tlcol;
                rf = sr->brrow;
                cf = sr->brcol;
            }
            if (any_locked_cells(r, c, rf, cf)) {
                scerror("Locked cells encountered. Nothing changed");
                return;
            }
            dateformat(lookat(r, c), lookat(rf, cf), f);
            update(TRUE);
            break;
        #else
            scinfo("Build made without USELOCALE enabled");
        #endif
            }

        // CTRL f
        case ctl('f'):
        case OKEY_PGDOWN:
            {
            int n = LINES - RESROW - 1;
            if (atoi(get_conf_value("half_page_scroll"))) n = n / 2;
            struct ent * e = forw_row(n);
            currow = e->row;
            unselect_ranges();
            scroll_down(n);
            update(TRUE);
            break;
            }

        // CTRL b
        case ctl('b'):
        case OKEY_PGUP:
            {
            int n = LINES - RESROW - 1;
            if (atoi(get_conf_value("half_page_scroll"))) n = n / 2;
            currow = back_row(n)->row;
            unselect_ranges();
            scroll_up(n);
            update(TRUE);
            break;
            }

        case 'w':
            e = go_forward();
            currow = e->row;
            curcol = e->col;
            unselect_ranges();
            update(TRUE);
            break;

        case 'b':
            e = go_backward();
            currow = e->row;
            curcol = e->col;
            unselect_ranges();
            update(TRUE);
            break;

        case '/':
            {
            char cadena[] = ":int goto ";
            int i;
            for (i=0; i<strlen(cadena); i++) {
                flush_buf(buf);
                addto_buf(buf, cadena[i]);
                exec_single_cmd(buf);
            }
            break;
            }

        case 'H':
            currow = vert_top()->row;
            unselect_ranges();
            update(TRUE);
            break;

        case 'M':
            currow = vert_middle()->row;
            unselect_ranges();
            update(TRUE);
            break;

        case 'L':
            currow = vert_bottom()->row;
            unselect_ranges();
            update(TRUE);
            break;

        case 'G': // goto end
            e = go_end();
            currow = e->row;
            curcol = e->col;
            unselect_ranges();
            update(TRUE);
            break;

        // GOTO goto
        case ctl('a'):
            e = go_home();
            curcol = e->col;
            currow = e->row;
            unselect_ranges();
            update(TRUE);
            break;

        case 'g':
            if (buf->pnext->value == '0') {                               // g0
                curcol = go_bol()->col;

            } else if (buf->pnext->value == '$') {                        // g$
                curcol = go_eol()->col;

            } else if (buf->pnext->value == 'g') {                        // gg
                e = go_home();
                curcol = e->col;
                currow = e->row;

            } else if (buf->pnext->value == 'G') {                        // gG
                e = go_end();
                currow = e->row;
                curcol = e->col;

            } else if (buf->pnext->value == 'M') {                        // gM
                curcol = horiz_middle()->col;

            } else {                                                      // gA4 (goto cell)
                (void) sprintf(interp_line, "goto %s", parse_cell_name(1, buf));
                send_to_interp(interp_line);
            }
            unselect_ranges();
            update(TRUE);
            break;

        // repeat last command
        case '.':
            copybuffer(lastcmd_buffer, buf); // nose graba en lastcmd_buffer!!
            cmd_multiplier = 1;
            exec_mult(buf, COMPLETECMDTIMEOUT);
            break;

        // enter command mode
        case ':':
            clr_header(input_win, 0);
            chg_mode(':');
#ifdef HISTORY_FILE
            add(commandline_history, "");
#endif
            print_mode(input_win);
            wrefresh(input_win);
            handle_cursor();
            inputline_pos = 0;
            break;

        // enter visual mode
        case 'v':
            chg_mode('v');
            handle_cursor();
            clr_header(input_win, 0);
            print_mode(input_win);
            wrefresh(input_win);
            start_visualmode(currow, curcol, currow, curcol);
            break;

        // INPUT COMMANDS
        case '=':
        case '\\':
        case '<':
        case '>':
            if (locked_cell(currow, curcol)) return;
            insert_edit_submode = buf->value;
            chg_mode(insert_edit_submode);
            clr_header(input_win, 0);
            print_mode(input_win);
            wrefresh(input_win);
            inputline_pos = 0;
            break;

        // EDITION COMMANDS
        // edit cell (v)
        case 'e':
            if (locked_cell(currow, curcol)) return;
            clr_header(input_win, 0);
            inputline_pos = 0;
            if (start_edit_mode(buf, 'v')) show_header(input_win);
            break;

        // edit cell (s)
        case 'E':
            if (locked_cell(currow, curcol)) return;
            clr_header(input_win, 0);
            inputline_pos = 0;
            if (start_edit_mode(buf, 's')) show_header(input_win);
            else {
                scinfo("No string value to edit");
                chg_mode('.');
                show_celldetails(input_win);
                print_mode(input_win);
                wrefresh(input_win);
            }
            break;

        // del current cell or range
        case 'x':
            del_selected_cells();
            update(TRUE);
            break;

        // format col
        case 'f':
            if (bs != 2) return;
            formatcol(buf->pnext->value);
            break;

        // mark cell or range
        case 'm':
            if (bs != 2) break;
            int p = is_range_selected();
            if (p != -1) { // mark range
                struct srange * sr = get_range_by_pos(p);
                set_range_mark(buf->pnext->value, sr);
            } else         // mark cell 
                set_cell_mark(buf->pnext->value, currow, curcol);
            modflg++;
            break;

        // copy
        case 'c':
            {
            if (bs != 2) break;
            struct mark * m = get_mark(buf->pnext->value);
            if ( m == NULL) return;
            // if m represents a range
            if ( m->row == -1 && m->col == -1) {
                srange * r = m->rng;
                yank_area(r->tlrow, r->tlcol, r->brrow, r->brcol, 'a', cmd_multiplier);
                if (paste_yanked_ents(0, 'c') == -1) {
                    scerror("Locked cells encountered. Nothing changed");
                    break;
                }

            // if m represents just one cell
            } else {
                struct ent * p = *ATBL(tbl, get_mark(buf->pnext->value)->row, get_mark(buf->pnext->value)->col);
                struct ent * n;
                int c1;

#ifdef UNDO
                create_undo_action();
#endif
                for (c1 = curcol; cmd_multiplier-- && c1 < maxcols; c1++) {
                    if ((n = * ATBL(tbl, currow, c1))) {
                        if (n->flags & is_locked)
                            continue;
                        if (! p) {
                            clearent(n);
                            continue;
                        }
                    } else {
                        if (! p) break;
                        n = lookat(currow, c1);
                    }
#ifdef UNDO
                    copy_to_undostruct(currow, c1, currow, c1, 'd');
#endif
                    copyent(n, p, currow - get_mark(buf->pnext->value)->row, c1 - get_mark(buf->pnext->value)->col, 0, 0, maxrow, maxcol, 0);

                    n->row += currow - get_mark(buf->pnext->value)->row;
                    n->col += c1 - get_mark(buf->pnext->value)->col;

                    n->flags |= is_changed;
#ifdef UNDO
                    copy_to_undostruct(currow, c1, currow, c1, 'a');
#endif
                }
#ifdef UNDO
                end_undo_action();
#endif
            }

            if (atoi(get_conf_value("autocalc"))) EvalAll();
            update(TRUE);
            break;
            }

        // repeat last goto command
        case 'n':
            go_last();
            update(TRUE);
            break;

        // range lock / unlock / valueize
        case 'r':
            {
            int p, r = currow, c = curcol, rf = currow, cf = curcol;
            if ( (p = is_range_selected()) != -1) {
                struct srange * sr = get_range_by_pos(p);
                r = sr->tlrow;
                c = sr->tlcol;
                rf = sr->brrow;
                cf = sr->brcol;
            }
            if (buf->pnext->value == 'l') {
                lock_cells(lookat(r, c), lookat(rf, cf));
            } else if (buf->pnext->value == 'u') {
                unlock_cells(lookat(r, c), lookat(rf, cf));
            } else if (buf->pnext->value == 'v') {
                valueize_area(r, c, rf, cf);
            }
            update(TRUE);
            break;
            }

        // create range with two marks
        case 'R':
            if (bs == 3) {
                create_range(buf->pnext->value, buf->pnext->pnext->value, NULL, NULL);
                update(TRUE);
            }
            break;

        // Zr Zc - Zap col or row - Show col or row - Sr Sc
        case 'Z':
        case 'S':
            {
            int rs, r = currow, c = curcol, arg = cmd_multiplier;
            struct srange * sr;
            if ( (rs = is_range_selected()) != -1) {
                sr = get_range_by_pos(rs);
                cmd_multiplier = 1;
                r = sr->tlrow;
                c = sr->tlcol;
                arg = buf->pnext->value == 'r' ? sr->brrow - sr->tlrow + 1 : sr->brcol - sr->tlcol + 1;
            }
            if (buf->value == 'Z' && buf->pnext->value == 'r') {
                hide_row(r, arg);
            } else if (buf->value == 'Z' && buf->pnext->value == 'c') {
                hide_col(c, arg);
            } else if (buf->value == 'S' && buf->pnext->value == 'r') {
                show_row(r, arg);
            } else if (buf->value == 'S' && buf->pnext->value == 'c') {
                show_col(c, arg);
            }
            cmd_multiplier = 0;
            update(TRUE);
            break;
            }

        // shift range or cell
        case 's':
            {
            int p, r = currow, c = curcol, rf = currow, cf = curcol;
            if ( (p = is_range_selected()) != -1) {
                struct srange * sr = get_range_by_pos(p);
                r = sr->tlrow;
                c = sr->tlcol;
                rf = sr->brrow;
                cf = sr->brcol;
            }
            if ( any_locked_cells(r, c, rf, cf) && (buf->pnext->value == 'h' || buf->pnext->value == 'k') ) {
                scerror("Locked cells encountered. Nothing changed");
                return;
            }
#ifdef UNDO
            create_undo_action();
#endif
            int ic = cmd_multiplier + 1;
            switch (buf->pnext->value) {
                case 'j':
                    fix_marks(  (rf - r + 1) * cmd_multiplier, 0, r, maxrow, c, cf);
#ifdef UNDO
                    save_undo_range_shift(cmd_multiplier, 0, r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf);
#endif
                    while (ic--) shift_range(ic, 0, r, c, rf, cf);
                    break;
                case 'k':
                    fix_marks( -(rf - r + 1) * cmd_multiplier, 0, r, maxrow, c, cf);
                    yank_area(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf, 'a', cmd_multiplier); // keep ents in yanklist for sk
#ifdef UNDO
                    copy_to_undostruct(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf, 'd');
                    save_undo_range_shift(-cmd_multiplier, 0, r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf);
#endif
                    while (ic--) shift_range(-ic, 0, r, c, rf, cf);
#ifdef UNDO
                    copy_to_undostruct(r, c, rf + (rf-r+1) * (cmd_multiplier - 1), cf, 'a');
#endif
                    break;
                case 'h':
                    fix_marks(0, -(cf - c + 1) * cmd_multiplier, r, rf, c, maxcol);
                    yank_area(r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1), 'a', cmd_multiplier); // keep ents in yanklist for sk
#ifdef UNDO
                    copy_to_undostruct(r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1), 'd');
                    save_undo_range_shift(0, -cmd_multiplier, r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1));
#endif
                    while (ic--) shift_range(0, -ic, r, c, rf, cf);
#ifdef UNDO
                    copy_to_undostruct(r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1), 'a');
#endif
                    break;
                case 'l':
                    fix_marks(0,  (cf - c + 1) * cmd_multiplier, r, rf, c, maxcol);
#ifdef UNDO
                    save_undo_range_shift(0, cmd_multiplier, r, c, rf, cf + (cf-c+1) * (cmd_multiplier - 1));
#endif
                    while (ic--) shift_range(0, ic, r, c, rf, cf);
                    break;
            }
#ifdef UNDO
            end_undo_action();
#endif
            cmd_multiplier = 0;
            unselect_ranges();
            update(TRUE);
            break;
            }

        // delete row or column, or selected cell or range
        case 'd':
            {
            if (bs != 2) return;
            int ic = cmd_multiplier; // orig

            if (buf->pnext->value == 'r') {
                if (any_locked_cells(currow, 0, currow + cmd_multiplier, maxcol)) {
                    scerror("Locked cells encountered. Nothing changed");
                    return;
                }
#ifdef UNDO
                create_undo_action();
                copy_to_undostruct(currow, 0, currow + ic - 1, maxcol, 'd');
                save_undo_range_shift(-ic, 0, currow, 0, currow - 1 + ic, maxcol);
#endif
                fix_marks(-ic, 0, currow + ic - 1, maxrow, 0, maxcol);
                yank_area(currow, 0, currow - 1 + cmd_multiplier, maxcol, 'r', ic);
                while (ic--) deleterow();
#ifdef UNDO
                copy_to_undostruct(currow, 0, currow - 1 + cmd_multiplier, maxcol, 'a');
                end_undo_action();
#endif
                if (cmd_multiplier > 0) cmd_multiplier = 0;

            } else if (buf->pnext->value == 'c') {
                if (any_locked_cells(0, curcol, maxrow, curcol + cmd_multiplier)) {
                    scerror("Locked cells encountered. Nothing changed");
                    return;
                }
#ifdef UNDO
                create_undo_action();
                copy_to_undostruct(0, curcol, maxrow, curcol - 1 + ic, 'd');
                save_undo_range_shift(0, -ic, 0, curcol, maxrow, curcol - 1 + ic);
#endif
                fix_marks(0, -ic, 0, maxrow,  curcol - 1 + ic, maxcol);
                yank_area(0, curcol, maxrow, curcol + cmd_multiplier - 1, 'c', ic);
                while (ic--) deletecol();
#ifdef UNDO
                copy_to_undostruct(0, curcol, maxrow, curcol + cmd_multiplier - 1, 'a');
                end_undo_action();
#endif
                if (cmd_multiplier > 0) cmd_multiplier = 0;

            } else if (buf->pnext->value == 'd') {
                del_selected_cells(); 
            }
            update(TRUE);
            break;
            }

        // insert row or column
        case 'i':
            {
            if (bs != 2) return;
#ifdef UNDO
            create_undo_action();
#endif
            if (buf->pnext->value == 'r') {
#ifdef UNDO
                save_undo_range_shift(1, 0, currow, 0, currow, maxcol);
#endif
                fix_marks(1, 0, currow, maxrow, 0, maxcol);
                insert_row(0);

            } else if (buf->pnext->value == 'c') {
#ifdef UNDO
                save_undo_range_shift(0, 1, 0, curcol, maxrow, curcol);
#endif
                fix_marks(0, 1, 0, maxrow, curcol, maxcol);
                insert_col(0);
            }
#ifdef UNDO
            end_undo_action();
#endif
            update(TRUE);
            break;
            }

        case 'y':
            // yank row
            if ( bs == 2 && buf->pnext->value == 'r') {
                yank_area(currow, 0, currow + cmd_multiplier - 1, maxcol, 'r', cmd_multiplier);
                if (cmd_multiplier > 0) cmd_multiplier = 0;

            // yank col
            } else if ( bs == 2 && buf->pnext->value == 'c') {
                yank_area(0, curcol, maxrow, curcol + cmd_multiplier - 1, 'c', cmd_multiplier);
                if (cmd_multiplier > 0) cmd_multiplier = 0;

            // yank cell
            } else if ( bs == 2 && buf->pnext->value == 'y' && is_range_selected() == -1) {
                yank_area(currow, curcol, currow, curcol, 'e', cmd_multiplier);

            // yank range
            } else if ( bs == 1 && is_range_selected() != -1) {
                srange * r = get_selected_range();
                yank_area(r->tlrow, r->tlcol, r->brrow, r->brcol, 'a', cmd_multiplier);
            }
            break;

        // paste cell below or left
        case 'p':
            if (paste_yanked_ents(0, 'a') == -1) {
                scerror("Locked cells encountered. Nothing changed");
                break;
            }
            update(TRUE);
            break;

        case 'P':
        case 'T':
            if (bs != 2) break;
            if (buf->pnext->value == 'v' || buf->pnext->value == 'f' || buf->pnext->value == 'c') {
                int res = buf->value == 'P' ? paste_yanked_ents(0, buf->pnext->value) : paste_yanked_ents(1, buf->pnext->value); // paste cell above or right
                if (res == -1) {
                    scerror("Locked cells encountered. Nothing changed");
                    break;
                }
                update(TRUE);
            }
            break;

        // paste cell above or right
        case 't':
            if (paste_yanked_ents(1, 'a') == -1) {
                scerror("Locked cells encountered. Nothing changed");
                break;
            }
            update(TRUE);
            break;

        // select inner range - Vir
        case 'V':
            if (buf->value == 'V' && bs == 3 &&
            buf->pnext->value == 'i' && buf->pnext->pnext->value == 'r') {
                int tlrow = currow;
                int brrow = currow;
                int tlcol = curcol;
                int brcol = curcol;
                int * tlr = &tlrow;
                int * brr = &brrow;
                int * tlc = &tlcol;
                int * brc = &brcol;
                select_inner_range(tlr, tlc, brr, brc);
                start_visualmode(*tlr, *tlc, *brr, *brc);
            }
            break;

        // autojus
        case 'a':
            if ( bs != 2 ) break;

            if (buf->pnext->value == 'a') {
                int p, r = currow, c = curcol, rf = currow, cf = curcol;
                if ( (p = is_range_selected()) != -1) {
                    struct srange * sr = get_range_by_pos(p);
                    r = sr->tlrow;
                    c = sr->tlcol;
                    rf = sr->brrow;
                    cf = sr->brcol;
                }
                if (any_locked_cells(r, c, rf, cf)) {
                    scerror("Locked cells encountered. Nothing changed");
                    return;
                }
                char cline [BUFFERSIZE];
                sprintf(cline, "autojus %s:", coltoa(c));
                sprintf(cline + strlen(cline), "%s", coltoa(cf));
                send_to_interp(cline);
                update(TRUE);
            }
            break;

        // scroll
        case 'z':
            if ( bs != 2 ) break;
            int scroll = 0;

            switch (buf->pnext->value) {
                case 'l':
                    scroll_right(1);
                    //unselect_ranges();
                    break;

                case 'h':
                    scroll_left(1);
                    //unselect_ranges();
                    break;

                case 'H':
                    scroll = calc_offscr_sc_cols();
                    if (atoi(get_conf_value("half_page_scroll"))) scroll /= 2;
                    scroll_left(scroll);
                    //unselect_ranges();
                    break;

                case 'L':
                    scroll = calc_offscr_sc_cols();
                    if (atoi(get_conf_value("half_page_scroll"))) scroll /= 2;
                    scroll_right(scroll);
                    //unselect_ranges();
                    break;

                case 'm':
                    ;
                    int i = 0, c = 0, ancho = rescol;
                    offscr_sc_cols = 0;

                    for (i = 0; i < curcol; i++) {
                        for (c = i; c < curcol; c++) {
                            if (!col_hidden[c]) ancho += fwidth[c];
                            if (ancho >= (COLS - rescol)/ 2) {
                                ancho = rescol;
                                break;
                            } 
                        }
                        if (c == curcol) break;
                    }
                    offscr_sc_cols = i;
                    break;

                case 'z':
                case '.':
                case 't':
                case 'b':
                    if (buf->pnext->value == 'z' || buf->pnext->value == '.')
                        scroll = currow - offscr_sc_rows + LINES - RESROW - 2 - (LINES - RESROW - 2)/2; // zz
                    else if (buf->pnext->value == 't')
                        scroll = currow - offscr_sc_rows + 1;
                    else if (buf->pnext->value == 'b')
                        scroll = currow - offscr_sc_rows - LINES + RESROW + 2;

                    if (scroll > 0)
                        scroll_down(scroll);
//                    else if (scroll > offscr_sc_rows)
//                        scroll_up(-scroll);
                    else if (scroll < 0)
                        scroll_up(-scroll);
//                    else if (offscr_sc_rows > 0)
//                        scroll_up(offscr_sc_rows);
                    break;

            }
            update(TRUE);
            break;

        // scroll up a line
        case ctl('y'):
            scroll_up(1);
            update(TRUE);
            break;

        // scroll down a line
        case ctl('e'):
            scroll_down(1);
            update(TRUE);
            break;

        // undo
        case 'u':
            #ifdef UNDO
            do_undo();
            // sync_refs();
            EvalAll();
            update(TRUE);
            break;
            #else
            scerror("Build was done without UNDO support");
            #endif

        // redo
        case ctl('r'):
            #ifdef UNDO
            do_redo();
            // sync_refs();
            EvalAll();
            update(TRUE);
            break;
            #else
            scerror("Build was done without UNDO support");
            #endif

        case '{': // left align
        case '}': // right align
        case '|': // center align
            {
            int p, r = currow, c = curcol, rf = currow, cf = curcol;
            struct srange * sr;
            if ( (p = is_range_selected()) != -1) {
                sr = get_range_by_pos(p);
                r = sr->tlrow;
                c = sr->tlcol;
                rf = sr->brrow;
                cf = sr->brcol;
            }
            if (any_locked_cells(r, c, rf, cf)) {
                scerror("Locked cells encountered. Nothing changed");
                return;
            }
#ifdef UNDO
            create_undo_action();
#endif
            if (buf->value == '{')      sprintf(interp_line, "leftjustify %s", v_name(r, c));
            else if (buf->value == '}') sprintf(interp_line, "rightjustify %s", v_name(r, c));
            else if (buf->value == '|') sprintf(interp_line, "center %s", v_name(r, c));
            if (p != -1) sprintf(interp_line + strlen(interp_line), ":%s", v_name(rf, cf));
#ifdef UNDO
            copy_to_undostruct(r, c, rf, cf, 'd');
#endif
            send_to_interp(interp_line);
#ifdef UNDO
            copy_to_undostruct(r, c, rf, cf, 'a');
            end_undo_action();
#endif
            cmd_multiplier = 0;
            update(TRUE);
            break;
            }

        case ctl('l'):
            /*
            endwin();
            start_screen();
            clearok(stdscr, TRUE);
            update(TRUE);
            flushinp();
            show_header(input_win);
            show_celldetails(input_win);
            wrefresh(input_win);
            update(TRUE);
            */
            winchg();
            break;

        case '@':
            EvalAll();
            update(TRUE);
            break;

        // increase or decrease numeric value of cell or range
        case '-':
        case '+':
            {
            int r, c, tlrow = currow, tlcol = curcol, brrow = currow, brcol = curcol;
            if ( is_range_selected() != -1 ) {
                struct srange * sr = get_selected_range();
                tlrow = sr->tlrow;
                tlcol = sr->tlcol;
                brrow = sr->brrow;
                brcol = sr->brcol;
            }
            if (any_locked_cells(tlrow, tlcol, brrow, brcol)) {
                scerror("Locked cells encountered. Nothing changed");
                return;
            }
            if (atoi(get_conf_value("numeric")) == 1) goto numeric;
            struct ent * p;
#ifdef UNDO
            create_undo_action();
#endif
            int arg = cmd_multiplier;
            int mf = modflg; // keep original modflg
            for (r = tlrow; r <= brrow; r++) {
                for (c = tlcol; c <= brcol; c++) {
                    p = *ATBL(tbl, r, c);
                    if ( ! p )  {
                        continue;
                    } else if (p->expr && !(p->flags & is_strexpr)) {
                        //scerror("Can't increment / decrement a formula");
                        continue;
                    } else if (p->flags & is_valid) {
#ifdef UNDO
                        copy_to_undostruct(r, c, r, c, 'd');
#endif
                        p->v += buf->value == '+' ? (double) arg : - 1 * (double) arg;
#ifdef UNDO
                        copy_to_undostruct(r, c, r, c, 'a');
#endif
                        if (mf == modflg) modflg++; // increase just one time
                    }
                }
            }
#ifdef UNDO
            end_undo_action();
#endif
            if (atoi(get_conf_value("autocalc"))) EvalAll();
            cmd_multiplier = 0;
            update(TRUE);
            }
            break;

        // input of numbers
        default:
        numeric:
            if ( (isdigit(buf->value) || buf->value == '-' || buf->value == '+') &&
                atoi(get_conf_value("numeric")) ) {
                insert_edit_submode='=';
                chg_mode(insert_edit_submode);
                inputline_pos = 0;
                ins_in_line(buf->value);
                show_header(input_win);
            }
    }
    return;
}
Exemplo n.º 30
0
void test_internal_type_conversion() {
  // Create a table and insert rows.
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");
  table->insert_row();
  table->insert_row();
  table->insert_row();
  table->insert_row();

  auto column = table->create_column("Column", GRNXX_INT);

  // Set the first 8-bit integer.
  column->set(grnxx::Int(0), grnxx::Int(int64_t(1) << 0));
  grnxx::Datum datum;
  column->get(grnxx::Int(0), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 0));

  // Conversion from 8-bit to 16-bit.
  column->set(grnxx::Int(1), grnxx::Int(int64_t(1) << 8));
  column->get(grnxx::Int(0), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 0));
  column->get(grnxx::Int(1), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 8));

  // Conversion from 16-bit to 32-bit.
  column->set(grnxx::Int(2), grnxx::Int(int64_t(1) << 16));
  column->get(grnxx::Int(0), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 0));
  column->get(grnxx::Int(1), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 8));
  column->get(grnxx::Int(2), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 16));

  // Conversion from 32-bit to 64-bit.
  column->set(grnxx::Int(3), grnxx::Int(int64_t(1) << 32));
  column->get(grnxx::Int(0), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 0));
  column->get(grnxx::Int(1), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 8));
  column->get(grnxx::Int(2), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 16));
  column->get(grnxx::Int(3), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 32));

  table->remove_column("Column");
  column = table->create_column("Column", GRNXX_INT);

  // Conversion from 8-bit to 32-bit.
  column->set(grnxx::Int(0), grnxx::Int(int64_t(1) << 0));
  column->set(grnxx::Int(1), grnxx::Int(int64_t(1) << 16));
  column->get(grnxx::Int(0), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 0));
  column->get(grnxx::Int(1), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 16));

  table->remove_column("Column");
  column = table->create_column("Column", GRNXX_INT);

  // Conversion from 8-bit to 64-bit.
  column->set(grnxx::Int(0), grnxx::Int(int64_t(1) << 0));
  column->set(grnxx::Int(1), grnxx::Int(int64_t(1) << 32));
  column->get(grnxx::Int(0), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 0));
  column->get(grnxx::Int(1), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 32));

  table->remove_column("Column");
  column = table->create_column("Column", GRNXX_INT);

  // Conversion from 16-bit to 64-bit.
  column->set(grnxx::Int(0), grnxx::Int(int64_t(1) << 8));
  column->set(grnxx::Int(1), grnxx::Int(int64_t(1) << 32));
  column->get(grnxx::Int(0), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 8));
  column->get(grnxx::Int(1), &datum);
  assert(datum.as_int().raw() == (int64_t(1) << 32));
}