| 1 |
#include "pconf.h" |
| 2 |
|
| 3 |
|
| 4 |
static int PConfEnableFeature( |
| 5 |
pconf_core_struct *core_ptr, platform_struct *platform_ptr, |
| 6 |
const char *name |
| 7 |
); |
| 8 |
static int PConfDisableFeature( |
| 9 |
pconf_core_struct *core_ptr, platform_struct *platform_ptr, |
| 10 |
const char *name |
| 11 |
); |
| 12 |
void PConfApplyArgsToPlatform( |
| 13 |
pconf_core_struct *core_ptr, platform_struct *platform_ptr, |
| 14 |
int argc, char *argv[] |
| 15 |
); |
| 16 |
|
| 17 |
static int PConfScanFileString( |
| 18 |
const char *filename, const char *s |
| 19 |
); |
| 20 |
static char *PConfDependMatchFile( |
| 21 |
platform_struct *platform_ptr, int type, const char *path, |
| 22 |
struct stat *stat_buf |
| 23 |
); |
| 24 |
static int PConfDependCheck( |
| 25 |
pconf_core_struct *core_ptr, |
| 26 |
platform_struct *platform_ptr, depend_struct *depend_ptr, |
| 27 |
const char *feature_name, |
| 28 |
int dep_cur, int dep_total |
| 29 |
); |
| 30 |
int PConfCheckDepends( |
| 31 |
pconf_core_struct *core_ptr, platform_struct *platform_ptr |
| 32 |
); |
| 33 |
|
| 34 |
|
| 35 |
/* |
| 36 |
* Enables the feature on the given platform specified by name, |
| 37 |
* marking its must_exist value to PCONF_MUST_EXIST_YES. |
| 38 |
* |
| 39 |
* Returns 0 on success, -1 on error, -2 no such feature. |
| 40 |
*/ |
| 41 |
static int PConfEnableFeature( |
| 42 |
pconf_core_struct *core_ptr, platform_struct *platform_ptr, |
| 43 |
const char *name |
| 44 |
) |
| 45 |
{ |
| 46 |
int feature_num; |
| 47 |
feature_struct *feature_ptr; |
| 48 |
|
| 49 |
if((core_ptr == NULL) || (platform_ptr == NULL) || (name == NULL)) |
| 50 |
return(-1); |
| 51 |
|
| 52 |
feature_ptr = PConfMatchFeatureByName( |
| 53 |
platform_ptr, name, &feature_num |
| 54 |
); |
| 55 |
if(feature_ptr == NULL) |
| 56 |
return(-2); |
| 57 |
|
| 58 |
feature_ptr->must_exist = PCONF_MUST_EXIST_YES; |
| 59 |
|
| 60 |
return(0); |
| 61 |
} |
| 62 |
|
| 63 |
/* |
| 64 |
* Disables the feature on the given platform specified by name, |
| 65 |
* marking its must_exist value to PCONF_MUST_EXIST_NO. |
| 66 |
* |
| 67 |
* Returns 0 on success, -1 on error, -2 no such feature, -3 |
| 68 |
* if the feature's must_exist was initially PCONF_MUST_EXIST_YES. |
| 69 |
*/ |
| 70 |
static int PConfDisableFeature( |
| 71 |
pconf_core_struct *core_ptr, platform_struct *platform_ptr, |
| 72 |
const char *name |
| 73 |
) |
| 74 |
{ |
| 75 |
int feature_num; |
| 76 |
feature_struct *feature_ptr; |
| 77 |
|
| 78 |
if((core_ptr == NULL) || (platform_ptr == NULL) || (name == NULL)) |
| 79 |
return(-1); |
| 80 |
|
| 81 |
feature_ptr = PConfMatchFeatureByName( |
| 82 |
platform_ptr, name, &feature_num |
| 83 |
); |
| 84 |
if(feature_ptr == NULL) |
| 85 |
return(-2); |
| 86 |
|
| 87 |
/* Cannot disable this? */ |
| 88 |
if(feature_ptr->must_exist == PCONF_MUST_EXIST_YES) |
| 89 |
return(-3); |
| 90 |
|
| 91 |
feature_ptr->must_exist = PCONF_MUST_EXIST_NO; |
| 92 |
|
| 93 |
return(0); |
| 94 |
} |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
/* |
| 99 |
* Applies environments and given arguments to the given platform's |
| 100 |
* values. |
| 101 |
*/ |
| 102 |
void PConfApplyArgsToPlatform( |
| 103 |
pconf_core_struct *core_ptr, platform_struct *platform_ptr, |
| 104 |
int argc, char *argv[] |
| 105 |
) |
| 106 |
{ |
| 107 |
int i, status; |
| 108 |
const char *arg_ptr; |
| 109 |
|
| 110 |
if((core_ptr == NULL) || (platform_ptr == NULL)) |
| 111 |
return; |
| 112 |
|
| 113 |
/* Can we initially get values from environment variables? */ |
| 114 |
if(!core_ptr->ignore_environments) |
| 115 |
{ |
| 116 |
const char *cstrptr; |
| 117 |
|
| 118 |
/* Prefix. */ |
| 119 |
cstrptr = GETENV("PREFIX"); |
| 120 |
if(cstrptr != NULL) |
| 121 |
{ |
| 122 |
FREE(platform_ptr->prefix); |
| 123 |
platform_ptr->prefix = STRDUP(cstrptr); |
| 124 |
} |
| 125 |
/* Compiler flags. */ |
| 126 |
cstrptr = GETENV("CFLAGS"); |
| 127 |
if(cstrptr != NULL) |
| 128 |
{ |
| 129 |
FREE(platform_ptr->cflags); |
| 130 |
platform_ptr->cflags = STRDUP(cstrptr); |
| 131 |
} |
| 132 |
/* Include directories. */ |
| 133 |
cstrptr = GETENV("INC_DIRS"); |
| 134 |
if(cstrptr != NULL) |
| 135 |
{ |
| 136 |
FREE(platform_ptr->inc_dirs); |
| 137 |
platform_ptr->inc_dirs = STRDUP(cstrptr); |
| 138 |
} |
| 139 |
/* Libraries. */ |
| 140 |
cstrptr = GETENV("LIBS"); |
| 141 |
if(cstrptr != NULL) |
| 142 |
{ |
| 143 |
FREE(platform_ptr->libs); |
| 144 |
platform_ptr->libs = STRDUP(cstrptr); |
| 145 |
} |
| 146 |
/* Library directories. */ |
| 147 |
cstrptr = GETENV("LIB_DIRS"); |
| 148 |
if(cstrptr != NULL) |
| 149 |
{ |
| 150 |
FREE(platform_ptr->lib_dirs); |
| 151 |
platform_ptr->lib_dirs = STRDUP(cstrptr); |
| 152 |
} |
| 153 |
/* C compiler. */ |
| 154 |
cstrptr = GETENV("CC"); |
| 155 |
if(cstrptr != NULL) |
| 156 |
{ |
| 157 |
FREE(platform_ptr->cc); |
| 158 |
platform_ptr->cc = STRDUP(cstrptr); |
| 159 |
} |
| 160 |
/* C++ compiler. */ |
| 161 |
cstrptr = GETENV("CPP"); |
| 162 |
if(cstrptr != NULL) |
| 163 |
{ |
| 164 |
FREE(platform_ptr->cpp); |
| 165 |
platform_ptr->cpp = STRDUP(cstrptr); |
| 166 |
} |
| 167 |
/* Parse LD library paths. */ |
| 168 |
cstrptr = GETENV("LD_LIBRARY_PATH"); |
| 169 |
if(cstrptr != NULL) |
| 170 |
{ |
| 171 |
char *new_path, *strptr2; |
| 172 |
|
| 173 |
/* Itterate through value string. */ |
| 174 |
while((*cstrptr) != '\0') |
| 175 |
{ |
| 176 |
/* Seek past ' ' and ':' characters. */ |
| 177 |
while(ISBLANK(*cstrptr) || ((*cstrptr) == ':')) |
| 178 |
cstrptr++; |
| 179 |
|
| 180 |
/* Skip "-L" prefixes. */ |
| 181 |
if(STRPFX(cstrptr, "-L")) |
| 182 |
{ |
| 183 |
cstrptr += STRLEN("-L"); |
| 184 |
} |
| 185 |
|
| 186 |
/* Copy string at position of cstrptr. */ |
| 187 |
new_path = STRDUP(cstrptr); |
| 188 |
if(new_path != NULL) |
| 189 |
{ |
| 190 |
/* Deliminate at next ' ' or ':' if any. */ |
| 191 |
strptr2 = (char *)STRCHR((char *)new_path, ':'); |
| 192 |
if(strptr2 != NULL) |
| 193 |
(*strptr2) = '\0'; |
| 194 |
strptr2 = (char *)STRCHR((char *)new_path, ' '); |
| 195 |
if(strptr2 != NULL) |
| 196 |
(*strptr2) = '\0'; |
| 197 |
|
| 198 |
/* Add this to the library path. */ |
| 199 |
STRLISTAPPEND( |
| 200 |
&platform_ptr->path_library, |
| 201 |
&platform_ptr->total_path_libraries, |
| 202 |
new_path |
| 203 |
); |
| 204 |
|
| 205 |
if(core_ptr->verbose) |
| 206 |
printf( |
| 207 |
"Adding platform's library path: %s\n", |
| 208 |
new_path |
| 209 |
); |
| 210 |
|
| 211 |
|
| 212 |
FREE(new_path); |
| 213 |
new_path = NULL; |
| 214 |
} |
| 215 |
|
| 216 |
/* Seek cstrptr to next argument, seeking to |
| 217 |
* next ' ' or ':' character. |
| 218 |
*/ |
| 219 |
while(!ISBLANK(*cstrptr) && ((*cstrptr) != ':') && |
| 220 |
((*cstrptr) != '\0') |
| 221 |
) |
| 222 |
cstrptr++; |
| 223 |
} |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
/* Itterate through each argument. */ |
| 228 |
for(i = 0; i < argc; i++) |
| 229 |
{ |
| 230 |
arg_ptr = (const char *)argv[i]; |
| 231 |
if(arg_ptr == NULL) |
| 232 |
continue; |
| 233 |
|
| 234 |
/* Skip any args that don't begin with - or --. */ |
| 235 |
if((*arg_ptr) != '-') |
| 236 |
continue; |
| 237 |
/* Seek past '-' characters. */ |
| 238 |
while((*arg_ptr) == '-') |
| 239 |
arg_ptr++; |
| 240 |
|
| 241 |
/* Enable or with? */ |
| 242 |
if(STRCASEPFX(arg_ptr, "enable") || |
| 243 |
STRCASEPFX(arg_ptr, "with") |
| 244 |
) |
| 245 |
{ |
| 246 |
/* Enable what? */ |
| 247 |
const char *cstrptr = STRCHR(arg_ptr, '='); |
| 248 |
if(cstrptr == NULL) |
| 249 |
cstrptr = STRCHR(arg_ptr, '-'); |
| 250 |
if(cstrptr != NULL) |
| 251 |
{ |
| 252 |
cstrptr++; |
| 253 |
while(ISBLANK(*cstrptr)) |
| 254 |
cstrptr++; |
| 255 |
|
| 256 |
status = PConfEnableFeature( |
| 257 |
core_ptr, platform_ptr, cstrptr |
| 258 |
); |
| 259 |
switch(status) |
| 260 |
{ |
| 261 |
case -2: |
| 262 |
if(core_ptr->warnings) |
| 263 |
{ |
| 264 |
fprintf(stderr, "%s: ", cstrptr); |
| 265 |
PConfSetColor(core_ptr, stderr, |
| 266 |
PCONF_COLOR_WARNING |
| 267 |
); |
| 268 |
fprintf(stderr, |
| 269 |
"No such feature to enable.\n" |
| 270 |
); |
| 271 |
} |
| 272 |
break; |
| 273 |
case -1: |
| 274 |
if(core_ptr->warnings) |
| 275 |
{ |
| 276 |
fprintf(stderr, "%s: ", cstrptr); |
| 277 |
PConfSetColor(core_ptr, stderr, |
| 278 |
PCONF_COLOR_FAILURE |
| 279 |
); |
| 280 |
fprintf(stderr, |
| 281 |
"Error enabling this feature.\n" |
| 282 |
); |
| 283 |
} |
| 284 |
break; |
| 285 |
} |
| 286 |
PConfSetColor(core_ptr, stderr, |
| 287 |
PCONF_COLOR_DEFAULT |
| 288 |
); |
| 289 |
} |
| 290 |
else |
| 291 |
{ |
| 292 |
if(core_ptr->warnings) |
| 293 |
fprintf( |
| 294 |
stderr, |
| 295 |
"--%s: Argument must have a value separated by a '='.\n", |
| 296 |
arg_ptr |
| 297 |
); |
| 298 |
} |
| 299 |
} |
| 300 |
/* Disable or without? */ |
| 301 |
else if(STRCASEPFX(arg_ptr, "disable") || |
| 302 |
STRCASEPFX(arg_ptr, "without") || |
| 303 |
STRCASEPFX(arg_ptr, "with-out") || |
| 304 |
STRCASEPFX(arg_ptr, "with_out") |
| 305 |
) |
| 306 |
{ |
| 307 |
/* Disable what? */ |
| 308 |
const char *cstrptr = STRCHR(arg_ptr, '='); |
| 309 |
if(cstrptr == NULL) |
| 310 |
cstrptr = STRCHR(arg_ptr, '-'); |
| 311 |
if(cstrptr != NULL) |
| 312 |
{ |
| 313 |
cstrptr++; |
| 314 |
while(ISBLANK(*cstrptr)) |
| 315 |
cstrptr++; |
| 316 |
|
| 317 |
status = PConfDisableFeature( |
| 318 |
core_ptr, platform_ptr, cstrptr |
| 319 |
); |
| 320 |
switch(status) |
| 321 |
{ |
| 322 |
case -3: |
| 323 |
if(core_ptr->warnings) |
| 324 |
{ |
| 325 |
fprintf(stderr, "%s: ", cstrptr); |
| 326 |
PConfSetColor(core_ptr, stderr, |
| 327 |
PCONF_COLOR_FAILURE |
| 328 |
); |
| 329 |
fprintf( |
| 330 |
stderr, |
| 331 |
"This feature is not allowed to be disabled.\n" |
| 332 |
); |
| 333 |
} |
| 334 |
break; |
| 335 |
|
| 336 |
case -2: |
| 337 |
if(core_ptr->warnings) |
| 338 |
{ |
| 339 |
fprintf(stderr, "%s: ", cstrptr); |
| 340 |
PConfSetColor(core_ptr, stderr, |
| 341 |
PCONF_COLOR_WARNING |
| 342 |
); |
| 343 |
fprintf( |
| 344 |
stderr, |
| 345 |
"No such feature to disable.\n" |
| 346 |
); |
| 347 |
} |
| 348 |
break; |
| 349 |
|
| 350 |
case -1: |
| 351 |
fprintf(stderr, "%s: ", cstrptr); |
| 352 |
PConfSetColor(core_ptr, stderr, |
| 353 |
PCONF_COLOR_FAILURE |
| 354 |
); |
| 355 |
fprintf( |
| 356 |
stderr, |
| 357 |
"Error encountered while attempting to disable feature.\n" |
| 358 |
); |
| 359 |
break; |
| 360 |
} |
| 361 |
PConfSetColor(core_ptr, stderr, |
| 362 |
PCONF_COLOR_DEFAULT |
| 363 |
); |
| 364 |
} |
| 365 |
else |
| 366 |
{ |
| 367 |
if(core_ptr->warnings) |
| 368 |
fprintf( |
| 369 |
stderr, |
| 370 |
"--%s: Argument must have a value separated by a '=' or '-' character.\n", |
| 371 |
arg_ptr |
| 372 |
); |
| 373 |
} |
| 374 |
} |
| 375 |
/* Platform PREFIX? */ |
| 376 |
else if(STRCASEPFX(arg_ptr, "PREFIX") || |
| 377 |
STRCASEPFX(arg_ptr, "PlatformPREFIX") |
| 378 |
) |
| 379 |
{ |
| 380 |
const char *cstrptr = STRCHR(arg_ptr, '='); |
| 381 |
if(cstrptr != NULL) |
| 382 |
{ |
| 383 |
cstrptr++; |
| 384 |
while(ISBLANK(*cstrptr)) |
| 385 |
cstrptr++; |
| 386 |
|
| 387 |
FREE(platform_ptr->prefix); |
| 388 |
platform_ptr->prefix = STRDUP(cstrptr); |
| 389 |
} |
| 390 |
else |
| 391 |
{ |
| 392 |
if(core_ptr->warnings) |
| 393 |
fprintf( |
| 394 |
stderr, |
| 395 |
"--%s: Argument must have a value separated by a '='.\n", |
| 396 |
arg_ptr |
| 397 |
); |
| 398 |
} |
| 399 |
} |
| 400 |
/* Platform CFLAGS? */ |
| 401 |
else if(STRCASEPFX(arg_ptr, "CFLAGS") || |
| 402 |
STRCASEPFX(arg_ptr, "PlatformCFLAGS") |
| 403 |
) |
| 404 |
{ |
| 405 |
const char *cstrptr = STRCHR(arg_ptr, '='); |
| 406 |
if(cstrptr != NULL) |
| 407 |
{ |
| 408 |
cstrptr++; |
| 409 |
while(ISBLANK(*cstrptr)) |
| 410 |
cstrptr++; |
| 411 |
|
| 412 |
FREE(platform_ptr->cflags); |
| 413 |
platform_ptr->cflags = STRDUP(cstrptr); |
| 414 |
} |
| 415 |
else |
| 416 |
{ |
| 417 |
if(core_ptr->warnings) |
| 418 |
fprintf( |
| 419 |
stderr, |
| 420 |
"--%s: Argument must have a value separated by a '='.\n", |
| 421 |
arg_ptr |
| 422 |
); |
| 423 |
} |
| 424 |
} |
| 425 |
/* Platform INC_DIRS? */ |
| 426 |
else if(STRCASEPFX(arg_ptr, "INC_DIRS") || |
| 427 |
STRCASEPFX(arg_ptr, "PlatformINC_DIRS") || |
| 428 |
STRCASEPFX(arg_ptr, "INCDIRS") || |
| 429 |
STRCASEPFX(arg_ptr, "PlatformINCDIRS") || |
| 430 |
STRCASEPFX(arg_ptr, "INC_DIR") || |
| 431 |
STRCASEPFX(arg_ptr, "PlatformINC_DIR") || |
| 432 |
STRCASEPFX(arg_ptr, "INCDIR") || |
| 433 |
STRCASEPFX(arg_ptr, "PlatformINCDIR") |
| 434 |
) |
| 435 |
{ |
| 436 |
const char *cstrptr = STRCHR(arg_ptr, '='); |
| 437 |
if(cstrptr != NULL) |
| 438 |
{ |
| 439 |
cstrptr++; |
| 440 |
while(ISBLANK(*cstrptr)) |
| 441 |
cstrptr++; |
| 442 |
|
| 443 |
FREE(platform_ptr->inc_dirs); |
| 444 |
platform_ptr->inc_dirs = STRDUP(cstrptr); |
| 445 |
} |
| 446 |
else |
| 447 |
{ |
| 448 |
if(core_ptr->warnings) |
| 449 |
fprintf( |
| 450 |
stderr, |
| 451 |
"--%s: Argument must have a value separated by a '='.\n", |
| 452 |
arg_ptr |
| 453 |
); |
| 454 |
} |
| 455 |
} |
| 456 |
/* Platform LIBS? */ |
| 457 |
else if(STRCASEPFX(arg_ptr, "LIBS") || |
| 458 |
STRCASEPFX(arg_ptr, "PlatformLIBS") |
| 459 |
) |
| 460 |
{ |
| 461 |
const char *cstrptr = STRCHR(arg_ptr, '='); |
| 462 |
if(cstrptr != NULL) |
| 463 |
{ |
| 464 |
cstrptr++; |
| 465 |
while(ISBLANK(*cstrptr)) |
| 466 |
cstrptr++; |
| 467 |
|
| 468 |
FREE(platform_ptr->libs); |
| 469 |
platform_ptr->libs = STRDUP(cstrptr); |
| 470 |
} |
| 471 |
else |
| 472 |
{ |
| 473 |
if(core_ptr->warnings) |
| 474 |
fprintf( |
| 475 |
stderr, |
| 476 |
"--%s: Argument must have a value separated by a '='.\n", |
| 477 |
arg_ptr |
| 478 |
); |
| 479 |
} |
| 480 |
} |
| 481 |
/* Platform LIB_DIRS? */ |
| 482 |
else if(STRCASEPFX(arg_ptr, "LIB_DIRS") || |
| 483 |
STRCASEPFX(arg_ptr, "PlatformLIB_DIRS") || |
| 484 |
STRCASEPFX(arg_ptr, "LIBDIRS") || |
| 485 |
STRCASEPFX(arg_ptr, "PlatformLIBDIRS") || |
| 486 |
STRCASEPFX(arg_ptr, "LIB_DIR") || |
| 487 |
STRCASEPFX(arg_ptr, "PlatformLIB_DIR") || |
| 488 |
STRCASEPFX(arg_ptr, "LIBDIR") || |
| 489 |
STRCASEPFX(arg_ptr, "PlatformLIBDIR") |
| 490 |
) |
| 491 |
{ |
| 492 |
const char *cstrptr = STRCHR(arg_ptr, '='); |
| 493 |
if(cstrptr != NULL) |
| 494 |
{ |
| 495 |
cstrptr++; |
| 496 |
while(ISBLANK(*cstrptr)) |
| 497 |
cstrptr++; |
| 498 |
|
| 499 |
FREE(platform_ptr->lib_dirs); |
| 500 |
platform_ptr->lib_dirs = STRDUP(cstrptr); |
| 501 |
} |
| 502 |
else |
| 503 |
{ |
| 504 |
if(core_ptr->warnings) |
| 505 |
fprintf( |
| 506 |
stderr, |
| 507 |
"--%s: Argument must have a value separated by a '='.\n", |
| 508 |
arg_ptr |
| 509 |
); |
| 510 |
} |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
return; |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
/* |
| 519 |
* Opens the file for reading and returns the number of occurances of |
| 520 |
* s found in the file. File must be a regular file. |
| 521 |
*/ |
| 522 |
static int PConfScanFileString( |
| 523 |
const char *filename, const char *s |
| 524 |
) |
| 525 |
{ |
| 526 |
int c, matches = 0; |
| 527 |
FILE *fp; |
| 528 |
|
| 529 |
if((filename == NULL) || (s == NULL)) |
| 530 |
return(matches); |
| 531 |
|
| 532 |
if((*s) == '\0') |
| 533 |
return(matches); |
| 534 |
|
| 535 |
|
| 536 |
fp = FOPEN(filename, "rb"); |
| 537 |
if(fp == NULL) |
| 538 |
return(matches); |
| 539 |
|
| 540 |
do |
| 541 |
{ |
| 542 |
c = FGETC(fp); |
| 543 |
if(c == EOF) |
| 544 |
break; |
| 545 |
|
| 546 |
/* Got start of matching string? */ |
| 547 |
if(c == (*s)) |
| 548 |
{ |
| 549 |
/* Get next character and match string position. */ |
| 550 |
const char *sp = s + 1; |
| 551 |
c = FGETC(fp); |
| 552 |
|
| 553 |
/* Itterate sp. */ |
| 554 |
while((*sp) != '\0') |
| 555 |
{ |
| 556 |
if(((*sp) != c) || (c == EOF)) |
| 557 |
break; |
| 558 |
|
| 559 |
sp++; |
| 560 |
c = FGETC(fp); |
| 561 |
} |
| 562 |
|
| 563 |
/* Got a match if sp itterated to end. */ |
| 564 |
if((*sp) == '\0') |
| 565 |
matches++; |
| 566 |
} |
| 567 |
|
| 568 |
} while(1); |
| 569 |
|
| 570 |
|
| 571 |
FCLOSE(fp); |
| 572 |
|
| 573 |
return(matches); |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
/* |
| 578 |
* Itterates through a list of paths on the given platform |
| 579 |
* structure and matches each one with the given path. |
| 580 |
* |
| 581 |
* Type specifies the depend type, one of PCONF_DEP_TYPE_*. |
| 582 |
* |
| 583 |
* On success, returns a dynamically allocated full path with |
| 584 |
* must be deallocated by the calling function. Can return NULL on |
| 585 |
* error. |
| 586 |
*/ |
| 587 |
static char *PConfDependMatchFile( |
| 588 |
platform_struct *platform_ptr, int type, const char *path, |
| 589 |
struct stat *stat_buf |
| 590 |
) |
| 591 |
{ |
| 592 |
int i, len1, len2; |
| 593 |
char *base_path, *new_path; |
| 594 |
char **path_list = NULL; |
| 595 |
int total_paths = 0; |
| 596 |
|
| 597 |
|
| 598 |
if((platform_ptr == NULL) || (path == NULL)) |
| 599 |
return(NULL); |
| 600 |
|
| 601 |
switch(type) |
| 602 |
{ |
| 603 |
case PCONF_DEP_TYPE_PROGRAM: |
| 604 |
path_list = platform_ptr->path_program; |
| 605 |
total_paths = platform_ptr->total_path_programs; |
| 606 |
break; |
| 607 |
case PCONF_DEP_TYPE_HEADER: |
| 608 |
path_list = platform_ptr->path_header; |
| 609 |
total_paths = platform_ptr->total_path_headers; |
| 610 |
break; |
| 611 |
case PCONF_DEP_TYPE_LIBRARY: |
| 612 |
path_list = platform_ptr->path_library; |
| 613 |
total_paths = platform_ptr->total_path_libraries; |
| 614 |
break; |
| 615 |
case PCONF_DEP_TYPE_CONFIG: |
| 616 |
path_list = platform_ptr->path_config; |
| 617 |
total_paths = platform_ptr->total_path_configs; |
| 618 |
break; |
| 619 |
case PCONF_DEP_TYPE_OS: |
| 620 |
case PCONF_DEP_TYPE_MACHINE: |
| 621 |
/* Should not call this function for checking these |
| 622 |
* dependencies. |
| 623 |
*/ |
| 624 |
fprintf( |
| 625 |
stderr, |
| 626 |
"PConfDependMatchFile(): Internal error, dependency is not looking for a file.\n" |
| 627 |
); |
| 628 |
return(NULL); |
| 629 |
break; |
| 630 |
|
| 631 |
default: /* PCONF_DEP_TYPE_DATA or PCONF_DEP_TYPE_OTHER. */ |
| 632 |
path_list = platform_ptr->path_data; |
| 633 |
total_paths = platform_ptr->total_path_datas; |
| 634 |
break; |
| 635 |
} |
| 636 |
/* Empty path list? */ |
| 637 |
if((path_list == NULL) || (total_paths < 1)) |
| 638 |
return(NULL); |
| 639 |
|
| 640 |
/* Itterate through search paths. */ |
| 641 |
new_path = NULL; |
| 642 |
len2 = STRLEN(path); |
| 643 |
for(i = 0; i < total_paths; i++) |
| 644 |
{ |
| 645 |
base_path = path_list[i]; |
| 646 |
if(base_path == NULL) |
| 647 |
continue; |
| 648 |
|
| 649 |
/* Deallocate previous new path and get new one. */ |
| 650 |
FREE(new_path); |
| 651 |
new_path = NULL; |
| 652 |
|
| 653 |
/* Prefix paths and allocate new path. */ |
| 654 |
len1 = STRLEN(base_path); |
| 655 |
new_path = (char *)malloc((len1 + len2 + 10) * sizeof(char)); |
| 656 |
if(new_path != NULL) |
| 657 |
{ |
| 658 |
if((len1 > 0) ? |
| 659 |
(base_path[len1 - 1] != DIR_DELIMINATOR) : 1 |
| 660 |
) |
| 661 |
sprintf(new_path, "%s%c%s", |
| 662 |
base_path, DIR_DELIMINATOR, path |
| 663 |
); |
| 664 |
else |
| 665 |
sprintf(new_path, "%s%s", |
| 666 |
base_path, path |
| 667 |
); |
| 668 |
|
| 669 |
/* Exists? */ |
| 670 |
if(!stat(new_path, stat_buf)) |
| 671 |
return(new_path); |
| 672 |
} |
| 673 |
} |
| 674 |
|
| 675 |
/* Deallocate failed matched new path. */ |
| 676 |
FREE(new_path); |
| 677 |
new_path = NULL; |
| 678 |
|
| 679 |
return(NULL); |
| 680 |
} |
| 681 |
|
| 682 |
/* |
| 683 |
* Checks dependency on the given depend structure. |
| 684 |
* |
| 685 |
* Returns false on failure and true on success. |
| 686 |
*/ |
| 687 |
static int PConfDependCheck( |
| 688 |
pconf_core_struct *core_ptr, |
| 689 |
platform_struct *platform_ptr, depend_struct *depend_ptr, |
| 690 |
const char *feature_name, |
| 691 |
int dep_cur, int dep_total |
| 692 |
) |
| 693 |
{ |
| 694 |
int i, found, missing_depend = 0; |
| 695 |
const char *path_ptr; |
| 696 |
char *new_path; |
| 697 |
const char *cstrptr; |
| 698 |
struct stat stat_buf; |
| 699 |
|
| 700 |
|
| 701 |
if((core_ptr == NULL) || (platform_ptr == NULL) || (depend_ptr == NULL)) |
| 702 |
return(0); |
| 703 |
|
| 704 |
if(core_ptr->verbose) |
| 705 |
printf("Feature: %s (%i of %i) Dependency: %s...\n", |
| 706 |
feature_name, |
| 707 |
dep_cur + 1, dep_total, |
| 708 |
depend_ptr->name |
| 709 |
); |
| 710 |
else |
| 711 |
printf("Checking Dependency: %s...\n", depend_ptr->name); |
| 712 |
|
| 713 |
|
| 714 |
/* Special case handling for dependencies that do not look for |
| 715 |
* files. |
| 716 |
*/ |
| 717 |
switch(depend_ptr->type) |
| 718 |
{ |
| 719 |
case PCONF_DEP_TYPE_OS: |
| 720 |
/* Match operating system name. */ |
| 721 |
cstrptr = (const char *)depend_ptr->os_name; |
| 722 |
if((cstrptr == NULL) ? 1 : ((*cstrptr) == '\0')) |
| 723 |
{ |
| 724 |
/* No name so impossible to match, return false. */ |
| 725 |
return(0); |
| 726 |
} |
| 727 |
else |
| 728 |
{ |
| 729 |
if(core_ptr->os_name != NULL) |
| 730 |
{ |
| 731 |
if(!STRCASECMP(core_ptr->os_name, cstrptr)) |
| 732 |
return(1); |
| 733 |
else |
| 734 |
return(0); |
| 735 |
} |
| 736 |
else |
| 737 |
{ |
| 738 |
return(0); |
| 739 |
} |
| 740 |
} |
| 741 |
break; |
| 742 |
|
| 743 |
case PCONF_DEP_TYPE_MACHINE: |
| 744 |
/* Match machine name. */ |
| 745 |
cstrptr = (const char *)depend_ptr->machine_name; |
| 746 |
if((cstrptr == NULL) ? 1 : ((*cstrptr) == '\0')) |
| 747 |
{ |
| 748 |
/* No name so impossible to match, return false. */ |
| 749 |
return(0); |
| 750 |
} |
| 751 |
else |
| 752 |
{ |
| 753 |
if(core_ptr->machine_name != NULL) |
| 754 |
{ |
| 755 |
if(!STRCASECMP(core_ptr->machine_name, cstrptr)) |
| 756 |
return(1); |
| 757 |
else |
| 758 |
return(0); |
| 759 |
} |
| 760 |
else |
| 761 |
{ |
| 762 |
return(0); |
| 763 |
} |
| 764 |
} |
| 765 |
break; |
| 766 |
|
| 767 |
default: |
| 768 |
/* All other dependency checks, keep going. */ |
| 769 |
break; |
| 770 |
} |
| 771 |
|
| 772 |
/* Begin handling all other dependencies that look for files here. */ |
| 773 |
|
| 774 |
/* Itterate through dependency paths. */ |
| 775 |
new_path = NULL; |
| 776 |
for(i = 0; i < depend_ptr->total_paths; i++) |
| 777 |
{ |
| 778 |
path_ptr = (const char *)depend_ptr->path[i]; |
| 779 |
if(path_ptr == NULL) |
| 780 |
continue; |
| 781 |
|
| 782 |
/* If we're not forcing, then stop checking dependencies |
| 783 |
* on just one failed dependency. |
| 784 |
*/ |
| 785 |
if(!core_ptr->force && (missing_depend > 0)) |
| 786 |
break; |
| 787 |
|
| 788 |
/* Deallocate previous new path. */ |
| 789 |
FREE(new_path); |
| 790 |
new_path = NULL; |
| 791 |
|
| 792 |
/* Reset found marker. */ |
| 793 |
found = 0; |
| 794 |
|
| 795 |
/* Check if the path exists on this platform. */ |
| 796 |
new_path = PConfDependMatchFile( |
| 797 |
platform_ptr, depend_ptr->type, path_ptr, |
| 798 |
&stat_buf |
| 799 |
); |
| 800 |
if(new_path != NULL) |
| 801 |
{ |
| 802 |
if(core_ptr->verbose) |
| 803 |
{ |
| 804 |
printf(" Scanning: %s...", new_path); |
| 805 |
fflush(stdout); |
| 806 |
} |
| 807 |
|
| 808 |
/* Is it a directory? */ |
| 809 |
#ifdef S_ISDIR |
| 810 |
if(S_ISDIR(stat_buf.st_mode)) |
| 811 |
#else |
| 812 |
if(0) |
| 813 |
#endif |
| 814 |
{ |
| 815 |
/* Accept this as is even if there are |
| 816 |
* strings to be greped. |
| 817 |
*/ |
| 818 |
if(core_ptr->verbose) |
| 819 |
{ |
| 820 |
PConfSetColor(core_ptr, stdout, |
| 821 |
PCONF_COLOR_SUCCESS |
| 822 |
); |
| 823 |
printf(" OK "); |
| 824 |
PConfSetColor(core_ptr, stdout, |
| 825 |
PCONF_COLOR_DEFAULT |
| 826 |
); |
| 827 |
printf("(Directory)\n"); |
| 828 |
} |
| 829 |
found = 1; |
| 830 |
} |
| 831 |
/* Is it a character device? */ |
| 832 |
#ifdef S_ISCHR |
| 833 |
if(S_ISCHR(stat_buf.st_mode)) |
| 834 |
#else |
| 835 |
if(0) |
| 836 |
#endif |
| 837 |
{ |
| 838 |
/* Accept this as is even if there are |
| 839 |
* strings to be greped. |
| 840 |
*/ |
| 841 |
if(core_ptr->verbose) |
| 842 |
{ |
| 843 |
PConfSetColor(core_ptr, stdout, |
| 844 |
PCONF_COLOR_SUCCESS |
| 845 |
); |
| 846 |
printf(" OK "); |
| 847 |
PConfSetColor(core_ptr, stdout, |
| 848 |
PCONF_COLOR_DEFAULT |
| 849 |
); |
| 850 |
printf("(Character Device)\n"); |
| 851 |
} |
| 852 |
found = 1; |
| 853 |
} |
| 854 |
/* Is it a block device? */ |
| 855 |
#ifdef S_ISBLK |
| 856 |
if(S_ISBLK(stat_buf.st_mode)) |
| 857 |
#else |
| 858 |
if(0) |
| 859 |
#endif |
| 860 |
{ |
| 861 |
/* Accept this as is even if there are |
| 862 |
* strings to be greped. |
| 863 |
*/ |
| 864 |
if(core_ptr->verbose) |
| 865 |
{ |
| 866 |
PConfSetColor(core_ptr, stdout, |
| 867 |
PCONF_COLOR_SUCCESS |
| 868 |
); |
| 869 |
printf(" OK "); |
| 870 |
PConfSetColor(core_ptr, stdout, |
| 871 |
PCONF_COLOR_DEFAULT |
| 872 |
); |
| 873 |
printf("(Block Device)\n"); |
| 874 |
} |
| 875 |
found = 1; |
| 876 |
} |
| 877 |
/* Is it a FIFO pipe? */ |
| 878 |
#ifdef S_ISFIFO |
| 879 |
if(S_ISFIFO(stat_buf.st_mode)) |
| 880 |
#else |
| 881 |
if(0) |
| 882 |
#endif |
| 883 |
{ |
| 884 |
/* Accept this as is even if there are |
| 885 |
* strings to be greped. |
| 886 |
*/ |
| 887 |
if(core_ptr->verbose) |
| 888 |
{ |
| 889 |
PConfSetColor(core_ptr, stdout, |
| 890 |
PCONF_COLOR_SUCCESS |
| 891 |
); |
| 892 |
printf(" OK "); |
| 893 |
PConfSetColor(core_ptr, stdout, |
| 894 |
PCONF_COLOR_DEFAULT |
| 895 |
); |
| 896 |
printf("(FIFO Pipe)\n"); |
| 897 |
} |
| 898 |
found = 1; |
| 899 |
} |
| 900 |
/* Is it a socket? */ |
| 901 |
#ifdef S_ISSOCK |
| 902 |
if(S_ISSOCK(stat_buf.st_mode)) |
| 903 |
#else |
| 904 |
if(0) |
| 905 |
#endif |
| 906 |
{ |
| 907 |
/* Accept this as is even if there are |
| 908 |
* strings to be greped. |
| 909 |
*/ |
| 910 |
if(core_ptr->verbose) |
| 911 |
{ |
| 912 |
PConfSetColor(core_ptr, stdout, |
| 913 |
PCONF_COLOR_SUCCESS |
| 914 |
); |
| 915 |
printf(" OK "); |
| 916 |
PConfSetColor(core_ptr, stdout, |
| 917 |
PCONF_COLOR_DEFAULT |
| 918 |
); |
| 919 |
printf("(Socket)\n"); |
| 920 |
} |
| 921 |
found = 1; |
| 922 |
} |
| 923 |
/* Is it a regular file? */ |
| 924 |
#ifdef S_ISREG |
| 925 |
if(S_ISREG(stat_buf.st_mode)) |
| 926 |
#else |
| 927 |
if(1) |
| 928 |
#endif |
| 929 |
{ |
| 930 |
/* Check for corresponding string for grepping on |
| 931 |
* this dependency structure. If there is one, then |
| 932 |
* grep for it. |
| 933 |
*/ |
| 934 |
if((i >= 0) && (i < depend_ptr->total_grep_strings)) |
| 935 |
{ |
| 936 |
const char *grep_string = depend_ptr->grep_string[i]; |
| 937 |
/* Grep string not NULL and not empty? */ |
| 938 |
if((grep_string == NULL) ? 0 : ((*grep_string) != '\0')) |
| 939 |
{ |
| 940 |
if(PConfScanFileString( |
| 941 |
new_path, grep_string |
| 942 |
) > 0) |
| 943 |
{ |
| 944 |
if(core_ptr->verbose) |
| 945 |
{ |
| 946 |
PConfSetColor(core_ptr, stdout, |
| 947 |
PCONF_COLOR_SUCCESS |
| 948 |
); |
| 949 |
printf(" OK\n"); |
| 950 |
PConfSetColor(core_ptr, stdout, |
| 951 |
PCONF_COLOR_DEFAULT |
| 952 |
); |
| 953 |
} |
| 954 |
found = 1; |
| 955 |
} |
| 956 |
else |
| 957 |
{ |
| 958 |
if(core_ptr->verbose) |
| 959 |
{ |
| 960 |
PConfSetColor(core_ptr, stdout, |
| 961 |
PCONF_COLOR_FAILURE |
| 962 |
); |
| 963 |
printf(" Failed\n"); |
| 964 |
PConfSetColor(core_ptr, stdout, |
| 965 |
PCONF_COLOR_DEFAULT |
| 966 |
); |
| 967 |
} |
| 968 |
|
| 969 |
if(core_ptr->warnings) |
| 970 |
{ |
| 971 |
PConfSetColor(core_ptr, stderr, |
| 972 |
PCONF_COLOR_DEFAULT |
| 973 |
); |
| 974 |
fprintf(stderr, " *** "); |
| 975 |
PConfSetColor(core_ptr, stderr, |
| 976 |
PCONF_COLOR_FAILURE |
| 977 |
); |
| 978 |
fprintf( |
| 979 |
stderr, |
| 980 |
"Could not find `%s' in file %s!", |
| 981 |
grep_string, new_path |
| 982 |
); |
| 983 |
PConfSetColor(core_ptr, stderr, |
| 984 |
PCONF_COLOR_DEFAULT |
| 985 |
); |
| 986 |
fprintf(stderr, " ***\n"); |
| 987 |
} |
| 988 |
} |
| 989 |
} |
| 990 |
else |
| 991 |
{ |
| 992 |
/* Grep string is empty, imply always match. */ |
| 993 |
found = 1; |
| 994 |
if(core_ptr->verbose) |
| 995 |
{ |
| 996 |
PConfSetColor(core_ptr, stdout, |
| 997 |
PCONF_COLOR_SUCCESS |
| 998 |
); |
| 999 |
printf(" OK\n"); |
| 1000 |
PConfSetColor(core_ptr, stdout, |
| 1001 |
PCONF_COLOR_DEFAULT |
| 1002 |
); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
} |
| 1006 |
else |
| 1007 |
{ |
| 1008 |
/* No grep string, so imply always match. */ |
| 1009 |
if(core_ptr->verbose) |
| 1010 |
{ |
| 1011 |
PConfSetColor(core_ptr, stdout, |
| 1012 |
PCONF_COLOR_SUCCESS |
| 1013 |
); |
| 1014 |
printf(" OK\n"); |
| 1015 |
PConfSetColor(core_ptr, stdout, |
| 1016 |
PCONF_COLOR_DEFAULT |
| 1017 |
); |
| 1018 |
} |
| 1019 |
/* Mark this dependency as found. */ |
| 1020 |
found = 1; |
| 1021 |
} |
| 1022 |
} |
| 1023 |
|
| 1024 |
/* Not found? */ |
| 1025 |
if(!found) |
| 1026 |
{ |
| 1027 |
/* Increment missing dependencies count. */ |
| 1028 |
missing_depend++; |
| 1029 |
} |
| 1030 |
} |
| 1031 |
else |
| 1032 |
{ |
| 1033 |
/* Object does not exist. */ |
| 1034 |
if(core_ptr->warnings) |
| 1035 |
{ |
| 1036 |
PConfSetColor(core_ptr, stderr, |
| 1037 |
PCONF_COLOR_DEFAULT |
| 1038 |
); |
| 1039 |
fprintf(stderr, " *** "); |
| 1040 |
PConfSetColor(core_ptr, stderr, |
| 1041 |
PCONF_COLOR_WARNING |
| 1042 |
); |
| 1043 |
fprintf( |
| 1044 |
stderr, |
| 1045 |
"Object `%s' not found in defined platform paths!", |
| 1046 |
path_ptr |
| 1047 |
); |
| 1048 |
PConfSetColor(core_ptr, stderr, |
| 1049 |
PCONF_COLOR_DEFAULT |
| 1050 |
); |
| 1051 |
fprintf(stderr, " ***\n"); |
| 1052 |
} |
| 1053 |
|
| 1054 |
/* Increment missing dependency count. */ |
| 1055 |
missing_depend++; |
| 1056 |
} |
| 1057 |
} /* Itterate through dependency paths. */ |
| 1058 |
|
| 1059 |
|
| 1060 |
/* Deallocate new path just in case. */ |
| 1061 |
FREE(new_path); |
| 1062 |
new_path = NULL; |
| 1063 |
|
| 1064 |
/* All depends met? */ |
| 1065 |
if(missing_depend <= 0) |
| 1066 |
return(1); |
| 1067 |
else |
| 1068 |
return(0); |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
/* |
| 1073 |
* Checks for dependencies on all enabled features. |
| 1074 |
* |
| 1075 |
* Any feature's must_exist marked as PCONF_MUST_EXIST_PREFERRED will |
| 1076 |
* be set to PCONF_MUST_EXIST_YES if they exist or set to |
| 1077 |
* PCONF_MUST_EXIST_NO if they do not exist. |
| 1078 |
* |
| 1079 |
* Returns the number of failed dependencies who's must_exist |
| 1080 |
* is set to PCONF_MUST_EXIST_YES. |
| 1081 |
*/ |
| 1082 |
int PConfCheckDepends( |
| 1083 |
pconf_core_struct *core_ptr, platform_struct *platform_ptr |
| 1084 |
) |
| 1085 |
{ |
| 1086 |
int i, failed_depends = 0; |
| 1087 |
int depend_progress_ratio = 0; /* In percent. */ |
| 1088 |
feature_struct *feature_ptr; |
| 1089 |
|
| 1090 |
|
| 1091 |
if((core_ptr == NULL) || (platform_ptr == NULL)) |
| 1092 |
return(failed_depends); |
| 1093 |
|
| 1094 |
|
| 1095 |
/* Itterate through each feature. */ |
| 1096 |
for(i = 0; i < platform_ptr->total_features; i++) |
| 1097 |
{ |
| 1098 |
feature_ptr = platform_ptr->feature[i]; |
| 1099 |
if(feature_ptr == NULL) |
| 1100 |
continue; |
| 1101 |
|
| 1102 |
/* Update progress ratio. */ |
| 1103 |
if(platform_ptr->total_features > 0) |
| 1104 |
depend_progress_ratio = (i + 1) * 100 / |
| 1105 |
platform_ptr->total_features; |
| 1106 |
|
| 1107 |
|
| 1108 |
/* Do not want this feature? */ |
| 1109 |
if(feature_ptr->must_exist == PCONF_MUST_EXIST_NO) |
| 1110 |
continue; |
| 1111 |
|
| 1112 |
/* Would like to have this feature (preffered)? */ |
| 1113 |
if(feature_ptr->must_exist == PCONF_MUST_EXIST_PREFERRED) |
| 1114 |
{ |
| 1115 |
int n, k = 0; |
| 1116 |
depend_struct *depend_ptr; |
| 1117 |
|
| 1118 |
/* Check if we have dependencies. */ |
| 1119 |
for(n = 0; n < feature_ptr->total_depends; n++) |
| 1120 |
{ |
| 1121 |
depend_ptr = feature_ptr->depend[n]; |
| 1122 |
if(depend_ptr == NULL) |
| 1123 |
continue; |
| 1124 |
|
| 1125 |
if(depend_ptr->must_exist == PCONF_MUST_EXIST_YES) |
| 1126 |
{ |
| 1127 |
/* Dependency found? */ |
| 1128 |
if(!PConfDependCheck( |
| 1129 |
core_ptr, platform_ptr, depend_ptr, |
| 1130 |
feature_ptr->name, |
| 1131 |
i, platform_ptr->total_features |
| 1132 |
)) |
| 1133 |
{ |
| 1134 |
k++; |
| 1135 |
/* Do not count this as a failed dependency. */ |
| 1136 |
} |
| 1137 |
} |
| 1138 |
} |
| 1139 |
/* No failed dependencies? */ |
| 1140 |
if(k == 0) |
| 1141 |
{ |
| 1142 |
if(core_ptr->warnings) |
| 1143 |
{ |
| 1144 |
printf( |
| 1145 |
" Preferred feature `%s' ", |
| 1146 |
feature_ptr->name |
| 1147 |
); |
| 1148 |
PConfSetColor(core_ptr, stdout, |
| 1149 |
PCONF_COLOR_SUCCESS |
| 1150 |
); |
| 1151 |
printf("detected and enabled"); |
| 1152 |
PConfSetColor(core_ptr, stdout, |
| 1153 |
PCONF_COLOR_DEFAULT |
| 1154 |
); |
| 1155 |
printf(".\n"); |
| 1156 |
} |
| 1157 |
/* No failed dependencies, so mark this as enabled. */ |
| 1158 |
feature_ptr->must_exist = PCONF_MUST_EXIST_YES; |
| 1159 |
} |
| 1160 |
else |
| 1161 |
{ |
| 1162 |
/* Got one or more failed dependency. */ |
| 1163 |
if(core_ptr->warnings) |
| 1164 |
{ |
| 1165 |
printf(" Preferred ("); |
| 1166 |
PConfSetColor(core_ptr, stdout, |
| 1167 |
PCONF_COLOR_SUCCESS |
| 1168 |
); |
| 1169 |
printf("not required"); |
| 1170 |
PConfSetColor(core_ptr, stdout, |
| 1171 |
PCONF_COLOR_DEFAULT |
| 1172 |
); |
| 1173 |
printf(") feature `%s' ", |
| 1174 |
feature_ptr->name |
| 1175 |
); |
| 1176 |
PConfSetColor(core_ptr, stdout, |
| 1177 |
PCONF_COLOR_WARNING |
| 1178 |
); |
| 1179 |
printf("not detected and disabled"); |
| 1180 |
PConfSetColor(core_ptr, stdout, |
| 1181 |
PCONF_COLOR_DEFAULT |
| 1182 |
); |
| 1183 |
printf(".\n"); |
| 1184 |
} |
| 1185 |
/* Got failed dependencies, so mark this as disabled. */ |
| 1186 |
feature_ptr->must_exist = PCONF_MUST_EXIST_NO; |
| 1187 |
} |
| 1188 |
} |
| 1189 |
/* Must have this feature? */ |
| 1190 |
else if(feature_ptr->must_exist == PCONF_MUST_EXIST_YES) |
| 1191 |
{ |
| 1192 |
int n, k = 0; |
| 1193 |
depend_struct *depend_ptr; |
| 1194 |
|
| 1195 |
/* Check if we have dependencies. */ |
| 1196 |
for(n = 0; n < feature_ptr->total_depends; n++) |
| 1197 |
{ |
| 1198 |
depend_ptr = feature_ptr->depend[n]; |
| 1199 |
if(depend_ptr == NULL) |
| 1200 |
continue; |
| 1201 |
|
| 1202 |
/* If not forcing and we got one or more failed |
| 1203 |
* dependencies then we should give up immediatly. |
| 1204 |
*/ |
| 1205 |
if(!core_ptr->force && (failed_depends > 0)) |
| 1206 |
break; |
| 1207 |
|
| 1208 |
/* Check for dependency of feature only if feature |
| 1209 |
* says the dependency must exist. |
| 1210 |
*/ |
| 1211 |
if(depend_ptr->must_exist == PCONF_MUST_EXIST_YES) |
| 1212 |
{ |
| 1213 |
/* Dependency found? */ |
| 1214 |
if(!PConfDependCheck( |
| 1215 |
core_ptr, platform_ptr, depend_ptr, |
| 1216 |
feature_ptr->name, |
| 1217 |
i, platform_ptr->total_features |
| 1218 |
)) |
| 1219 |
{ |
| 1220 |
k++; |
| 1221 |
failed_depends++; |
| 1222 |
} |
| 1223 |
} |
| 1224 |
} |
| 1225 |
/* Got more than one failed dependency? */ |
| 1226 |
if(k > 0) |
| 1227 |
{ |
| 1228 |
PConfSetColor(core_ptr, stderr, |
| 1229 |
PCONF_COLOR_DEFAULT |
| 1230 |
); |
| 1231 |
fprintf(stderr, " *** "); |
| 1232 |
PConfSetColor(core_ptr, stderr, |
| 1233 |
PCONF_COLOR_FAILURE |
| 1234 |
); |
| 1235 |
fprintf( |
| 1236 |
stderr, |
| 1237 |
"Could not find all dependencies for required feature `%s'!", |
| 1238 |
feature_ptr->name |
| 1239 |
); |
| 1240 |
PConfSetColor(core_ptr, stderr, |
| 1241 |
PCONF_COLOR_DEFAULT |
| 1242 |
); |
| 1243 |
fprintf(stderr, " ***\n"); |
| 1244 |
|
| 1245 |
/* Got failed dependencies so mark this as disabled |
| 1246 |
* if we are not forcing. |
| 1247 |
*/ |
| 1248 |
if(!core_ptr->force) |
| 1249 |
feature_ptr->must_exist = PCONF_MUST_EXIST_NO; |
| 1250 |
|
| 1251 |
/* This is a halting error, halt if not forcing. */ |
| 1252 |
if(core_ptr->force) |
| 1253 |
{ |
| 1254 |
if(core_ptr->verbose && core_ptr->warnings) |
| 1255 |
fprintf( |
| 1256 |
stderr, |
| 1257 |
"*** Force enabled, continuing dependency check... ***\n" |
| 1258 |
); |
| 1259 |
} |
| 1260 |
else |
| 1261 |
{ |
| 1262 |
break; |
| 1263 |
} |
| 1264 |
} |
| 1265 |
} |
| 1266 |
} /* Itterate through each feature. */ |
| 1267 |
|
| 1268 |
|
| 1269 |
return(failed_depends); |
| 1270 |
} |