示例#1
0
//returns -1 if the given row/col doesn't exist.
int index_add_node(mnode_t **mnodes, size_t dim, size_t row, double val, bool is_margin){
    int index = find_val(val, mnodes[dim]);
    if (index == -1) return -1;
    if (is_margin) mnodes[dim][index].margin_ptrs[row] = true;
    else           mnodes[dim][index].fit_ptrs[row] = true;
    return 0;
}
示例#2
0
// найти аргумент
cli_result_t cli_parse ( cli_arg_t *Args, int argc, char** argv )
{
    cli_result_t Result = CLI_SUCCESS;
    // номер аргумента из полученного списка
    int i = 1;
    // кол-во необходимых аргументов
    size_t NeedArgAmount = get_need_arg_amount ( Args );
    while ( ( i < argc ) && ( Result == CLI_SUCCESS ) )
    {
        // найти аргумент
        cli_arg_t *Arg;
        
        switch ( get_argtype ( argv[ i ] ) )
        {
            case CLI_LONG_ARG:
                Arg = find_arg_by_longname ( Args, argv[ i ] + 2 );
                break;
            case CLI_SHORT_ARG:
                Arg = find_arg_by_shortname ( Args, argv[ i ][ 1 ] );
                break;
            default:
                Arg = NULL;
                Result = CLI_ERROR_ARGTYPE; // ошибка определения типа аргумента
                break;
        }
        
        if ( Arg != NULL )
        {
            // аргумент обязателен
            if ( Arg->ArgNeed == CLI_REQUIRED_ARG )
                NeedArgAmount--;
            
            // поиск значения аргумента
            const char *Val;
            if ( Arg->ValNeed != CLI_NO_VAL ) // обязателен или опционален
            {
                Val = find_val ( argv[ i ] );
                if ( Arg->ValNeed == CLI_REQUIRED_VAL && Val == NULL )
                {
                    Result = CLI_ERROR_NOVAL;
                }
                
                Result = ( Arg->Handler ( Arg->Var, Val ) == 0 ) ? CLI_SUCCESS : CLI_ERROR_HANDLER;
            }
            else
            {
                Val = NULL;
                Result = ( Arg->Handler ( Arg->Var, Val ) == 0 ) ? CLI_SUCCESS : CLI_ERROR_HANDLER;
            }
        }
        i++;
    }
    
    return ( !NeedArgAmount ) ? Result : CLI_ERROR_NEEDARG;
}
示例#3
0
/* Performs set/add/remove operations on options of set kind.  Returns not zero
 * if set was modified. */
static int
set_op(opt_t *opt, const char value[], SetOp op)
{
	char val[1024];
	const char *p;
	const int old_val = opt->val.set_items;
	int new_val = (op == SO_SET) ? 0 : old_val;

	while(*value != '\0')
	{
		int i;
		p = strchr(value, ',');
		if(p == NULL)
			p = value + strlen(value);

		snprintf(val, p - value + 1, "%s", value);

		i = find_val(opt, val);
		if(i != -1)
		{
			if(op == SO_SET || op == SO_ADD)
				new_val |= 1 << i;
			else
				new_val &= ~(1 << i);
		}

		if(*p == '\0')
			break;

		value = p + 1;
		while(*value == ',')
			++value;
	}

	opt->val.set_items = new_val;
	return new_val != old_val;
}
示例#4
0
文件: statsp.c 项目: chris-moreton/tb
void collect_stats_table(long64 *total_stats, ubyte *table, int wtm, int phase, int local, long64 *work)
{
  int i, j;
  int n;
  int sval;

  sval = (local == 0) ? 0 : stats_val[local - 1];

  for (i = 0; i < 256 * numthreads; i++)
    thread_stats[i] = 0;

  count_stats_table = table;
  run_threaded(count_stats, work, 0);

  if (local == 0)
    n = REDUCE_PLY - 2;
  else
    n = REDUCE_PLY_RED;
  if (phase == 1) n += 2;

#ifndef SUICIDE
  for (i = 0; i < numthreads; i++) {
    long64 *stats = thread_data[i].stats;
    if (local == 0) {
      total_stats[STAT_CAPT_WIN] += stats[CAPT_WIN];
      total_stats[STAT_CAPT_CWIN] += stats[CAPT_CWIN];
      total_stats[STAT_PAWN_WIN] += stats[PAWN_WIN];
      total_stats[STAT_PAWN_CWIN] += stats[PAWN_CWIN];
      total_stats[STAT_MATE] += stats[MATE];
      for (j = 0; j < DRAW_RULE; j++) {
	total_stats[1 + j] += stats[WIN_IN_ONE + j];
	total_stats[STAT_MATE - 1 - j] += stats[LOSS_IN_ONE - j];
      }
      for (; j < n; j++) {
	total_stats[1 + j] += stats[WIN_IN_ONE + j + 2];
	total_stats[STAT_MATE - 1 - j] += stats[LOSS_IN_ONE - j];
      }
      total_stats[STAT_MATE - 1 - j] += stats[LOSS_IN_ONE - j];
    } else {
      for (j = 0; j < n; j++) {
	total_stats[1 + sval + j] += stats[CAPT_CWIN_RED + j + 2];
	total_stats[STAT_MATE - 1 - sval - j - 1] += stats[LOSS_IN_ONE - j - 1];
      }
    }
  }
#else
  for (i = 0; i < numthreads; i++) {
    long64 *stats = thread_data[i].stats;
    if (local == 0) {
      total_stats[0] += stats[STALE_WIN];
      total_stats[1] += stats[STALE_WIN + 1];
      for (j = 2; j <= DRAW_RULE + 1; j++)
	total_stats[j] += stats[BASE_WIN + j];
      for (; j < REDUCE_PLY; j++)
	total_stats[j] += stats[BASE_WIN + j + 2];
      for (j = 0; j < REDUCE_PLY; j++)
	total_stats[STAT_MATE - j] += stats[BASE_LOSS - j];
      total_stats[STAT_CAPT_WIN] += stats[CAPT_WIN];
      total_stats[STAT_CAPT_CWIN] += stats[CAPT_CWIN];
      total_stats[STAT_CAPT_DRAW] += stats[CAPT_DRAW];
      total_stats[STAT_CAPT_LOSS] += stats[CAPT_LOSS];
      total_stats[STAT_CAPT_CLOSS] += stats[CAPT_CLOSS];
      total_stats[STAT_THREAT_WIN2] += stats[THREAT_WIN2];
      total_stats[STAT_THREAT_WIN1] += stats[THREAT_WIN1];
      total_stats[STAT_THREAT_CWIN2] += stats[THREAT_CWIN2];
      total_stats[STAT_THREAT_CWIN1] += stats[THREAT_CWIN1];
    } else {
      for (j = 0; j < n; j++) {
	total_stats[sval + j] += stats[BASE_CWIN_RED + 1 + j];
	total_stats[STAT_MATE - sval - j] += stats[BASE_CLOSS_RED -1 - j];
      }
    }
  }
#endif

  if (local == 0) {
    for (i = DRAW_RULE; i >= 0; i--)
      if (total_stats[i]) break;
    if (i >= 0) {
#ifndef SUICIDE
      j = WIN_IN_ONE + i - 1;
#else
      j = (i < 2) ? STALE_WIN + i : BASE_WIN + i;
#endif
      if (wtm) {
	if (i > lw_ply) {
	  lw_ply = i;
	  lw_clr = 1;
	  lw_idx = find_val(table, j, work);
	}
      } else {
	if (i > lb_ply) {
	  lb_ply = i;
	  lb_clr = 0;
	  lb_idx = find_val(table, j, work);
	}
      }
    }
    for (i = DRAW_RULE; i >= 0; i--)
      if (total_stats[STAT_MATE - i]) break;
    if (i >= 0) {
#ifndef SUICIDE
      j = MATE - i;
#else
      j = BASE_LOSS - i;
#endif
      if (wtm) {
	if (i > lb_ply) {
	  lb_ply = i;
	  lb_clr = 1;
	  lb_idx = find_val(table, j, work);
	}
      } else {
	if (i > lw_ply) {
	  lw_ply = i;
	  lw_clr = 0;
	  lw_idx = find_val(table, j, work);
	}
      }
    }
  }

  for (i = MAX_PLY; i > DRAW_RULE; i--)
    if (total_stats[i]) break;
  if (i > DRAW_RULE) {
#ifndef SUICIDE
    if (local == 0)
      j = WIN_IN_ONE + i + 1;
    else
      j = CAPT_CWIN_RED + 1 + i - sval;
#else
    if (local == 0)
      j = (i == DRAW_RULE + 1) ? BASE_WIN + i : BASE_WIN + i + 2;
    else
      j = BASE_CWIN_RED + i + 1 - sval;
#endif
    if (wtm) {
      if (i > lcw_ply) {
	lcw_ply = i;
	lcw_clr = 1;
	lcw_idx = find_val(table, j, work);
      }
    } else {
      if (i > lcb_ply) {
	lcb_ply = i;
	lcb_clr = 0;
	lcb_idx = find_val(table, j, work);
      }
    }
  }

  for (i = MAX_PLY; i > DRAW_RULE; i--)
    if (total_stats[STAT_MATE - i]) break;
  if (i > DRAW_RULE) {
#ifndef SUICIDE
    j = MATE - i + sval;
#else
    if (local == 0)
      j = BASE_LOSS - i;
    else
      j = BASE_CLOSS_RED - 1 - i + sval;
#endif
    if (wtm) {
      if (i > lcb_ply) {
	lcb_ply = i;
	lcb_clr = 1;
	lcb_idx = find_val(table, j, work);
      }
    } else {
      if (i > lcw_ply) {
	lcw_ply = i;
	lcw_clr = 0;
	lcw_idx = find_val(table, j, work);
      }
    }
  }

#ifndef SUICIDE
  if (phase == 1)
    for (i = 0; i < numthreads; i++) {
      total_stats[STAT_DRAW] += thread_data[i].stats[UNKNOWN];
      total_stats[STAT_DRAW] += thread_data[i].stats[PAWN_DRAW];
      total_stats[STAT_CAPT_DRAW] += thread_data[i].stats[CAPT_DRAW];
    }
#else
  if (phase == 1)
    for (i = 0; i < numthreads; i++) {
      total_stats[STAT_DRAW] += thread_data[i].stats[UNKNOWN];
      total_stats[STAT_DRAW] += thread_data[i].stats[PAWN_DRAW];
      total_stats[STAT_THREAT_DRAW] += thread_data[i].stats[THREAT_DRAW];
    }
#endif
}
示例#5
0
/* Assigns value to an option of all kinds except boolean.  Returns non-zero in
 * case of error. */
static int
set_set(opt_t *opt, const char value[])
{
	if(opt->type == OPT_BOOL)
		return -1;

	if(opt->type == OPT_SET)
	{
		if(set_op(opt, value, SO_SET))
		{
			notify_option_update(opt, OP_SET, opt->val);
		}
	}
	else if(opt->type == OPT_ENUM)
	{
		int i = find_val(opt, value);
		if(i == -1)
			return -1;

		if(opt->val.enum_item != i)
		{
			opt->val.enum_item = i;
			notify_option_update(opt, OP_SET, opt->val);
		}
	}
	else if(opt->type == OPT_STR || opt->type == OPT_STRLIST)
	{
		if(opt->val.str_val == NULL || strcmp(opt->val.str_val, value) != 0)
		{
			(void)replace_string(&opt->val.str_val, value);
			notify_option_update(opt, OP_SET, opt->val);
		}
	}
	else if(opt->type == OPT_INT)
	{
		char *end;
		int int_val = strtoll(value, &end, 10);
		if(opt->val.int_val != int_val)
		{
			opt->val.int_val = int_val;
			notify_option_update(opt, OP_SET, opt->val);
		}
	}
	else if(opt->type == OPT_CHARSET)
	{
		const size_t valid_len = strspn(value, *opt->vals);
		if(valid_len != strlen(value))
		{
			text_buffer_addf("Illegal character: <%c>", value[valid_len]);
			return -1;
		}
		if(charset_set(opt, value))
		{
			notify_option_update(opt, OP_SET, opt->val);
		}
	}
	else
	{
		assert(0 && "Unknown type of option.");
	}

	return 0;
}
示例#6
0
void index_add_node(mnode_t **mnodes, size_t dim, size_t row, double val){
    int index = find_val(val, mnodes[dim]);
    mnodes[dim][index].margin_ptrs[row] = 1;
}
示例#7
0
void do_editmode(struct block * sb) {

    if (sb->value == 'h' || sb->value == OKEY_LEFT) {  // LEFT
        inputline_pos = back_char();

    } else if (sb->value == 'l' || sb->value == OKEY_RIGHT) { // RIGHT
        inputline_pos = for_char();

    } else if (sb->value == 'x') {         // x
        del_back_char();

    } else if (sb->value == 'X') {         // X
        del_for_char();

    } else if (sb->value == ' ' && ( strlen(inputline) < (COLS - 14) ) ) {         // SPACE
        add_char(inputline, ' ', inputline_pos);

    } else if (sb->value == 'r') {         // r
        curs_set(1);
        int c = get_key();
        if (c != -1) inputline[inputline_pos] = c;
        curs_set(2);

    } else if (sb->value == 'R') {         // R
        curs_set(1);
        int c = get_key();
        while (c != OKEY_ENTER && c != -1) {
            if (isprint(c)) {
                inputline[inputline_pos] = c;
                ++inputline_pos;
                mvwprintw(input_win, 0, 1 + rescol, "%s", inputline);
                wmove(input_win, 0, inputline_pos + 1 + rescol);
                wrefresh(input_win);
            }
            c = get_key();
        }
        curs_set(2);

    } else if (sb->value == 'f') {         // f
        int c = get_key();
        if (c != -1) inputline_pos = look_for(c);

    } else if (sb->value == 'd' || sb->value == 'c') {         // d or c
        int c, d;
        if ( (c = get_key()) != -1 ) {
             switch (c) {
             case 'e':                     // de or ce
                 del_range_chars(inputline, inputline_pos, for_word(1, 0, 0));
                 break;

             case 'E':                     // dE or cE
                 del_range_chars(inputline, inputline_pos, for_word(1, 0, 1));
                 break;

             case 'w':                     // dw or cw
                 del_range_chars(inputline, inputline_pos, for_word(0, 1, 0) - 1);
                 if (inputline_pos == strlen(inputline) && inputline_pos) inputline_pos--;
                 break;

             case 'W':                     // dW or cW
                 del_range_chars(inputline, inputline_pos, for_word(0, 1, 1) - 1);
                 if (inputline_pos == strlen(inputline) && inputline_pos) inputline_pos--;
                 break;

             case 'b':                     // db or cb
                 d = back_word(0);
                 del_range_chars(inputline, d, inputline_pos-1);
                 inputline_pos = d;
                 break;

             case 'B':                     // dB or cB
                 d = back_word(1);
                 del_range_chars(inputline, d, inputline_pos-1);
                 inputline_pos = d;
                 break;

             case 'l':                     // dl or cl
             case OKEY_RIGHT:
                 del_back_char();
                 break;

             case 'h':                     // dh or ch
             case OKEY_LEFT:
                 del_for_char();
                 break;

             case 'a':
                 if ( (d = get_key()) == 'W' ) {     // daW or caW
                     c = ( inputline_pos && inputline[inputline_pos-1] == ' ' ) ? inputline_pos : back_word(1);
                     del_range_chars(inputline, c, for_word(0, 1, 1) - 1);
                     inputline_pos = (strlen(inputline) > inputline_pos) ? c : strlen(inputline)-2;
                 } else if ( d == 'w' ) { // daw or caw
                     d = ( inputline_pos && ! istext( inputline[inputline_pos-1]) ) ? inputline_pos : back_word(0);
                     del_range_chars(inputline, d, for_word(0, 1, 0) - 1);
                     inputline_pos = (strlen(inputline) > inputline_pos) ? d : strlen(inputline)-2;
                 }
                 break;
             }
             if (sb->value == 'c') chg_mode(insert_edit_submode);
        }

    } else if (find_val(sb, OKEY_ENTER)) { // ENTER
        insert_or_edit_cell(); 
        return;

    } else if (sb->value == '$') {         // $
        inputline_pos = strlen(inputline) - 1;

    } else if (sb->value == 'w') {         // w
        inputline_pos = for_word(0, 0, 0);

    } else if (sb->value == 'W') {         // W
        inputline_pos = for_word(0, 0, 1);

    } else if (sb->value == 'e') {         // e
        inputline_pos = for_word(1, 0, 0);

    } else if (sb->value == 'E') {         // E
        inputline_pos = for_word(1, 0, 1);

    } else if (sb->value == 'b') {         // b
        inputline_pos = back_word(0);

    } else if (sb->value == 'B') {         // B
        inputline_pos = back_word(1);

    } else if (sb->value == '0') {         // 0
        inputline_pos = 0;

    } else if (sb->value == 'a') {         // a
        inputline_pos++;
        chg_mode(insert_edit_submode);

    } else if (sb->value == 'i' ||  sb->value == '=') {         // i o =
        chg_mode(insert_edit_submode);

    } else if (sb->value == 's') {         // s
        if (inputline_pos <= strlen(inputline)) del_char(inputline, inputline_pos);
        chg_mode(insert_edit_submode);

    } else if (sb->value == 'A') {         // A
        inputline_pos = strlen(inputline);
        chg_mode(insert_edit_submode);

    } else if (sb->value == 'I') {         // I
        inputline_pos = 0;
        chg_mode(insert_edit_submode);

    } else if (sb->value == 'D') {         // D
        inputline_pos = 0;
        inputline[0] = '\0';
        chg_mode(insert_edit_submode);
    }

    show_header(input_win);
    return;
}