本文整理汇总了C++中ds_cstr函数的典型用法代码示例。如果您正苦于以下问题:C++ ds_cstr函数的具体用法?C++ ds_cstr怎么用?C++ ds_cstr使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ds_cstr函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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));
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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;
}
}