示例#1
0
result Expr() {
    result lhs = Term(), rhs;
    token op;
    if(lhs.error !=  ERR_NONE) {
        return lhs;
    }
    for(op = next_token(); op.type == TT_PLUS || op.type == TT_MINUS; op = next_token() ) { 
        rhs = Term();
#ifdef DEBUG_1        
        print_result("Expr:lhs:", lhs);
        printf("Expr:op:%d\n", op.type);
        print_result("Expr:rhs:", rhs);
#endif
        if(rhs.error !=  ERR_NONE) {
            return rhs;
        }
        if(op.type == TT_PLUS) {
            lhs.value += rhs.value;
        }
        else if(op.type == TT_MINUS) {
            lhs.value -= rhs.value;
        } 
        else {
            return make_result(ERR_UNEXPECTED_TOKEN, 0);
        }
    }
    if(op.type !=  TT_END && op.type != TT_BR_CLOSE) {
        return make_result(ERR_UNEXPECTED_TOKEN, (int) op.type);    
    }
    else {
        rollback();
        return make_result(ERR_NONE, lhs.value); 
    }
}
示例#2
0
文件: checks.c 项目: rtaph/checkmate
SEXP c_check_array(SEXP x, SEXP mode, SEXP any_missing, SEXP d, SEXP min_d, SEXP max_d) {
    if (!isArray(x))
        return make_type_error(x, "array");

    assert(check_storage(x, mode));

    if (!asFlag(any_missing, "any.missing") && any_missing_atomic(x))
        return make_result("Contains missing values");

    R_len_t ndim = length(getAttrib(x, R_DimSymbol));
    if (!isNull(d)) {
        R_len_t di = asCount(d, "d");
        if (ndim != di)
            return make_result("Must be a %i-d array, but has dimension %i", di, ndim);
    }

    if (!isNull(min_d)) {
        R_len_t di = asCount(min_d, "min.d");
        if (ndim < di)
            return make_result("Must have >=%i dimensions, but has dimension %i", di, ndim);
    }

    if (!isNull(max_d)) {
        R_len_t di = asCount(max_d, "max.d");
        if (ndim > di)
            return make_result("Must have <=%i dimensions, but has dimension %i", di, ndim);
    }

    return ScalarLogical(TRUE);
}
示例#3
0
文件: checks.c 项目: rtaph/checkmate
SEXP c_check_dataframe(SEXP x, SEXP any_missing, SEXP all_missing, SEXP min_rows, SEXP min_cols, SEXP rows, SEXP cols, SEXP row_names, SEXP col_names) {
    if (!isFrame(x))
        return make_type_error(x, "data.frame");
    assert(check_matrix_dims(x, min_rows, min_cols, rows, cols));

    if (!isNull(row_names)) {
        SEXP nn = getAttrib(x, install("row.names"));
        msg_t msg;

        if (isInteger(nn)) {
            nn = PROTECT(coerceVector(nn, STRSXP));
            msg = check_names(nn, row_names, "Rows");
            UNPROTECT(1);
        } else {
            msg = check_names(nn, row_names, "Rows");
        }
        if (!msg.ok)
            return make_result(msg.msg);
    }

    if (!isNull(col_names))
        assert(check_names(getAttrib(x, R_NamesSymbol), col_names, "Columns"));
    if (!asFlag(any_missing, "any.missing") && any_missing_frame(x))
        return make_result("Contains missing values");
    if (!asFlag(all_missing, "all.missing") && all_missing_frame(x))
        return make_result("Contains only missing values");
    return ScalarLogical(TRUE);
}
示例#4
0
extern "C" void * yami4_outgoing_message_wait_for_completion(
    void * pmsg, int timeout)
{
    yami::outgoing_message * msg =
        static_cast<yami::outgoing_message *>(pmsg);
    try
    {
        bool result;
        if (timeout > 0)
        {
            result = msg->wait_for_completion(
                static_cast<std::size_t>(timeout));
        }
        else
        {
            msg->wait_for_completion();
            result = true;
        }

        return make_result(result ? 1 : 0);
    }
    catch (const std::exception & e)
    {
        return make_result(e);
    }
}
示例#5
0
extern "C" void * yami4_agent_send(void * pa,
    const char * target, const char * object_name, const char * message_name,
    const char * serialized_content, int buffer_len,
    int priority, int auto_connect)
{
    agent_wrapper * wrapper = static_cast<agent_wrapper *>(pa);
    yami::agent * a = wrapper->a_;
    try
    {
        yami::raw_buffer_data_source raw_content(
            serialized_content, static_cast<std::size_t>(buffer_len));

        std::auto_ptr<yami::outgoing_message> msg(
            a->send(target, object_name, message_name,
                raw_content, priority, auto_connect));

        void * res = make_result(msg.get());
        msg.release();
        return res;
    }
    catch (const std::exception & e)
    {
        return make_result(e);
    }
}
TEST(result_storage, unsequenced) {
  const int n = 5;
  const double batch_interval = 1;

  result_storage storage(n);

  storage.store(make_result(0, batch_interval, 10));
  storage.store(make_result(1, batch_interval, 10));
  storage.store(make_result(2, batch_interval, 10));
  storage.store(make_result(3, batch_interval, 10));
  storage.store(make_result(2, batch_interval, 10));
  storage.store(make_result(3, batch_interval, 10));
  storage.store(make_result(4, batch_interval, 10));
  storage.store(make_result(3, batch_interval, 10));
  storage.store(make_result(2, batch_interval, 10));
  storage.store(make_result(1, batch_interval, 10));

  // first stored result should not be erased
  ASSERT_DOUBLE_EQ(0, storage.get_result_at(0.5).get_start_pos());

  // sequenced
  ASSERT_DOUBLE_EQ(1, storage.get_result_at(1.5).get_start_pos());
  ASSERT_DOUBLE_EQ(2, storage.get_result_at(2.5).get_start_pos());
  ASSERT_DOUBLE_EQ(3, storage.get_result_at(3.5).get_start_pos());
  ASSERT_DOUBLE_EQ(4, storage.get_result_at(4.5).get_start_pos());
}
示例#7
0
result Term() {
    result lhs = Factor(), rhs;
    token op;
    if(lhs.error !=  ERR_NONE) {
        return lhs;
    }
    for(op = next_token(); op.type == TT_ASTERISK || op.type == TT_SLASH; op = next_token() ) { 
        rhs = Factor();
#ifdef DEBUG_1
        print_result("Term:lhs:", lhs);
        printf("Term:op:%d\n", op.type);
        print_result("Term:rhs:", rhs);
#endif
        if(rhs.error != ERR_NONE) {
            return rhs;
        }
        if(op.type == TT_ASTERISK) {
            lhs.value *= rhs.value;
        }
        else if(op.type == TT_SLASH) {
            if(rhs.value != 0) {
                lhs.value /= rhs.value;
            }
            else {
                return make_result(ERR_DIVISION_BY_ZERO, 0); 
            }
        }
        else {
            return make_result(ERR_UNEXPECTED_TOKEN, 0);
        }
    }
    rollback();
    return make_result(ERR_NONE, lhs.value);
}
示例#8
0
文件: main.c 项目: cmatthew/Nin-Situ
/** Check the condition of the local IP address.

Is is private, is it routable?

*/
static result * test_ip_address(void) {
    struct ifaddrs *myaddrs, *ifa;
    void *in_addr;
    ssize_t buf_siz = 64 * sizeof(char);
    char * buf = (char *) malloc(buf_siz);
    memset(buf, 0, buf_siz);
    if(getifaddrs(&myaddrs) != 0) {
        perror("getifaddrs failed.");
    }

    for (ifa = myaddrs; ifa != NULL; ifa = ifa->ifa_next) {
        if (ifa->ifa_addr == NULL) {
            continue;
        }
        if (!(ifa->ifa_flags & IFF_UP)) {
            continue;
        }

        switch (ifa->ifa_addr->sa_family) {
            case AF_INET: 
                {
                struct sockaddr_in *s4 = (struct sockaddr_in *)ifa->ifa_addr;
                in_addr = &s4->sin_addr;
                break;
                }

            default:
                continue;
        }

        if (inet_ntop(ifa->ifa_addr->sa_family, in_addr, buf, buf_siz) == NULL) {
            freeifaddrs(myaddrs);
            perror("inet_ntop failed");
        } else {
            // Are we a private IP address
            if ( starts_with(LINK_LOCAL_PREFIX, buf) ) {
                freeifaddrs(myaddrs);
                return make_result( FAILED, "Private Link Local IP address found", buf);
            }
            // Are we a non-routable IP
            if ( starts_with(PRIVATE_PREFIX1, buf)) {
                #warning "20-bit private addressing check is not implemented yet"
                freeifaddrs(myaddrs);
                return make_result( PASSED, "Private non-routable IP address found", buf);
            }
            // Are we a private IP address
            if ( starts_with(PRIVATE_PREFIX3, buf)) {
                freeifaddrs(myaddrs);
                return make_result( PASSED, "Private non-routable IP address found", buf);
            }
        }
    }
    result * r =  make_result(PASSED, "Routable IP addresses found.", strdup(buf));
    free(buf);
    freeifaddrs(myaddrs);
    return r;
}
示例#9
0
static cosmetic_find_result find_cosmetic(
    const std::vector<submap::cosmetic_t> &cosmetics, const point &p, const std::string &type )
{
    for( size_t i = 0; i < cosmetics.size(); ++i ) {
        if( cosmetics[i].pos == p && cosmetics[i].type == type ) {
            return make_result( true, i );
        }
    }
    return make_result( false, -1 );
}
示例#10
0
TEST(result_storage, get_diff_and_put_diff) {
  const int n = 5;
  const double batch_interval = 1;

  result_storage storage(n);

  storage.store(make_result(0, batch_interval, 10));
  storage.store(make_result(1, batch_interval, 10));
  storage.store(make_result(2, batch_interval, 10));

  ASSERT_DOUBLE_EQ(0, storage.get_result_at(0.5).get_start_pos());
  ASSERT_DOUBLE_EQ(1, storage.get_result_at(1.5).get_start_pos());
  ASSERT_DOUBLE_EQ(2, storage.get_result_at(2.5).get_start_pos());

  result_storage::diff_t diff = storage.get_diff();
  ASSERT_EQ(3u, diff.size());
  ASSERT_DOUBLE_EQ(2, diff[0].get_start_pos());
  ASSERT_DOUBLE_EQ(1, diff[1].get_start_pos());
  ASSERT_DOUBLE_EQ(0, diff[2].get_start_pos());

  storage.put_diff(diff);
  // results are not changed
  ASSERT_DOUBLE_EQ(0, storage.get_result_at(0.5).get_start_pos());
  ASSERT_DOUBLE_EQ(1, storage.get_result_at(1.5).get_start_pos());
  ASSERT_DOUBLE_EQ(2, storage.get_result_at(2.5).get_start_pos());

  // put diff clears diff
  diff = storage.get_diff();
  ASSERT_EQ(0u, diff.size());
  // put-diff empty diff
  storage.put_diff(diff);
  // results are not changed
  ASSERT_DOUBLE_EQ(0, storage.get_result_at(0.5).get_start_pos());
  ASSERT_DOUBLE_EQ(1, storage.get_result_at(1.5).get_start_pos());
  ASSERT_DOUBLE_EQ(2, storage.get_result_at(2.5).get_start_pos());

  // add result after put-diff
  storage.store(make_result(3, batch_interval, 10));

  diff = storage.get_diff();
  ASSERT_EQ(1u, diff.size());
  ASSERT_DOUBLE_EQ(3, diff[0].get_start_pos());

  // modify diff
  diff.push_back(make_result(4, batch_interval, 10));

  storage.put_diff(diff);
  ASSERT_DOUBLE_EQ(0, storage.get_result_at(0.5).get_start_pos());
  ASSERT_DOUBLE_EQ(1, storage.get_result_at(1.5).get_start_pos());
  ASSERT_DOUBLE_EQ(2, storage.get_result_at(2.5).get_start_pos());
  ASSERT_DOUBLE_EQ(3, storage.get_result_at(3.5).get_start_pos());
  ASSERT_DOUBLE_EQ(4, storage.get_result_at(4.5).get_start_pos());
}
示例#11
0
文件: main.c 项目: cmatthew/Nin-Situ
static result * test_echo_server(void) {

    struct hostent     *he = NULL;
    struct sockaddr_in  server;
    int sockfd = -1;

    memset(&server, 0, sizeof(server));
    sockfd = socket(AF_INET, SOCK_STREAM, 0);

    if (sockfd < 0) {
        perror("opening socket failed");
    }
    /* resolve localhost to an IP (should be 127.0.0.1) */
    if ((he = gethostbyname(SERVER_NAME)) == NULL) {
        perror( "error resolving the hostname");
    }

    /*
     * copy the network address part of the structure to the 
     * sockaddr_in structure which is passed to connect() 
     */
    memcpy(&server.sin_addr, he->h_addr_list[0], he->h_length);
    server.sin_family = AF_INET;
    server.sin_port = htons(TCP_PORT);
    
    /* connect */
    if (connect(sockfd, (struct sockaddr *) &server, sizeof(server))) {
        perror("error connecting to server");
    }

    int rc = write( sockfd, ECHO_MESSAGE, strlen(ECHO_MESSAGE)+1);

    if (rc != strlen(ECHO_MESSAGE) + 1) {
        return make_result(FAILED, "Could not send data to the server","");
    }

    char buf[65];
    memset(&buf, 0, 65);

    int read_len = read( sockfd, &buf, 65);

    if (read_len != strlen(ECHO_MESSAGE) + 1) {
        return make_result(FAILED, "Could not read data from the server","");
    }

    if (strcmp(ECHO_MESSAGE, buf)==0) {
        return make_result(PASSED, "TCP Echo test works","I message was relayed by the server");
    } else {
        return make_result(FAILED, "TCP Echo test failed","Payload was not as expected");
    }

}
示例#12
0
文件: checks.c 项目: rtaph/checkmate
SEXP c_check_count(SEXP x, SEXP na_ok, SEXP positive, SEXP tol) {
    Rboolean is_na = is_scalar_na(x);
    double dtol = asNumber(tol, "tol");
    if (xlength(x) != 1 || (!is_na && !isIntegerish(x, dtol)))
        return make_type_error(x, "count");
    if (is_na) {
        if (!asFlag(na_ok, "na.ok"))
            return make_result("May not be NA");
    } else  {
        const int pos = (int) asFlag(positive, "positive");
        if (asInteger(x) < pos)
            return make_result("Must be >= %i", pos);
    }
    return ScalarLogical(TRUE);
}
示例#13
0
extern "C" void * yami4_outgoing_message_get_exception_msg(void * pmsg)
{
    yami::outgoing_message * msg =
        static_cast<yami::outgoing_message *>(pmsg);
    try
    {
        const std::string & exc_msg = msg->get_exception_msg();

        return make_result(exc_msg);
    }
    catch (const std::exception & e)
    {
        return make_result(e);
    }
}
示例#14
0
extern "C" void * yami4_incoming_message_get_message_name(void * pmsg)
{
    yami::incoming_message * msg =
        static_cast<yami::incoming_message *>(pmsg);
    try
    {
        const std::string & msg_name = msg->get_message_name();

        return make_result(msg_name);
    }
    catch (const std::exception & e)
    {
        return make_result(e);
    }
}
示例#15
0
extern "C" void * yami4_agent_open_connection(void * pa,
    const char * target)
{
    agent_wrapper * wrapper = static_cast<agent_wrapper *>(pa);
    yami::agent * a = wrapper->a_;
    try
    {
        a->open_connection(target);

        return make_result(1);
    }
    catch (const std::exception & e)
    {
        return make_result(e);
    }
}
示例#16
0
extern "C" void * yami4_outgoing_message_get_raw_reply(void * pmsg)
{
    yami::outgoing_message * msg =
        static_cast<yami::outgoing_message *>(pmsg);
    try
    {
        const std::vector<char> & reply = msg->get_raw_reply();

        return make_result(
            const_cast<char *>(&reply[0]), static_cast<int>(reply.size()));
    }
    catch (const std::exception & e)
    {
        return make_result(e);
    }
}
示例#17
0
文件: GSEA.cpp 项目: koralgooll/GSEA
//----Constructors----//
GSEA::GSEA(const char* database_file_, const char* population_file_, const char* sample_file_)
	: database_file(database_file_), population_file(population_file_), sample_file(sample_file_)
{	
	/*
		This constructor handles the GSEA object.
		Sets the given file paths.
		Calls the make methods in sequence.
	*/
	clock_t tStart = clock();
	make_population();
	printf("make_population: %.2fs\n", (double)(clock() - tStart) / CLOCKS_PER_SEC);
	
	clock_t tpop_suc = clock();
	make_db_pop();
	printf("population success: %.2fs\n", (double)(clock() - tpop_suc) / CLOCKS_PER_SEC);
	
	clock_t tmake_sample = clock();
	make_sample();
	printf("make_sample: %.2fs\n", (double)(clock() - tmake_sample) / CLOCKS_PER_SEC);
	
	clock_t tsample = clock();
	make_result(sample);
	printf("make_result: %.2fs\n", (double)(clock() - tsample) / CLOCKS_PER_SEC);
	
};
示例#18
0
extern "C" void * yami4_agent_add_listener(void * pa,
    const char * listener)
{
    agent_wrapper * wrapper = static_cast<agent_wrapper *>(pa);
    yami::agent * a = wrapper->a_;
    try
    {
        std::string resolved_address = a->add_listener(listener);

        return make_result(resolved_address);
    }
    catch (const std::exception & e)
    {
        return make_result(e);
    }
}
示例#19
0
extern "C" void * yami4_incoming_message_get_raw_content(void * pmsg)
{
    yami::incoming_message * msg =
        static_cast<yami::incoming_message *>(pmsg);
    try
    {
        const std::vector<char> & content = msg->get_raw_content();

        return make_result(
            const_cast<char *>(&content[0]),
            static_cast<int>(content.size()));
    }
    catch (const std::exception & e)
    {
        return make_result(e);
    }
}
示例#20
0
文件: checks.c 项目: rtaph/checkmate
SEXP c_check_scalar(SEXP x, SEXP na_ok) {
    Rboolean is_na = is_scalar_na(x);
    if (xlength(x) != 1 || (!is_na && !isVectorAtomic(x)))
        return make_type_error(x, "atomic scalar");
    if (is_na && !asFlag(na_ok, "na.ok"))
        return make_result("May not be NA");
    return ScalarLogical(TRUE);
}
示例#21
0
文件: and.c 项目: JakobR/hammer
static HParseResult *parse_and(void* env, HParseState* state) {
  HInputStream bak = state->input_stream;
  HParseResult *res = h_do_parse((HParser*)env, state);
  state->input_stream = bak;
  if (res)
    return make_result(state->arena, NULL);
  return NULL;
}
示例#22
0
extern "C" void * yami4_agent_get_next_connection_event(void * pa)
{
    agent_wrapper * wrapper = static_cast<agent_wrapper *>(pa);

    const std::string event_description =
        wrapper->get_next_connection_event();

    return make_result(event_description);
}
示例#23
0
文件: not.c 项目: spease/hammer
static HParseResult* parse_not(void* env, HParseState* state) {
  HInputStream bak = state->input_stream;
  if (h_do_parse((HParser*)env, state))
    return NULL;
  else {
    state->input_stream = bak;
    return make_result(state, NULL);
  }
}
示例#24
0
文件: optional.c 项目: JakobR/hammer
static HParseResult* parse_optional(void* env, HParseState* state) {
  HInputStream bak = state->input_stream;
  HParseResult *res0 = h_do_parse((HParser*)env, state);
  if (res0)
    return res0;
  state->input_stream = bak;
  HParsedToken *ast = a_new(HParsedToken, 1);
  ast->token_type = TT_NONE;
  return make_result(state->arena, ast);
}
示例#25
0
文件: bits.c 项目: kmitwork/hammer
static HParseResult* parse_bits(void* env, HParseState *state) {
  struct bits_env *env_ = env;
  HParsedToken *result = a_new(HParsedToken, 1);
  result->token_type = (env_->signedp ? TT_SINT : TT_UINT);
  if (env_->signedp)
    result->sint = h_read_bits(&state->input_stream, env_->length, true);
  else
    result->uint = h_read_bits(&state->input_stream, env_->length, false);
  return make_result(state, result);
}
示例#26
0
static HParseResult* parse_charset(void *env, HParseState *state) {
  uint8_t in = h_read_bits(&state->input_stream, 8, false);
  HCharset cs = (HCharset)env;

  if (charset_isset(cs, in)) {
    HParsedToken *tok = a_new(HParsedToken, 1);
    tok->token_type = TT_UINT; tok->uint = in;
    return make_result(state->arena, tok);    
  } else
    return NULL;
}
示例#27
0
文件: token.c 项目: spease/hammer
static HParseResult* parse_token(void *env, HParseState *state) {
  HToken *t = (HToken*)env;
  for (int i=0; i<t->len; ++i) {
    uint8_t chr = (uint8_t)h_read_bits(&state->input_stream, 8, false);
    if (t->str[i] != chr) {
      return NULL;
    }
  }
  HParsedToken *tok = a_new(HParsedToken, 1);
  tok->token_type = TT_BYTES; tok->bytes.token = t->str; tok->bytes.len = t->len;
  return make_result(state, tok);
}
示例#28
0
文件: checks.c 项目: rtaph/checkmate
SEXP c_check_int(SEXP x, SEXP na_ok, SEXP lower, SEXP upper, SEXP tol) {
    Rboolean is_na = is_scalar_na(x);
    double dtol = asNumber(tol, "tol");
    if (xlength(x) != 1 || (!is_na && !isIntegerish(x, dtol)))
        return make_type_error(x, "single integerish value");
    if (is_na) {
        if (!asFlag(na_ok, "na.ok"))
            return make_result("May not be NA");
    }
    assert(check_bounds(x, lower, upper));
    return ScalarLogical(TRUE);
}
示例#29
0
result Factor() {
    token next = next_token();
    result res;
    if (next.type == TT_NUMBER) {
        return make_result(ERR_NONE, next.value);
    }
    else if(next.type == TT_BR_OPEN) {
        res = Expr();
        if(res.error != ERR_NONE) {
            return res;
        }
        if(next_token().type == TT_BR_CLOSE) {
            return make_result(ERR_NONE, res.value);
        }
        else {
            return make_result(ERR_EXPECTED_BR_CLOSE, 0);
        }
    }
    else {
        return make_result(ERR_UNEXPECTED_TOKEN, 0);
    }
}
示例#30
0
文件: main.c 项目: cmatthew/Nin-Situ
static result * test_dns_resolution(void) {

    struct hostent *hp = gethostbyname(KNOWN_DNS_NAME);

    if (hp == NULL) {
        perror("DNS resolution failed");
    }

    struct in_addr* address = (struct in_addr *) hp -> h_addr_list[0];
    char * str_address = inet_ntoa( *( struct in_addr*) address );
    if (strcmp(str_address, KNOWN_DNS_ADDRESS)==0){
        return make_result(PASSED, "DNS resolution worked","query of " KNOWN_DNS_NAME
                           " returned the expected 1.2.3.4");
    } else {
        return make_result(FAILED, "DNS resolution failed",
                           "query of " KNOWN_DNS_NAME " did not return"
                           " the expected 1.2.3.4");
    }

    return make_result(PASSED, "DNS resolution works","");

}