예제 #1
0
int main(){
    List list;
    List list2;
    int i;
    
    init_list( &list );
    printf( "Empty: %d\n", empty_list( list ) );
    for( i = 1; i <= 5; i++ ){
        append_node( &i, sizeof( int ), list );
        printf( "Length: %d | ", length( list ) );
        print_list( list );
    }
    for( i = 6; i <= 10; i++ ){
        insert_front( &i, sizeof( int ), list );
        printf( "Length: %d | ", length( list ) );
        print_list( list );
    }
    printf( "Empty: %d\n", empty_list( list ) );
    printf( "First: %d\n", get_int( list_op_first( list ) -> data ) );
    printf( "Last:  %d\n", get_int( list_op_last( list ) -> data ) );
    printf( "Second to last: %d\n", get_int( list_op_prev( list_op_last( list ), list ) -> data ) );
    printf( "Second element: %d\n", get_int( get_elem_at( 1, list ) -> data ) );
    
    place_after( &i, sizeof( int ), get_elem_at( 1, list ), list );
    print_list( list );
    i++;
    insert_at( &i, sizeof( int ), 2, list );
    print_list( list );
    i++;
    insert_at( &i, sizeof( int ), 0, list );
    print_list( list );
    
    init_list( &list2 );
    for( i = 100; i > 95; i-- ){
        insert_front( &i, sizeof( int ), list2 );
    }
    append_list( list, &list2 );
    free( list2 );
    print_list( list );
    
    printf( "Erasing 5th element...\n" );
    erase_at( 4, list );
    print_list( list );
    printf( "Erasing 1st element...\n" );
    erase_at( 0, list );
    print_list( list );
    printf( "Erasing last element...\n" );
    erase_node( list_op_last( list ), list );
    print_list( list );
    printf( "Erasing 3rd element...\n" );
    erase_node( get_elem_at( 2, list ), list );
    print_list( list );
    
    clear_list( &list );
    
    return 0;
}
예제 #2
0
static void do_backspace(struct hexedit *buf)
{
	size_t off;
	bool do_erase = true;

	if (buf->cursor_offset == 0) {
		return;
	}

	off = buf->cursor_offset;
	if (buf->cursor_x == ASCII_COL) {
		cursor_up(buf);
		buf->cursor_line_offset = 7;
		buf->cursor_x = ASCII_COL_END - 1;
		calc_cursor_offset(buf);
	} else if (buf->cursor_x == HEX_COL1) {
		cursor_up(buf);
		buf->cursor_line_offset = 7;
		buf->cursor_x = HEX_COL2_END - 1;
		buf->nibble = 1;
		calc_cursor_offset(buf);
	} else {
		if (buf->cursor_x < ASCII_COL && buf->nibble) {
			do_erase = false;
		}
		cursor_left(buf);
	}
	if (do_erase) {
		erase_at(buf, off - 1);
	}
}
예제 #3
0
void behavior_stack::pop_async_back() {
    if (m_elements.empty()) { } // nothing to do
    else if (!m_elements.back().second.valid()) erase_at(m_elements.end() - 1);
    else rerase_if([](const element_type& e) {
        return e.second.valid() == false;
    });
}
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
clear()
{
  for (size_type i = 0; i < m_size; ++i)
    erase_at(m_a_entries, i, s_no_throw_copies_ind);

  __try
    {
      const size_type actual_size = resize_policy::get_new_size_for_arbitrary(0);

      entry_pointer a_entries = s_entry_allocator.allocate(actual_size);

      resize_policy::notify_arbitrary(actual_size);

      s_entry_allocator.deallocate(m_a_entries, m_actual_size);

      m_actual_size = actual_size;

      m_a_entries = a_entries;
    }
  __catch(...)
    { }

  m_size = 0;

  _GLIBCXX_DEBUG_ONLY(assert_valid();)
}
  __catch(...)
    {
      for (size_type i = 0; i < m_size; ++i)
	erase_at(m_a_entries, i, s_no_throw_copies_ind);

      s_entry_allocator.deallocate(m_a_entries, m_actual_size);
      __throw_exception_again;
    }
예제 #6
0
/* erase to the end of the line */
static void
ntconio_eeol(void)
{
    COORD coordCursor;
    int length;

    scflush();
    length = csbi.dwMaximumWindowSize.X - ccol;
    coordCursor.X = (SHORT) ccol;
    coordCursor.Y = (SHORT) crow;
    TRACE2(("ntconio_eeol [%d,%d] erase %d with %04x\n", crow, ccol, length, currentAttribute));
    erase_at(coordCursor, length);
}
예제 #7
0
static void
ntconio_eeop(void)
{
    DWORD cnt;
    COORD coordCursor;

    scflush();
    coordCursor.X = (SHORT) ccol;
    coordCursor.Y = (SHORT) crow;
    cnt = csbi.dwMaximumWindowSize.X - ccol
	+ (csbi.dwMaximumWindowSize.Y - crow - 1)
	* csbi.dwMaximumWindowSize.X;
    TRACE2(("ntconio_eeop [%d,%d] erase %d with %04x\n", crow, ccol, cnt, currentAttribute));
    erase_at(coordCursor, cnt);
}
예제 #8
0
PB_DS_CLASS_T_DEC
inline void
PB_DS_CLASS_C_DEC::
pop()
{
  PB_DS_ASSERT_VALID((*this))
  _GLIBCXX_DEBUG_ASSERT(!empty());

  pop_heap();
  erase_at(m_a_entries, m_size - 1, s_no_throw_copies_ind);
  resize_for_erase_if_needed();
  _GLIBCXX_DEBUG_ASSERT(m_size > 0);
  --m_size;

  PB_DS_ASSERT_VALID((*this))
}
예제 #9
0
PB_DS_CLASS_T_DEC
void
PB_DS_CLASS_C_DEC::
clear()
{
  for (size_type i = 0; i < m_size; ++i)
    erase_at(m_a_entries, i, s_no_throw_copies_ind);

  __try
    {
      const size_type new_size = resize_policy::get_new_size_for_arbitrary(0);
      entry_pointer new_entries = s_entry_allocator.allocate(new_size);
      resize_policy::notify_arbitrary(new_size);
      s_entry_allocator.deallocate(m_a_entries, m_actual_size);
      m_actual_size = new_size;
      m_a_entries = new_entries;
    }
  __catch(...)
    { }

  m_size = 0;
  PB_DS_ASSERT_VALID((*this))
}
예제 #10
0
/* move howmany lines starting at from to to */
static void
ntconio_scroll(int from, int to, int n)
{
    SMALL_RECT sRect;
    COORD dest;
    CHAR_INFO fill;
    int scroll_pause;

    scflush();
    if (to == from)
	return;
#if OPT_PRETTIER_SCROLL
    if (ABS(from - to) > 1) {
	ntconio_scroll(from, (from < to) ? to - 1 : to + 1, n);
	if (from < to)
	    from = to - 1;
	else
	    from = to + 1;
    }
#endif
#ifdef UNICODE
    fill.Char.UnicodeChar = ' ';
#else
    fill.Char.AsciiChar = ' ';
#endif
    fill.Attributes = currentAttribute;

    sRect.Left = 0;
    sRect.Top = (SHORT) from;
    sRect.Right = (SHORT) (csbi.dwMaximumWindowSize.X - 1);
    sRect.Bottom = (SHORT) (from + n - 1);

    dest.X = 0;
    dest.Y = (SHORT) to;

    ScrollConsoleScreenBuffer(hConsoleOutput, &sRect, NULL, dest, &fill);
    if ((scroll_pause = global_g_val(GVAL_SCROLLPAUSE)) > 0) {
	/*
	 * If the user has cheap video HW (1 MB or less) and
	 * there's a busy background app (say, dev studio), then
	 * the console version of vile can exhibit serious repaint
	 * problems when the display is rapidly scrolled.  By
	 * inserting a user-defined sleep after the scroll, the
	 * video HW has a chance to properly paint before the
	 * next scroll operation.
	 */

	Sleep(scroll_pause);
    }
#if !OPT_PRETTIER_SCROLL
    if (ABS(from - to) > n) {
	DWORD cnt;
	COORD coordCursor;

	coordCursor.X = 0;
	if (to > from) {
	    coordCursor.Y = (SHORT) (from + n);
	    cnt = to - from - n;
	} else {
	    coordCursor.Y = (SHORT) (to + n);
	    cnt = from - to - n;
	}
	cnt *= csbi.dwMaximumWindowSize.X;
	erase_at(coordCursor, cnt);
    }
#endif
}
예제 #11
0
static void do_delete(struct hexedit *buf)
{
	erase_at(buf, buf->cursor_offset);
}
예제 #12
0
 inline void erase_if(UnaryPredicate p) {
     erase_at(std::find_if(m_elements.begin(), m_elements.end(), p));
 }
예제 #13
0
 inline void rerase_at(std::vector<element_type>::reverse_iterator i) {
     // base iterator points to the element *after* the correct element
     if (i != m_elements.rend()) erase_at(i.base() - 1);
 }