예제 #1
0
파일: Helper.cpp 프로젝트: bengreenier/bot
/***************************************************************************************************

Explode a string into a vector

***************************************************************************************************/
void Helper::ExplodeString(std::string base, std::string delim, std::vector<std::string>& str_store){
    size_t pos = base.find(delim);

    if(pos == std::string::npos){
        if(base != ""){
            str_store.push_back(base);
        }
        return;
    }else{
        str_store.push_back(base.substr(0, pos));
        ExplodeString(base.substr(pos+1, base.length()), delim, str_store);
    }
}
예제 #2
0
// 
// findArgument
// ------------
//   Performs a binary search on the argument vector and returns the integer 
//   corresponding to the argument, if it exists.  Otherwise returns -1.
//   arg is a pipe-delimited list of acceptable arguments.
//
int Arguments::findArgument(const string& arg) const throw()
{
	if (d_arguments.size() == 0)
	{
		return -1;
	}

	vector<std::string> tokens;
	ExplodeString(arg, tokens, '|');

	for(unsigned int i = 0;i < tokens.size();++i)
	{
		int low = 0;
		int high = d_arguments.size() - 1;

		while(low <= high)
		{
			unsigned int mid = (low + high) / 2;

			if (tokens[i] < d_arguments[mid].first)	
			{
				high = mid - 1;
			}

			else if (tokens[i] > d_arguments[mid].first) 
			{
				low = mid + 1;
			}
			
			else 
			{
				return mid;
			}
		}
	}

	return -1;
}
예제 #3
0
// 
// Arguments::setArgumentsWithSpaces
// ---------------------------------
//   Adds all tokens of the pipe-delimited string, args, to the
//   spaces vector.  keeps the vector sorted.
//
void Arguments::setArgumentsWithSpaces(const string& args) 
throw(std::bad_alloc)
{
	ExplodeString(args, s_spaceArgs, '|');
	std::sort(s_spaceArgs.begin(), s_spaceArgs.end());
}
예제 #4
0
int cMpvPluginConfig::ProcessArgs(int argc, char *const argv[])
{
  char *s;
  if ((s = getenv("DISPLAY")))
  {
    X11Display = s;
  }
  else
    setenv("DISPLAY", X11Display.c_str(), 1);

  for (;;)
  {
    switch (getopt(argc, argv, "a:v:h:d:b:l:x:rm:s"))
    {
      case 'a': // audio out
        AudioOut = optarg;
      continue;
      case 'v': // video out
        VideoOut = optarg;
      continue;
      case 'h': // hwdec-codecs
        HwDec = optarg;
      continue;
      case 'd': // dvd-device
        DiscDevice = optarg;
      continue;
      case 'b': // browser root
        BrowserRoot = optarg;
      continue;
      case 'l':  // languages
        Languages = optarg;
      continue;
      case 'x':  // playlist extensions
        PlayListExtString = optarg;
      continue;
      case 'r': // refresh rate
        RefreshRate = 1;
      continue;
      case 'm':
        MainMenuEntry = optarg;
      continue;
      case 's':
        NoScripts = 1;
      continue;
      case EOF:
      break;
      case ':':
        esyslog("[mpv]: missing argument for option '%c'\n", optopt);
        return 0;
      default:
        esyslog("[mpv]: unkown option '%c'\n", optopt);
        return 0;
    }
    break;
  }
  while (optind < argc)
  {
    esyslog("[mpv]: unhandled argument '%s'\n", argv[optind++]);
  }

  //convert the playlist extension string to a vector
  PlaylistExtensions = ExplodeString(PlayListExtString);

  return 1;
}