本文整理汇总了C++中ds_cstr函数的典型用法代码示例。如果您正苦于以下问题:C++ ds_cstr函数的具体用法?C++ ds_cstr怎么用?C++ ds_cstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ds_cstr函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: parse_actions
static int
parse_actions(void)
{
struct ds in;
ds_init(&in);
vlog_set_levels_from_string_assert("odp_util:console:dbg");
while (!ds_get_test_line(&in, stdin)) {
struct ofpbuf odp_actions;
struct ds out;
int error;
/* Convert string to OVS DP actions. */
ofpbuf_init(&odp_actions, 0);
error = odp_actions_from_string(ds_cstr(&in), NULL, &odp_actions);
if (error) {
printf("odp_actions_from_string: error\n");
goto next;
}
/* Convert odp_actions back to string. */
ds_init(&out);
format_odp_actions(&out, odp_actions.data, odp_actions.size);
puts(ds_cstr(&out));
ds_destroy(&out);
next:
ofpbuf_uninit(&odp_actions);
}
ds_destroy(&in);
return 0;
}
开发者ID:emaste,项目名称:openvswitch,代码行数:33,代码来源:test-odp.c
示例2: main
int
main(void)
{
struct ds in;
ds_init(&in);
while (!ds_get_line(&in, stdin)) {
struct ofpbuf odp_key;
struct flow flow;
struct ds out;
int error;
char *s;
/* Delete comments, skip blank lines. */
s = ds_cstr(&in);
if (*s == '#') {
puts(s);
continue;
}
if (strchr(s, '#')) {
*strchr(s, '#') = '\0';
}
if (s[strspn(s, " ")] == '\0') {
putchar('\n');
continue;
}
/* Convert string to OVS DP key. */
ofpbuf_init(&odp_key, 0);
error = odp_flow_key_from_string(ds_cstr(&in), &odp_key);
if (error) {
printf("odp_flow_key_from_string: error\n");
goto next;
}
/* Convert odp_key to flow. */
error = odp_flow_key_to_flow(odp_key.data, odp_key.size, &flow);
if (error) {
printf("odp_flow_key_to_flow: error\n");
goto next;
}
/* Convert cls_rule back to odp_key. */
ofpbuf_uninit(&odp_key);
ofpbuf_init(&odp_key, 0);
odp_flow_key_from_flow(&odp_key, &flow);
/* Convert odp_key to string. */
ds_init(&out);
odp_flow_key_format(odp_key.data, odp_key.size, &out);
puts(ds_cstr(&out));
ds_destroy(&out);
next:
ofpbuf_uninit(&odp_key);
}
ds_destroy(&in);
return 0;
}
开发者ID:Danesca,项目名称:openvswitch,代码行数:60,代码来源:test-odp.c
示例3: IntrospectArguments
static void IntrospectArguments(adbus_Member* m, d_String* out)
{
size_t argi = 0;
const char* arg = ds_cstr(&m->argsig);
while (arg && *arg) {
const char* next = adbus_nextarg(arg);
ds_cat(out, "\t\t\t<arg type=\"");
ds_cat_n(out, arg, next - arg);
if (argi < dv_size(&m->arguments)) {
ds_cat(out, "\" name=\"");
ds_cat(out, dv_a(&m->arguments, argi));
}
ds_cat(out, "\"/>\n");
arg = next;
argi++;
}
assert(argi >= dv_size(&m->arguments));
argi = 0;
arg = ds_cstr(&m->retsig);
while (arg && *arg) {
const char* next = adbus_nextarg(arg);
ds_cat(out, "\t\t\t<arg type=\"");
ds_cat_n(out, arg, next - arg);
if (argi < dv_size(&m->returns)) {
ds_cat(out, "\" name=\"");
ds_cat(out, dv_a(&m->returns, argi));
}
ds_cat(out, "\" direction=\"out\"/>\n");
arg = next;
argi++;
}
assert(argi >= dv_size(&m->returns));
}
开发者ID:jmckaskill,项目名称:adbus,代码行数:35,代码来源:interface.c
示例4: test_lex
static void
test_lex(const char *input)
{
struct ds output;
ds_init(&output);
struct lexer lexer;
lexer_init(&lexer, input);
ds_clear(&output);
while (lexer_get(&lexer) != LEX_T_END) {
size_t len = output.length;
lex_token_format(&lexer.token, &output);
/* Check that the formatted version can really be parsed back
* losslessly. */
if (lexer.token.type != LEX_T_ERROR) {
const char *s = ds_cstr(&output) + len;
struct lexer l2;
lexer_init(&l2, s);
lexer_get(&l2);
compare_token(&lexer.token, &l2.token);
lexer_destroy(&l2);
}
ds_put_char(&output, ' ');
}
lexer_destroy(&lexer);
ds_chomp(&output, ' ');
puts(ds_cstr(&output));
ds_destroy(&output);
}
开发者ID:blp,项目名称:ovs-reviews,代码行数:33,代码来源:expr_parse_target.c
示例5: get_label
/* Parse all the labels for the VAR_CNT variables in VARS and add
the specified labels to those variables. */
static int
get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt,
const char *dict_encoding)
{
/* Parse all the labels and add them to the variables. */
do
{
enum { MAX_LABEL_LEN = 255 };
int width = var_get_width (vars[0]);
union value value;
struct string label;
size_t trunc_len;
size_t i;
/* Set value. */
value_init (&value, width);
if (!parse_value (lexer, &value, vars[0]))
{
value_destroy (&value, width);
return 0;
}
lex_match (lexer, T_COMMA);
/* Set label. */
if (lex_token (lexer) != T_ID && !lex_force_string (lexer))
{
value_destroy (&value, width);
return 0;
}
ds_init_substring (&label, lex_tokss (lexer));
trunc_len = utf8_encoding_trunc_len (ds_cstr (&label), dict_encoding,
MAX_LABEL_LEN);
if (ds_length (&label) > trunc_len)
{
msg (SW, _("Truncating value label to %d bytes."), MAX_LABEL_LEN);
ds_truncate (&label, trunc_len);
}
for (i = 0; i < var_cnt; i++)
var_replace_value_label (vars[i], &value, ds_cstr (&label));
ds_destroy (&label);
value_destroy (&value, width);
lex_get (lexer);
lex_match (lexer, T_COMMA);
}
while (lex_token (lexer) != T_SLASH && lex_token (lexer) != T_ENDCMD);
return 1;
}
开发者ID:RobertDash,项目名称:pspp,代码行数:55,代码来源:value-labels.c
示例6: process_escape_args
char *
process_escape_args(char **argv)
{
struct ds ds = DS_EMPTY_INITIALIZER;
char **argp;
for (argp = argv; *argp; argp++) {
const char *arg = *argp;
const char *p;
if (argp != argv) {
ds_put_char(&ds, ' ');
}
if (arg[strcspn(arg, " \t\r\n\v\\\'\"")]) {
ds_put_char(&ds, '"');
for (p = arg; *p; p++) {
if (*p == '\\' || *p == '\"') {
ds_put_char(&ds, '\\');
}
ds_put_char(&ds, *p);
}
ds_put_char(&ds, '"');
} else {
ds_put_cstr(&ds, arg);
}
}
return ds_cstr(&ds);
}
开发者ID:InCNTRE,项目名称:OFTT,代码行数:26,代码来源:process.c
示例7: process_status_msg
/* Given 'status', which is a process status in the form reported by waitpid(2)
* and returned by process_status(), returns a string describing how the
* process terminated. The caller is responsible for freeing the string when
* it is no longer needed. */
char *
process_status_msg(int status)
{
struct ds ds = DS_EMPTY_INITIALIZER;
if (WIFEXITED(status)) {
ds_put_format(&ds, "exit status %d", WEXITSTATUS(status));
} else if (WIFSIGNALED(status) || WIFSTOPPED(status)) {
int signr = WIFSIGNALED(status) ? WTERMSIG(status) : WSTOPSIG(status);
const char *name = NULL;
#ifdef HAVE_STRSIGNAL
name = strsignal(signr);
#endif
ds_put_format(&ds, "%s by signal %d",
WIFSIGNALED(status) ? "killed" : "stopped", signr);
if (name) {
ds_put_format(&ds, " (%s)", name);
}
} else {
ds_put_format(&ds, "terminated abnormally (%x)", status);
}
if (WCOREDUMP(status)) {
ds_put_cstr(&ds, ", core dumped");
}
return ds_cstr(&ds);
}
开发者ID:InCNTRE,项目名称:OFTT,代码行数:29,代码来源:process.c
示例8: process_status_msg
/* Given 'status', which is a process status in the form reported by waitpid(2)
* and returned by process_status(), returns a string describing how the
* process terminated. The caller is responsible for freeing the string when
* it is no longer needed. */
char *
process_status_msg(int status)
{
struct ds ds = DS_EMPTY_INITIALIZER;
#ifndef _WIN32
if (WIFEXITED(status)) {
ds_put_format(&ds, "exit status %d", WEXITSTATUS(status));
} else if (WIFSIGNALED(status)) {
char namebuf[SIGNAL_NAME_BUFSIZE];
ds_put_format(&ds, "killed (%s)",
signal_name(WTERMSIG(status), namebuf, sizeof namebuf));
} else if (WIFSTOPPED(status)) {
char namebuf[SIGNAL_NAME_BUFSIZE];
ds_put_format(&ds, "stopped (%s)",
signal_name(WSTOPSIG(status), namebuf, sizeof namebuf));
} else {
ds_put_format(&ds, "terminated abnormally (%x)", status);
}
if (WCOREDUMP(status)) {
ds_put_cstr(&ds, ", core dumped");
}
#else
ds_put_cstr(&ds, "function not supported.");
#endif
return ds_cstr(&ds);
}
开发者ID:wenxueliu,项目名称:code_clips,代码行数:32,代码来源:daemon-unix.c
示例9: flow_to_string
char *
flow_to_string(const struct flow *flow)
{
struct ds ds = DS_EMPTY_INITIALIZER;
flow_format(&ds, flow);
return ds_cstr(&ds);
}
开发者ID:Grace-Liu,项目名称:dpdk-ovs,代码行数:7,代码来源:flow.c
示例10: flow_table_create
struct flow_table *
flow_table_create(struct datapath *dp, uint8_t table_id) {
struct flow_table *table;
struct ds string = DS_EMPTY_INITIALIZER;
ds_put_format(&string, "table_%u", table_id);
table = xmalloc(sizeof(struct flow_table));
table->dp = dp;
table->stats = xmalloc(sizeof(struct ofl_table_stats));
table->stats->table_id = table_id;
table->stats->name = ds_cstr(&string);
table->stats->match = DP_SUPPORTED_MATCH_FIELDS;
table->stats->instructions = DP_SUPPORTED_INSTRUCTIONS;
table->stats->write_actions = DP_SUPPORTED_ACTIONS;
table->stats->apply_actions = DP_SUPPORTED_ACTIONS;
table->stats->config = OFPTC_TABLE_MISS_CONTROLLER;
table->stats->max_entries = FLOW_TABLE_MAX_ENTRIES;
table->stats->active_count = 0;
table->stats->lookup_count = 0;
table->stats->matched_count = 0;
list_init(&table->match_entries);
list_init(&table->hard_entries);
list_init(&table->idle_entries);
return table;
}
开发者ID:mmonaco,项目名称:of12softswitch,代码行数:29,代码来源:flow_table.c
示例11: test_pcap
static void
test_pcap(struct ovs_cmdl_context *ctx)
{
size_t total_count, batch_size_;
struct pcap_file *pcap;
int err = 0;
pcap = ovs_pcap_open(ctx->argv[1], "rb");
if (!pcap) {
return;
}
batch_size_ = 1;
if (ctx->argc > 2) {
batch_size_ = strtoul(ctx->argv[2], NULL, 0);
if (batch_size_ == 0 || batch_size_ > NETDEV_MAX_BURST) {
ovs_fatal(0,
"batch_size must be between 1 and NETDEV_MAX_BURST(%u)",
NETDEV_MAX_BURST);
}
}
fatal_signal_init();
ct = conntrack_init();
total_count = 0;
for (;;) {
struct dp_packet *packet;
struct dp_packet_batch pkt_batch_;
struct dp_packet_batch *batch = &pkt_batch_;
dp_packet_batch_init(batch);
for (int i = 0; i < batch_size_; i++) {
err = ovs_pcap_read(pcap, &packet, NULL);
if (err) {
break;
}
dp_packet_batch_add(batch, packet);
}
if (dp_packet_batch_is_empty(batch)) {
break;
}
pcap_batch_execute_conntrack(ct, batch);
DP_PACKET_BATCH_FOR_EACH (i, packet, batch) {
struct ds ds = DS_EMPTY_INITIALIZER;
total_count++;
format_flags(&ds, ct_state_to_string, packet->md.ct_state, '|');
printf("%"PRIuSIZE": %s\n", total_count, ds_cstr(&ds));
ds_destroy(&ds);
}
dp_packet_delete_batch(batch, true);
}
conntrack_destroy(ct);
ovs_pcap_close(pcap);
}
开发者ID:openvswitch,项目名称:ovs,代码行数:60,代码来源:test-conntrack.c
示例12: jsonrpc_log_msg
static void
jsonrpc_log_msg(const struct jsonrpc *rpc, const char *title,
const struct jsonrpc_msg *msg)
{
if (VLOG_IS_DBG_ENABLED()) {
struct ds s = DS_EMPTY_INITIALIZER;
if (msg->method) {
ds_put_format(&s, ", method=\"%s\"", msg->method);
}
if (msg->params) {
ds_put_cstr(&s, ", params=");
json_to_ds(msg->params, 0, &s);
}
if (msg->result) {
ds_put_cstr(&s, ", result=");
json_to_ds(msg->result, 0, &s);
}
if (msg->error) {
ds_put_cstr(&s, ", error=");
json_to_ds(msg->error, 0, &s);
}
if (msg->id) {
ds_put_cstr(&s, ", id=");
json_to_ds(msg->id, 0, &s);
}
VLOG_DBG("%s: %s %s%s", rpc->name, title,
jsonrpc_msg_type_to_string(msg->type), ds_cstr(&s));
ds_destroy(&s);
}
}
开发者ID:rafaelfonte,项目名称:ovs,代码行数:30,代码来源:jsonrpc.c
示例13: parse_actions
static int
parse_actions(const char *in)
{
struct ofpbuf odp_actions;
struct ds out;
int error;
/* Convert string to OVS DP actions. */
ofpbuf_init(&odp_actions, 0);
error = odp_actions_from_string(in, NULL, &odp_actions);
if (error) {
printf("odp_actions_from_string: error\n");
goto next;
}
/* Convert odp_actions back to string. */
ds_init(&out);
format_odp_actions(&out, odp_actions.data, odp_actions.size, NULL);
puts(ds_cstr(&out));
ds_destroy(&out);
next:
ofpbuf_uninit(&odp_actions);
return 0;
}
开发者ID:blp,项目名称:ovs-reviews,代码行数:25,代码来源:odp_target.c
示例14: handle_acl_log
void
handle_acl_log(const struct flow *headers, struct ofpbuf *userdata)
{
if (!VLOG_IS_INFO_ENABLED()) {
return;
}
struct log_pin_header *lph = ofpbuf_try_pull(userdata, sizeof *lph);
if (!lph) {
VLOG_WARN("log data missing");
return;
}
size_t name_len = userdata->size;
char *name = name_len ? xmemdup0(userdata->data, name_len) : NULL;
struct ds ds = DS_EMPTY_INITIALIZER;
ds_put_cstr(&ds, "name=");
json_string_escape(name_len ? name : "<unnamed>", &ds);
ds_put_format(&ds, ", verdict=%s, severity=%s: ",
log_verdict_to_string(lph->verdict),
log_severity_to_string(lph->severity));
flow_format(&ds, headers, NULL);
VLOG_INFO("%s", ds_cstr(&ds));
ds_destroy(&ds);
free(name);
}
开发者ID:Grim-lock,项目名称:ovs,代码行数:28,代码来源:acl-log.c
示例15: new_value_append_syntax
/* Generate a syntax fragment for NV and append it to STR */
static void
new_value_append_syntax (GString *str, const struct new_value *nv)
{
switch (nv->type)
{
case NV_NUMERIC:
g_string_append_printf (str, "%g", nv->v.v);
break;
case NV_STRING:
{
struct string ds = DS_EMPTY_INITIALIZER;
syntax_gen_string (&ds, ss_cstr (nv->v.s));
g_string_append (str, ds_cstr (&ds));
ds_destroy (&ds);
}
break;
case NV_COPY:
g_string_append (str, "COPY");
break;
case NV_SYSMIS:
g_string_append (str, "SYSMIS");
break;
default:
/* Shouldn't ever happen */
g_warning ("Invalid type in new recode value");
g_string_append (str, "???");
break;
}
}
开发者ID:RobertDash,项目名称:pspp,代码行数:30,代码来源:recode-dialog.c
示例16: ovsdb_type_to_english
char *
ovsdb_type_to_english(const struct ovsdb_type *type)
{
const char *key = ovsdb_atomic_type_to_string(type->key.type);
const char *value = ovsdb_atomic_type_to_string(type->value.type);
if (ovsdb_type_is_scalar(type)) {
return xstrdup(key);
} else {
struct ds s = DS_EMPTY_INITIALIZER;
ds_put_cstr(&s, ovsdb_type_is_set(type) ? "set" : "map");
if (type->n_max == UINT_MAX) {
if (type->n_min) {
ds_put_format(&s, " of %u or more", type->n_min);
} else {
ds_put_cstr(&s, " of");
}
} else if (type->n_min) {
ds_put_format(&s, " of %u to %u", type->n_min, type->n_max);
} else {
ds_put_format(&s, " of up to %u", type->n_max);
}
if (ovsdb_type_is_set(type)) {
ds_put_format(&s, " %ss", key);
} else {
ds_put_format(&s, " (%s, %s) pairs", key, value);
}
return ds_cstr(&s);
}
}
开发者ID:AnyBucket,项目名称:OpenStack-Install-and-Understand-Guide,代码行数:29,代码来源:ovsdb-types.c
示例17: parse_ofp_flow_mod_file
void
parse_ofp_flow_mod_file(const char *file_name, uint16_t command,
struct ofputil_flow_mod **fms, size_t *n_fms)
{
size_t allocated_fms;
FILE *stream;
struct ds s;
stream = !strcmp(file_name, "-") ? stdin : fopen(file_name, "r");
if (stream == NULL) {
ovs_fatal(errno, "%s: open", file_name);
}
allocated_fms = *n_fms;
ds_init(&s);
while (!ds_get_preprocessed_line(&s, stream)) {
if (*n_fms >= allocated_fms) {
*fms = x2nrealloc(*fms, &allocated_fms, sizeof **fms);
}
parse_ofp_flow_mod_str(&(*fms)[*n_fms], ds_cstr(&s), command, false);
*n_fms += 1;
}
ds_destroy(&s);
if (stream != stdin) {
fclose(stream);
}
}
开发者ID:yamt,项目名称:openvswitch,代码行数:28,代码来源:ofp-parse.c
示例18: adbus_msg_interface
/** Returns the current value of the interface header field.
*
* \relates adbus_MsgFactory
*
* \return NULL if the field is not set
*/
const char* adbus_msg_interface(const adbus_MsgFactory* m, size_t* len)
{
if (len)
*len = ds_size(&m->interface);
if (ds_size(&m->interface) > 0)
return ds_cstr(&m->interface);
else
return NULL;
}
开发者ID:jmckaskill,项目名称:adbus,代码行数:15,代码来源:message.c
示例19: flush_help_string
static void
flush_help_string(struct ds *ds)
{
if (ds->length > 2 ) {
ds->length -= 2;
printf ("%s\n", ds_cstr(ds));
ds_clear(ds);
}
}
开发者ID:Altiscale,项目名称:ovs,代码行数:9,代码来源:ovstest.c
示例20: adbus_msg_destination
/** Returns the current value of the destination header field.
*
* \relates adbus_MsgFactory
*
* \return NULL if the field is not set
*/
const char* adbus_msg_destination(const adbus_MsgFactory* m, size_t* len)
{
if (len)
*len = ds_size(&m->destination);
if (ds_size(&m->destination) > 0)
return ds_cstr(&m->destination);
else
return NULL;
}
开发者ID:jmckaskill,项目名称:adbus,代码行数:15,代码来源:message.c
注:本文中的ds_cstr函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论