ccmake.cxx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #include "../cmCacheManager.h"
  2. #include "../cmSystemTools.h"
  3. #include "../cmake.h"
  4. #include <signal.h>
  5. #include <sys/ioctl.h>
  6. #include "cmCursesMainForm.h"
  7. #include <curses.h>
  8. #include <form.h>
  9. cmCursesForm* cmCursesForm::CurrentForm=0;
  10. void onsig(int sig)
  11. {
  12. if (cmCursesForm::CurrentForm)
  13. {
  14. endwin();
  15. initscr(); /* Initialization */
  16. noecho(); /* Echo off */
  17. cbreak(); /* nl- or cr not needed */
  18. keypad(stdscr,TRUE); /* Use key symbols as
  19. KEY_DOWN*/
  20. refresh();
  21. int x,y;
  22. getmaxyx(stdscr, y, x);
  23. cmCursesForm::CurrentForm->Render(1,1,x,y);
  24. cmCursesForm::CurrentForm->UpdateStatusBar();
  25. }
  26. signal(SIGWINCH, onsig);
  27. }
  28. void CMakeErrorHandler(const char* message, const char* title, bool& disable)
  29. {
  30. cmCursesForm::CurrentForm->AddError(message, title);
  31. }
  32. int main(int argc, char** argv)
  33. {
  34. unsigned int i;
  35. int j;
  36. cmake msg;
  37. std::vector<std::string> args;
  38. for(j =0; j < argc; ++j)
  39. {
  40. args.push_back(argv[j]);
  41. }
  42. for(i=1; i < args.size(); ++i)
  43. {
  44. std::string arg = args[i];
  45. if(arg.find("-help",0) != std::string::npos ||
  46. arg.find("--help",0) != std::string::npos ||
  47. arg.find("/?",0) != std::string::npos ||
  48. arg.find("-usage",0) != std::string::npos)
  49. {
  50. msg.Usage(args[0].c_str());
  51. return -1;
  52. }
  53. }
  54. cmSystemTools::DisableRunCommandOutput();
  55. cmCacheManager::GetInstance()->LoadCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
  56. initscr(); /* Initialization */
  57. noecho(); /* Echo off */
  58. cbreak(); /* nl- or cr not needed */
  59. keypad(stdscr,TRUE); /* Use key symbols as
  60. KEY_DOWN*/
  61. signal(SIGWINCH, onsig);
  62. int x,y;
  63. getmaxyx(stdscr, y, x);
  64. if ( x < cmCursesMainForm::MIN_WIDTH ||
  65. y < cmCursesMainForm::MIN_HEIGHT )
  66. {
  67. endwin();
  68. std::cerr << "Window is too small. A size of at least "
  69. << cmCursesMainForm::MIN_WIDTH << " x "
  70. << cmCursesMainForm::MIN_HEIGHT
  71. << " is required to run ccmake." << std::endl;
  72. return 1;
  73. }
  74. cmCursesMainForm* myform;
  75. myform = new cmCursesMainForm(args);
  76. cmSystemTools::SetErrorCallback(CMakeErrorHandler);
  77. cmCursesForm::CurrentForm = myform;
  78. myform->InitializeUI();
  79. myform->RunCMake(false);
  80. myform->Render(1, 1, x, y);
  81. myform->HandleInput();
  82. // Need to clean-up better
  83. curses_clear();
  84. touchwin(stdscr);
  85. endwin();
  86. delete cmCursesForm::CurrentForm;
  87. cmCursesForm::CurrentForm = 0;
  88. return 0;
  89. }