esdlcmd_common.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include <stdio.h>
  14. #include "jlog.hpp"
  15. #include "jfile.hpp"
  16. #include "jargv.hpp"
  17. #include "junicode.hpp"
  18. #include "build-config.h"
  19. #include "esdlcmd_common.hpp"
  20. void outputMultiExceptions(const IMultiException &me)
  21. {
  22. fprintf(stderr, "\nException(s):\n");
  23. aindex_t count = me.ordinality();
  24. for (aindex_t i=0; i<count; i++)
  25. {
  26. IException& e = me.item(i);
  27. StringBuffer msg;
  28. fprintf(stderr, "%d: %s\n", e.errorCode(), e.errorMessage(msg).str());
  29. }
  30. fprintf(stderr, "\n");
  31. }
  32. //=========================================================================================
  33. #define PE_OFFSET_LOCATION_IN_DOS_SECTION 0x3C
  34. esdlCmdOptionMatchIndicator EsdlCmdCommon::matchCommandLineOption(ArgvIterator &iter, bool finalAttempt)
  35. {
  36. bool boolValue;
  37. if (iter.matchFlag(boolValue, ESDLOPT_HELP))
  38. {
  39. usage();
  40. return EsdlCmdOptionCompletion;
  41. }
  42. if (iter.matchFlag(boolValue, ESDLOPT_VERSION))
  43. {
  44. fprintf(stdout, "%s\n", BUILD_TAG);
  45. return EsdlCmdOptionCompletion;
  46. }
  47. if (iter.matchFlag(optVerbose, ESDL_OPTION_VERBOSE) || iter.matchFlag(optVerbose, ESDL_OPT_VERBOSE))
  48. {
  49. return EsdlCmdOptionMatch;
  50. }
  51. StringAttr tempArg;
  52. if (iter.matchOption(tempArg, "-brk"))
  53. {
  54. #if defined(_WIN32) && defined(_DEBUG)
  55. unsigned id = atoi(tempArg.str());
  56. if (id == 0)
  57. DebugBreak();
  58. else
  59. _CrtSetBreakAlloc(id);
  60. #endif
  61. return EsdlCmdOptionMatch;
  62. }
  63. if (finalAttempt)
  64. {
  65. fprintf(stderr, "\n%s option not recognized\n", iter.query());
  66. usage();
  67. }
  68. return EsdlCmdOptionNoMatch;
  69. }
  70. bool EsdlCmdCommon::finalizeOptions(IProperties *globals)
  71. {
  72. if (!optVerbose)
  73. {
  74. Owned<ILogMsgFilter> filter = getCategoryLogMsgFilter(MSGAUD_user, MSGCLS_error);
  75. queryLogMsgManager()->changeMonitorFilter(queryStderrLogMsgHandler(), filter);
  76. }
  77. return true;
  78. }
  79. bool EsdlConvertCmd::parseCommandLineOptions(ArgvIterator &iter)
  80. {
  81. if (iter.done())
  82. {
  83. usage();
  84. return false;
  85. }
  86. for (; !iter.done(); iter.next())
  87. {
  88. if (parseCommandLineOption(iter))
  89. return true;
  90. if (matchCommandLineOption(iter, true)!=EsdlCmdOptionMatch)
  91. return false;
  92. }
  93. return true;
  94. }
  95. bool EsdlConvertCmd::parseCommandLineOption(ArgvIterator &iter)
  96. {
  97. if (iter.matchOption(optSource, ESDL_CONVERT_SOURCE))
  98. return true;
  99. if (iter.matchOption(optOutDirPath, ESDL_CONVERT_OUTDIR))
  100. return true;
  101. return false;
  102. }
  103. esdlCmdOptionMatchIndicator EsdlConvertCmd::matchCommandLineOption(ArgvIterator &iter, bool finalAttempt)
  104. {
  105. if (iter.matchOption(optSource, ESDL_CONVERT_SOURCE))
  106. return EsdlCmdOptionMatch;
  107. if (iter.matchOption(optOutDirPath, ESDL_CONVERT_OUTDIR))
  108. return EsdlCmdOptionMatch;
  109. return EsdlCmdCommon::matchCommandLineOption(iter, true);
  110. }
  111. bool EsdlConvertCmd::finalizeOptions(IProperties *globals)
  112. {
  113. if (optSource.isEmpty())
  114. {
  115. fprintf(stderr, "\nError: Source esdl parameter required\n");
  116. return false;
  117. }
  118. if (optOutDirPath.isEmpty())
  119. {
  120. fprintf(stderr, "\nError: Target output directory path parameter required\n");
  121. return false;
  122. }
  123. return EsdlCmdCommon::finalizeOptions(globals);
  124. }