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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
|
/*
* cook - file construction tool
* Copyright (C) 1999, 2001 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 values
*/
#include <fingerprint/value.h>
#include <mem.h>
#include <str.h>
#include <trace.h>
/*
* NAME
* fp_value_constructor
*
* SYNOPSIS
* void fp_value_constructor(fp_value_ty *this);
*
* DESCRIPTION
* The fp_value_constructor function is used to initialize a
* fp_value_ty structure to empty.
*/
void
fp_value_constructor(this)
fp_value_ty *this;
{
trace(("fp_value_constructor(this = %08lX)\n{\n", (long)this));
this->oldest = 0;
this->newest = 0;
this->contents_fingerprint = 0;
this->ingredients_fingerprint = 0;
trace(("}\n"));
}
/*
* NAME
* fp_value_constructor_copy
*
* SYNOPSIS
* void fp_value_constructor_copy(void);
*
* DESCRIPTION
* The fp_value_constructor_copy function is used to initialize
* a fp_value_ty structure with a copy of the value of another
* fp_value_ty structure.
*/
void
fp_value_constructor_copy(this, fp)
fp_value_ty *this;
const fp_value_ty *fp;
{
trace(("fp_value_constructor_copy(this = %08lX, fp = %08lX)\n{\n",
(long)this, (long)fp));
this->oldest = fp->oldest;
this->newest = fp->newest;
this->contents_fingerprint =
(
fp->contents_fingerprint
?
str_copy(fp->contents_fingerprint)
:
0
);
this->ingredients_fingerprint =
(
fp->ingredients_fingerprint
?
str_copy(fp->ingredients_fingerprint)
:
0
);
trace(("}\n"));
}
/*
* NAME
* fp_value_constructor3
*
* SYNOPSIS
* void fp_value_constructor3(fp_value_ty *, time_t, time_t, string_ty *);
*
* DESCRIPTION
* The fp_value_constructor3 function is used to initialize a
* fp_value_ty structure with explicit instance variable values.
*/
void
fp_value_constructor3(this, a1, a2, a3)
fp_value_ty *this;
time_t a1;
time_t a2;
string_ty *a3;
{
trace(("fp_value_constructor3(this = %08lX, oldest = %ld, \
youngest = %ld, crypto = \"%s\")\n{\n", (long)this, a1, a2,
(a3 ? a3->str_text : "")));
if (a1 > a2)
a1 = a2;
this->oldest = a1;
this->newest = a2;
this->contents_fingerprint = (a3 ? str_copy(a3) : 0);
this->ingredients_fingerprint = 0;
trace(("}\n"));
}
/*
* NAME
* fp_value_constructor4
*
* SYNOPSIS
* void fp_value_constructor4(fp_value_ty *, time_t, time_t, string_ty *,
* string_ty *);
*
* DESCRIPTION
* The fp_value_constructor4 function is used to initialize a
* fp_value_ty structure with explicit instance variable values.
*/
void
fp_value_constructor4(this, a1, a2, a3, a4)
fp_value_ty *this;
time_t a1;
time_t a2;
string_ty *a3;
string_ty *a4;
{
trace(("fp_value_constructor4(this = %08lX, oldest = %ld, youngest = \
%ld, cfp = \"%s\", ifp = \"%s\")\n{\n",
(long)this, a1, a2, (a3 ? a3->str_text : ""),
(a4 ? a4->str_text : "")));
if (a1 > a2)
a1 = a2;
this->oldest = a1;
this->newest = a2;
this->contents_fingerprint = (a3 ? str_copy(a3) : 0);
this->ingredients_fingerprint = (a4 ? str_copy(a4) : 0);
trace(("}\n"));
}
/*
* NAME
* fp_value_destructor
*
* SYNOPSIS
* void fp_value_destructor(fp_value_ty *);
*
* DESCRIPTION
* The fp_value_destructor function is used to release the resources
* held by a fp_value_ty structure.
*/
void
fp_value_destructor(this)
fp_value_ty *this;
{
trace(("fp_value_destructor(this = %08lX)\n{\n", (long)this));
this->oldest = 0;
this->newest = 0;
if (this->contents_fingerprint)
str_free(this->contents_fingerprint);
this->contents_fingerprint = 0;
if (this->ingredients_fingerprint)
str_free(this->ingredients_fingerprint);
this->ingredients_fingerprint = 0;
trace(("}\n"));
}
/*
* NAME
* fp_value_ty
*
* SYNOPSIS
* void fp_value_ty(void);
*
* DESCRIPTION
* The fp_value_ty function is used to allocate a fp_value_ty
* structure on the heap, and initialize it as empty.
*
* Use fo_value_delete when you are done with it.
*/
fp_value_ty *
fp_value_new()
{
fp_value_ty *this;
trace(("fp_value_new()\n{\n"));
this = mem_alloc(sizeof(fp_value_ty));
fp_value_constructor(this);
trace(("return %08lX;\n", (long)this));
trace(("}\n"));
return this;
}
/*
* NAME
* fp_value_delete
*
* SYNOPSIS
* void fp_value_delete(void);
*
* DESCRIPTION
* The fp_value_delete function is used to release the resources
* held by a fp_vaolue_ty structure on the heap.
*/
void
fp_value_delete(this)
fp_value_ty *this;
{
trace(("fp_value_delete(this = %08lX)\n{\n", (long)this));
fp_value_destructor(this);
mem_free(this);
trace(("}\n"));
}
/*
* NAME
* fp_value_copy
*
* SYNOPSIS
* void fp_value_copy(void);
*
* DESCRIPTION
* The fp_value_copy function is used to copy the value of one
* fp_value_ty structure into another, releasing relaced resourecs
* as appropriate.
*/
void
fp_value_copy(to, from)
fp_value_ty *to;
const fp_value_ty *from;
{
trace(("fp_value_copy(to = %08lX, from = %08lX)\n{\n",
(long)to, (long)from));
if (from == to)
{
trace(("}\n"));
return;
}
to->newest = from->newest;
to->oldest = from->oldest;
if (to->contents_fingerprint)
str_free(to->contents_fingerprint);
if (from->contents_fingerprint)
to->contents_fingerprint = str_copy(from->contents_fingerprint);
else
to->contents_fingerprint = 0;
if (to->ingredients_fingerprint)
str_free(to->ingredients_fingerprint);
if (from->ingredients_fingerprint)
to->ingredients_fingerprint =
str_copy(from->ingredients_fingerprint);
else
to->ingredients_fingerprint = 0;
trace(("}\n"));
}
/*
* NAME
* fp_value_write
*
* SYNOPSIS
* void fp_value_write(fp_value_ty *this, string_ty *key, FILE *fp);
*
* DESCRIPTION
* The fp_value_write function is used to write a fp_value_ty
* structure into an on-disk fingerprint cache file.
*
* It will not be printed if it is empty.
*/
void
fp_value_write(this, key, fp)
fp_value_ty *this;
string_ty *key;
FILE *fp;
{
if (!this->contents_fingerprint && !this->ingredients_fingerprint)
return;
trace(("fp_value_write(this = %08lX, key = \"%s\", fp = %08lX)\n{\n",
(long)this, key->str_text, (long)fp));
fprintf(fp, "\"%s\" = { %ld", key->str_text, (long)this->oldest);
if (this->oldest < this->newest)
fprintf(fp, " %ld", (long)this->newest);
fprintf
(
fp,
"\n\"%s\"",
(
this->contents_fingerprint
?
this->contents_fingerprint->str_text
:
""
)
);
if (this->ingredients_fingerprint)
{
fprintf
(
fp,
"\n\"%s\"",
this->ingredients_fingerprint->str_text
);
}
fprintf(fp, " }\n");
trace(("}\n"));
}
/*
* NAME
* fp_value_equal
*
* SYNOPSIS
* void fp_value_equal(void);
*
* DESCRIPTION
* The fp_value_equal function is used to compare two fp_value_ty
* structures for equality.
*
* The ingredients_fingerprint is not compared. This is because
* the principal use of this function is to determine if a file
* has changed.
*
* RETURNS
* int; zero if they are not equal, non-zero if they are equal.
*/
int
fp_value_equal(v1, v2)
const fp_value_ty *v1;
const fp_value_ty *v2;
{
/* DON'T compare the ingredients FP */
return
(
str_equal(v1->contents_fingerprint, v2->contents_fingerprint)
&&
v1->newest == v2->newest
&&
v1->oldest == v2->oldest
);
}
/*
* NAME
* fp_value_equal_all
*
* SYNOPSIS
* void fp_value_equal_all(void);
*
* DESCRIPTION
* The fp_value_equal_all function is used to compare two fp_value_ty
* structures for equality. The principal use of this function is to
* determine if the fingerprint cache has changed and needs writing.
*
* RETURNS
* int; zero if they are not equal, non-zero if they are equal.
*/
int
fp_value_equal_all(v1, v2)
const fp_value_ty *v1;
const fp_value_ty *v2;
{
return
(
str_equal(v1->contents_fingerprint, v2->contents_fingerprint)
&&
str_equal(v1->ingredients_fingerprint,
v2->ingredients_fingerprint)
&&
v1->newest == v2->newest
&&
v1->oldest == v2->oldest
);
}
|