<div class="gmail_quote">On Thu, Nov 3, 2011 at 11:51 AM, Wesley Peck <span dir="ltr"><<a href="mailto:peckw@wesleypeck.com">peckw@wesleypeck.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div class="HOEnZb"><div class="h5"><br>
On Nov 3, 2011, at 12:30 PM, Daniel Dunbar wrote:<br>
> +  for (int i = 1; i != argc; ++i) {<br>
> +    StringRef Arg = argv[i];<br>
> +<br>
> +    if (Arg.startswith("-")) {<br>
> +      HasAnyOption = true;<br>
> +      if (Arg == "--version") {<br>
> +        OS << PACKAGE_VERSION << '\n';<br>
> +      } else if (Arg == "--prefix") {<br>
> +        OS << ActivePrefix << '\n';<br>
> +      } else if (Arg == "--bindir") {<br>
> +        OS << ActiveBinDir << '\n';<br>
> +      } else if (Arg == "--includedir") {<br>
> +        OS << ActiveIncludeDir << '\n';<br>
> +      } else if (Arg == "--libdir") {<br>
> +        OS << ActiveLibDir << '\n';<br>
> +      } else if (Arg == "--cppflags") {<br>
> +        OS << ActiveIncludeOption << ' ' << LLVM_CPPFLAGS << '\n';<br>
> +      } else if (Arg == "--cflags") {<br>
> +        OS << ActiveIncludeOption << ' ' << LLVM_CFLAGS << '\n';<br>
> +      } else if (Arg == "--cxxflags") {<br>
> +        OS << ActiveIncludeOption << ' ' << LLVM_CXXFLAGS << '\n';<br>
> +      } else if (Arg == "--ldflags") {<br>
> +        OS << "-L" << ActiveLibDir << ' ' << LLVM_LDFLAGS<br>
> +           << ' ' << LLVM_SYSTEM_LIBS << '\n';<br>
> +      } else if (Arg == "--libs") {<br>
> +        PrintLibs = true;<br>
> +      } else if (Arg == "--libnames") {<br>
> +        PrintLibNames = true;<br>
> +      } else if (Arg == "--libfiles") {<br>
> +        PrintLibFiles = true;<br>
> +      } else if (Arg == "--components") {<br>
> +        for (unsigned j = 0; j != NumAvailableComponents; ++j) {<br>
> +          if (j)<br>
> +            OS << ' ';<br>
> +          OS << AvailableComponents[j].Name;<br>
> +        }<br>
> +        OS << '\n';<br>
> +      } else if (Arg == "--targets-built") {<br>
> +        bool First = true;<br>
> +        for (TargetRegistry::iterator I = TargetRegistry::begin(),<br>
> +               E = TargetRegistry::end(); I != E; First = false, ++I) {<br>
> +          if (!First)<br>
> +            OS << ' ';<br>
> +          OS << I->getName();<br>
> +        }<br>
> +        OS << '\n';<br>
> +      } else if (Arg == "--host-target") {<br>
> +        OS << LLVM_DEFAULT_TARGET_TRIPLE << '\n';<br>
> +      } else if (Arg == "--build-mode") {<br>
> +        OS << LLVM_BUILDMODE << '\n';<br>
> +      } else if (Arg == "--obj-root") {<br>
> +        OS << LLVM_OBJ_ROOT << '\n';<br>
> +      } else if (Arg == "--src-root") {<br>
> +        OS << LLVM_SRC_ROOT << '\n';<br>
> +      } else {<br>
> +        usage();<br>
> +      }<br>
> +    } else {<br>
> +      Components.push_back(Arg);<br>
> +    }<br>
> +  }<br>
> +<br>
> +  if (!HasAnyOption)<br>
> +    usage();<br>
<br>
</div></div>Just out of curiosity, why not use LLVM's command line parsing library for this? Is is not capable of parsing the required syntax or are you trying to avoid some sort of dependency? It seems like it would be a lot cleaner and easier to maintain than this code.</blockquote>
<div><br></div><div>Agreed, this would be much cleaner using the commandline library.</div><div><br></div><div>Also, there is a lot of string manipulation and path manipulation that I think would be cleaner using StringRef / Twine / raw_ostream-derivatives / PathV2... if those libraries don't quite fit or aren't so clean to use, we should improve them so that we can use them for exactly this type of ced. </div>
</div>