bool CommandData::IsConfigEnabled(int argc,char *argv[]) { bool ConfigEnabled=true; for (int I=1;I<argc;I++) if (IsSwitch(*argv[I])) { if (stricomp(&argv[I][1],"-")==0) break; if (stricomp(&argv[I][1],"cfg-")==0) ConfigEnabled=false; #ifndef GUI if (strnicomp(&argv[I][1],"ilog",4)==0) { // Ensure that correct log file name is already set // if we need to report an error when processing the command line. ProcessSwitch(&argv[I][1]); InitLogOptions(LogName); } #endif if (strnicomp(&argv[I][1],"sc",2)==0) { // Process -sc before reading any file lists. ProcessSwitch(&argv[I][1]); } } return(ConfigEnabled); }
// first arg should be file path (ie exactly what comes from crt) CCommandLineParser::CCommandLineParser(char** argv, int argc, s_arg_entry* arglist, size_t nargs) : argv(argv), argc(argc), cur(1), nargs(nargs), arglist(arglist) { char* command; while (ReadString(&command)) { size_t size = strlen(command); if (size == 0) continue; if (size > 1 && command[0] == '-') { // switch #ifdef CP_LONG_SWITCH bool long_switch = command[1] == '-'; if (long_switch) ProcessSwitch(command + 2); else { for (size_t x = 1; x < size; x++) ProcessSwitch(command[x]); } #else ProcessSwitch(command + 1); #endif } else { ProcessCommand(command); } } cur_switch = switches.begin(); }
// Preprocess those parameters, which must be processed before the rest of // command line. Return 'false' to stop further processing. void CommandData::PreprocessArg(const wchar *Arg) { if (IsSwitch(Arg[0]) && !NoMoreSwitches) { Arg++; if (Arg[0]=='-' && Arg[1]==0) // Switch "--". NoMoreSwitches=true; if (wcsicomp(Arg,L"cfg-")==0) ConfigDisabled=true; if (wcsnicomp(Arg,L"ilog",4)==0) { // Ensure that correct log file name is already set // if we need to report an error when processing the command line. ProcessSwitch(Arg); InitLogOptions(LogName,ErrlogCharset); } if (wcsnicomp(Arg,L"sc",2)==0) { // Process -sc before reading any file lists. ProcessSwitch(Arg); if (*LogName!=0) InitLogOptions(LogName,ErrlogCharset); } } else if (*Command==0) wcsncpy(Command,Arg,ASIZE(Command)); // Need for rar.ini. }
// Preprocess those parameters, which must be processed before the rest of // command line. Return 'false' to stop further processing. bool CommandData::PreprocessSwitch(const char *Switch) { if (IsSwitch(Switch[0])) { Switch++; if (stricomp(Switch,"-")==0) // Switch "--". return false; if (stricomp(Switch,"cfg-")==0) ConfigDisabled=true; #ifndef GUI if (strnicomp(Switch,"ilog",4)==0) { // Ensure that correct log file name is already set // if we need to report an error when processing the command line. ProcessSwitch(Switch); InitLogOptions(LogName); } #endif if (strnicomp(Switch,"sc",2)==0) { // Process -sc before reading any file lists. ProcessSwitch(Switch); } } return true; }
void CommandData::ProcessSwitchesString(const wchar *Str) { wchar *Par; while ((Str=AllocCmdParam(Str,&Par))!=NULL) { if (IsSwitch(*Par)) ProcessSwitch(Par+1); free(Par); } }
/*----------------------------------------------------------------------------- * program start */ int main(void) { int sioHandle; uint8_t windThreshold1; uint8_t windThreshold2; MCUSR = 0; wdt_disable(); /* get module address from EEPROM */ sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS); windThreshold1 = eeprom_read_byte((const uint8_t *)WIND_THRESHOLD1); windThreshold2 = eeprom_read_byte((const uint8_t *)WIND_THRESHOLD2); GetClientListFromEeprom(); PortInit(); TimerInit(); SioInit(); sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, eSioStopBits1, eSioModeHalfDuplex); SioSetIdleFunc(sioHandle, IdleSio); SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown); BusTransceiverPowerDown(true); BusInit(sioHandle); spRxBusMsg = BusMsgBufGet(); /* enable global interrupts */ ENABLE_INT; SendStartupMsg(); /* wait for controller startup delay for sending first state telegram */ DELAY_S(STARTUP_DELAY); while (1) { Idle(); ProcessSwitch(); ProcessBus(); if (sWind >= windThreshold1) { sWindSwitch |= 0x01; } else { sWindSwitch &= ~0x01; } if (sWind >= windThreshold2) { sWindSwitch |= 0x02; } else { sWindSwitch &= ~0x02; } } return 0; /* never reached */ }
bool CommandData::IsConfigEnabled(int argc,char *argv[]) { bool ConfigEnabled=true; for (int I=1;I<argc;I++) if (IsSwitch(*argv[I])) { if (stricomp(&argv[I][1],"cfg-")==0) ConfigEnabled=false; if (strnicomp(&argv[I][1],"ilog",4)==0) { ProcessSwitch(&argv[I][1]); InitLogOptions(LogName); } } return(ConfigEnabled); }
void CommandData::ProcessSwitchesString(char *Str) { while (*Str) { while (!IsSwitch(*Str) && *Str!=0) Str++; if (*Str==0) break; char *Next=Str; while (!(Next[0]==' ' && IsSwitch(Next[1])) && *Next!=0) Next++; char NextChar=*Next; *Next=0; ProcessSwitch(Str+1); *Next=NextChar; Str=Next; } }
void ProcessCommandline(int argc, char * argv[]) { if (argc < 4 || strlen(argv[1]) != 1) { ShowUsage(); } for (int i = 4; i < argc; ++i) { if (argv[i][0] == '-') { ProcessSwitch(&argv[i][1]); } else { ShowUsage(); } } }
void CommandData::ParseArg(char *Arg,wchar *ArgW) { if (IsSwitch(*Arg) && !NoMoreSwitches) if (Arg[1]=='-') NoMoreSwitches=true; else ProcessSwitch(&Arg[1]); else if (*Command==0) { strncpy(Command,Arg,sizeof(Command)); if (ArgW!=NULL) strncpyw(CommandW,ArgW,sizeof(CommandW)/sizeof(CommandW[0])); if (toupper(*Command)=='S') { const char *SFXName=Command[1] ? Command+1:DefSFXName; if (PointToName(SFXName)!=SFXName || FileExist(SFXName)) strcpy(SFXModule,SFXName); else GetConfigName(SFXName,SFXModule,true); } #ifndef GUI *Command=toupper(*Command); if (*Command!='I' && *Command!='S') strupper(Command); #endif } else if (*ArcName==0) { strncpy(ArcName,Arg,sizeof(ArcName)); if (ArgW!=NULL) strncpyw(ArcNameW,ArgW,sizeof(ArcNameW)/sizeof(ArcNameW[0])); } else { int Length=strlen(Arg); char EndChar=Arg[Length-1]; char CmdChar=toupper(*Command); bool Add=strchr("AFUM",CmdChar)!=NULL; bool Extract=CmdChar=='X' || CmdChar=='E'; if ((IsDriveDiv(EndChar) || IsPathDiv(EndChar)) && !Add) strcpy(ExtrPath,Arg); else if ((Add || CmdChar=='T') && *Arg!='@') FileArgs->AddString(Arg); else { struct FindData FileData; bool Found=FindFile::FastFind(Arg,NULL,&FileData); if (!Found && *Arg=='@' && !IsWildcard(Arg)) { ReadTextFile(Arg+1,FileArgs,false,true,true,true,true); FileLists=true; } else if (Found && FileData.IsDir && Extract && *ExtrPath==0) { strcpy(ExtrPath,Arg); AddEndSlash(ExtrPath); } else FileArgs->AddString(Arg); } } }
void CommandData::ParseArg(char *Arg,wchar *ArgW) { if (IsSwitch(*Arg) && !NoMoreSwitches) if (Arg[1]=='-') NoMoreSwitches=true; else ProcessSwitch(Arg+1,(ArgW!=NULL && *ArgW!=0 ? ArgW+1:NULL)); else if (*Command==0) { strncpyz(Command,Arg,ASIZE(Command)); if (ArgW!=NULL) wcsncpy(CommandW,ArgW,ASIZE(CommandW)); #ifndef GUI *Command=etoupper(*Command); // 'I' and 'S' commands can contain case sensitive strings after // the first character, so we must not modify their case. // 'S' can contain SFX name, which case is important in Unix. if (*Command!='I' && *Command!='S') strupper(Command); #endif } else if (*ArcName==0 && *ArcNameW==0) { strncpyz(ArcName,Arg,ASIZE(ArcName)); if (ArgW!=NULL) wcsncpyz(ArcNameW,ArgW,ASIZE(ArcNameW)); } else { bool EndSeparator; // If last character is the path separator. if (ArgW!=NULL) { size_t Length=wcslen(ArgW); wchar EndChar=Length==0 ? 0:ArgW[Length-1]; EndSeparator=IsDriveDiv(EndChar) || IsPathDiv(EndChar); } else { size_t Length=strlen(Arg); char EndChar=Length==0 ? 0:Arg[Length-1]; EndSeparator=IsDriveDiv(EndChar) || IsPathDiv(EndChar); } char CmdChar=etoupper(*Command); bool Add=strchr("AFUM",CmdChar)!=NULL; bool Extract=CmdChar=='X' || CmdChar=='E'; if (EndSeparator && !Add) { strncpyz(ExtrPath,Arg,ASIZE(ExtrPath)); if (ArgW!=NULL) wcsncpyz(ExtrPathW,ArgW,ASIZE(ExtrPathW)); } else if ((Add || CmdChar=='T') && *Arg!='@') FileArgs->AddString(Arg,ArgW); else { FindData FileData; bool Found=FindFile::FastFind(Arg,ArgW,&FileData); if (!Found && *Arg=='@' && !IsWildcard(Arg,ArgW)) { FileLists=true; RAR_CHARSET Charset=FilelistCharset; #if defined(_WIN_ALL) && !defined(GUI) // for compatibility reasons we use OEM encoding // in Win32 console version by default if (Charset==RCH_DEFAULT) Charset=RCH_OEM; #endif wchar *WideArgName=(ArgW!=NULL && *ArgW!=0 ? ArgW+1:NULL); ReadTextFile(Arg+1,WideArgName,FileArgs.get(),false,true,Charset,true,true,true); } else if (Found && FileData.IsDir && Extract && *ExtrPath==0 && *ExtrPathW==0) { strncpyz(ExtrPath,Arg,ASIZE(ExtrPath)-1); AddEndSlash(ExtrPath); if (ArgW!=NULL) { wcsncpyz(ExtrPathW,ArgW,ASIZE(ExtrPathW)-1); AddEndSlash(ExtrPathW); } } else FileArgs->AddString(Arg,ArgW); } } }
void CommandData::ParseArg(wchar *Arg) { if (IsSwitch(*Arg) && !NoMoreSwitches) if (Arg[1]=='-' && Arg[2]==0) NoMoreSwitches=true; else ProcessSwitch(Arg+1); else if (*Command==0) { wcsncpyz(Command,Arg,ASIZE(Command)); *Command=toupperw(*Command); // 'I' and 'S' commands can contain case sensitive strings after // the first character, so we must not modify their case. // 'S' can contain SFX name, which case is important in Unix. if (*Command!='I' && *Command!='S') wcsupper(Command); } else if (*ArcName==0) wcsncpyz(ArcName,Arg,ASIZE(ArcName)); else { // Check if last character is the path separator. size_t Length=wcslen(Arg); wchar EndChar=Length==0 ? 0:Arg[Length-1]; bool EndSeparator=IsDriveDiv(EndChar) || IsPathDiv(EndChar); wchar CmdChar=toupperw(*Command); bool Add=wcschr(L"AFUM",CmdChar)!=NULL; bool Extract=CmdChar=='X' || CmdChar=='E'; if (EndSeparator && !Add) wcsncpyz(ExtrPath,Arg,ASIZE(ExtrPath)); else if ((Add || CmdChar=='T') && (*Arg!='@' || ListMode==RCLM_REJECT_LISTS)) FileArgs.AddString(Arg); else { FindData FileData; bool Found=FindFile::FastFind(Arg,&FileData); if ((!Found || ListMode==RCLM_ACCEPT_LISTS) && ListMode!=RCLM_REJECT_LISTS && *Arg=='@' && !IsWildcard(Arg)) { FileLists=true; ReadTextFile(Arg+1,&FileArgs,false,true,FilelistCharset,true,true,true); } else if (Found && FileData.IsDir && Extract && *ExtrPath==0) { wcsncpyz(ExtrPath,Arg,ASIZE(ExtrPath)); AddEndSlash(ExtrPath,ASIZE(ExtrPath)); } else FileArgs.AddString(Arg); } } }
void CommandData::ParseArg(char *Arg,wchar *ArgW) { if (IsSwitch(*Arg) && !NoMoreSwitches) if (Arg[1]=='-') NoMoreSwitches=true; else ProcessSwitch(&Arg[1],(ArgW!=NULL && *ArgW!=0 ? &ArgW[1]:NULL)); else if (*Command==0) { strncpyz(Command,Arg,ASIZE(Command)); if (ArgW!=NULL) strncpyw(CommandW,ArgW,sizeof(CommandW)/sizeof(CommandW[0])); if (etoupper(*Command)=='S') { const char *SFXName=Command[1] ? Command+1:DefSFXName; if (PointToName(SFXName)!=SFXName || FileExist(SFXName)) strcpy(SFXModule,SFXName); else GetConfigName(SFXName,SFXModule,true); } #ifndef GUI *Command=etoupper(*Command); if (*Command!='I' && *Command!='S') strupper(Command); #endif } else if (*ArcName==0) { strncpyz(ArcName,Arg,ASIZE(ArcName)); if (ArgW!=NULL) strncpyzw(ArcNameW,ArgW,ASIZE(ArcNameW)); } else { size_t Length=strlen(Arg); char EndChar=Length==0 ? 0:Arg[Length-1]; char CmdChar=etoupper(*Command); bool Add=strchr("AFUM",CmdChar)!=NULL; bool Extract=CmdChar=='X' || CmdChar=='E'; if ((IsDriveDiv(EndChar) || IsPathDiv(EndChar)) && !Add) { strncpyz(ExtrPath,Arg,ASIZE(ExtrPath)); if (ArgW!=NULL) strncpyzw(ExtrPathW,ArgW,ASIZE(ExtrPathW)); } else if ((Add || CmdChar=='T') && *Arg!='@') FileArgs->AddString(Arg); else { struct FindData FileData; bool Found=FindFile::FastFind(Arg,NULL,&FileData); if (!Found && *Arg=='@' && !IsWildcard(Arg)) { FileLists=true; RAR_CHARSET Charset=FilelistCharset; #if defined(_WIN_32) && !defined(GUI) // for compatibility reasons we use OEM encoding // in Win32 console version by default if (Charset==RCH_DEFAULT) Charset=RCH_OEM; #endif ReadTextFile(Arg+1,FileArgs,false,true,Charset,true,true,true); } else if (Found && FileData.IsDir && Extract && *ExtrPath==0) { strcpy(ExtrPath,Arg); AddEndSlash(ExtrPath); } else FileArgs->AddString(Arg); } } }
/** * @brief The application starting point. */ int WINAPI WinMain(HINSTANCE hIconInstance, HINSTANCE, LPSTR, int) { OleInitialize(NULL); InitCommonControls(); LPWSTR szCmdLine = GetCommandLineW(); // Load the heksedit component. hMainInstance = LoadLibrary(szHexBinary); if (hMainInstance == NULL) { TCHAR complain[100]; wsprintf(complain, _T("Unable to load the %s"), szHexBinary); MessageBox(NULL, complain, NULL, MB_ICONSTOP); return 3; } // Register window class and open window. MSG msg; WNDCLASS wndclass; ZeroMemory(&wndclass, sizeof wndclass); //Register the main window class wndclass.style = CS_HREDRAW | CS_VREDRAW; wndclass.lpfnWndProc = MainWndProc; wndclass.hIcon = LoadIcon(hIconInstance, MAKEINTRESOURCE(IDI_FRHED)); wndclass.hCursor = LoadCursor(NULL, IDC_ARROW); wndclass.hInstance = hMainInstance; wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MAINMENU); wndclass.lpszClassName = szMainClass; RegisterClass(&wndclass); int iInstCount = 0; EnumWindows(WndEnumProcCountInstances, (LPARAM)&iInstCount); CreateWindow(szMainClass, 0, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL, hMainInstance, NULL); if (!pHexWnd) { MessageBox(NULL, _T("Unable to create the heksedit control"), NULL, MB_ICONSTOP); return 3; } // Read in the last saved preferences. pHexWnd->iInstCount = iInstCount; pHexWnd->read_ini_data(); // The if prevents the window from being resized to 0x0 it becomes just a title bar if (pHexWnd->iWindowX != CW_USEDEFAULT) { // Prevent window creep when Taskbar is at top or left of screen WINDOWPLACEMENT wp; wp.length = sizeof wp; GetWindowPlacement(hwndMain, &wp); wp.showCmd = pHexWnd->iWindowShowCmd; wp.rcNormalPosition.left = pHexWnd->iWindowX; wp.rcNormalPosition.top = pHexWnd->iWindowY; wp.rcNormalPosition.right = pHexWnd->iWindowWidth + pHexWnd->iWindowX; wp.rcNormalPosition.bottom = pHexWnd->iWindowHeight + pHexWnd->iWindowY; SetWindowPlacement(hwndMain, &wp); } ShowWindow(hwndMain, pHexWnd->iWindowShowCmd); UpdateWindow(hwndMain); //Parse the command line // (frhed.exe) [/s[offset]] [/l[offset]] [/e[another]] [filename] int iNumberOfArgs; LPWSTR* szArguments = CommandLineToArgvW(szCmdLine, &iNumberOfArgs); if(iNumberOfArgs > 1) { //There are command line parameters. DWORD dwStart = 0, dwLength = 0, dwEnd = 0; LPWSTR szFileToLoad = NULL; LPWSTR szNextArgument = NULL; bool bSkipNextArg = false; for (int i = 1; i < iNumberOfArgs; i++) { LPWSTR szArgUnderTest = szArguments[i]; if (i + 1 < iNumberOfArgs) szNextArgument = szArguments[i+1]; else szNextArgument = NULL; if (szArgUnderTest[0] == '/') { switch (szArgUnderTest[1]) { case 'S': // Start offset case 's': dwStart = ProcessSwitch(szArgUnderTest, szNextArgument, &bSkipNextArg); break; case 'L': // Length of selection case 'l': dwLength = ProcessSwitch(szArgUnderTest, szNextArgument, &bSkipNextArg); break; case 'E': // End of selection case 'e': dwEnd = ProcessSwitch(szArgUnderTest, szNextArgument, &bSkipNextArg); break; } if (bSkipNextArg) { //The ProcessSwitch function pulled the number out of the next command line //parameter. Don't attempt to use it for anything else! i++; } } else { szFileToLoad = szArgUnderTest; } } // If a user only selects switches, there's no file to load. if (szFileToLoad != NULL) { pHexWnd->open_file(szFileToLoad); if (dwLength) dwEnd = dwStart + dwLength - 1; if (dwEnd) pHexWnd->CMD_setselection(dwStart, dwEnd); } } while (GetMessage(&msg, NULL, 0, 0)) { if (!pHexWnd || !pHexWnd->translate_accelerator(&msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } LocalFree(szArguments); #ifdef _DEBUG // The System32 build cannot safely FreeLibrary(hMainInstance) because // frhed.exe and heksedit.dll share the same atexit list. ::FreeLibrary(hMainInstance); _CrtDumpMemoryLeaks(); #endif OleUninitialize(); return msg.wParam; }
void CCommandLineParser::ProcessSwitch(char c) { char switch_str[2] = {c, 0}; return ProcessSwitch(switch_str); }
/*----------------------------------------------------------------------------- * program start */ int main(void) { int sioHandle; uint8_t inputState; MCUSR = 0; wdt_disable(); /* get module address from EEPROM */ sMyAddr = eeprom_read_byte((const uint8_t *)MODUL_ADDRESS); sInputType = eeprom_read_byte((const uint8_t *)INPUT_TYPE); if (sInputType > INPUT_TYPE_MOTION_DETECTOR) { sInputType = INPUT_TYPE_DUAL_BUTTON; } PortInit(); TimerInit(); SioInit(); SioRandSeed(sMyAddr); sioHandle = SioOpen("USART0", eSioBaud9600, eSioDataBits8, eSioParityNo, eSioStopBits1, eSioModeHalfDuplex); SioSetIdleFunc(sioHandle, IdleSio); SioSetTransceiverPowerDownFunc(sioHandle, BusTransceiverPowerDown); BusTransceiverPowerDown(true); BusInit(sioHandle); spRxBusMsg = BusMsgBufGet(); /* enable global interrupts */ ENABLE_INT; SendStartupMsg(); if ((sInputType == INPUT_TYPE_DUAL_SWITCH) || (sInputType == INPUT_TYPE_MOTION_DETECTOR)) { /* wait for controller startup delay for sending first state telegram */ DELAY_S(STARTUP_DELAY); } if ((sInputType == INPUT_TYPE_DUAL_SWITCH) || (sInputType == INPUT_TYPE_MOTION_DETECTOR)) { inputState = GetInputState(); sSwitchStateOld = ~inputState; ProcessSwitch(inputState); } while (1) { Idle(); inputState = GetInputState(); if ((sInputType == INPUT_TYPE_DUAL_SWITCH) || (sInputType == INPUT_TYPE_MOTION_DETECTOR)) { ProcessSwitch(inputState); } else if (sInputType == INPUT_TYPE_DUAL_BUTTON) { ProcessButton(inputState); } ProcessBus(); } return 0; /* never reached */ }