ccmake.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. extern "C"
  23. {
  24. void onsig(int)
  25. {
  26. if (cmCursesForm::CurrentForm)
  27. {
  28. endwin();
  29. initscr(); /* Initialization */
  30. noecho(); /* Echo off */
  31. cbreak(); /* nl- or cr not needed */
  32. keypad(stdscr,TRUE); /* Use key symbols as
  33. KEY_DOWN*/
  34. refresh();
  35. int x,y;
  36. getmaxyx(stdscr, y, x);
  37. cmCursesForm::CurrentForm->Render(1,1,x,y);
  38. cmCursesForm::CurrentForm->UpdateStatusBar();
  39. }
  40. signal(SIGWINCH, onsig);
  41. }
  42. }
  43. void CMakeErrorHandler(const char* message, const char* title, bool&, void* clientData)
  44. {
  45. cmCursesForm* self = static_cast<cmCursesForm*>( clientData );
  46. self->AddError(message, title);
  47. }
  48. int main(int argc, char** argv)
  49. {
  50. bool debug = false;
  51. unsigned int i;
  52. int j;
  53. cmake msg;
  54. std::vector<std::string> args;
  55. for(j =0; j < argc; ++j)
  56. {
  57. if(strcmp(argv[j], "-debug") == 0)
  58. {
  59. debug = true;
  60. }
  61. else
  62. {
  63. args.push_back(argv[j]);
  64. }
  65. }
  66. std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
  67. for(i=1; i < args.size(); ++i)
  68. {
  69. std::string arg = args[i];
  70. if(arg.find("-B",0) == 0)
  71. {
  72. cacheDir = arg.substr(2);
  73. }
  74. if(arg.find("-help",0) != std::string::npos ||
  75. arg.find("--help",0) != std::string::npos ||
  76. arg.find("/?",0) != std::string::npos ||
  77. arg.find("-usage",0) != std::string::npos)
  78. {
  79. msg.Usage(args[0].c_str());
  80. return -1;
  81. }
  82. }
  83. cmSystemTools::DisableRunCommandOutput();
  84. if (debug)
  85. {
  86. cmCursesForm::DebugStart();
  87. }
  88. initscr(); /* Initialization */
  89. noecho(); /* Echo off */
  90. cbreak(); /* nl- or cr not needed */
  91. keypad(stdscr,TRUE); /* Use key symbols as
  92. KEY_DOWN*/
  93. signal(SIGWINCH, onsig);
  94. int x,y;
  95. getmaxyx(stdscr, y, x);
  96. if ( x < cmCursesMainForm::MIN_WIDTH ||
  97. y < cmCursesMainForm::MIN_HEIGHT )
  98. {
  99. endwin();
  100. std::cerr << "Window is too small. A size of at least "
  101. << cmCursesMainForm::MIN_WIDTH << " x "
  102. << cmCursesMainForm::MIN_HEIGHT
  103. << " is required to run ccmake." << std::endl;
  104. return 1;
  105. }
  106. cmCursesMainForm* myform;
  107. myform = new cmCursesMainForm(args, x);
  108. myform->LoadCache(cacheDir.c_str());
  109. cmSystemTools::SetErrorCallback(CMakeErrorHandler, myform);
  110. cmCursesForm::CurrentForm = myform;
  111. myform->InitializeUI();
  112. if (myform->Configure() == 0 )
  113. {
  114. myform->Render(1, 1, x, y);
  115. myform->HandleInput();
  116. }
  117. // Need to clean-up better
  118. curses_clear();
  119. touchwin(stdscr);
  120. endwin();
  121. delete cmCursesForm::CurrentForm;
  122. cmCursesForm::CurrentForm = 0;
  123. std::cout << std::endl << std::endl;
  124. return 0;
  125. }