esdl2xml.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2014 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 <stdlib.h>
  15. #include <string.h>
  16. #include "esdl2xml.hpp"
  17. #include "jprop.hpp"
  18. #include "esdlcmdutils.hpp"
  19. char** gArgv = NULL;
  20. int gArgc = 0;
  21. StringBuffer includePath;
  22. //------------------------------------------------------
  23. // usage
  24. void static usage(const char* programName)
  25. {
  26. printf("\nESDL Compiler\n\n");
  27. printf("Usage: %s [options] filename.(ecm|esdl) [<outdir>]\n", programName);
  28. printf("Output: (srcdir|<outdir>)/filename.xml\n\n");
  29. puts("Available options:");
  30. puts(" -r|--recursive: process all includes");
  31. puts(" -I|--include-path <include path>: Locations to look for included esdl files");
  32. puts(" -v|--verbose: display information");
  33. puts(" -?/-h/--help: show this usage page");
  34. exit(1);
  35. }
  36. void parseCommandLine(int argc, char* argv[], Esdl2Esxdl * cmd)
  37. {
  38. gArgv = new char*[argc+1];
  39. gArgc = 0;
  40. // parse options
  41. for (int i=0; i<argc; i++)
  42. {
  43. if (*argv[i]=='-')
  44. {
  45. if (stricmp(argv[i], "-?")==0 || stricmp(argv[i], "-h")==0 || stricmp(argv[i], "--help")==0)
  46. {
  47. usage(argv[0]);
  48. }
  49. else if (stricmp(argv[i], "-r")==0 || stricmp(argv[i], "--recursive")==0)
  50. {
  51. cmd->setRecursive(true);
  52. }
  53. else if (stricmp(argv[i], "-I")==0 || stricmp(argv[i], "--include-path")==0)
  54. {
  55. if (i < argc - 1)
  56. {
  57. if(includePath.length() > 0)
  58. includePath.append(ENVSEPSTR);
  59. includePath.append(argv[++i]);
  60. }
  61. }
  62. else if (stricmp(argv[i], "-v")==0 || stricmp(argv[i], "--verbose")==0)
  63. {
  64. cmd->setVerbose(true);
  65. }
  66. else
  67. {
  68. fprintf(stderr, "Unknown option: %s\n", argv[i]);
  69. usage(argv[0]);
  70. }
  71. }
  72. else
  73. gArgv[gArgc++] = argv[i];
  74. }
  75. gArgv[gArgc] = NULL;
  76. if (gArgc<2 || gArgc>4)
  77. usage(argv[0]);
  78. }
  79. //------------------------------------------------------
  80. // main
  81. int main(int argc, char* argv[])
  82. {
  83. Owned<Esdl2Esxdl> cmd = new Esdl2Esxdl();
  84. parseCommandLine(argc, argv, cmd.get());
  85. extractEsdlCmdOption(includePath, NULL, "ESDL_INCLUDE_PATH", "esdlIncludePath", NULL, NULL);
  86. cmd->setIncluePath(includePath.str());
  87. cmd->transform(gArgv[1], (char*)gArgv[2]);
  88. delete [] gArgv;
  89. return 0;
  90. }
  91. // end
  92. //------------------------------------------------------