static int do_read_data(libcouchbase_server_t *c) { /* ** Loop and try to parse the data... We don't want to lock up the ** event loop completely, so set a max number of packets to process ** before backing off.. */ libcouchbase_size_t processed = 0; /* @todo Make the backoff number tunable from the instance */ const libcouchbase_size_t operations_per_call = 1000; int rv = 0; /* ** The timers isn't supposed to be _that_ accurate.. it's better ** to shave off system calls :) */ hrtime_t stop = gethrtime(); while (processed < operations_per_call) { switch ((rv = parse_single(c, stop))) { case -1: return -1; case 0: /* need more data */ if ((rv = do_fill_input_buffer(c)) < 1) { /* error or would block ;) */ return rv; } break; default: ++processed; } } return rv; }
DataFrame human_parse::parse_vector(std::vector < std::string > names){ // Measure and construct output unsigned int input_size = names.size(); std::vector < std::string > salutation(input_size); std::vector < std::string > first_name(input_size); std::vector < std::string > middle_name(input_size); std::vector < std::string > last_name(input_size); std::vector < std::string > suffix(input_size); std::vector < std::string > holding(5); // For each element, go nuts for(unsigned int i = 0; i < input_size; i++){ if((i % 10000) == 0){ Rcpp::checkUserInterrupt(); } holding = parse_single(names[i]); salutation[i] = holding[0]; first_name[i] = holding[1]; middle_name[i] = holding[2]; last_name[i] = holding[3]; suffix[i] = holding[4]; } return DataFrame::create(_["salutation"] = salutation, _["first_name"] = first_name, _["middle_name"] = middle_name, _["last_name"] = last_name, _["suffix"] = suffix, _["full_name"] = names, _["stringsAsFactors"] = false); }
ib_status_t ib_flags_string( const ib_strval_t *map, const char *str, int num, ib_flags_t *pflags, ib_flags_t *pmask) { if ( (map == NULL) || (str == NULL) || (pflags == NULL) || (pmask == NULL) ) { return IB_EINVAL; } ib_flags_op_t oper; ib_flags_t flags; ib_status_t rc; rc = parse_single(map, str, &oper, &flags); if (rc != IB_OK) { return rc; } rc = apply_operation(oper, flags, num, pflags, pmask); if (rc != IB_OK) { return rc; } return IB_OK; }
struct instruction *parse_instruction() { struct instruction *i; i = malloc(sizeof(struct instruction)); if (i == NULL) { perror("No memory"); return NULL; } i->s = parse_single(); if (i->s == NULL) { free(i); return NULL; } if (get_token().type != T_SEP) { unget_token(); i->i = NULL; return i; } i->i = parse_instruction(); if (i->i == NULL) { unget_token(); } return i; }
ib_status_t ib_flags_oplist_parse( const ib_strval_t *map, ib_mpool_t *mp, const char *str, const char *sep, ib_list_t *oplist) { if ( (map == NULL) || (str == NULL) || (sep == NULL) || (oplist == NULL) ) { return IB_EINVAL; } char *copy; const char *tmp; /* Make a copy of the string that we can use for strtok */ copy = ib_mpool_strdup(mp, str); if (copy == NULL) { return IB_EALLOC; } /* Clear the list */ ib_list_clear(oplist); /* Walk through the separated list, parser each operator, build the list */ tmp = strtok(copy, sep); do { ib_status_t rc; ib_flags_op_t op; ib_flags_t flags; ib_flags_operation_t *operation; rc = parse_single(map, tmp, &op, &flags); if (rc != IB_OK) { return rc; } operation = ib_mpool_alloc(mp, sizeof(*operation)); if (operation == NULL) { return IB_EALLOC; } operation->op = op; operation->flags = flags; rc = ib_list_push(oplist, operation); if (rc != IB_OK) { return rc; } } while ( (tmp = strtok(NULL, sep)) != NULL); return IB_OK; }
static int parse_request(prelude_client_t *client, int rtype, char *request, prelude_string_t *out) { config_t *cfg; void *context = client; char pname[256], iname[256]; prelude_option_t *last = NULL; int ret = 0, last_cmd = 0, ent; char *str, *value, *prev = NULL, *ptr = NULL; unsigned int line = 0; ret = _config_open(&cfg, prelude_client_get_config_filename(client)); if ( ret < 0 ) return ret; value = request; strsep(&value, "="); while ( (str = (option_strsep(&request))) ) { if ( ! request ) { last_cmd = 1; ptr = value; } *pname = 0; *iname = 0; ent = ret = sscanf(str, "%255[^[][%255[^]]", pname, iname); if ( ret < 1 ) { prelude_string_sprintf(out, "Error parsing option path"); break; } ret = parse_single(&context, &last, last_cmd, rtype, pname, (ent == 2) ? iname : ptr, out); if ( ret < 0 ) break; config_save_value(cfg, rtype, last, last_cmd, &prev, pname, (ent == 2) ? iname : ptr, &line); } _config_close(cfg); free(prev); return ret; }
DataFrame human_parse::parse_vector(CharacterVector names){ // Measure and construct output unsigned int input_size = names.size(); CharacterVector salutation(input_size); CharacterVector first_name(input_size); CharacterVector middle_name(input_size); CharacterVector last_name(input_size); CharacterVector suffix(input_size); CharacterVector holding(5); // For each element, go nuts for(unsigned int i = 0; i < input_size; i++){ if((i % 10000) == 0){ Rcpp::checkUserInterrupt(); } if(names[i] == NA_STRING){ salutation[i] = NA_STRING; first_name[i] = NA_STRING; middle_name[i] = NA_STRING; last_name[i] = NA_STRING; suffix[i] = NA_STRING; } else { holding = parse_single(Rcpp::as<std::string>(names[i])); salutation[i] = holding[0]; first_name[i] = holding[1]; middle_name[i] = holding[2]; last_name[i] = holding[3]; suffix[i] = holding[4]; } } return DataFrame::create(_["salutation"] = salutation, _["first_name"] = first_name, _["middle_name"] = middle_name, _["last_name"] = last_name, _["suffix"] = suffix, _["full_name"] = names, _["stringsAsFactors"] = false); }
std::string human_getset::set_single(std::string name, int element, std::string replacement){ std::vector < std::string > split_name = parse_single(name); split_name[element] = replacement; std::string output; for(unsigned int i = 0; i < split_name.size(); i++){ output.append(split_name[i]); if(i < (split_name.size() - 1) && split_name[i] != ""){ output.append(" "); } } // Final check for trailing spaces if(output[output.size()-1] == ' '){ output.erase(output.size()-1,1); } return output; }
/* Parse and evaluate string */ object *eval_str(const char *s, env_hashtable *env) { object *obj = parse_single(s); return eval(obj, env); }
std::string human_getset::get_single(std::string name, int element){ std::vector < std::string > split_name = parse_single(name); return split_name[element]; }