Lines Matching refs:config
327 static UINTN entry_lookup_key(Config *config, UINTN start, CHAR16 key) {
336 if (i > config->entry_count)
337 i = config->entry_count;
341 /* find matching key in config entries */
342 for (i = start; i < config->entry_count; i++)
343 if (config->entries[i]->key == key)
347 if (config->entries[i]->key == key)
353 static VOID print_status(Config *config, CHAR16 *loaded_image_path) {
391 Print(L"timeout: %d\n", config->timeout_sec);
392 if (config->timeout_sec_efivar >= 0)
393 Print(L"timeout (EFI var): %d\n", config->timeout_sec_efivar);
394 Print(L"timeout (config): %d\n", config->timeout_sec_config);
395 if (config->entry_default_pattern)
396 Print(L"default pattern: '%s'\n", config->entry_default_pattern);
397 Print(L"editor: %s\n", yes_no(!config->no_editor));
400 Print(L"config entry count: %d\n", config->entry_count);
401 Print(L"entry selected idx: %d\n", config->idx_default);
402 if (config->idx_default_efivar >= 0)
403 Print(L"entry EFI var idx: %d\n", config->idx_default_efivar);
408 if (config->entry_oneshot)
409 Print(L"LoaderEntryOneShot: %s\n", config->entry_oneshot);
422 for (i = 0; i < config->entry_count; i++) {
428 entry = config->entries[i];
429 Print(L"config entry: %d/%d\n", i+1, config->entry_count);
465 static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, CHAR16 *loaded_image_path) {
505 if (config->timeout_sec > 0)
506 timeout_remain = config->timeout_sec * 10;
510 idx_highlight = config->idx_default;
515 if ((UINTN)config->idx_default >= visible_max)
516 idx_first = config->idx_default-1;
527 for (i = 0; i < config->entry_count; i++) {
530 entry_len = StrLen(config->entries[i]->title_show);
539 if (config->entry_count < visible_max)
540 y_start = ((visible_max - config->entry_count) / 2) + 1;
545 lines = AllocatePool(sizeof(CHAR16 *) * config->entry_count);
546 for (i = 0; i < config->entry_count; i++) {
553 for (k = 0; config->entries[i]->title_show[k] != '\0' && j < x_max; j++, k++)
554 lines[i][j] = config->entries[i]->title_show[k];
571 for (i = 0; i < config->entry_count; i++) {
582 if ((INTN)i == config->idx_default_efivar) {
592 if ((INTN)idx_highlight_prev == config->idx_default_efivar) {
600 if ((INTN)idx_highlight == config->idx_default_efivar) {
672 if (idx_highlight < config->entry_count-1)
686 if (idx_highlight < config->entry_count-1) {
688 idx_highlight = config->entry_count-1;
701 if (idx_highlight > config->entry_count-1)
702 idx_highlight = config->entry_count-1;
722 if (config->idx_default_efivar != (INTN)idx_highlight) {
724 efivar_set(L"LoaderEntryDefault", config->entries[idx_highlight]->file, TRUE);
725 config->idx_default_efivar = idx_highlight;
730 config->idx_default_efivar = -1;
738 if (config->timeout_sec_efivar > 0) {
739 config->timeout_sec_efivar--;
740 efivar_set_int(L"LoaderConfigTimeout", config->timeout_sec_efivar, TRUE);
741 if (config->timeout_sec_efivar > 0)
742 status = PoolPrint(L"Menu timeout set to %d sec.", config->timeout_sec_efivar);
745 } else if (config->timeout_sec_efivar <= 0){
746 config->timeout_sec_efivar = -1;
748 if (config->timeout_sec_config > 0)
750 config->timeout_sec_config);
758 if (config->timeout_sec_efivar == -1 && config->timeout_sec_config == 0)
759 config->timeout_sec_efivar++;
760 config->timeout_sec_efivar++;
761 efivar_set_int(L"LoaderConfigTimeout", config->timeout_sec_efivar, TRUE);
762 if (config->timeout_sec_efivar > 0)
764 config->timeout_sec_efivar);
771 if (config->no_editor || config->entries[idx_highlight]->type == LOADER_UNDEFINED)
776 if (line_edit(config->entries[idx_highlight]->options, &config->options_edit, x_max-1, y_max-1))
789 print_status(config, loaded_image_path);
800 idx = entry_lookup_key(config, idx_highlight+1, KEYCHAR(key));
821 *chosen_entry = config->entries[idx_highlight];
823 for (i = 0; i < config->entry_count; i++)
833 static VOID config_add_entry(Config *config, ConfigEntry *entry) {
834 if ((config->entry_count & 15) == 0) {
837 i = config->entry_count + 16;
838 if (config->entry_count == 0)
839 config->entries = AllocatePool(sizeof(VOID *) * i);
841 config->entries = ReallocatePool(config->entries,
842 sizeof(VOID *) * config->entry_count, sizeof(VOID *) * i);
844 config->entries[config->entry_count++] = entry;
974 static VOID config_defaults_load_from_file(Config *config, CHAR8 *content) {
985 config->timeout_sec_config = Atoi(s);
986 config->timeout_sec = config->timeout_sec_config;
992 FreePool(config->entry_default_pattern);
993 config->entry_default_pattern = stra_to_str(value);
994 StrLwr(config->entry_default_pattern);
1003 config->no_editor = !on;
1008 static VOID config_entry_add_from_file(Config *config, EFI_HANDLE *device, CHAR16 *file, CHAR8 *content, CHAR16 *loaded_image_path) {
1133 config_add_entry(config, entry);
1136 static VOID config_load_defaults(Config *config, EFI_FILE *root_dir) {
1144 config_defaults_load_from_file(config, content);
1149 config->timeout_sec_efivar = sec;
1150 config->timeout_sec = sec;
1152 config->timeout_sec_efivar = -1;
1155 static VOID config_load_entries(Config *config, EFI_HANDLE *device, EFI_FILE *root_dir, CHAR16 *loaded_image_path) {
1189 config_entry_add_from_file(config, device, f->FileName, content, loaded_image_path);
1196 static VOID config_sort_entries(Config *config) {
1199 for (i = 1; i < config->entry_count; i++) {
1204 for (k = 0; k < config->entry_count - i; k++) {
1207 if (str_verscmp(config->entries[k]->file, config->entries[k+1]->file) <= 0)
1209 entry = config->entries[k];
1210 config->entries[k] = config->entries[k+1];
1211 config->entries[k+1] = entry;
1219 static VOID config_default_entry_select(Config *config) {
1232 for (i = 0; i < config->entry_count; i++) {
1233 if (StrCmp(config->entries[i]->file, var) == 0) {
1234 config->idx_default = i;
1240 config->entry_oneshot = StrDuplicate(var);
1257 for (i = 0; i < config->entry_count; i++) {
1258 if (StrCmp(config->entries[i]->file, var) == 0) {
1259 config->idx_default = i;
1260 config->idx_default_efivar = i;
1269 config->idx_default_efivar = -1;
1271 if (config->entry_count == 0)
1278 if (config->entry_default_pattern) {
1279 i = config->entry_count;
1281 if (config->entries[i]->no_autoselect)
1283 if (MetaiMatch(config->entries[i]->file, config->entry_default_pattern)) {
1284 config->idx_default = i;
1291 i = config->entry_count;
1293 if (config->entries[i]->no_autoselect)
1295 config->idx_default = i;
1300 config->idx_default = -1;
1304 static VOID config_title_generate(Config *config) {
1309 for (i = 0; i < config->entry_count; i++) {
1312 FreePool(config->entries[i]->title_show);
1313 title = config->entries[i]->title;
1315 title = config->entries[i]->file;
1316 config->entries[i]->title_show = StrDuplicate(title);
1320 for (i = 0; i < config->entry_count; i++) {
1321 for (k = 0; k < config->entry_count; k++) {
1324 if (StrCmp(config->entries[i]->title_show, config->entries[k]->title_show) != 0)
1328 config->entries[i]->non_unique = TRUE;
1329 config->entries[k]->non_unique = TRUE;
1336 for (i = 0; i < config->entry_count; i++) {
1339 if (!config->entries[i]->non_unique)
1341 if (!config->entries[i]->version)
1344 s = PoolPrint(L"%s (%s)", config->entries[i]->title_show, config->entries[i]->version);
1345 FreePool(config->entries[i]->title_show);
1346 config->entries[i]->title_show = s;
1347 config->entries[i]->non_unique = FALSE;
1351 for (i = 0; i < config->entry_count; i++) {
1352 for (k = 0; k < config->entry_count; k++) {
1355 if (StrCmp(config->entries[i]->title_show, config->entries[k]->title_show) != 0)
1359 config->entries[i]->non_unique = TRUE;
1360 config->entries[k]->non_unique = TRUE;
1367 for (i = 0; i < config->entry_count; i++) {
1371 if (!config->entries[i]->non_unique)
1373 if (!config->entries[i]->machine_id)
1376 m = StrDuplicate(config->entries[i]->machine_id);
1378 s = PoolPrint(L"%s (%s)", config->entries[i]->title_show, m);
1379 FreePool(config->entries[i]->title_show);
1380 config->entries[i]->title_show = s;
1381 config->entries[i]->non_unique = FALSE;
1386 for (i = 0; i < config->entry_count; i++) {
1387 for (k = 0; k < config->entry_count; k++) {
1390 if (StrCmp(config->entries[i]->title_show, config->entries[k]->title_show) != 0)
1394 config->entries[i]->non_unique = TRUE;
1395 config->entries[k]->non_unique = TRUE;
1402 for (i = 0; i < config->entry_count; i++) {
1405 if (!config->entries[i]->non_unique)
1407 s = PoolPrint(L"%s (%s)", config->entries[i]->title_show, config->entries[i]->file);
1408 FreePool(config->entries[i]->title_show);
1409 config->entries[i]->title_show = s;
1410 config->entries[i]->non_unique = FALSE;
1414 static BOOLEAN config_entry_add_call(Config *config, CHAR16 *title, EFI_STATUS (*call)(VOID)) {
1421 config_add_entry(config, entry);
1425 static ConfigEntry *config_entry_add_loader(Config *config, EFI_HANDLE *device,
1437 config_add_entry(config, entry);
1442 static BOOLEAN config_entry_add_loader_auto(Config *config, EFI_HANDLE *device, EFI_FILE *root_dir, CHAR16 *loaded_image_path,
1458 entry = config_entry_add_loader(config, device, LOADER_UNDEFINED, file, key, title, loader);
1468 static VOID config_entry_add_osx(Config *config) {
1484 found = config_entry_add_loader_auto(config, handles[i], root, NULL, L"auto-osx", 'a', L"OS X",
1495 static VOID config_entry_add_linux( Config *config, EFI_LOADED_IMAGE *loaded_image, EFI_FILE *root_dir) {
1584 entry = config_entry_add_loader(config, loaded_image->DeviceHandle, LOADER_LINUX, conf, 'l', os_name, path);
1609 static EFI_STATUS image_start(EFI_HANDLE parent_image, const Config *config, const ConfigEntry *entry) {
1629 if (config->options_edit)
1630 options = config->options_edit;
1681 static VOID config_free(Config *config) {
1684 for (i = 0; i < config->entry_count; i++)
1685 config_entry_free(config->entries[i]);
1686 FreePool(config->entries);
1687 FreePool(config->entry_default_pattern);
1688 FreePool(config->options_edit);
1689 FreePool(config->entry_oneshot);
1700 Config config;
1740 ZeroMem(&config, sizeof(Config));
1741 config_load_defaults(&config, root_dir);
1744 config_entry_add_linux(&config, loaded_image, root_dir);
1747 config_load_entries(&config, loaded_image->DeviceHandle, root_dir, loaded_image_path);
1750 config_sort_entries(&config);
1753 config_entry_add_loader_auto(&config, loaded_image->DeviceHandle, root_dir, loaded_image_path,
1755 config_entry_add_loader_auto(&config, loaded_image->DeviceHandle, root_dir, loaded_image_path,
1757 config_entry_add_loader_auto(&config, loaded_image->DeviceHandle, root_dir, loaded_image_path,
1759 config_entry_add_osx(&config);
1765 config_entry_add_call(&config, L"Reboot Into Firmware Interface", reboot_into_firmware);
1769 if (config.entry_count == 0) {
1775 config_title_generate(&config);
1778 config_default_entry_select(&config);
1781 if (config.idx_default == -1) {
1782 config.idx_default = 0;
1783 if (config.timeout_sec == 0)
1784 config.timeout_sec = 10;
1788 if (config.timeout_sec == 0) {
1795 /* find matching key in config entries */
1796 idx = entry_lookup_key(&config, config.idx_default, KEYCHAR(key));
1798 config.idx_default = idx;
1808 entry = config.entries[config.idx_default];
1812 if (!menu_run(&config, &entry, loaded_image_path))
1826 err = image_start(image, &config, entry);
1835 config.timeout_sec = 0;
1840 config_free(&config);