esdl2xml.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. char** gArgv = NULL;
  18. int gArgc = 0;
  19. //------------------------------------------------------
  20. // usage
  21. void static usage(const char* programName)
  22. {
  23. printf("\nESDL Compiler\n\n");
  24. printf("Usage: %s [options] filename.(ecm|esdl) [<outdir>]\n", programName);
  25. printf("Output: (srcdir|<outdir>)/filename.xml\n\n");
  26. puts("Available options:");
  27. puts(" -r|--recursive: process all includes");
  28. puts(" -v|--verbose: display information");
  29. puts(" -?/-h/--help: show this usage page");
  30. exit(1);
  31. }
  32. void parseCommandLine(int argc, char* argv[], Esdl2Esxdl * cmd)
  33. {
  34. gArgv = new char*[argc+1];
  35. gArgc = 0;
  36. // parse options
  37. for (int i=0; i<argc; i++)
  38. {
  39. if (*argv[i]=='-')
  40. {
  41. if (stricmp(argv[i], "-?")==0 || stricmp(argv[i], "-h")==0 || stricmp(argv[i], "--help")==0)
  42. {
  43. usage(argv[0]);
  44. }
  45. else if (stricmp(argv[i], "-r")==0 || stricmp(argv[i], "--recursive")==0)
  46. {
  47. cmd->setRecursive(true);
  48. }
  49. else if (stricmp(argv[i], "-v")==0 || stricmp(argv[i], "--verbose")==0)
  50. {
  51. cmd->setVerbose(true);
  52. }
  53. else
  54. {
  55. fprintf(stdout, "Unknown option: %s\n", argv[i]);
  56. usage(argv[0]);
  57. }
  58. }
  59. else
  60. gArgv[gArgc++] = argv[i];
  61. }
  62. gArgv[gArgc] = NULL;
  63. if (gArgc<2 || gArgc>4)
  64. usage(argv[0]);
  65. }
  66. //------------------------------------------------------
  67. // main
  68. int main(int argc, char* argv[])
  69. {
  70. Owned<Esdl2Esxdl> cmd = new Esdl2Esxdl();
  71. parseCommandLine(argc, argv, cmd.get());
  72. cmd->transform(gArgv[1], (char*)gArgv[2]);
  73. delete [] gArgv;
  74. return 0;
  75. }
  76. // end
  77. //------------------------------------------------------