Esempio n. 1
0
    Ecppc::Ecppc(int& argc, char* argv[])
      : _componentname(cxxtools::Arg<std::string>(argc, argv, 'n')),
        _inputfile(0),
        _ofile(cxxtools::Arg<std::string>(argc, argv, 'o')),
        _odir(cxxtools::Arg<std::string>(argc, argv, 'O')),
        _mimetype(cxxtools::Arg<std::string>(argc, argv, 'm')),
        _mimedb(cxxtools::Arg<std::string>(argc, argv, "--mimetypes", "/etc/mime.types")),
        _logCategory(cxxtools::Arg<std::string>(argc, argv, 'l'))
    {
      while (true)
      {
        cxxtools::Arg<std::string> include(argc, argv, 'I');
        if (!include.isSet())
          break;
        log_debug("include: " << include.getValue());
        _includes.push_back(include);
      }

      // boolean arguments have to be read after the includes
      // because else parts of the include directory string
      // might be interpreted as flags and taken out, often
      // resulting in an missing include error message.
      cxxtools::Arg<bool> version(argc, argv, 'V');
      cxxtools::Arg<bool> versionLong(argc, argv, "--version");
      if (version || versionLong)
      {
          std::cout << PACKAGE_STRING << std::endl;
          exit(0);
      }

      cxxtools::Arg<bool> help(argc, argv, 'h');
      cxxtools::Arg<bool> helpLong(argc, argv, "--help");

      if(help || helpLong)
      {
          std::cout << PACKAGE_STRING "\n\n"
              "ecppc-compiler\n\n"
              "usage: " << argv[0] << " [options] ecpp-source\n\n"
              "  -o filename       outputfile\n"
              "  -n name           componentname\n"
              "  -I dir            include-directory\n"
              "  -m type           mimetype\n"
              "  --mimetypes file  read mimetypes from file (default /etc/mime.types)\n"
              "  -b                binary\n"
              "  -bb               generate multibinary component\n"
              "  -i filename       read filenames for multibinary component from specified file\n"
              "  -z                compress constant data\n"
              "  -v                verbose\n"
              "  -M                generate dependency for Makefile\n"
              "  -p                keep path when generating component name from filename\n"
              "  -l log-category   set log category (default: component.compname)\n"
              "  -L                disable generation of #line-directives\n"
              "\n"
              "  -h, --help        display this information\n"
              "  -V, --version     display program version\n" << std::endl;

          exit(0);
      }

      _binary = cxxtools::Arg<bool>(argc, argv, 'b');
      _multibinary = cxxtools::Arg<bool>(argc, argv, 'b');
      _keepPath = cxxtools::Arg<bool>(argc, argv, 'p');
      _compress = cxxtools::Arg<bool>(argc, argv, 'z');
      _verbose = cxxtools::Arg<bool>(argc, argv, 'v');
      _generateDependencies = cxxtools::Arg<bool>(argc, argv, 'M');
      _disableLinenumbers = cxxtools::Arg<bool>(argc, argv, 'L');

      if (_multibinary)
      {
        cxxtools::Arg<const char*> ifiles(argc, argv, 'i');
        if (ifiles.isSet())
        {
          std::ifstream in(ifiles.getValue());
          std::string ifile;
          while (std::getline(in, ifile))
          {
            std::string key = ifile;
            if (!_keepPath)
            {
              // strip path
              std::string::size_type p;
              if ((p = key.find_last_of('/')) != std::string::npos)
                key.erase(0, p + 1);
            }

            _inputFiles.insert(inputfiles_type::value_type(key, ifile));
          }
        }

        for (int a = 1; a < argc; ++a)
        {
          std::string ifile = argv[a];
          std::string key = ifile;
          if (!_keepPath)
          {
            // strip path
            std::string::size_type p;
            if ((p = key.find_last_of('/')) != std::string::npos)
              key.erase(0, p + 1);
          }

          _inputFiles.insert(inputfiles_type::value_type(key, ifile));
        }
      }
      else
      {
        if (argc < 2 || argv[1][0] == '-')
          throw std::runtime_error(
            "error: exactly one input file has to be specified\n"
            "usage: " + std::string(argv[0]) + " [options] ecpp-source\n"
            "more info with -h / --help"
          );

        _inputfile = argv[1];
      }
    }
Esempio n. 2
0
File: ecppc.cpp Progetto: hdl/tntnet
Ecppc::Ecppc(int& argc, char* argv[])
    : requestname(cxxtools::Arg<std::string>(argc, argv, 'n')),
      ofile(cxxtools::Arg<std::string>(argc, argv, 'o')),
      odir(cxxtools::Arg<std::string>(argc, argv, 'O')),
      mimetype(cxxtools::Arg<std::string>(argc, argv, 'm')),
      mimedb(cxxtools::Arg<std::string>(argc, argv, "--mimetypes", "/etc/mime.types"))
{

    while (true)
    {
        cxxtools::Arg<std::string> include(argc, argv, 'I');
        if (!include.isSet())
            break;
        log_debug("include: " << include.getValue());
        includes.push_back(include);
    }

    binary = cxxtools::Arg<bool>(argc, argv, 'b');
    multibinary = cxxtools::Arg<bool>(argc, argv, 'b');
    keepPath = cxxtools::Arg<bool>(argc, argv, 'p');
    compress = cxxtools::Arg<bool>(argc, argv, 'z');
    verbose = cxxtools::Arg<bool>(argc, argv, 'v');
    generateDependencies = cxxtools::Arg<bool>(argc, argv, 'M');
    disableLinenumbers = cxxtools::Arg<bool>(argc, argv, 'L');
    logCategory = cxxtools::Arg<std::string>(argc, argv, 'l');

    if (multibinary)
    {
        cxxtools::Arg<const char*> ifiles(argc, argv, 'i');
        if (ifiles.isSet())
        {
            std::ifstream in(ifiles.getValue());
            std::string ifile;
            while (std::getline(in, ifile))
            {
                std::string key = ifile;
                if (!keepPath)
                {
                    // strip path
                    std::string::size_type p;
                    if ((p = key.find_last_of('/')) != std::string::npos)
                        key.erase(0, p + 1);
                }

                inputfiles.insert(inputfiles_type::value_type(key, ifile));
            }
        }

        for (int a = 1; a < argc; ++a)
        {
            std::string ifile = argv[a];
            std::string key = ifile;
            if (!keepPath)
            {
                // strip path
                std::string::size_type p;
                if ((p = key.find_last_of('/')) != std::string::npos)
                    key.erase(0, p + 1);
            }

            inputfiles.insert(inputfiles_type::value_type(key, ifile));
        }
    }
    else
    {
        if (argc < 2 || argv[1][0] == '-')
            throw Usage(argv[0]);
        inputfile = argv[1];
    }
}