示例#1
0
文件: main.c 项目: nanomsg/topologist
static void run_service(struct cfg_main *cfg) {
    struct errbuf err;
    struct graph *g = graph_build(cfg, &err);
    if(!g) {
        fprintf(stderr, "topology: Not enough memory to build graph");
        exit(1);
    }
    if(!err.empty) {
        err_print(&err, stderr);
        if(err.fatal) {
            graph_free(g);
            exit(1);
        }
    }

    topologist_loop(cfg, g);
}
示例#2
0
文件: cando.c 项目: cglinden/autocook
static int
interpret(string_list_ty *result, const string_list_ty *args,
    const struct expr_position_ty *pp, const struct opcode_context_ty *ocp)
{
    size_t          j;
    int             retval;
    graph_ty        *gp;

    (void)pp;
    (void)ocp;
    if (args->nstrings <= 1)
        return 0;

    /*
     * set interrupts to catch
     *
     * Note that tee(1) [see listing.c] must ignore them
     * for the generated messages to appear in the log file.
     */
    trace(("cando\n"));
    assert(result);
    assert(args);
    assert(args->nstrings);
    retval = 0;
    desist_enable();

    /*
     * build the graph
     */
    gp = graph_new();
    for (j = 1; j < args->nstrings; ++j)
    {
        graph_build_status_ty gb_status;

        /*
         * Build the dependency graph.
         */
        gb_status =
            graph_build
            (
                gp,
                args->string[j],
                graph_build_preference_backtrack,
                0
            );

        /*
         * it is only relevant that we know how to build this
         * graph, not that we walk it.
         */
        switch (gb_status)
        {
        case graph_build_status_error:
            retval = -1;
            break;

        case graph_build_status_backtrack:
            break;

        case graph_build_status_success:
            string_list_append(result, args->string[j]);
            break;
        }
    }

    /*
     * Release resources held by the graph.
     */
    if (option_test(OPTION_REASON))
        graph_print_statistics(gp);
    graph_delete(gp);
    return retval;
}
示例#3
0
文件: cook.c 项目: cglinden/autocook
static int
interpret(string_list_ty *result, const string_list_ty *args,
    const struct expr_position_ty *pp, const struct opcode_context_ty *ocp)
{
    size_t          j;
    int             retval;
    graph_ty        *gp;
    graph_build_status_ty gb_status;
    graph_walk_status_ty gw_status;

    trace(("cook\n"));
    (void)pp;
    (void)ocp;
    assert(result);
    assert(args);
    assert(args->nstrings);
    if (args->nstrings <= 1)
        return 0;

    /*
     * set interrupts to catch
     *
     * Note that tee(1) [see listing.c] must ignore them
     * for the generated messages to appear in the log file.
     */
    desist_enable();

    /*
     * Build the dependency graph.
     */
    retval = 0;
    gp = graph_new();
    for (j = 1; j < args->nstrings; ++j)
    {
        gb_status =
            graph_build
            (
                gp,
                args->string[j],
                graph_build_preference_backtrack,
                0
            );
        switch (gb_status)
        {
        case graph_build_status_error:
            retval = -1;
            break;

        case graph_build_status_backtrack:
            break;

        case graph_build_status_success:
            string_list_append(result, args->string[j]);
            break;
        }
    }

    /*
     * Walk the dependency graph.
     */
    if (retval >= 0)
    {
        if (option_test(OPTION_REASON))
            graph_print_statistics(gp);
        gw_status = graph_walk(gp);
        switch (gw_status)
        {
        case graph_walk_status_uptodate:
        case graph_walk_status_uptodate_done:
        case graph_walk_status_done:
            break;

        case graph_walk_status_done_stop:
        case graph_walk_status_wait:
            assert(0);
            /* fall through... */

        case graph_walk_status_error:
            retval = -1;
            break;
        }
    }

    /*
     * Release resources held by the graph.
     */
    graph_delete(gp);
    return retval;
}