ucmd_browser.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* browser launcher: the real browser ships in the rootfs pack as
  2. * bin/browser.app (and can be overridden by /share/BROWSER or a FAT mount).
  3. * This tiny command keeps `browser` on PATH and in the WM's Web button. */
  4. #include "ucmd_lib.h"
  5. /* The sentinel is part of the array; do not size it to the number of
  6. * candidate strings or the loop reads past the end (that was a user #PF at
  7. * 0x40001000 in the first net-dev build). */
  8. static const char *const candidates[] = {
  9. "/share/BROWSER",
  10. "/share/BROWSER.ELF",
  11. /* The copy shipped in the command-pack rootfs. */
  12. "/ramfs/bin/browser.app",
  13. "/floppy1/BROWSER",
  14. "/floppy1/BROWSER.ELF",
  15. "/ide0p1/BROWSER",
  16. "/sata0p1/BROWSER",
  17. "/ide0/BROWSER",
  18. "/sata0/BROWSER",
  19. 0
  20. };
  21. void _start(const char *arg)
  22. {
  23. char cwd[64];
  24. char argbuf[64];
  25. unsigned int i, n = 0;
  26. while (arg && arg[n] && n + 1 < sizeof(argbuf)) {
  27. argbuf[n] = arg[n];
  28. n++;
  29. }
  30. argbuf[n] = '\0';
  31. if (u_getcwd(cwd, sizeof(cwd)) != 0 || !cwd[0]) {
  32. cwd[0] = '/';
  33. cwd[1] = '\0';
  34. }
  35. for (i = 0; i < sizeof(candidates) / sizeof(candidates[0]) &&
  36. candidates[i]; i++) {
  37. int pid = u_spawn(candidates[i], argbuf, 0, cwd);
  38. if (pid > 0) {
  39. u_puts("browser: started ");
  40. u_puts(candidates[i]);
  41. u_puts("\n");
  42. u_exit(0);
  43. }
  44. }
  45. u_puts("browser: BROWSER is not installed in the pack or on a disk\n");
  46. u_puts(" put browser.elf on the root floppy or /share\n");
  47. u_exit(1);
  48. }