jargv.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 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. #ifndef __JARGV__
  14. #define __JARGV__
  15. #include "jiface.hpp"
  16. #include "jfile.hpp"
  17. typedef IArrayOf<IFile> IFileArray;
  18. //Supports wildcards and @ to indicate list of filenames provided in a file.
  19. extern jlib_decl bool processArgvFilename(IFileArray & filenames, const char * filename);
  20. extern jlib_decl bool processArgvFilenamesFromFile(IFileArray & filenames, const char * filename);
  21. extern jlib_decl void expandCommaList(StringArray & target, const char * text);
  22. class jlib_decl ArgvIterator
  23. {
  24. public:
  25. ArgvIterator(int _argc, const char* _argv[]) :
  26. argv(_argv), argc(_argc)
  27. {
  28. cur = 1;
  29. }
  30. bool matchFlag(StringAttr & value, const char * name); //-Xvalue, -X option
  31. bool matchFlag(bool & value, const char * name); //-X -X-
  32. bool matchOption(StringAttr & value, const char * name); //-option[=value], -option value
  33. bool matchOption(unsigned & value, const char * name); //-option[=value], -option value
  34. bool matchPathFlag(StringBuffer & option, const char * name); //-Ivalue, -I value
  35. inline const char * query() { return cur < argc ? argv[cur] : NULL; }
  36. inline bool hasMore(int num) { return (cur + num) < argc; }
  37. inline bool first() { cur = 1; return isValid(); }
  38. inline bool isValid() const { return cur < argc; }
  39. inline bool next() { cur++; return isValid(); }
  40. inline bool done() const { return cur >= argc; }
  41. private:
  42. const char * const *argv;
  43. int argc;
  44. int cur;
  45. };
  46. #endif