panda3dWinMain.cxx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Filename: panda3dWinMain.cxx
  2. // Created by: drose (23Oct09)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. //
  6. // PANDA 3D SOFTWARE
  7. // Copyright (c) Carnegie Mellon University. All rights reserved.
  8. //
  9. // All use of this software is subject to the terms of the revised BSD
  10. // license. You should have received a copy of this license along
  11. // with this source code in a file named "LICENSE."
  12. //
  13. ////////////////////////////////////////////////////////////////////
  14. #include "panda3d.h"
  15. // On Windows, we may need to build panda3dw.exe, a non-console
  16. // version of this program.
  17. // Returns a newly-allocated string representing the quoted argument
  18. // beginning at p. Advances p to the first character following the
  19. // close quote.
  20. static char *
  21. parse_quoted_arg(char *&p) {
  22. char quote = *p;
  23. ++p;
  24. string result;
  25. while (*p != '\0' && *p != quote) {
  26. // TODO: handle escape characters? Not sure if we need to.
  27. result += *p;
  28. ++p;
  29. }
  30. if (*p == quote) {
  31. ++p;
  32. }
  33. return strdup(result.c_str());
  34. }
  35. // Returns a newly-allocated string representing the unquoted argument
  36. // beginning at p. Advances p to the first whitespace following the
  37. // argument.
  38. static char *
  39. parse_unquoted_arg(char *&p) {
  40. string result;
  41. while (*p != '\0' && !isspace(*p)) {
  42. result += *p;
  43. ++p;
  44. }
  45. return strdup(result.c_str());
  46. }
  47. int WINAPI
  48. WinMain(HINSTANCE, HINSTANCE, LPSTR, int) {
  49. char *command_line = GetCommandLine();
  50. vector<char *> argv;
  51. char *p = command_line;
  52. while (*p != '\0') {
  53. if (*p == '"') {
  54. char *arg = parse_quoted_arg(p);
  55. argv.push_back(arg);
  56. } else {
  57. char *arg = parse_unquoted_arg(p);
  58. argv.push_back(arg);
  59. }
  60. // Skip whitespace.
  61. while (*p != '\0' && isspace(*p)) {
  62. ++p;
  63. }
  64. }
  65. assert(!argv.empty());
  66. Panda3D program(false);
  67. return program.run_command_line(argv.size(), &argv[0]);
  68. }