ccmake.cxx 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*=========================================================================
  2. Program: Insight Segmentation & Registration Toolkit
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Insight Consortium. All rights reserved.
  8. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #include "../cmCacheManager.h"
  14. #include "../cmSystemTools.h"
  15. #include "../cmake.h"
  16. #include <signal.h>
  17. #include <sys/ioctl.h>
  18. #include "cmCursesMainForm.h"
  19. #include <curses.h>
  20. #include <form.h>
  21. cmCursesForm* cmCursesForm::CurrentForm=0;
  22. void onsig(int sig)
  23. {
  24. if (cmCursesForm::CurrentForm)
  25. {
  26. endwin();
  27. initscr(); /* Initialization */
  28. noecho(); /* Echo off */
  29. cbreak(); /* nl- or cr not needed */
  30. keypad(stdscr,TRUE); /* Use key symbols as
  31. KEY_DOWN*/
  32. refresh();
  33. int x,y;
  34. getmaxyx(stdscr, y, x);
  35. cmCursesForm::CurrentForm->Render(1,1,x,y);
  36. cmCursesForm::CurrentForm->UpdateStatusBar();
  37. }
  38. signal(SIGWINCH, onsig);
  39. }
  40. void CMakeErrorHandler(const char* message, const char* title, bool& disable)
  41. {
  42. cmCursesForm::CurrentForm->AddError(message, title);
  43. }
  44. int main(int argc, char** argv)
  45. {
  46. bool debug = false;
  47. unsigned int i;
  48. int j;
  49. cmake msg;
  50. std::vector<std::string> args;
  51. for(j =0; j < argc; ++j)
  52. {
  53. if(strcmp(argv[j], "-debug") == 0)
  54. {
  55. debug = true;
  56. }
  57. else
  58. {
  59. args.push_back(argv[j]);
  60. }
  61. }
  62. for(i=1; i < args.size(); ++i)
  63. {
  64. std::string arg = args[i];
  65. if(arg.find("-help",0) != std::string::npos ||
  66. arg.find("--help",0) != std::string::npos ||
  67. arg.find("/?",0) != std::string::npos ||
  68. arg.find("-usage",0) != std::string::npos)
  69. {
  70. msg.Usage(args[0].c_str());
  71. return -1;
  72. }
  73. }
  74. cmSystemTools::DisableRunCommandOutput();
  75. cmCacheManager::GetInstance()->LoadCache(cmSystemTools::GetCurrentWorkingDirectory().c_str());
  76. if (debug)
  77. {
  78. cmCursesForm::DebugStart();
  79. }
  80. initscr(); /* Initialization */
  81. noecho(); /* Echo off */
  82. cbreak(); /* nl- or cr not needed */
  83. keypad(stdscr,TRUE); /* Use key symbols as
  84. KEY_DOWN*/
  85. signal(SIGWINCH, onsig);
  86. int x,y;
  87. getmaxyx(stdscr, y, x);
  88. if ( x < cmCursesMainForm::MIN_WIDTH ||
  89. y < cmCursesMainForm::MIN_HEIGHT )
  90. {
  91. endwin();
  92. std::cerr << "Window is too small. A size of at least "
  93. << cmCursesMainForm::MIN_WIDTH << " x "
  94. << cmCursesMainForm::MIN_HEIGHT
  95. << " is required to run ccmake." << std::endl;
  96. return 1;
  97. }
  98. cmCursesMainForm* myform;
  99. myform = new cmCursesMainForm(args);
  100. cmSystemTools::SetErrorCallback(CMakeErrorHandler);
  101. cmCursesForm::CurrentForm = myform;
  102. myform->InitializeUI();
  103. myform->RunCMake(false);
  104. myform->Render(1, 1, x, y);
  105. myform->HandleInput();
  106. // Need to clean-up better
  107. curses_clear();
  108. touchwin(stdscr);
  109. endwin();
  110. delete cmCursesForm::CurrentForm;
  111. cmCursesForm::CurrentForm = 0;
  112. std::cout << std::endl << std::endl;
  113. return 0;
  114. }