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
|
/*
* -= Copyright 2005 Tim Baker (treectrl@hotmail.com) =-
*
* This file is part of depslib.
*
* License is hereby granted to use this software and distribute it
* freely, as long as this copyright notice is retained and modifications
* are clearly marked.
*
* ALL WARRANTIES ARE HEREBY DISCLAIMED.
*/
#include "depslib.h"
#include "jam.h"
#include "hash.h"
#include "lists.h"
#include "headers.h"
#include "newstr.h"
#include "pathsys.h"
#include "pathsplit.h"
#include "search.h"
#include "timestamp.h"
#ifdef USE_CACHE
#include "cache.h"
#endif
struct depsStats g_stats;
#define DEPS_STATE_INIT 0x0001
#define DEPS_STATE_DONE 0x0002
#define DEPS_STATE_SEARCH 0x0004
static int g_state = 0;
static int inState(int state)
{
return (g_state & state) == state;
}
static int s_error = 0;
static void setErr(int error)
{
s_error = error;
}
void depsStart(void)
{
if (inState(DEPS_STATE_INIT))
{
setErr(DEPS_ERROR_ALREADY_INIT);
return;
}
setErr(0);
memset((char *) &g_stats, 0, sizeof(g_stats));
g_state |= DEPS_STATE_INIT;
}
void depsSetCWD(const char *cwd)
{
if (!inState(DEPS_STATE_INIT))
{
setErr(DEPS_ERROR_NOT_INIT);
return;
}
setErr(0);
path_setcwd(cwd);
}
void depsSearchStart(void)
{
if (!inState(DEPS_STATE_INIT))
{
setErr(DEPS_ERROR_NOT_INIT);
return;
}
search_init();
g_state |= DEPS_STATE_SEARCH;
setErr(0);
}
void depsAddSearchDir(const char *path)
{
if (!inState(DEPS_STATE_INIT | DEPS_STATE_SEARCH))
{
if (!inState(DEPS_STATE_SEARCH)) setErr(DEPS_ERROR_NOT_SEARCH);
if (!inState(DEPS_STATE_INIT)) setErr(DEPS_ERROR_NOT_INIT);
return;
}
setErr(0);
search_adddir(path);
}
depsRef depsScanForHeaders(const char *path)
{
PATHSPLIT f;
char buf[MAXJPATH];
time_t time;
HEADER *h;
if (!inState(DEPS_STATE_INIT | DEPS_STATE_SEARCH))
{
if (!inState(DEPS_STATE_SEARCH)) setErr(DEPS_ERROR_NOT_SEARCH);
if (!inState(DEPS_STATE_INIT)) setErr(DEPS_ERROR_NOT_INIT);
return NULL;
}
setErr(0);
path_split(path, &f);
path_normalize(&f, NULL);
path_tostring(&f, buf);
timestamp(buf, &time);
if (!time)
return NULL;
h = headers(buf, time);
return (depsRef) h;
}
const char *depsGetNewest(depsRef ref, time_t *time)
{
HEADER *h = (HEADER * )ref;
headernewest(h);
*time = h->newest->time;
return h->newest->key;
}
void depsTimeStamp(const char *path, time_t *time)
{
PATHSPLIT f;
char buf[MAXJPATH];
if (!inState(DEPS_STATE_INIT))
{
setErr(DEPS_ERROR_NOT_INIT);
return;
}
setErr(0);
path_split(path, &f);
path_normalize(&f, NULL);
path_tostring(&f, buf);
timestamp(buf, time);
}
void depsGetStats(struct depsStats *stats)
{
if (!inState(DEPS_STATE_INIT))
{
setErr(DEPS_ERROR_NOT_INIT);
return;
}
setErr(0);
*stats = g_stats;
}
void depsCacheRead(const char *path)
{
#ifdef USE_CACHE
cache_read(path);
#endif
}
void depsCacheWrite(const char *path)
{
#ifdef USE_CACHE
cache_write(path);
#endif
}
void depsDone(void)
{
if (!inState(DEPS_STATE_INIT))
{
setErr(DEPS_ERROR_NOT_INIT);
return;
}
setErr(0);
donestamps();
donestr();
donelist();
donehdrs();
donesearch();
donepath();
#ifdef USE_CACHE
donecache();
#endif
g_state = DEPS_STATE_DONE;
}
int depsError(void)
{
return s_error;
}
|