Skip to content

Commit

Permalink
Issue 56, offer menu when multiple init choices configured
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Valencia committed May 29, 2015
1 parent 5d3ec9b commit 916d789
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions samo-lib/grifo/applications/init/init.c
Expand Up @@ -53,36 +53,46 @@ struct {
char buffer[65536];


bool ReadCommands(const char *filename);
int ReadCommands(const char *filename);
int MenuHandler(void);
int CursorPosition(int x, int y);
bool ReadIcon(void *icon, ssize_t size, const char *filename);


int grifo_main(int argc, char *argv[])
{
int nelem, m;

debug_print("init starting\n");

if (!ReadCommands("init.ini")) {
nelem = ReadCommands("init.ini");

// Nothing good in the file, give up
if (nelem == 0) {
debug_print("init no init.ini entries\n");
return EXIT_POWER_OFF;
}

// run the auto-boot item 0
if (argc > 1 && 0 == strcmp("auto-boot", argv[1]) && MenuRecord[0].ok) {
// One menu item, run it if autobooting
if ((nelem == 1) && MenuRecord[0].ok) {
debug_print("init boot only\n");
chain(MenuRecord[0].command);
}

// menu for non-auto-boot
int m = MenuHandler();
debug_print("init choosing...\n");
m = MenuHandler();
if (MenuRecord[m].ok) {
debug_printf("init chose %d\n", m);
chain(MenuRecord[m].command);
}

return EXIT_POWER_OFF;
}


bool ReadCommands(const char *filename)
int
ReadCommands(const char *filename)
{
int handle = file_open(filename, FILE_OPEN_READ);
if (handle < 0) {
Expand Down Expand Up @@ -185,7 +195,7 @@ bool ReadCommands(const char *filename)
}
}

return item > 0;
return(item);
}


Expand Down

0 comments on commit 916d789

Please sign in to comment.