Exemple #1
0
Test(cntr_mt, read_wait)
{
	int i, j;
	pthread_t threads[NUM_EPS];
	const int msg_size = 128;
	struct tinfo info = { msg_size, 500 /* iters */};

	cr_assert(NUM_EPS*msg_size <= BUF_SZ);

	memset(source, 0, NUM_EPS*msg_size);
	for (i = 0; i < NUM_EPS; i++) {
		memset(&target[i*msg_size], get_mark(i), msg_size);
	}

	dbg_printf("creating threads\n");
	for (i = 1; i < NUM_EPS; i++) {
		pthread_create(&threads[i], NULL, do_thread_read_wait, &info);
	}

	dbg_printf("joining\n");

	for (i = 1; i < NUM_EPS; i++) {
		pthread_join(threads[i], NULL);
		for (j = 0; j < msg_size; j++) {
			cr_assert(source[i*msg_size+j] == get_mark(i));
		}
	}

	dbg_printf("done\n");

}
Exemple #2
0
Test(cntr_mt, write_wait)
{
	int i, j;
	pthread_t threads[NUM_EPS];
	const int msg_size = 128;
	struct tinfo info = { msg_size, 500 /* iters */};

	cr_assert(NUM_EPS*msg_size <= BUF_SZ);

	memset(target, 0, NUM_EPS*msg_size);
	for (i = 0; i < NUM_EPS; i++) {
		memset(&source[i*msg_size], get_mark(i), msg_size);
	}

	dbg_printf("creating threads\n");
	for (i = 1; i < NUM_EPS; i++) {
		pthread_create(&threads[i], NULL, do_thread_write_wait, &info);
	}

	dbg_printf("joining\n");

	for (i = 1; i < NUM_EPS; i++) {
		pthread_join(threads[i], NULL);
	}

	/* Must wait until all threads are done, since we don't know
	 * which thread got which id */
	for (i = 1; i < NUM_EPS; i++) {
		for (j = 0; j < msg_size; j++) {
			cr_assert(target[i*msg_size+j] == get_mark(i));
		}
	}

	dbg_printf("done\n");
}
Exemple #3
0
/* Writes marks to vifminfo file.  marks is a list of length nmarks marks read
 * from vifminfo. */
static void
write_marks(FILE *const fp, const char non_conflicting_marks[],
		char *marks[], const int timestamps[], int nmarks)
{
	int active_marks[NUM_MARKS];
	const int len = init_active_marks(valid_marks, active_marks);
	int i;

	fputs("\n# Marks:\n", fp);
	for(i = 0; i < len; ++i)
	{
		const int index = active_marks[i];
		const char m = index2mark(index);
		if(!is_spec_mark(index) && char_is_one_of(non_conflicting_marks, m))
		{
			const mark_t *const mark = get_mark(index);

			fprintf(fp, "%c%c\n", LINE_TYPE_MARK, m);
			fprintf(fp, "\t%s\n", mark->directory);
			fprintf(fp, "\t%s\n", mark->file);
			fprintf(fp, "%lld\n", (long long)mark->timestamp);
		}
	}
	for(i = 0; i < nmarks; i += 3)
	{
		fprintf(fp, "%c%c\n", LINE_TYPE_MARK, marks[i][0]);
		fprintf(fp, "\t%s\n", marks[i + 1]);
		fprintf(fp, "\t%s\n", marks[i + 2]);
		fprintf(fp, "%d\n", timestamps[i/3]);
	}
}
Exemple #4
0
void status_redraw()
{
struct view_rec *v;
struct mark_rec *m;
struct sheet *s;
//v= (struct view_rec *)Mem::vmem_trans (active_view);
//s= (struct sheet *)Mem::vmem_trans (active_sheet);

v = my_active_view;                      // mod 8-27-93
s = my_active_sheet;                     // mod 8-25-93
statw.clearwin(YELLOW, _RED,' ');
statw.put(0,62, "R       C");
status_name();
m= get_mark (v->cursor);
status_block (v->block_active==view_rec::bk_on ? v->block_mode : -1);
DBG_STATUS(dout<<"status redraw row = "<<(m->row)<<endl);
DBG_STATUS(dout<<"status redraw col = "<<(m->col)<<endl);
status_row (m->row);
status_col (m->col);
status_delta (s->changed);
status_insertmode (v->flags&1);
status_indentmode (v->flags&2);
status_numlockmode ();
                                                        /* other indicators */
statw.put(0, 43, "ESC=menus F1=Help");
                                                        /* update color */
statw.highlight(0,0,settings.colors[STATUS_COLORS][NORMAL_COLOR],statw.get_width());
//statw.show();
}
Exemple #5
0
void set_mark()

{

	int inval;

	if ((inval = get_mark()) == -1)
		return;

	Fil[optind].markers[inval] = (Opt.tpos) ?
	    Fil[optind].fpos + Fil[optind].sfpos : Fil[optind].fpos;
	Fil[optind].mark_flag = on;
	if (Ute.statline_flag == on)
		stl_clr(0);

}
Exemple #6
0
int
init_active_marks(const char marks[], int active_marks[])
{
	int i, x;

	i = 0;
	for(x = 0; x < NUM_MARKS; ++x)
	{
		if(!char_is_one_of(marks, index2mark(x)))
			continue;
		if(is_empty(get_mark(x)))
			continue;
		active_marks[i++] = x;
	}
	return i;
}
Exemple #7
0
void write_marks(register FILE *f) {
    int i;
    struct mark * m;

    for ( i='a'; i<='z'; i++ ) {
        m = get_mark((char) i);
    
        // m->rng should never be NULL if both m->col and m->row are -1 !!
        if ( m->row == -1 && m->col == -1) { // && m->rng != NULL ) {  
            fprintf(f, "mark %c %s%d ", i, coltoa(m->rng->tlcol), m->rng->tlrow);
            fprintf(f, "%s%d\n", coltoa(m->rng->brcol), m->rng->brrow);
        } else if ( m->row != 0 && m->row != 0) { // && m->rng == NULL) {
            fprintf(f, "mark %c %s%d\n", i, coltoa(m->col), m->row);
        }
    }

    return;
}
void AdaptiveRegularRefiner_MultiGrid::
get_parents_of_marked_closure_elements(std::vector<GridObject*>& parents,
									   Selector::status_t mark)
{
	UG_ASSERT(multi_grid(), "A multi grid has to be assigned to the refiner.");
	MultiGrid& mg = *multi_grid();

	typedef typename BaseClass::selector_t::template traits<TElem>::iterator	TIter;
	for(TIter iter = m_selMarkedElements.begin<TElem>();
		iter != m_selMarkedElements.end<TElem>(); ++iter)
	{
		TElem* e = *iter;
		if(!m_closureElems.is_selected(e))
			continue;

		if(get_mark(e) & mark){
			GridObject* parent = mg.get_parent(e);
			if(parent && !m_closureElems.is_selected(parent))
				parents.push_back(parent);
		}
	}
}
Exemple #9
0
void status_redraw()
{
struct view_rec *v;
struct mark_rec *m;
struct sheet *s;
//v= (struct view_rec *)Mem::vmem_trans (active_view);
//s= (struct sheet *)Mem::vmem_trans (active_sheet);

v = my_active_view;                      // mod 8-27-93
s = my_active_sheet;                     // mod 8-25-93
status_name();
m= get_mark (v->cursor);
status_block (v->block_active==view_rec::bk_on ? v->block_mode : -1);
DBG_STATUS(dout<<"status redraw row = "<<(m->row)<<endl);
DBG_STATUS(dout<<"status redraw col = "<<(m->col)<<endl);
status_quick_redraw(m->row, m->col, s->changed);
//statwptr[v->view_num]->put(0,75,(v->flags&1)?"I":"O");       // insert status
//status_numlockmode ();
                                                        /* other indicators */
//statwptr[v->view_num]->put(0, 43, "ESC=menus F1=Help");
                                                        /* update color */
statwptr[v->view_num]->highlight(0,0,settings.colors[STATUS_COLORS][NORMAL_COLOR],statwptr[v->view_num]->get_width());
//statwptr[v->view_num]->show();
}
Exemple #10
0
void maze()
{
     char start_dir, dir;
     int **maze_map;
     stack_node_t *top, *n;
     int r, c, tor, toc;
     int mark;


     maze_map = (int **)new_grid(map.num_row , map.num_col , sizeof(int));

     top = NULL;

     /* mark all cells as unmarked */
     for( r = 0; r < map.num_row; r++ )
          for( c = 0; c < map.num_col; c++ )
               maze_map[r][c] = UNMARKED;


     /* pick a random starting point */
     r = rand() % map.num_row;
     c = rand() % map.num_col;
printf("start: %d, %d\n", r, c);

     top = push_stack_node(top, r, c);

     while( top != NULL )
     {
          n = top;
          r = n->x;
          c = n->y;

          /* pick random direction that leads to an unmarked cell */
          mark = UNMARKED;
          dir = rand()%4;
          start_dir = dir;
          get_cell(&tor, &toc, r, c, dir);
          /* the -1 checks is to skip dirs that lead off the map */
          while( (tor == -1 || toc == -1) || maze_map[tor][toc] != UNMARKED )
          {
               dir++;
               if( dir >= 4 ) dir = 0;
               if( dir == start_dir )
               {
                    /* we've tried every dir so quit */
                    mark = DEAD_END;
                    break;
               }
               get_cell(&tor, &toc, r, c, dir);
          }

          /* if we can't go any where */
          if( mark == DEAD_END )
          {
               maze_map[r][c] |= DEAD_END;
               top = pop_stack_node(top, &n);
               free(n);
          }
          else
          {
               /* mark current cell as going that direction */
               mark = get_mark(dir);
               maze_map[r][c] |= mark;

               /* push new cell */
               top = push_stack_node(top, tor, toc);
          }

     } /* while stack not empty */



     /* draw the maze */
	for( r = 0; r < map.num_row; r++ )
	{
     	for( c = 0; c < map.num_col; c++ )
	     {
     	     /* if maze path went RIGHT then remove the right wall */
          	/* or if the cell to EAST went LEFT then remove the right wall */
               /* so if not A and not B then draw LEFT wall */
          	if( !(maze_map[r][c] & RIGHT)
               && !(c < map.num_col-1 && maze_map[r][c+1] & LEFT) )
               {
                    draw_right_wall(r, c);
               }


               if( !(maze_map[r][c] & DOWN)
               && !(r < map.num_row-1 && maze_map[r+1][c] & UP) )
               {
                    draw_lower_wall(r, c);
               }
	     }
	}

return;
}
Exemple #11
0
static uint64_t
__get_mark(arguments_t args, struct qbuff * buff)
{
	return (uint64_t)JUST(get_mark(buff));
}
Exemple #12
0
static LISP lget_mark(void)
{
	return MAKE_POSITION(get_mark(w_list));
}
Exemple #13
0
static bool
pred_has_mark(arguments_t args, SkBuff b)
{
	const uint32_t value = GET_ARG(uint32_t, args);
	return get_mark(b) == value;
}
static void*
par_alloc_from_fragment (SgenFragmentAllocator *allocator, SgenFragment *frag, size_t size)
{
	char *p = frag->fragment_next;
	char *end = p + size;

	if (end > frag->fragment_end)
		return NULL;

	/* p = frag->fragment_next must happen before */
	mono_memory_barrier ();

	if (InterlockedCompareExchangePointer ((volatile gpointer*)&frag->fragment_next, end, p) != p)
		return NULL;

	if (frag->fragment_end - end < SGEN_MAX_NURSERY_WASTE) {
		SgenFragment *next, **prev_ptr;
		
		/*
		 * Before we clean the remaining nursery, we must claim the remaining space
		 * as it could end up been used by the range allocator since it can end up
		 * allocating from this dying fragment as it doesn't respect SGEN_MAX_NURSERY_WASTE
		 * when doing second chance allocation.
		 */
		if ((sgen_get_nursery_clear_policy () == CLEAR_AT_TLAB_CREATION || sgen_get_nursery_clear_policy () == CLEAR_AT_TLAB_CREATION_DEBUG) && claim_remaining_size (frag, end)) {
			sgen_clear_range (end, frag->fragment_end);
			HEAVY_STAT (stat_wasted_bytes_trailer += frag->fragment_end - end);
#ifdef NALLOC_DEBUG
			add_alloc_record (end, frag->fragment_end - end, BLOCK_ZEROING);
#endif
		}

		prev_ptr = find_previous_pointer_fragment (allocator, frag);

		/*Use Michaels linked list remove*/

		/*prev_ptr will be null if the fragment was removed concurrently */
		while (prev_ptr) {
			next = frag->next;

			/*already deleted*/
			if (!get_mark (next)) {
				/*frag->next read must happen before the first CAS*/
				mono_memory_write_barrier ();

				/*Fail if the next node is removed concurrently and its CAS wins */
				if (InterlockedCompareExchangePointer ((volatile gpointer*)&frag->next, mask (next, 1), next) != next) {
					continue;
				}
			}

			/* The second CAS must happen after the first CAS or frag->next. */
			mono_memory_write_barrier ();

			/* Fail if the previous node was deleted and its CAS wins */
			if (InterlockedCompareExchangePointer ((volatile gpointer*)prev_ptr, unmask (next), frag) != frag) {
				prev_ptr = find_previous_pointer_fragment (allocator, frag);
				continue;
			}
			break;
		}
	}

	return p;
}
Exemple #15
0
static uint64_t
__get_mark(arguments_t args, SkBuff b)
{
	return JUST(get_mark(b));
}
Exemple #16
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;
}
Exemple #17
0
static void*
alloc_from_fragment (Fragment *frag, size_t size)
{
	char *p = frag->fragment_next;
	char *end = p + size;

	if (end > frag->fragment_end)
		return NULL;

	/* p = frag->fragment_next must happen before */
	mono_memory_barrier ();

	if (InterlockedCompareExchangePointer ((volatile gpointer*)&frag->fragment_next, end, p) != p)
		return NULL;

	if (frag->fragment_end - end < SGEN_MAX_NURSERY_WASTE) {
		Fragment *next, **prev_ptr;
		
		/*
		 * Before we clean the remaining nursery, we must claim the remaining space
		 * as it could end up been used by the range allocator since it can end up
		 * allocating from this dying fragment as it doesn't respect SGEN_MAX_NURSERY_WASTE
		 * when doing second chance allocation.
		 */
		if (mono_sgen_get_nursery_clear_policy () == CLEAR_AT_TLAB_CREATION && claim_remaining_size (frag, end)) {
			/* Clear the remaining space, pinning depends on this. FIXME move this to use phony arrays */
			memset (end, 0, frag->fragment_end - end);
			HEAVY_STAT (InterlockedExchangeAdd (&stat_wasted_bytes_trailer, frag->fragment_end - end));
#ifdef NALLOC_DEBUG
			add_alloc_record (end, frag->fragment_end - end, BLOCK_ZEROING);
#endif
		}

		prev_ptr = find_previous_pointer_fragment (frag);

		/*Use Michaels linked list remove*/

		/*prev_ptr will be null is the fragment was removed concurrently */
		while (prev_ptr) {
			next = frag->next;

			/*already deleted*/
			if (!get_mark (next)) {
				/*frag->next read must happen before the first CAS*/
				mono_memory_write_barrier ();

				/*Fail if the next done is removed concurrently and its CAS wins */
				if (InterlockedCompareExchangePointer ((volatile gpointer*)&frag->next, mask (next, 1), next) != next) {
					continue;
				}
			}

			/* The second CAS must happen after the first CAS or frag->next. */
			mono_memory_write_barrier ();

			/* Fail if the previous node was deleted and its CAS wins */
			if (InterlockedCompareExchangePointer ((volatile gpointer*)prev_ptr, next, frag) != frag) {
				prev_ptr = find_previous_pointer_fragment (frag);
				continue;
			}

			/* No need to membar here since the worst that can happen is a CAS failure. */
			do {
				frag->next_free = fragment_freelist;
			} while (InterlockedCompareExchangePointer ((volatile gpointer*)&fragment_freelist, frag, frag->next_free) != frag->next_free);

			break;
		}
	}

	return p;
}