Example #1
0
mack::options::selection_option::selection_option(
    std::string const& short_flag,
    std::string const& long_flag,
    std::string const& brief_description,
    std::string const& detailed_description,
    std::vector<std::string> const& selection_values,
    std::string const& default_value,
    std::string const& start_value)
  : mack::options::option(
      short_flag,
      long_flag,
      brief_description,
      detailed_description,
      default_value,
      start_value),
    _selection_values(selection_values)
{
  if (_selection_values.empty())
  {
    BOOST_THROW_EXCEPTION(no_selection_error()
        << errinfo_option_flag(long_flag));
  }
  if (!is_valid_value(default_value))
  {
    BOOST_THROW_EXCEPTION(invalid_value_error()
        << errinfo_option_flag(get_long_flag())
        << errinfo_option_value(default_value));
  }
  else if (!is_valid_value(start_value))
  {
    BOOST_THROW_EXCEPTION(invalid_value_error()
        << errinfo_option_flag(get_long_flag())
        << errinfo_option_value(start_value));
  }
}
Example #2
0
static int update_buffer(const char *buf, struct pru_data *pru)
{
	uint32_t *prumem = (uint32_t *) pru->prumem;
	int digit = 0;
	int period = 0;
	int val;
	int i;

	/*
	 * Cycle right to left from input string
	 */
	for (i = strlen(buf); i >= 0; i--) {
		char chr = buf[i];

		/*
		 * DP are part of digits
		 */
		if (chr == '.') {
			period = 1;
			continue;
		}

		val = is_valid_value(chr);
		if (val < 0)
			continue;

		val = char_to_segment(digit, val, period);
		if (val < 0)
			continue;

		prumem[digit] = val;
		period = 0;
		digit++;
	}

	if (period) {
		val = is_valid_value('.');
		if (val < 0)
			goto leave;
		val = char_to_segment(digit, val, 0);
		prumem[digit] = val;
	}
	memset((uint32_t *) prumem + digit, 0, sizeof(uint32_t) * (NUM_DIGITS - digit));

leave:
#ifdef DEBUG
	print_buffer(pru);
#endif
	return 0;
}
Example #3
0
etcd_response etcd_test_and_set(const char *key, const char *value, const char *oldValue, unsigned ttl) {
    char *url, *data, *tmpdata;
    const struct etcd_data *retdata;
    etcd_response response;
    int ret;

    if (!is_valid_key(key) || !is_valid_value(value)) {
        return ETCD_FAILURE;
    }

    if (!is_valid_value(oldValue)) {
        /* If the old value is NULL, then this should act like etcd_set() */
        if (oldValue == NULL) {
            return etcd_set(key, value, ttl);
        }
        return ETCD_FAILURE;
    }

    url = etcd_url(key, NULL);
    ret = asprintf(&data, "value=%s&prevValue=%s", value, oldValue);
    assert(ret >= 0);

    if (ttl > 0) {
        ret = asprintf(&tmpdata, "%s&ttl=%u", data, ttl);
        assert(ret >= 0);

        free(data);
        data = tmpdata;
    }

    retdata = http_request(url, ETCD_SET, data);
    assert(retdata != NULL);

    response = retdata->response;

    if (response == ETCD_FAILURE) {
        debug(retdata->errmsg);
    }

    free(url);
    free(data);
    free((struct etcd_data *)retdata);
    return response;
}
Example #4
0
static int setvar(const char *varname, const char *val)
{
	dummy_info_t *item;

	upsdebugx(2, "entering setvar(%s, %s)", varname, val);

	/* FIXME: the below is only valid if (mode == MODE_DUMMY)
	 * if (mode == MODE_REPEATER) => forward
	 * if (mode == MODE_META) => ?
	 */
	if (!strncmp(varname, "ups.status", 10))
	{
		status_init();
		 /* FIXME: split and check values (support multiple values), à la usbhid-ups */
		status_set(val);
		status_commit();

		return STAT_SET_HANDLED;
	}

	/* Check variable validity */
	if (!is_valid_data(varname))
	{
		upsdebugx(2, "setvar: invalid variable name (%s)", varname);
		return STAT_SET_UNKNOWN;
	}

	/* Check value validity */
	if (!is_valid_value(varname, val))
	{
		upsdebugx(2, "setvar: invalid value (%s) for variable (%s)", val, varname);
		return STAT_SET_UNKNOWN;
	}

	/* If value is empty, remove the variable (FIXME: do we need
	 * a magic word?) */
	if (strlen(val) == 0)
	{
		dstate_delinfo(varname);
	}
	else
	{
		dstate_setinfo(varname, "%s", val);

		if ( (item = find_info(varname)) != NULL)
		{
			dstate_setflags(item->info_type, item->info_flags);

			/* Set max length for strings, if needed */
			if (item->info_flags & ST_FLAG_STRING)
				dstate_setaux(item->info_type, item->info_len);
		}
	}
	return STAT_SET_HANDLED;
}
Example #5
0
 void domain_update_value_operation::evaluate( transaction_evaluation_state& eval_state )
 {
     auto odomain_rec = eval_state._current_state->get_domain_record( this->domain_name );
     auto now = eval_state._current_state->now().sec_since_epoch();
     FC_ASSERT( odomain_rec.valid(), "Trying to update domain which does not exist" );
     FC_ASSERT( odomain_rec->get_true_state(now) == domain_record::owned,
                "Attempting to update a domain which is not in 'owned' state");
     FC_ASSERT( is_valid_value( this->value ), "Trying to update with invalid value" );
     FC_ASSERT( eval_state.check_signature( odomain_rec->owner ), "Update not signed by owner" );
     odomain_rec->value = this->value;
     odomain_rec->last_update = eval_state._current_state->now().sec_since_epoch();
     eval_state._current_state->store_domain_record( *odomain_rec );
 }
Example #6
0
void
mack::options::option::set_default_value(
    std::string const& default_value)
{
  if (!is_valid_value(default_value))
  {
    BOOST_THROW_EXCEPTION(invalid_value_error()
        << errinfo_option_value(default_value)
        << errinfo_option_flag(get_long_flag()));
  }
  else
  {
    _default_value = default_value;
  }
}
Example #7
0
SgObject Sg_ListToByteVector(SgObject lst, int bitCount, int signP)
{
  SgByteVector *bv;
  SgObject cp;
  int len = 0, i;
  SG_FOR_EACH(cp, lst) {
    SgObject num = SG_CAR(cp);
    if (SG_INTP(num) &&
	is_valid_value(SG_INT_VALUE(num), bitCount, signP)) {
      len++;
      continue;
    } else {
      Sg_WrongTypeOfArgumentViolation(SG_INTERN("list->bytevector"),
				      signP
				      ? SG_MAKE_STRING("unsigned integer list")
				      : SG_MAKE_STRING("integer list"),
				      num, lst);
      return SG_UNDEF;
    }
  }
Example #8
0
int replace_deck(unsigned int count, unsigned char *values) {
	if (NULL != deck) {
		free(deck);
	}
	if (0 == count) {
		return -1;
	}

	deck = malloc(sizeof(Deck) + count * sizeof(Card));
	MALLOC_OK(deck);

	deck->count = count;
	for (int i = 0; i < count; i++) {
		if (FALSE == is_valid_value(values[i])) {
			DBG("invaild card %H\n", values[i]);
			return -1;
		}
		deck->cards[i].value = values[i];
	}

	return SUCCESS;
}
Example #9
0
etcd_response etcd_set(const char *key, const char *value, unsigned ttl) {
    char *url, *data, *tmpdata;
    const struct etcd_data *retdata;
    int ret;
    etcd_response response;

    if (!is_valid_key(key) || !is_valid_value(value)) {
        return ETCD_FAILURE;
    }

    url = etcd_url(key, NULL);
    ret = asprintf(&data, "value=%s", value);
    assert(ret >= 0);

    if (ttl > 0) {
        ret = asprintf(&tmpdata, "%s&ttl=%u", data, ttl);
        assert(ret >= 0);

        free(data);
        data = tmpdata;
    }

    retdata = http_request(url, ETCD_SET, data);
    assert(retdata != NULL);

    response = retdata->response;

    if (response == ETCD_FAILURE) {
        debug(retdata->errmsg);
    }

    free(url);
    free(data);
    free((struct etcd_data *)retdata);
    return response;
}
Example #10
0
int main(int argc, char* argv[])
{
	int a = 0;
	int b = 0;
	char op = 0;
	std::string line;
	std::getline(std::cin, line);
	std::string op1, op2, op3;
	int max_ops = 3;
	bool b_reading_val = false;
	for (size_t i = 0; i != line.size(); i++) {
		char c = line[i];
		if (c == '\t')
			return 0;
		else if (my_is_digit(c)) {
			b_reading_val = true;
			if (max_ops == 3) {
				op1 += c;
			} else if (max_ops == 2) {
				return 0;
			} else if (max_ops == 1) {
				op3 += c;
			} else if (max_ops == 0) {
				return 0;
			}
		} else if (my_is_operand(c)) {
			
			if (b_reading_val) {
				b_reading_val = false;
				max_ops--;
			}

			if (max_ops != 2) {
				return 0;
			}
			op2 = c;
			max_ops--;
		} else {
			if (b_reading_val) {
				b_reading_val = false;
				max_ops--;
			}
		}
	}
	//line >> a >> op >> b;
	/*int ret = sscanf(line.c_str(), "%d %c %d", &a, &op, &b);
	if (ret == 0 || ret == EOF) {
		return 0;
	}*/
	a = atoi(op1.c_str());
	op = op2.c_str()[0];
	b = atoi(op3.c_str());

	if (!is_valid_value(a) || !is_valid_value(b)) {
		//std::cout << "You must input 2 positive integers." << std::endl;
	} else {
		Operation *operation = OperationFactory::CreateOperation(op);
		if (operation) {
			operation->m_number1 = a;
			operation->m_number2 = b;
			long long result = operation->GetResult();
			std::cout << result << std::endl;
			delete operation;
		} else {
			//std::cout << "Illegal expression." << std::endl;
		}
		
	}
	//getchar();
	return 0;
}