/* $Id$ */ /******************************************************************************* StdIONDS.c - initializes various NDS subsystems, queries the user for command-line options, and calls the actual main program. *******************************************************************************/ #include /* Standard I/O definitions. */ #include /* Standard C Library definitions. */ #include /* Standard C string functions. */ #include /* NDS definitions. */ #include /* DS file system functions. */ extern int PROGRAM (int argc, /* The actual program to be called. */ char **argv) ; #define MAXARGS 32 #define MAXINPUT 1024 /******************************************************************************* keyPressed() - echo the character that was typed. *******************************************************************************/ static void keyPressed (int c) { if (c > 0) iprintf ("%c", c) ; } /******************************************************************************* The main program. *******************************************************************************/ int main (void) { /* Local variables. */ char *argv[MAXARGS], *buffer, *commandLine, *keyword, *s ; FILE *file ; int argc ; Keyboard *kb ; size_t length ; /* Initialize the screen for printing. */ #ifdef BOTTOM_SCREEN consoleDemoInit () ; #else videoSetMode(MODE_0_2D); videoSetModeSub(MODE_0_2D); vramSetBankA(VRAM_A_MAIN_BG); vramSetBankC(VRAM_C_SUB_BG); PrintConsole topScreen = *consoleInit(0, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, true); PrintConsole bottomScreen = *consoleInit(0, 3,BgType_Text4bpp, BgSize_T_256x256, 31, 0, false); consoleSelect(&topScreen); #endif iprintf ("Console initialized ...\n") ; /* Initialize the keyboard for typing. */ kb = keyboardGetDefault () ; kb->OnKeyPressed = keyPressed ; keyboardInit (kb) ; iprintf ("Keyboard initialized ...\n") ; /* Initialize the file system utilities. */ if (fatInitDefault ()) iprintf ("FAT library initialized ...\n") ; else iprintf ("Error initializing the file system.\n") ; /* Open the program's optional configuration file. */ commandLine = NULL ; buffer = malloc (MAXINPUT) ; sprintf (buffer, "/etc/%s.conf", SPROGRAM) ; file = fopen (buffer, "r") ; while ((file != NULL) && (fgets (buffer, MAXINPUT, file) != NULL)) { length = strlen (buffer) ; keyword = strtok (buffer, " \t\n\r") ; if ((keyword == NULL) || (*keyword == '#')) continue ; if (strcmp (keyword, "putenv") == 0) { s = strtok (NULL, " \t\n\r") ; if (s != NULL) putenv (s) ; } else if (strcmp (keyword, SPROGRAM) == 0) { s = keyword + strlen (keyword) ; if (s != (buffer + length)) s++ ; /* Arguments after keyword? */ commandLine = strdup (s) ; } } if (file != NULL) fclose (file) ; free (buffer) ; /* Ask the user to type in the command-line arguments on the keyboard. */ if (commandLine == NULL) { commandLine = malloc (MAXINPUT) ; iprintf ("\nEnter the command-line arguments: \n") ; gets (commandLine) ; } /* Parse the command-line arguments and add them to the argv[] array. */ argc = 0 ; argv[argc++] = SPROGRAM ; s = strtok (commandLine, " \t\n\r") ; while ((s != NULL) && (argc < MAXARGS)) { argv[argc++] = s ; s = strtok (NULL, " \t\n\r") ; } swiWaitForVBlank () ; /* Call the actual program. */ iprintf ("Calling %s ...\n", SPROGRAM) ; return (PROGRAM (argc, argv)) ; }