// Parses command-line arguments to fill up config object. Also performs some // semantic checks. static int ParseCommandLine(int argc, const char* argv[], WebPMuxConfig* config) { int i = 0; int feature_arg_index = 0; int ok = 1; while (i < argc) { Feature* const feature = &config->feature_; FeatureArg* const arg = &feature->args_[feature_arg_index]; if (argv[i][0] == '-') { // One of the action types or output. if (!strcmp(argv[i], "-set")) { if (ACTION_IS_NIL) { config->action_type_ = ACTION_SET; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } ++i; } else if (!strcmp(argv[i], "-get")) { if (ACTION_IS_NIL) { config->action_type_ = ACTION_GET; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } ++i; } else if (!strcmp(argv[i], "-strip")) { if (ACTION_IS_NIL) { config->action_type_ = ACTION_STRIP; feature->arg_count_ = 0; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } ++i; } else if (!strcmp(argv[i], "-frame")) { CHECK_NUM_ARGS_LESS(3, ErrParse); if (ACTION_IS_NIL || config->action_type_ == ACTION_SET) { config->action_type_ = ACTION_SET; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } if (FEATURETYPE_IS_NIL || feature->type_ == FEATURE_ANMF) { feature->type_ = FEATURE_ANMF; } else { ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse); } arg->subtype_ = SUBTYPE_ANMF; arg->filename_ = argv[i + 1]; arg->params_ = argv[i + 2]; ++feature_arg_index; i += 3; } else if (!strcmp(argv[i], "-loop") || !strcmp(argv[i], "-bgcolor")) { CHECK_NUM_ARGS_LESS(2, ErrParse); if (ACTION_IS_NIL || config->action_type_ == ACTION_SET) { config->action_type_ = ACTION_SET; } else { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } if (FEATURETYPE_IS_NIL || feature->type_ == FEATURE_ANMF) { feature->type_ = FEATURE_ANMF; } else { ERROR_GOTO1("ERROR: Multiple features specified.\n", ErrParse); } arg->subtype_ = !strcmp(argv[i], "-loop") ? SUBTYPE_LOOP : SUBTYPE_BGCOLOR; arg->params_ = argv[i + 1]; ++feature_arg_index; i += 2; } else if (!strcmp(argv[i], "-o")) { CHECK_NUM_ARGS_LESS(2, ErrParse); config->output_ = argv[i + 1]; i += 2; } else if (!strcmp(argv[i], "-info")) { CHECK_NUM_ARGS_NOT_EQUAL(2, ErrParse); if (config->action_type_ != NIL_ACTION) { ERROR_GOTO1("ERROR: Multiple actions specified.\n", ErrParse); } else { config->action_type_ = ACTION_INFO; feature->arg_count_ = 0; config->input_ = argv[i + 1]; } i += 2; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "-help")) { PrintHelp(); DeleteConfig(config); exit(0); } else if (!strcmp(argv[i], "-version")) { const int version = WebPGetMuxVersion(); printf("%d.%d.%d\n", (version >> 16) & 0xff, (version >> 8) & 0xff, version & 0xff); DeleteConfig(config); exit(0); } else if (!strcmp(argv[i], "--")) { if (i < argc - 1) { ++i; if (config->input_ == NULL) { config->input_ = argv[i]; } else { ERROR_GOTO2("ERROR at '%s': Multiple input files specified.\n", argv[i], ErrParse); } } break; } else { ERROR_GOTO2("ERROR: Unknown option: '%s'.\n", argv[i], ErrParse); } } else { // One of the feature types or input. if (ACTION_IS_NIL) {
bool OpenFilesInPrevInst(const wxString& flist) { #ifdef __WXMSW__ g_Mutex = CreateMutex(NULL, true, wxT("wxMEdit_App")); if(GetLastError() != ERROR_ALREADY_EXISTS) return false; const wxChar wxCanvasClassNameNR[] = wxT("wxWindowClassNR"); // class name of MadEditFrame wxChar title[256]={0}; HWND prevapp = ::FindWindowEx(NULL, NULL, wxCanvasClassNameNR, nullptr); for(;;) // find wxCanvasClassNameNR { if(prevapp) { int len = ::GetWindowText(prevapp, title, 256); if(len>=8 && title[len-1]==wxT(' ')) // last wchar is space? { title[7]=0; if(lstrcmp(title, wxT("wxMEdit"))==0) // compare first 7 wchars break; } } else { Sleep(50); } prevapp =::FindWindowEx(NULL, prevapp, wxCanvasClassNameNR, nullptr); } if(prevapp == NULL) return false; // send msg to the previous instance WINDOWPLACEMENT wp; wp.length=sizeof(WINDOWPLACEMENT); GetWindowPlacement(prevapp, &wp); if(wp.showCmd!=SW_SHOWMINIMIZED) { ::SetForegroundWindow(prevapp); } COPYDATASTRUCT cds = { (ULONG_PTR)prevapp, DWORD((flist.length()+1)*sizeof(wxChar)), (PVOID)(const wxChar*)flist.c_str() }; ::SendMessage(prevapp, WM_COPYDATA, 0, (LPARAM) &cds); g_DoNotSaveSettings = true; DeleteConfig(); return true; #elif defined(__WXGTK__) g_Display=GDK_DISPLAY(); g_MadEdit_atom = XInternAtom(g_Display, "g_wxMEdit_atom", False); Window madedit_win; if ((madedit_win=XGetSelectionOwner(g_Display, g_MadEdit_atom)) == None) return false; send_message(madedit_win, flist); g_DoNotSaveSettings = true; DeleteConfig(); return true; #else // not supported return false; #endif }