Debian Codegraph @

pconf/proc.c

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