Ejemplo n.º 1
0
static error_t parse_opt(int key, char* arg, struct argp_state* state) {
    Args& a = *((Args*)state->input);

    switch (key) {
        case 'g':
            a.generator = getMGTypeFromName(arg);
            if (a.generator == MazeGenerator::Type::UNKNOWN) {
                argp_error(state, "unknown generator -- '%s'", arg);
            }
            break;
        case 'c':
            a.renderer = ConsoleMazeRenderer::RenderType::COLOR;
            break;
        case 'n':
            a.renderer = ConsoleMazeRenderer::RenderType::NO_COLOR;
            break;
        case ARGP_KEY_ARG:
            handleArg(state, arg, a);
            break;
        case ARGP_KEY_END:
            if (!a.valid()) argp_error(state, "too few arguments");
            break;
        default:
            return ARGP_ERR_UNKNOWN;
    }
    return 0;
}
Ejemplo n.º 2
0
CrustaApp::
CrustaApp(int& argc, char**& argv, char**& appDefaults) :
    Vrui::Application(argc, argv, appDefaults),
    dataDialog(NULL),
    paletteEditor(new PaletteEditor), layerSettings(paletteEditor)
{
    crusta = new Crusta(argv[0]);
    paletteEditor->getColorMapEditor()->getColorMapChangedCallbacks().add(this, &CrustaApp::changeColorMapCallback);
    paletteEditor->getRangeEditor()->getRangeChangedCallbacks().add(this, &CrustaApp::changeColorMapRangeCallback);

    for (int i=1; i<argc; ++i) handleArg(argv[i]);
    crusta->start();

    produceMainMenu();

    /* Set the navigational coordinate system unit: */
    Vrui::getCoordinateManager()->setUnit(
        Geometry::LinearUnit(Geometry::LinearUnit::METER, 1));

    /* Register a geodetic coordinate transformer with Vrui's coordinate manager: */
    VruiCoordinateTransform* userTransform;
    userTransform=new VruiCoordinateTransform;
    userTransform->setupComponent(crusta);
    Vrui::getCoordinateManager()->setCoordinateTransform(userTransform); // coordinate manager owns userTransform

    resetNavigationCallback(NULL);

#if CRUSTA_ENABLE_DEBUG
    DebugTool::init();
#endif //CRUSTA_ENABLE_DEBUG
}
Ejemplo n.º 3
0
void CrustaApp::handleArg(const std::string& arg)
{
  int file = open(arg.c_str(), O_RDONLY | O_NONBLOCK);
  if (file == -1) {
    std::cerr << "Warning: skipping unreadable file " << arg << std::endl;
    return;
  }
  struct stat stat_buf;
  int stat_status = fstat(file, &stat_buf);
  if (stat_status == -1) {
    std::cerr << "Warning: skipping unstatable file " << arg << std::endl;
  }
  std::string ext = get_extension(arg);
  if (ext == "cfg") {
    std::cerr << "Config: " << arg << std::endl;
    SETTINGS->mergeFromCfgFile(arg);
  } else if (ext == "wrl") {
    std::cerr << "VRML: " << arg << std::endl;
    crusta->loadSceneGraph(arg);
  } else if (ext == "pal") {
    std::cerr << "Palette: " << arg << std::endl;
    crusta->setPalette(arg);
  } else if (S_ISDIR(stat_buf.st_mode)) {
      std::cerr << "Globe: " << arg << std::endl;
      crusta->loadGlobe(arg);
  } else {
    std::cerr << "Project: " << arg << std::endl;
    std::string basedir = "./";
    size_t pos = arg.find_last_of("/");
    if (pos != string::npos) basedir = arg.substr(0, pos+1);
    std::string line;
    fcntl(file, F_SETFL, 0); // clear O_NONBLOCK
    while (true) {
      char buf;
      ssize_t s = read(file, &buf, 1);
      if (s <= 0 || buf == '\n' || buf == '\r') {
        if (!line.empty() && line[0] != '#') {
          if (line[0] != '/') line = basedir + line;
          handleArg(line);
        }
        if (s > 0) line.clear(); else break;
      } else {
        line += buf;
      }
    }
  }
  close(file);
}