Deleted Added
full compact
aslfiles.c (234623) aslfiles.c (235945)
1
2/******************************************************************************
3 *
4 * Module Name: aslfiles - file I/O suppoert
5 *
6 *****************************************************************************/
7
8/*

--- 478 unchanged lines hidden (view full) ---

487 {
488 Gbl_IncludeDirList = NewDir;
489 }
490}
491
492
493/*******************************************************************************
494 *
1
2/******************************************************************************
3 *
4 * Module Name: aslfiles - file I/O suppoert
5 *
6 *****************************************************************************/
7
8/*

--- 478 unchanged lines hidden (view full) ---

487 {
488 Gbl_IncludeDirList = NewDir;
489 }
490}
491
492
493/*******************************************************************************
494 *
495 * FUNCTION: FlMergePathnames
496 *
497 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be NULL or
498 * a zero length string.
499 * FilePathname - The include filename from the source ASL.
500 *
501 * RETURN: Merged pathname string
502 *
503 * DESCRIPTION: Merge two pathnames that (probably) have common elements, to
504 * arrive at a minimal length string. Merge can occur if the
505 * FilePathname is relative to the PrefixDir.
506 *
507 ******************************************************************************/
508
509char *
510FlMergePathnames (
511 char *PrefixDir,
512 char *FilePathname)
513{
514 char *CommonPath;
515 char *Pathname;
516 char *LastElement;
517
518
519 DbgPrint (ASL_PARSE_OUTPUT, "Include: Prefix path - \"%s\"\n"
520 "Include: FilePathname - \"%s\"\n",
521 PrefixDir, FilePathname);
522
523 /*
524 * If there is no prefix directory or if the file pathname is absolute,
525 * just return the original file pathname
526 */
527 if (!PrefixDir || (!*PrefixDir) ||
528 (*FilePathname == '/') ||
529 (FilePathname[1] == ':'))
530 {
531 Pathname = ACPI_ALLOCATE (strlen (FilePathname) + 1);
532 strcpy (Pathname, FilePathname);
533 goto ConvertBackslashes;
534 }
535
536 /* Need a local copy of the prefix directory path */
537
538 CommonPath = ACPI_ALLOCATE (strlen (PrefixDir) + 1);
539 strcpy (CommonPath, PrefixDir);
540
541 /*
542 * Walk forward through the file path, and simultaneously backward
543 * through the prefix directory path until there are no more
544 * relative references at the start of the file path.
545 */
546 while (*FilePathname && (!strncmp (FilePathname, "../", 3)))
547 {
548 /* Remove last element of the prefix directory path */
549
550 LastElement = strrchr (CommonPath, '/');
551 if (!LastElement)
552 {
553 goto ConcatenatePaths;
554 }
555
556 *LastElement = 0; /* Terminate CommonPath string */
557 FilePathname += 3; /* Point to next path element */
558 }
559
560 /*
561 * Remove the last element of the prefix directory path (it is the same as
562 * the first element of the file pathname), and build the final merged
563 * pathname.
564 */
565 LastElement = strrchr (CommonPath, '/');
566 if (LastElement)
567 {
568 *LastElement = 0;
569 }
570
571 /* Build the final merged pathname */
572
573ConcatenatePaths:
574 Pathname = ACPI_ALLOCATE_ZEROED (strlen (CommonPath) + strlen (FilePathname) + 2);
575 if (LastElement && *CommonPath)
576 {
577 strcpy (Pathname, CommonPath);
578 strcat (Pathname, "/");
579 }
580 strcat (Pathname, FilePathname);
581 ACPI_FREE (CommonPath);
582
583 /* Convert all backslashes to normal slashes */
584
585ConvertBackslashes:
586 UtConvertBackslashes (Pathname);
587
588 DbgPrint (ASL_PARSE_OUTPUT, "Include: Merged Pathname - \"%s\"\n",
589 Pathname);
590 return (Pathname);
591}
592
593
594/*******************************************************************************
595 *
495 * FUNCTION: FlOpenIncludeWithPrefix
496 *
497 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero
498 * length string.
499 * Filename - The include filename from the source ASL.
500 *
501 * RETURN: Valid file descriptor if successful. Null otherwise.
502 *

--- 7 unchanged lines hidden (view full) ---

510 char *Filename)
511{
512 FILE *IncludeFile;
513 char *Pathname;
514
515
516 /* Build the full pathname to the file */
517
596 * FUNCTION: FlOpenIncludeWithPrefix
597 *
598 * PARAMETERS: PrefixDir - Prefix directory pathname. Can be a zero
599 * length string.
600 * Filename - The include filename from the source ASL.
601 *
602 * RETURN: Valid file descriptor if successful. Null otherwise.
603 *

--- 7 unchanged lines hidden (view full) ---

611 char *Filename)
612{
613 FILE *IncludeFile;
614 char *Pathname;
615
616
617 /* Build the full pathname to the file */
618
518 Pathname = ACPI_ALLOCATE (strlen (PrefixDir) + strlen (Filename) + 1);
619 Pathname = FlMergePathnames (PrefixDir, Filename);
519
620
520 strcpy (Pathname, PrefixDir);
521 strcat (Pathname, Filename);
522
523 DbgPrint (ASL_PARSE_OUTPUT, "\nAttempt to open include file: path %s\n\n",
621 DbgPrint (ASL_PARSE_OUTPUT, "Include: Opening file - \"%s\"\n\n",
524 Pathname);
525
526 /* Attempt to open the file, push if successful */
527
528 IncludeFile = fopen (Pathname, "r");
529 if (IncludeFile)
530 {
531 /* Push the include file on the open input file stack */

--- 485 unchanged lines hidden ---
622 Pathname);
623
624 /* Attempt to open the file, push if successful */
625
626 IncludeFile = fopen (Pathname, "r");
627 if (IncludeFile)
628 {
629 /* Push the include file on the open input file stack */

--- 485 unchanged lines hidden ---