コード例 #1
0
ファイル: svec.c プロジェクト: BiangHoo/ofsoftswitch13
void
svec_diff(const struct svec *a, const struct svec *b,
          struct svec *a_only, struct svec *both, struct svec *b_only)
{
    size_t i, j;

    assert(svec_is_sorted(a));
    assert(svec_is_sorted(b));
    if (a_only) {
        svec_init(a_only);
    }
    if (both) {
        svec_init(both);
    }
    if (b_only) {
        svec_init(b_only);
    }
    for (i = j = 0; i < a->n && j < b->n; ) {
        int cmp = strcmp(a->names[i], b->names[j]);
        if (cmp < 0) {
            if (a_only) {
                svec_add(a_only, a->names[i]);
            }
            i++;
        } else if (cmp > 0) {
            if (b_only) {
                svec_add(b_only, b->names[j]);
            }
            j++;
        } else {
            if (both) {
                svec_add(both, a->names[i]);
            }
            i++;
            j++;
        }
    }
    if (a_only) {
        for (; i < a->n; i++) {
            svec_add(a_only, a->names[i]);
        }
    }
    if (b_only) {
        for (; j < b->n; j++) {
            svec_add(b_only, b->names[j]);
        }
    }
}
コード例 #2
0
ファイル: ovs-brcompatd.c プロジェクト: Danesca/openvswitch
static char *
capture_vsctl_valist(const char *arg0, va_list args)
{
    char *stdout_log, *stderr_log;
    enum vlog_level log_level;
    struct svec argv;
    int status;
    char *msg;

    /* Compose arguments. */
    svec_init(&argv);
    svec_add(&argv, arg0);
    for (;;) {
        const char *arg = va_arg(args, const char *);
        if (!arg) {
            break;
        }
        svec_add(&argv, arg);
    }
    svec_terminate(&argv);

    /* Run process. */
    if (process_run_capture(argv.names, &stdout_log, &stderr_log, SIZE_MAX,
                            &status)) {
        svec_destroy(&argv);
        return NULL;
    }

    /* Log results. */
    if (WIFEXITED(status)) {
        int code = WEXITSTATUS(status);
        log_level = code == 0 ? VLL_DBG : code == 1 ? VLL_WARN : VLL_ERR;
    } else {
        log_level = VLL_ERR;
    }
    msg = process_status_msg(status);
    VLOG(log_level, "ovs-vsctl exited (%s)", msg);
    if (stdout_log && *stdout_log) {
        VLOG(log_level, "ovs-vsctl wrote to stdout:\n%s\n", stdout_log);
    }
    if (stderr_log && *stderr_log) {
        VLOG(log_level, "ovs-vsctl wrote to stderr:\n%s\n", stderr_log);
    }
    free(msg);

    svec_destroy(&argv);

    free(stderr_log);
    if (WIFEXITED(status) && !WEXITSTATUS(status)) {
        return stdout_log;
    } else {
        free(stdout_log);
        return NULL;
    }
}
コード例 #3
0
int
main(void)
{
    extern struct vlog_module VLM_reconnect;
    struct reconnect_stats prev;
    unsigned int old_max_tries;
    int old_time;
    char line[128];

    vlog_set_levels(&VLM_reconnect, VLF_ANY_FACILITY, VLL_OFF);

    now = 1000;
    reconnect = reconnect_create(now);
    reconnect_set_name(reconnect, "remote");
    reconnect_get_stats(reconnect, now, &prev);
    printf("### t=%d ###\n", now);
    old_time = now;
    old_max_tries = reconnect_get_max_tries(reconnect);
    while (fgets(line, sizeof line, stdin)) {
        struct reconnect_stats cur;
        struct svec args;

        fputs(line, stdout);
        if (line[0] == '#') {
            continue;
        }

        svec_init(&args);
        svec_parse_words(&args, line);
        svec_terminate(&args);
        if (!svec_is_empty(&args)) {
            run_command(args.n, args.names, commands);
        }
        svec_destroy(&args);

        if (old_time != now) {
            printf("\n### t=%d ###\n", now);
        }

        reconnect_get_stats(reconnect, now, &cur);
        diff_stats(&prev, &cur, now - old_time);
        prev = cur;
        if (reconnect_get_max_tries(reconnect) != old_max_tries) {
            old_max_tries = reconnect_get_max_tries(reconnect);
            printf("  %u tries left\n", old_max_tries);
        }

        old_time = now;
    }

    return 0;
}
コード例 #4
0
ファイル: svec.c プロジェクト: BiangHoo/ofsoftswitch13
void
svec_unique(struct svec *svec)
{
    assert(svec_is_sorted(svec));
    if (svec->n > 1) {
        /* This algorithm is lazy and sub-optimal, but it's "obviously correct"
         * and asymptotically optimal . */
        struct svec tmp;
        size_t i;

        svec_init(&tmp);
        svec_add(&tmp, svec->names[0]);
        for (i = 1; i < svec->n; i++) {
            if (strcmp(svec->names[i - 1], svec->names[i])) {
                svec_add(&tmp, svec->names[i]);
            }
        }
        svec_swap(&tmp, svec);
        svec_destroy(&tmp);
    }
}
コード例 #5
0
ファイル: objvbo.c プロジェクト: ptytb/blender-scene-renderer
int vbo_model(const model_t *mdl, const model_d_t *d_mdl,
		vbo_model_t *vbo_mdl, GLenum usage)
{
	svec_iter_t mtl_use;
	svec_iter_t group;
	mtl_use_t *p_mtl_use;
	group_t *p_group;

	vbo_part_t *p;
	int part_begin, part_end, flags, flags_current,
	    chunk, chunk_sum;

	chunk_sum = 0;

	vbo_mdl->mtl = mdl->mtl;
	vbo_mdl->mtl_use = mdl->mtl_use;
	vbo_mdl->group = mdl->group;
	svec_init(&vbo_mdl->part, mdl->mtl_use.elems * mdl->group.elems + 1,
			sizeof(vbo_part_t));
	
	svec_iter_init(&mtl_use, &mdl->mtl_use);
	svec_iter_init(&group, &mdl->group);

	part_begin = 0;
	part_end = 0;
	flags = 0;
	flags_current = 0;
	p_mtl_use = svec_iter_next(&mtl_use);
	p_group = svec_iter_next(&group);

	for (; part_begin != mdl->face.elems;) {

		part_begin = part_end;

		if (p_mtl_use && p_group) {
			if (p_mtl_use->face_id < p_group->face_id) {
				part_end = p_mtl_use->face_id;
				flags |= VPF_MATERIAL;
				p_mtl_use = svec_iter_next(&mtl_use);
			} else if (p_group->face_id < p_mtl_use->face_id) {
				part_end = p_group->face_id;
				flags |= VPF_GROUP;
				p_group = svec_iter_next(&group);
			} else {
				part_end = p_mtl_use->face_id;
				flags = VPF_MATERIAL | VPF_GROUP;
				p_mtl_use = svec_iter_next(&mtl_use);
				p_group = svec_iter_next(&group);
			}
		} else if (p_mtl_use) {
			part_end = p_mtl_use->face_id;
			flags |= VPF_MATERIAL;
			p_mtl_use = svec_iter_next(&mtl_use);
		} else if (p_group) {
			part_end = p_group->face_id;
			flags |= VPF_GROUP;
			p_group = svec_iter_next(&group);
		} else {
			part_end = mdl->face.elems;
		}
		
		if (part_end - part_begin > 0) {
			p = svec_put(&vbo_mdl->part);
			p->flags = flags_current;

			p->elems = 3 * (part_end - part_begin);
			p->offset = p->elems * sizeof(vert_t);
			chunk = 2 * p->offset + p->elems * sizeof(vtex_t);

			p->data_buffer_id = vbo_create(GL_ARRAY_BUFFER,
					chunk, NULL, usage);
			vbo_push(p, p->elems,
					d_mdl->vert + part_begin * 3,
					d_mdl->vtex + part_begin * 3,
					d_mdl->vnor + part_begin * 3);
			chunk_sum += chunk;
		}

		flags_current = flags;
		flags = 0;
	}

	svec_shrink(&vbo_mdl->part);
	return chunk_sum;
}
コード例 #6
0
ファイル: ovsdb-client.c プロジェクト: ALutzG/ovs
int
main(int argc, char *argv[])
{
    const struct ovsdb_client_command *command;
    char *database;
    struct jsonrpc *rpc;

    ovs_cmdl_proctitle_init(argc, argv);
    set_program_name(argv[0]);
    parse_options(argc, argv);
    fatal_ignore_sigpipe();

    daemon_become_new_user(false);
    if (optind >= argc) {
        ovs_fatal(0, "missing command name; use --help for help");
    }

    for (command = get_all_commands(); ; command++) {
        if (!command->name) {
            VLOG_FATAL("unknown command '%s'; use --help for help",
                       argv[optind]);
        } else if (!strcmp(command->name, argv[optind])) {
            break;
        }
    }
    optind++;

    if (command->need != NEED_NONE) {
        if (argc - optind > command->min_args
            && (isalpha((unsigned char) argv[optind][0])
                && strchr(argv[optind], ':'))) {
            rpc = open_jsonrpc(argv[optind++]);
        } else {
            char *sock = xasprintf("unix:%s/db.sock", ovs_rundir());
            rpc = open_jsonrpc(sock);
            free(sock);
        }
    } else {
        rpc = NULL;
    }

    if (command->need == NEED_DATABASE) {
        struct svec dbs;

        svec_init(&dbs);
        fetch_dbs(rpc, &dbs);
        if (argc - optind > command->min_args
            && svec_contains(&dbs, argv[optind])) {
            database = xstrdup(argv[optind++]);
        } else if (dbs.n == 1) {
            database = xstrdup(dbs.names[0]);
        } else if (svec_contains(&dbs, "Open_vSwitch")) {
            database = xstrdup("Open_vSwitch");
        } else {
            jsonrpc_close(rpc);
            ovs_fatal(0, "no default database for `%s' command, please "
                      "specify a database name", command->name);
        }
        svec_destroy(&dbs);
    } else {
        database = NULL;
    }

    if (argc - optind < command->min_args ||
        argc - optind > command->max_args) {
        free(database);
        VLOG_FATAL("invalid syntax for '%s' (use --help for help)",
                    command->name);
    }

    command->handler(rpc, database, argc - optind, argv + optind);

    free(database);
    jsonrpc_close(rpc);

    if (ferror(stdout)) {
        VLOG_FATAL("write to stdout failed");
    }
    if (ferror(stderr)) {
        VLOG_FATAL("write to stderr failed");
    }

    return 0;
}
コード例 #7
0
entity_t::entity_t()
{
	svec_init(&modelv, 10, sizeof(model_t));
	svec_init(&animv, 10, sizeof(bvh_t));
}
コード例 #8
0
ファイル: inst.cpp プロジェクト: ptytb/blender-scene-renderer
inst_t::inst_t()
{
	svec_init(&vbo_modelv, 1, sizeof(vbo_model_t));
	svec_init(&model_dv, 3, sizeof(model_d_t));
}