loader/config.c
static LOADER_ENTRY * AddStanzaEntries(REFIT_FILE *File, REFIT_VOLUME *Volume, CHAR16 *Title) {
   CHAR16       **TokenList;
   UINTN        TokenCount;
   LOADER_ENTRY *Entry;
   BOOLEAN      DefaultsSet = FALSE, AddedSubmenu = FALSE;
   REFIT_VOLUME *CurrentVolume = Volume;

   // prepare the menu entry
   Entry = InitializeLoaderEntry(NULL);
   if (Entry == NULL)
      return NULL;

   Entry->Title           = StrDuplicate(Title);
   Entry->me.Title        = AllocateZeroPool(256 * sizeof(CHAR16));
   SPrint(Entry->me.Title, 255, L"Boot %s from %s", (Title != NULL) ? Title : L"Unknown", CurrentVolume->VolName);
   Entry->me.Row          = 0;
   Entry->me.BadgeImage   = CurrentVolume->VolBadgeImage;
   Entry->Volume          = CurrentVolume;
   Entry->DiscoveryType   = DISCOVERY_TYPE_MANUAL;

   // Parse the config file to add options for a single stanza, terminating when the token
   // is "}" or when the end of file is reached.
   while (((TokenCount = ReadTokenLine(File, &TokenList)) > 0) && (StrCmp(TokenList[0], L"}") != 0)) {
      if (MyStriCmp(TokenList[0], L"loader") && (TokenCount > 1)) { // set the boot loader filename
         Entry->LoaderPath = StrDuplicate(TokenList[1]);
         SetLoaderDefaults(Entry, TokenList[1], CurrentVolume);
         MyFreePool(Entry->LoadOptions);
         Entry->LoadOptions = NULL; // Discard default options, if any
         DefaultsSet = TRUE;

      } else if (MyStriCmp(TokenList[0], L"volume") && (TokenCount > 1)) {
         if (FindVolume(&CurrentVolume, TokenList[1])) {
            if ((CurrentVolume != NULL) && (CurrentVolume->IsReadable) && (CurrentVolume->RootDir)) {
               MyFreePool(Entry->me.Title);
               Entry->me.Title        = AllocateZeroPool(256 * sizeof(CHAR16));
               SPrint(Entry->me.Title, 255, L"Boot %s from %s", (Title != NULL) ? Title : L"Unknown", CurrentVolume->VolName);
               Entry->me.BadgeImage   = CurrentVolume->VolBadgeImage;
               Entry->Volume          = CurrentVolume;
            } // if volume is readable
         } // if match found

      } else if (MyStriCmp(TokenList[0], L"icon") && (TokenCount > 1)) {
         MyFreePool(Entry->me.Image);
         Entry->me.Image = egLoadIcon(CurrentVolume->RootDir, TokenList[1], GlobalConfig.IconSizes[ICON_SIZE_BIG]);
         if (Entry->me.Image == NULL) {
            Entry->me.Image = DummyImage(GlobalConfig.IconSizes[ICON_SIZE_BIG]);
         }

      } else if (MyStriCmp(TokenList[0], L"initrd") && (TokenCount > 1)) {
         MyFreePool(Entry->InitrdPath);
         Entry->InitrdPath = StrDuplicate(TokenList[1]);

      } else if (MyStriCmp(TokenList[0], L"options") && (TokenCount > 1)) {
         MyFreePool(Entry->LoadOptions);
         Entry->LoadOptions = StrDuplicate(TokenList[1]);

      } else if (MyStriCmp(TokenList[0], L"ostype") && (TokenCount > 1)) {
         if (TokenCount > 1) {
            Entry->OSType = TokenList[1][0];
         }

      } else if (MyStriCmp(TokenList[0], L"graphics") && (TokenCount > 1)) {
         Entry->UseGraphicsMode = MyStriCmp(TokenList[1], L"on");

      } else if (MyStriCmp(TokenList[0], L"disabled")) {
         Entry->Enabled = FALSE;

      } else if (MyStriCmp(TokenList[0], L"submenuentry") && (TokenCount > 1)) {
         AddSubmenu(Entry, File, CurrentVolume, TokenList[1]);
         AddedSubmenu = TRUE;

      } // set options to pass to the loader program
      FreeTokenLine(&TokenList, &TokenCount);
   } // while()

   if (AddedSubmenu)
       AddMenuEntry(Entry->me.SubScreen, &MenuEntryReturn);

   if (Entry->InitrdPath) {
      MergeStrings(&Entry->LoadOptions, L"initrd=", L' ');
      MergeStrings(&Entry->LoadOptions, Entry->InitrdPath, 0);
      MyFreePool(Entry->InitrdPath);
      Entry->InitrdPath = NULL;
   } // if

   if (!DefaultsSet)
      SetLoaderDefaults(Entry, L"\\EFI\\BOOT\\nemo.efi", CurrentVolume); // user included no "loader" line; use bogus one

   return(Entry);
}
// Adds the options from a SINGLE the configuration file stanza to a new loader entry and returns
// that entry. The calling function is then responsible for adding the entry to the
// list of entries.
Adds the options from a SINGLE the configuration file stanza to a new loader entry and returns
that entry. The calling function is then responsible for adding the entry to the
list of entries.
Adds the options from a SINGLE the configuration file stanza to a new loader entry and returns that entry . The calling function is then responsible for adding the entry to the list of entries .
static LOADER_ENTRY * AddStanzaEntries(REFIT_FILE *File, REFIT_VOLUME *Volume, CHAR16 *Title) {
   CHAR16       **TokenList;
   UINTN        TokenCount;
   LOADER_ENTRY *Entry;
   BOOLEAN      DefaultsSet = FALSE, AddedSubmenu = FALSE;
   REFIT_VOLUME *CurrentVolume = Volume;
   Entry = InitializeLoaderEntry(NULL);
   if (Entry == NULL)
      return NULL;
   Entry->Title           = StrDuplicate(Title);
   Entry->me.Title        = AllocateZeroPool(256 * sizeof(CHAR16));
   SPrint(Entry->me.Title, 255, L"Boot %s from %s", (Title != NULL) ? Title : L"Unknown", CurrentVolume->VolName);
   Entry->me.Row          = 0;
   Entry->me.BadgeImage   = CurrentVolume->VolBadgeImage;
   Entry->Volume          = CurrentVolume;
   Entry->DiscoveryType   = DISCOVERY_TYPE_MANUAL;
   while (((TokenCount = ReadTokenLine(File, &TokenList)) > 0) && (StrCmp(TokenList[0], L"}") != 0)) {
      if (MyStriCmp(TokenList[0], L"loader") && (TokenCount > 1)) { 
         Entry->LoaderPath = StrDuplicate(TokenList[1]);
         SetLoaderDefaults(Entry, TokenList[1], CurrentVolume);
         MyFreePool(Entry->LoadOptions);
         Entry->LoadOptions = NULL; 
         DefaultsSet = TRUE;
      } else if (MyStriCmp(TokenList[0], L"volume") && (TokenCount > 1)) {
         if (FindVolume(&CurrentVolume, TokenList[1])) {
            if ((CurrentVolume != NULL) && (CurrentVolume->IsReadable) && (CurrentVolume->RootDir)) {
               MyFreePool(Entry->me.Title);
               Entry->me.Title        = AllocateZeroPool(256 * sizeof(CHAR16));
               SPrint(Entry->me.Title, 255, L"Boot %s from %s", (Title != NULL) ? Title : L"Unknown", CurrentVolume->VolName);
               Entry->me.BadgeImage   = CurrentVolume->VolBadgeImage;
               Entry->Volume          = CurrentVolume;
            } 
         } 
      } else if (MyStriCmp(TokenList[0], L"icon") && (TokenCount > 1)) {
         MyFreePool(Entry->me.Image);
         Entry->me.Image = egLoadIcon(CurrentVolume->RootDir, TokenList[1], GlobalConfig.IconSizes[ICON_SIZE_BIG]);
         if (Entry->me.Image == NULL) {
            Entry->me.Image = DummyImage(GlobalConfig.IconSizes[ICON_SIZE_BIG]);
         }
      } else if (MyStriCmp(TokenList[0], L"initrd") && (TokenCount > 1)) {
         MyFreePool(Entry->InitrdPath);
         Entry->InitrdPath = StrDuplicate(TokenList[1]);
      } else if (MyStriCmp(TokenList[0], L"options") && (TokenCount > 1)) {
         MyFreePool(Entry->LoadOptions);
         Entry->LoadOptions = StrDuplicate(TokenList[1]);
      } else if (MyStriCmp(TokenList[0], L"ostype") && (TokenCount > 1)) {
         if (TokenCount > 1) {
            Entry->OSType = TokenList[1][0];
         }
      } else if (MyStriCmp(TokenList[0], L"graphics") && (TokenCount > 1)) {
         Entry->UseGraphicsMode = MyStriCmp(TokenList[1], L"on");
      } else if (MyStriCmp(TokenList[0], L"disabled")) {
         Entry->Enabled = FALSE;
      } else if (MyStriCmp(TokenList[0], L"submenuentry") && (TokenCount > 1)) {
         AddSubmenu(Entry, File, CurrentVolume, TokenList[1]);
         AddedSubmenu = TRUE;
      } 
      FreeTokenLine(&TokenList, &TokenCount);
   } 
   if (AddedSubmenu)
       AddMenuEntry(Entry->me.SubScreen, &MenuEntryReturn);
   if (Entry->InitrdPath) {
      MergeStrings(&Entry->LoadOptions, L"initrd=", L' ');
      MergeStrings(&Entry->LoadOptions, Entry->InitrdPath, 0);
      MyFreePool(Entry->InitrdPath);
      Entry->InitrdPath = NULL;
   } 
   if (!DefaultsSet)
      SetLoaderDefaults(Entry, L"\\EFI\\BOOT\\nemo.efi", CurrentVolume); 
   return(Entry);
}
static LOADER_ENTRY * AddStanzaEntries ( REFIT_FILE * File , REFIT_VOLUME * Volume , CHAR16 * Title ) { CHAR16 * * TokenList ; UINTN TokenCount ; LOADER_ENTRY * Entry ; BOOLEAN DefaultsSet = FALSE , AddedSubmenu = FALSE ; REFIT_VOLUME * CurrentVolume = Volume ; Entry = InitializeLoaderEntry ( NULL ) ; if ( Entry == NULL ) return NULL ; Entry -> Title = StrDuplicate ( Title ) ; Entry -> me . Title = AllocateZeroPool ( 256 * sizeof ( CHAR16 ) ) ; SPrint ( Entry -> me . Title , 255 , L" " , ( Title != NULL ) ? Title : L" " , CurrentVolume -> VolName ) ; Entry -> me . Row = 0 ; Entry -> me . BadgeImage = CurrentVolume -> VolBadgeImage ; Entry -> Volume = CurrentVolume ; Entry -> DiscoveryType = DISCOVERY_TYPE_MANUAL ; while ( ( ( TokenCount = ReadTokenLine ( File , & TokenList ) ) > 0 ) && ( StrCmp ( TokenList [ 0 ] , L" " ) != 0 ) ) { if ( MyStriCmp ( TokenList [ 0 ] , L" " ) && ( TokenCount > 1 ) ) { Entry -> LoaderPath = StrDuplicate ( TokenList [ 1 ] ) ; SetLoaderDefaults ( Entry , TokenList [ 1 ] , CurrentVolume ) ; MyFreePool ( Entry -> LoadOptions ) ; Entry -> LoadOptions = NULL ; DefaultsSet = TRUE ; } else if ( MyStriCmp ( TokenList [ 0 ] , L" " ) && ( TokenCount > 1 ) ) { if ( FindVolume ( & CurrentVolume , TokenList [ 1 ] ) ) { if ( ( CurrentVolume != NULL ) && ( CurrentVolume -> IsReadable ) && ( CurrentVolume -> RootDir ) ) { MyFreePool ( Entry -> me . Title ) ; Entry -> me . Title = AllocateZeroPool ( 256 * sizeof ( CHAR16 ) ) ; SPrint ( Entry -> me . Title , 255 , L" " , ( Title != NULL ) ? Title : L" " , CurrentVolume -> VolName ) ; Entry -> me . BadgeImage = CurrentVolume -> VolBadgeImage ; Entry -> Volume = CurrentVolume ; } } } else if ( MyStriCmp ( TokenList [ 0 ] , L" " ) && ( TokenCount > 1 ) ) { MyFreePool ( Entry -> me . Image ) ; Entry -> me . Image = egLoadIcon ( CurrentVolume -> RootDir , TokenList [ 1 ] , GlobalConfig . IconSizes [ ICON_SIZE_BIG ] ) ; if ( Entry -> me . Image == NULL ) { Entry -> me . Image = DummyImage ( GlobalConfig . IconSizes [ ICON_SIZE_BIG ] ) ; } } else if ( MyStriCmp ( TokenList [ 0 ] , L" " ) && ( TokenCount > 1 ) ) { MyFreePool ( Entry -> InitrdPath ) ; Entry -> InitrdPath = StrDuplicate ( TokenList [ 1 ] ) ; } else if ( MyStriCmp ( TokenList [ 0 ] , L" " ) && ( TokenCount > 1 ) ) { MyFreePool ( Entry -> LoadOptions ) ; Entry -> LoadOptions = StrDuplicate ( TokenList [ 1 ] ) ; } else if ( MyStriCmp ( TokenList [ 0 ] , L" " ) && ( TokenCount > 1 ) ) { if ( TokenCount > 1 ) { Entry -> OSType = TokenList [ 1 ] [ 0 ] ; } } else if ( MyStriCmp ( TokenList [ 0 ] , L" " ) && ( TokenCount > 1 ) ) { Entry -> UseGraphicsMode = MyStriCmp ( TokenList [ 1 ] , L" " ) ; } else if ( MyStriCmp ( TokenList [ 0 ] , L" " ) ) { Entry -> Enabled = FALSE ; } else if ( MyStriCmp ( TokenList [ 0 ] , L" " ) && ( TokenCount > 1 ) ) { AddSubmenu ( Entry , File , CurrentVolume , TokenList [ 1 ] ) ; AddedSubmenu = TRUE ; } FreeTokenLine ( & TokenList , & TokenCount ) ; } if ( AddedSubmenu ) AddMenuEntry ( Entry -> me . SubScreen , & MenuEntryReturn ) ; if ( Entry -> InitrdPath ) { MergeStrings ( & Entry -> LoadOptions , L" " , L' ' ) ; MergeStrings ( & Entry -> LoadOptions , Entry -> InitrdPath , 0 ) ; MyFreePool ( Entry -> InitrdPath ) ; Entry -> InitrdPath = NULL ; } if ( ! DefaultsSet ) SetLoaderDefaults ( Entry , L" \\ \\ \\ " , CurrentVolume ) ; return ( Entry ) ; }
Adds the options from a SINGLE the configuration file stanza to a new loader entry and returns
that entry.
Adds the options from a SINGLE the configuration file stanza to a new loader entry and returns that entry .
// prepare the menu entry // Parse the config file to add options for a single stanza, terminating when the token // is "}" or when the end of file is reached. // set the boot loader filename // Discard default options, if any // if volume is readable // if match found // set options to pass to the loader program // while() // if // user included no "loader" line; use bogus one