ucmd_browser.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* browser launcher: the real browser is a large disk app (BROWSER on a FAT
  2. * mount) because it links ngui, the full image library, TLS and uhttp. This
  3. * 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. "/floppy1/BROWSER",
  12. "/floppy1/BROWSER.ELF",
  13. "/ide0p1/BROWSER",
  14. "/sata0p1/BROWSER",
  15. "/ide0/BROWSER",
  16. "/sata0/BROWSER",
  17. 0
  18. };
  19. void _start(const char *arg)
  20. {
  21. char cwd[64];
  22. char argbuf[64];
  23. unsigned int i, n = 0;
  24. while (arg && arg[n] && n + 1 < sizeof(argbuf)) {
  25. argbuf[n] = arg[n];
  26. n++;
  27. }
  28. argbuf[n] = '\0';
  29. if (u_getcwd(cwd, sizeof(cwd)) != 0 || !cwd[0]) {
  30. cwd[0] = '/';
  31. cwd[1] = '\0';
  32. }
  33. for (i = 0; i < sizeof(candidates) / sizeof(candidates[0]) &&
  34. candidates[i]; i++) {
  35. int pid = u_spawn(candidates[i], argbuf, 0, cwd);
  36. if (pid > 0) {
  37. u_puts("browser: started ");
  38. u_puts(candidates[i]);
  39. u_puts("\n");
  40. u_exit(0);
  41. }
  42. }
  43. u_puts("browser: BROWSER is not installed on a mounted disk\n");
  44. u_puts(" put browser.elf on the root floppy or /share\n");
  45. u_exit(1);
  46. }