1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
|
/*
* cook - file construction tool
* Copyright (C) 1997 Peter Miller;
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
*
* MANIFEST: functions to manipulate dependency graphs
*/
#include <graph.h>
#include <graph/file.h>
#include <graph/file_pair.h>
#include <graph/recipe_list.h>
#include <mem.h>
#include <str_list.h>
#include <symtab.h>
/*
* NAME
* already_reap
*
* SYNOPSIS
* void already_reap(void *);
*
* DESCRIPTION
* The already_reap function is used to delete graph file instances
* when the graph file symbol table is deleted.
*/
static void already_reap _((void *));
static void
already_reap(p)
void *p;
{
graph_file_ty *gfp;
gfp = p;
graph_file_delete(gfp);
}
/*
* NAME
* graph_new
*
* SYNOPSIS
* graph_ty *graph_new(void);
*
* DESCRIPTION
* The graph_new function is used to allocate a new empty file
* dependency graph in dynamic memory.
*
* RETURNS
* graph_ty *
*
* CAVEAT
* Use graph_delete when you are done with it.
*/
graph_ty *
graph_new()
{
graph_ty *gp;
gp = mem_alloc(sizeof(graph_ty));
gp->try_list = 0;
gp->statistic.backtrack_bad_path = 0;
gp->statistic.backtrack_by_ingredient = 0;
gp->statistic.backtrack_cache = 0;
gp->statistic.error_by_ingredient = 0;
gp->statistic.error_cache = 0;
gp->statistic.error_in_expr = 0;
gp->statistic.explicit_applicable = 0;
gp->statistic.explicit_ingredients_applicable = 0;
gp->statistic.explicit_ingredients_not_applicable = 0;
gp->statistic.explicit_not_applicable = 0;
gp->statistic.implicit_applicable = 0;
gp->statistic.implicit_ingredients_applicable = 0;
gp->statistic.implicit_ingredients_not_applicable = 0;
gp->statistic.implicit_not_applicable = 0;
gp->statistic.infinite_loop = 0;
gp->statistic.inhibit_self_recursion = 0;
gp->statistic.leaf_backtrack = 0;
gp->statistic.leaf_error = 0;
gp->statistic.leaf_exists = 0;
gp->statistic.pattern_match_query = 0;
gp->statistic.phony = 0;
gp->statistic.precondition_rejection = 0;
gp->statistic.success = 0;
gp->statistic.success_reuse = 0;
gp->already = symtab_alloc(100);
gp->already->reap = already_reap;
gp->already_recipe = graph_recipe_list_new();
gp->file_pair = 0;
return gp;
}
/*
* NAME
* graph_delete
*
* SYNOPSIS
* void graph_delete(graph_ty *);
*
* DESCRIPTION
* The graph_delete function is used to release resources held by a
* file dependency graph.
*/
void
graph_delete(gp)
graph_ty *gp;
{
if (gp->try_list)
string_list_delete(gp->try_list);
symtab_free(gp->already);
graph_recipe_list_delete(gp->already_recipe);
if (gp->file_pair)
graph_file_pair_delete(gp->file_pair);
mem_free(gp);
}
int
graph_file_leaf_p(gp, filename)
graph_ty *gp;
string_ty *filename;
{
graph_file_ty *gfp;
gfp = symtab_query(gp->already, filename);
if (!gfp)
return -1;
return (gfp->input->nrecipes == 0);
}
static void walk_interior_files _((symtab_ty *, string_ty *, void *, void *));
static void
walk_interior_files(stp, key, data_p, aux_p)
symtab_ty *stp;
string_ty *key;
void *data_p;
void *aux_p;
{
graph_file_ty *gfp;
string_list_ty *result;
gfp = data_p;
result = aux_p;
if (gfp->input->nrecipes != 0)
string_list_append(result, key);
}
void
graph_interior_files(gp, result)
graph_ty *gp;
string_list_ty *result;
{
symtab_walk(gp->already, walk_interior_files, result);
}
static void walk_leaf_files _((symtab_ty *, string_ty *, void *, void *));
static void
walk_leaf_files(stp, key, data_p, aux_p)
symtab_ty *stp;
string_ty *key;
void *data_p;
void *aux_p;
{
graph_file_ty *gfp;
string_list_ty *result;
gfp = data_p;
result = aux_p;
if (gfp->input->nrecipes == 0)
string_list_append(result, key);
}
void
graph_leaf_files(gp, result)
graph_ty *gp;
string_list_ty *result;
{
symtab_walk(gp->already, walk_leaf_files, result);
}
|