Beispiel #1
0
void
AnyOption::processCommandArgs()
{
    if(!(valueStoreOK() && CommandSet())) {
        return;
    }

    if(max_legal_args == 0) {
        max_legal_args = argc;
    }
    new_argv = (int*) malloc((max_legal_args+1) * sizeof(int));
    for(int i = 1 ; i < argc ; i++) { /* ignore first argv */
        if(argv[i][0] == long_opt_prefix[0] &&
           argv[i][1] == long_opt_prefix[1]) {  /* long GNU option */
            int match_at = parseGNU(argv[i]+2);   /* skip -- */
            if(match_at >= 0 && i < argc-1) { /* found match */
                setValue(options[match_at], argv[++i]);
            }
        } else if(argv[i][0] ==  opt_prefix_char) {   /* POSIX char */
            if(POSIX()) {
                char ch =  parsePOSIX(argv[i]+1);  /* skip - */
                if(ch != '0' && i < argc-1) { /* matching char */
                    setValue(ch,  argv[++i]);
                }
            } else { /* treat it as GNU option with a - */
                int match_at = parseGNU(argv[i]+1);   /* skip - */
                if(match_at >= 0 && i < argc-1) { /* found match */
                    setValue(options[match_at], argv[++i]);
                }
            }
        } else { /* not option but an argument keep index */
            if(new_argc < max_legal_args) {
                new_argv[ new_argc ] = i ;
                new_argc++;
            } else { /* ignore extra arguments */
                printVerbose("Ignoring extra argument: ");
                printVerbose(argv[i]);
                printVerbose();
                printAutoUsage();
            }
            printVerbose("Unknown command argument option : ");
            printVerbose(argv[i]);
            printVerbose();
            printAutoUsage();
        }
    }
}
Beispiel #2
0
bool wxExEx::Command(const wxString& command)
{
  if (command.empty() || !command.StartsWith(":"))
  {
    return false;
  }
  
  bool result = true;

  if (command == ":")
  {
    m_Frame->GetExCommand(this, command);
    return true;
  }
  else if (command == ":$")
  {
    m_STC->DocumentEnd();
  }
  else if (command == ":close")
  {
    wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, wxID_CLOSE);
    wxPostEvent(wxTheApp->GetTopWindow(), event);
  }
  else if (command == ":d")
  {
    return Delete(1);
  }
  else if (command.StartsWith(":e"))
  {
    wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, wxID_OPEN);
    
    if (command.Contains(" "))
    {
      event.SetString(command.AfterFirst(' '));
    }
    
    wxPostEvent(wxTheApp->GetTopWindow(), event);
  }
  else if (command.StartsWith(":g"))
  {
    result = CommandGlobal(command.AfterFirst('g'));
  }
  else if (command == ":n")
  {
    wxExSTC* stc = m_Frame->ExecExCommand(ID_EDIT_NEXT);
    
    if (stc != NULL)
    {
      if (m_Macros.IsPlayback())
      {
        m_STC = stc;
      }
    }
    else
    {
      result = false;
    }
  }
  else if (command == ":prev")
  {
    wxExSTC* stc = m_Frame->ExecExCommand(ID_EDIT_PREVIOUS);
    
    if (stc != NULL)
    {
      if (m_Macros.IsPlayback())
      {
        m_STC = stc;
      }
    }
    else
    {
      result = false;
    }
  }
  else if (command == ":q")
  {
    wxCloseEvent event(wxEVT_CLOSE_WINDOW);
    wxPostEvent(wxTheApp->GetTopWindow(), event);
  }
  else if (command == ":q!")
  {
    wxCloseEvent event(wxEVT_CLOSE_WINDOW);
    event.SetCanVeto(false); 
    wxPostEvent(wxTheApp->GetTopWindow(), event);
  }
  else if (command.StartsWith(":r"))
  {
    wxString arg(command.AfterFirst(' '));
    arg.Trim(false); // from left
    
    if (arg.StartsWith("!"))
    {
      if (m_Process == NULL)
      {
        m_Process = new wxExProcess;
      }
    
      m_Process->Execute(arg.AfterFirst('!'), wxEXEC_SYNC);
      m_Process->HideDialog();
      
      m_STC->AddText(m_Process->GetOutput());
    }
    else
    {
      wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, ID_EDIT_READ);
      event.SetString(arg);
      wxPostEvent(wxTheApp->GetTopWindow(), event);
    }
  }
  // e.g. set ts=4
  else if (command.StartsWith(":set "))
  {
    result = CommandSet(command.Mid(5));
  }
  else if (command.StartsWith(":w"))
  {
    if (command.Contains(" "))
    {
      wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, wxID_SAVEAS);
      event.SetString(command.AfterFirst(' '));
      wxPostEvent(wxTheApp->GetTopWindow(), event);
    }
    else
    {
      wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, wxID_SAVE);
      wxPostEvent(wxTheApp->GetTopWindow(), event);
    }
  }
  else if (command == ":x")
  {
    wxPostEvent(wxTheApp->GetTopWindow(), 
      wxCommandEvent(wxEVT_COMMAND_MENU_SELECTED, wxID_SAVE));
      
    wxPostEvent(wxTheApp->GetTopWindow(), 
      wxCloseEvent(wxEVT_CLOSE_WINDOW));
  }
  else if (command == ":y")
  {
    Yank(1);
  }
  else if (command.Last() == '=')
  {
    const int no = ToLineNumber(command.AfterFirst(':').BeforeLast('='));
    
    if (no == 0)
    {
      return false;
    }
    
    m_Frame->ShowExMessage(wxString::Format("%d", no));
    return true;
  }
  else if (command.StartsWith(":!"))
  {
    if (m_Process == NULL)
    {
      m_Process = new wxExProcess;
    }
    
    m_Process->Execute(command.AfterFirst('!'));
  }
  else if (command.AfterFirst(':').IsNumber())
  {
    m_STC->GotoLineAndSelect(atoi(command.AfterFirst(':').c_str()));
  }
  else
  {
    result = CommandRange(command.AfterFirst(':'));
  }

  if (result)
  {  
    SetLastCommand(command);
    MacroRecord(command);
  }
  else
  {
    wxBell();
  }
  
  return result;
}