コード例 #1
0
ファイル: getoption.cpp プロジェクト: DemoHn/ss-libQ
/* store data function*/
void GetOption::process(int argc, char **argv)
{

    //if no other input
    if(argc <= 1){
        showHelpOption();
        return ;
    }

    for(int i=0;i<argc;i++){
        std::string str = std::string(argv[i]);
        if(str.at(0) == '-' && str.length() > 1){
            // show version data
            if(str == "-v" || str == "--version"){
                showVersionInfo();
                return ;
            }else if(str == "-h" || str == "--help"){
                showHelpOption();
                return ;
            }
            str = str.substr(1,str.length());

            if(str.at(0) == '-' && str.length() > 1){
                str = str.substr(1,str.length());
            }

            QString s = QString::fromLocal8Bit(str.c_str());
            if(isOptionKeyExists(s)){
                if(isFlagOption(s) == true){ // flag option
                    getItem(s).enableOptionFlag();
                }else{ // set value
                    if(i < argc - 1){ // not the last item
                        std::string next_str = std::string(argv[i+1]);
                        if(next_str[0] != '-'){
                            getItem(s).setOptionValue(QString::fromLocal8Bit(next_str.c_str()));
                        }
                    }
                }
            }else{
                // just ignore it
            }
        }
    }
}
コード例 #2
0
int main ( int argc, char *argv[] )
{
   struct option long_opts[] = {
	 { "help",      0, 0, 'H' },
	 { "version",   0, 0, 'V' },
	 { "nastiness", 0, 0, 'n' },
	 { "bell",      0, 0, 'b' },
	 { "flash",     0, 0, 'f' },
	 { "ugly",      0, 0, 'u' },
         { "hidekeys",  0, 0, 'k' },
	 { 0, 0, 0, 0 }
   };
   
   int opt_index = 0;
   int c;
   
   while (1) {
      c = getopt_long(argc, argv, "HVnbfuk", long_opts, &opt_index);
      if (c == -1) {
	 break;
      }
      
      switch (c) {
       case 'H':
	 showHelp();
	 return 1;
       case 'V':
	 showVersionInfo();
	 return 1;
       case 'b':
	 beepsArentIrritating = 1;
	 break;
       case 'f':
	 flashesArentIrritating = 1;
	 break;
       case 'n':
	 nastiness = 1;
	 break;
       case 'u':
	 tryToBePretty = 0;
	 break;
       case 'k':
	 hideKeys = 1;
	 break;
      }
   }
   
   initApp();

   if (optind < argc) {
      while (optind < argc) {
	 if (playFile(argv[optind]) < 0) {
	    closeApp();
	    printf ("%s: %s: %s\n", argv[0], argv[optind], postmortem);
	    return 1;
	 }
	 ++optind;
      }
   } else {
      menuInteractive();
   }
   
   closeApp();
   showVersionInfo();
    
   return 0;
}