/* * CD / CHDIR * */ INT cmd_chdir (LPTSTR param) { TCHAR szCurrent[MAX_PATH]; BOOL bChangeDrive = FALSE; /* Filter out special cases first */ /* Print Help */ if (!_tcsncmp(param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_CD_HELP); return 0; } /* Remove " */ StripQuotes(param); /* Set Error Level to Success */ nErrorLevel = 0; /* Print Current Directory on a disk */ if (_tcslen(param) == 2 && param[1] == _T(':')) { if (GetRootPath(param, szCurrent, MAX_PATH)) { error_invalid_drive(); return 1; } ConOutPuts(szCurrent); return 0; } /* Get Current Directory */ GetCurrentDirectory(MAX_PATH, szCurrent); if (param[0] == _T('\0')) { ConOutPuts(szCurrent); return 0; } /* Input String Contains /D Switch */ if (!_tcsncicmp(param, _T("/D"), 2)) { bChangeDrive = TRUE; param += 2; while (_istspace(*param)) param++; } if (!SetRootPath(bChangeDrive ? NULL : szCurrent, param)) return 1; return 0; }
/* * dirs command */ INT CommandDirs (LPTSTR rest) { LPDIRENTRY lpDir; if (!_tcsncmp(rest, _T("/?"), 2)) { ConOutResPuts(STRING_DIRSTACK_HELP3); return 0; } nErrorLevel = 0; lpDir = lpStackBottom; if (lpDir == NULL) { ConOutResPuts(STRING_DIRSTACK_HELP4); return 0; } while (lpDir != NULL) { ConOutPuts(lpDir->szPath); lpDir = lpDir->prev; } return 0; }
VOID PrintCommandList(VOID) { LPCOMMAND cmdptr; INT y; y = 0; cmdptr = cmds; while (cmdptr->name) { if (!(cmdptr->flags & CMD_HIDE)) { if (++y == 8) { ConOutPuts(cmdptr->name); y = 0; } else { ConOutPrintf (_T("%-10s"), cmdptr->name); } } cmdptr++; } if (y != 0) ConOutChar(_T('\n')); }
INT CommandEcho (LPTSTR param) { LPTSTR p1; TRACE ("CommandEcho: '%s'\n", debugstr_aw(param)); /* skip all spaces for the check of '/?', 'ON' and 'OFF' */ p1 = param; while(_istspace(*p1)) p1++; if (!_tcsncmp (p1, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_ECHO_HELP4); return 0; } if (!OnOffCommand(p1, &bEcho, STRING_ECHO_HELP5)) { /* skip the first character */ ConOutPuts(param + 1); ConOutChar(_T('\n')); } return 0; }
VOID ShortVersion (VOID) { OSVERSIONINFO VersionInfo; unsigned RosVersionLen; LPTSTR RosVersion; ConOutResPrintf(STRING_CMD_SHELLINFO, _T(KERNEL_RELEASE_STR), _T(KERNEL_VERSION_BUILD_STR)); VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); memset(VersionInfo.szCSDVersion, 0, sizeof(VersionInfo.szCSDVersion)); if (GetVersionEx(&VersionInfo)) { RosVersion = VersionInfo.szCSDVersion + _tcslen(VersionInfo.szCSDVersion) + 1; RosVersionLen = sizeof(VersionInfo.szCSDVersion) / sizeof(VersionInfo.szCSDVersion[0]) - (RosVersion - VersionInfo.szCSDVersion); if (7 <= RosVersionLen && 0 == _tcsnicmp(RosVersion, _T("IRTriage"), 7)) { ConOutResPrintf(STRING_VERSION_RUNVER, RosVersion); } } ConOutPuts (_T("\n")); }
int main (int argc, char **argv) { INT i; HANDLE hFind; HANDLE hConsoleIn, hConsoleOut, hFile; char buff[BUFF_SIZE]; DWORD dwRead,dwWritten; BOOL bRet; WIN32_FIND_DATA FindData; hConsoleIn = GetStdHandle(STD_INPUT_HANDLE); hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE); if (argc == 2 && _tcsncmp (argv[1], _T("/?"), 2) == 0) { ConOutPuts(_T("copy stdin to stdout and then files to stdout\n" "\n" "Y [files]\n" "\n" "files files to copy to stdout")); return 0; } /*stdin to stdout*/ do { bRet = ReadFile(hConsoleIn,buff,sizeof(buff),&dwRead,NULL); if (dwRead>0 && bRet) WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL); } while(dwRead>0 && bRet); /*files to stdout*/ Sleep(0); for (i = 1; i < argc; i++) { hFind=FindFirstFile(argv[i],&FindData); if (hFind==INVALID_HANDLE_VALUE) { ConErrPrintf("File not found - %s\n",argv[i]); continue; } do { hFile = CreateFile(FindData.cFileName, GENERIC_READ, FILE_SHARE_READ,NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL); if(hFile == INVALID_HANDLE_VALUE) { ConErrPrintf("File not found - %s\n",FindData.cFileName); continue; } do { bRet = ReadFile(hFile,buff,sizeof(buff),&dwRead,NULL); if (dwRead>0 && bRet) WriteFile(hConsoleOut,buff,dwRead,&dwWritten,NULL); } while(dwRead>0 && bRet); CloseHandle(hFile); } while(FindNextFile(hFind,&FindData)); FindClose(hFind); } return 0; }
INT cmd_time (LPTSTR param) { LPTSTR *arg; INT argc; INT i; INT nTimeString = -1; if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_TIME_HELP1); return 0; } nErrorLevel = 0; /* build parameter array */ arg = split (param, &argc, FALSE, FALSE); /* check for options */ for (i = 0; i < argc; i++) { if (_tcsicmp (arg[i], _T("/t")) == 0) { /* Display current time in short format */ SYSTEMTIME st; TCHAR szTime[20]; GetLocalTime(&st); FormatTime(szTime, &st); ConOutPuts(szTime); freep(arg); return 0; } if ((*arg[i] != _T('/')) && (nTimeString == -1)) nTimeString = i; } if (nTimeString == -1) { ConOutResPrintf(STRING_LOCALE_HELP1); ConOutPrintf(_T(": %s\n"), GetTimeString()); } while (1) { if (nTimeString == -1) { TCHAR s[40]; ConOutResPuts(STRING_TIME_HELP2); ConInString (s, 40); TRACE ("\'%s\'\n", debugstr_aw(s)); while (*s && s[_tcslen (s) - 1] < _T(' ')) s[_tcslen(s) - 1] = _T('\0'); if (ParseTime (s)) { freep (arg); return 0; } } else { if (ParseTime (arg[nTimeString])) { freep (arg); return 0; } /* force input the next time around. */ nTimeString = -1; } ConErrResPuts(STRING_TIME_ERROR1); nErrorLevel = 1; } freep (arg); return 0; }
INT cmd_set (LPTSTR param) { LPTSTR p; LPTSTR lpEnv; LPTSTR lpOutput; if ( !_tcsncmp (param, _T("/?"), 2) ) { ConOutResPaging(TRUE,STRING_SET_HELP); return 0; } param = (LPTSTR)skip_ws(param); /* if no parameters, show the environment */ if (param[0] == _T('\0')) { lpEnv = (LPTSTR)GetEnvironmentStrings (); if (lpEnv) { lpOutput = lpEnv; while (*lpOutput) { if (*lpOutput != _T('=')) ConOutPuts(lpOutput); lpOutput += _tcslen(lpOutput) + 1; } FreeEnvironmentStrings (lpEnv); } return 0; } /* the /A does *NOT* have to be followed by a whitespace */ if ( !_tcsnicmp (param, _T("/A"), 2) ) { BOOL Success; StripQuotes(param); Success = seta_eval ( skip_ws(param+2) ); if(!Success) { /*might seem random but this is what windows xp does */ nErrorLevel = 9165; } return !Success; } if (!_tcsnicmp(param, _T("/P"), 2)) { TCHAR value[1023]; param = GetQuotedString((LPTSTR)skip_ws(param + 2)); p = _tcschr(param, _T('=')); if (!p) { ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT); nErrorLevel = 1; return 1; } *p++ = _T('\0'); ConOutPrintf(_T("%s"), GetQuotedString(p)); ConInString(value, 1023); if (!*value || !SetEnvironmentVariable(param, value)) { nErrorLevel = 1; return 1; } return 0; } param = GetQuotedString(param); p = _tcschr (param, _T('=')); if (p) { /* set or remove environment variable */ if (p == param) { /* handle set =val case */ ConErrResPuts(STRING_SYNTAX_COMMAND_INCORRECT); nErrorLevel = 1; return 1; } *p++ = _T('\0'); if (!SetEnvironmentVariable(param, *p ? p : NULL)) { nErrorLevel = 1; return 1; } } else { /* display all environment variable with the given prefix */ BOOL bFound = FALSE; while (_istspace(*param) || *param == _T(',') || *param == _T(';')) param++; p = _tcsrchr(param, _T(' ')); if (!p) p = param + _tcslen(param); *p = _T('\0'); lpEnv = GetEnvironmentStrings(); if (lpEnv) { lpOutput = lpEnv; while (*lpOutput) { if (!_tcsnicmp(lpOutput, param, p - param)) { ConOutPuts(lpOutput); bFound = TRUE; } lpOutput += _tcslen(lpOutput) + 1; } FreeEnvironmentStrings(lpEnv); } if (!bFound) { ConErrResPrintf (STRING_PATH_ERROR, param); nErrorLevel = 1; return 1; } } return 0; }
//INT CommandMore (LPTSTR cmd, LPTSTR param) int main (int argc, char **argv) { SHORT maxx,maxy; SHORT line_count=0,ch_count=0; DWORD i, last; HANDLE hFile = INVALID_HANDLE_VALUE; TCHAR szFullPath[MAX_PATH]; TCHAR szMsg[1024]; /*reading/writing buffer*/ TCHAR *buff; /*bytes written by WriteFile and ReadFile*/ DWORD dwRead,dwWritten; /*ReadFile() return value*/ BOOL bRet; hStdIn = GetStdHandle(STD_INPUT_HANDLE); hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); hStdErr = GetStdHandle(STD_ERROR_HANDLE); hApp = GetModuleHandle(NULL); buff=malloc(4096); if (!buff) { ConOutPuts(_T("Error: no memory")); return 1; } if (argc > 1 && _tcsncmp (argv[1], _T("/?"), 2) == 0) { if (LoadString(hApp, IDS_USAGE, buff, 4096 / sizeof(TCHAR)) < (int)(4096 / sizeof(TCHAR))) { CharToOem(buff, buff); ConOutPuts(buff); } free(buff); return 0; } hKeyboard = CreateFile (_T("CONIN$"), GENERIC_READ|GENERIC_WRITE, 0,NULL,OPEN_ALWAYS,0,0); GetScreenSize(&maxx,&maxy); FlushConsoleInputBuffer (hKeyboard); if(argc > 1) { GetFullPathNameA(argv[1], MAX_PATH, szFullPath, NULL); hFile = CreateFile (szFullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, 0); if (hFile == INVALID_HANDLE_VALUE) { if (LoadString(hApp, IDS_FILE_ACCESS, szMsg, sizeof(szMsg) / sizeof(TCHAR)) < (int)(sizeof(szMsg) / sizeof(TCHAR))) { _stprintf(buff, szMsg, szFullPath); CharToOem(buff, buff); ConOutPuts(buff); } free(buff); return 0; } } else { hFile = hStdIn; } if (!LoadString(hApp, IDS_CONTINUE, szCont, sizeof(szCont) / sizeof(TCHAR))) { /* Shouldn't happen, so exit */ free(buff); return 1; } szContLength = _tcslen(szCont); do { bRet = ReadFile(hFile,buff,4096,&dwRead,NULL); for(last=i=0;i<dwRead && bRet;i++) { ch_count++; if(buff[i] == _T('\n') || ch_count == maxx) { ch_count=0; line_count++; if (line_count == maxy) { line_count = 0; WriteFile(hStdOut,&buff[last], i-last+1, &dwWritten, NULL); last=i+1; FlushFileBuffers (hStdOut); WaitForKey (); } } } if (last<dwRead && bRet) WriteFile(hStdOut,&buff[last], dwRead-last, &dwWritten, NULL); } while(dwRead>0 && bRet); free (buff); CloseHandle (hKeyboard); if (hFile != hStdIn) CloseHandle (hFile); return 0; }
/* * display shell version info internal command. * * */ INT cmd_ver (LPTSTR param) { INT i; nErrorLevel = 0; if (_tcsstr (param, _T("/?")) != NULL) { ConOutResPaging(TRUE,STRING_VERSION_HELP1); return 0; } ShortVersion(); /* Basic copyright notice */ if (param[0] != _T('\0')) { ConOutPuts (_T("Copyright (C) 1994-1998 FreeDOS, Tim Norman and others.")); ConOutPuts (_T("Copyright (C) 1998-2016 ReactOS, Eric Kohl and others.")); ConOutPuts (_T("Copyright (C) 2016-") _T(COPYRIGHT_YEAR) _T(" IRTriageCMD, Alain Martel and others.")); for (i = 0; param[i]; i++) { /* skip spaces */ if (param[i] == _T(' ')) continue; if (param[i] == _T('/')) { /* is this a lone '/' ? */ if (param[i + 1] == 0) { error_invalid_switch (_T(' ')); return 1; } continue; } if (_totupper (param[i]) == _T('W')) { /* Warranty notice */ ConOutResPuts(STRING_VERSION_HELP3); } else if (_totupper (param[i]) == _T('R')) { /* Redistribution notice */ ConOutResPuts(STRING_VERSION_HELP4); } else if (_totupper (param[i]) == _T('C')) { /* Developer listing */ ConOutResPuts(STRING_VERSION_HELP6); ConOutResPuts(STRING_FREEDOS_DEV); ConOutResPuts(STRING_VERSION_HELP7); ConOutResPuts(STRING_REACTOS_DEV); } else { error_invalid_switch ((TCHAR)_totupper (param[i])); return 1; } } ConOutResPuts(STRING_VERSION_HELP5); } return 0; }
INT CommandScreen (LPTSTR param) { SHORT x,y; BOOL bSkipText = FALSE; if (_tcsncmp (param, _T("/?"), 2) == 0) { ConOutResPaging(TRUE,STRING_SCREEN_HELP); return 0; } nErrorLevel = 0; //get row while(_istspace(*param)) param++; if(!(*param)) { error_req_param_missing (); return 1; } y = _ttoi(param); if (y<0 || y>(maxy-1)) { ConOutResPuts(STRING_SCREEN_ROW); return 1; } //get col if(!(param = _tcschr(param,_T(' ')))) { error_req_param_missing (); return 1; } while(_istspace(*param)) param++; if(!(*param)) { error_req_param_missing (); return 1; } x = _ttoi(param); if (x<0 || x>(maxx-1)) { ConErrResPuts(STRING_SCREEN_COL); return 1; } //get text if(!(param = _tcschr(param,_T(' ')))) { bSkipText = TRUE; } else { while(_istspace(*param)) param++; if(!(*param)) { bSkipText = TRUE; } } bIgnoreEcho = TRUE; if(bSkipText) x=0; SetCursorXY(x,y); if(!(bSkipText)) ConOutPuts(param); return 0; }
INT cmd_move (LPTSTR param) { LPTSTR *arg; INT argc, i, nFiles; LPTSTR pszDest; TCHAR szDestPath[MAX_PATH]; TCHAR szFullDestPath[MAX_PATH]; TCHAR szSrcDirPath[MAX_PATH]; TCHAR szSrcPath[MAX_PATH]; TCHAR szFullSrcPath[MAX_PATH]; DWORD dwFlags = 0; INT nOverwrite = 0; WIN32_FIND_DATA findBuffer; HANDLE hFile; /* used only when source and destination directories are on different volume*/ HANDLE hDestFile; WIN32_FIND_DATA findDestBuffer; TCHAR szMoveDest[MAX_PATH]; TCHAR szMoveSrc[MAX_PATH]; LPTSTR pszDestDirPointer; LPTSTR pszSrcDirPointer; INT nDirLevel = 0; LPTSTR pszFile; BOOL OnlyOneFile; BOOL FoundFile; BOOL MoveStatus; DWORD dwMoveFlags = 0; DWORD dwMoveStatusFlags = 0; if (!_tcsncmp (param, _T("/?"), 2)) { #if 0 ConOutPuts (_T("Moves files and renames files and directories.\n\n" "To move one or more files:\n" "MOVE [/N][/Y|/-Y][drive:][path]filename1[,...] destination\n" "\n" "To rename a directory:\n" "MOVE [/N][/Y|/-Y][drive:][path]dirname1 dirname2\n" "\n" " [drive:][path]filename1 Specifies the location and name of the file\n" " or files you want to move.\n" " /N Nothing. Don everthing but move files or direcories.\n" " /Y\n" " /-Y\n" "...")); #else ConOutResPaging(TRUE,STRING_MOVE_HELP2); #endif return 0; } nErrorLevel = 0; arg = splitspace(param, &argc); /* read options */ for (i = 0; i < argc; i++) { if (!_tcsicmp(arg[i], _T("/N"))) dwFlags |= MOVE_NOTHING; else if (!_tcsicmp(arg[i], _T("/Y"))) dwFlags |= MOVE_OVER_YES; else if (!_tcsicmp(arg[i], _T("/-Y"))) dwFlags |= MOVE_OVER_NO; else break; } nFiles = argc - i; if (nFiles < 1) { /* there must be at least one pathspec */ error_req_param_missing(); freep(arg); return 1; } if (nFiles > 2) { /* there are more than two pathspecs */ error_too_many_parameters(param); freep(arg); return 1; } /* If no destination is given, default to current directory */ pszDest = (nFiles == 1) ? _T(".") : arg[i + 1]; /* check for wildcards in source and destination */ if (_tcschr(pszDest, _T('*')) != NULL || _tcschr(pszDest, _T('?')) != NULL) { /* '*'/'?' in dest, this doesnt happen. give folder name instead*/ error_invalid_parameter_format(pszDest); freep(arg); return 1; } if (_tcschr(arg[i], _T('*')) != NULL || _tcschr(arg[i], _T('?')) != NULL) { dwMoveStatusFlags |= MOVE_SOURCE_HAS_WILD; } /* get destination */ GetFullPathName (pszDest, MAX_PATH, szDestPath, NULL); TRACE ("Destination: %s\n", debugstr_aw(szDestPath)); /* get source folder */ GetFullPathName(arg[i], MAX_PATH, szSrcDirPath, &pszFile); if (pszFile != NULL) *pszFile = _T('\0'); TRACE ("Source Folder: %s\n", debugstr_aw(szSrcDirPath)); hFile = FindFirstFile (arg[i], &findBuffer); if (hFile == INVALID_HANDLE_VALUE) { ErrorMessage (GetLastError (), arg[i]); freep (arg); return 1; } /* check for special cases "." and ".." and if found skip them */ FoundFile = TRUE; while(FoundFile && (_tcscmp(findBuffer.cFileName,_T(".")) == 0 || _tcscmp(findBuffer.cFileName,_T("..")) == 0)) FoundFile = FindNextFile (hFile, &findBuffer); if (!FoundFile) { /* what? we don't have anything to move? */ error_file_not_found(); FindClose(hFile); freep(arg); return 1; } OnlyOneFile = TRUE; /* check if there can be found files as files have first priority */ if (findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) dwMoveStatusFlags |= MOVE_SOURCE_IS_DIR; else dwMoveStatusFlags |= MOVE_SOURCE_IS_FILE; while(OnlyOneFile && FindNextFile(hFile,&findBuffer)) { if (!(findBuffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { ConOutPrintf(_T("")); if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE) OnlyOneFile = FALSE; else { /* this has been done this way so that we don't disturb other settings if they have been set before this */ dwMoveStatusFlags |= MOVE_SOURCE_IS_FILE; dwMoveStatusFlags &= ~MOVE_SOURCE_IS_DIR; } } } FindClose(hFile); TRACE ("Do we have only one file: %s\n", OnlyOneFile ? "TRUE" : "FALSE"); /* we have to start again to be sure we don't miss any files or folders*/ hFile = FindFirstFile (arg[i], &findBuffer); if (hFile == INVALID_HANDLE_VALUE) { ErrorMessage (GetLastError (), arg[i]); freep (arg); return 1; } /* check for special cases "." and ".." and if found skip them */ FoundFile = TRUE; while(FoundFile && (_tcscmp(findBuffer.cFileName,_T(".")) == 0 || _tcscmp(findBuffer.cFileName,_T("..")) == 0)) FoundFile = FindNextFile (hFile, &findBuffer); if (!FoundFile) { /* huh? somebody removed files and/or folders which were there */ error_file_not_found(); FindClose(hFile); freep(arg); return 1; } /* check if source and destination paths are on different volumes */ if (szSrcDirPath[0] != szDestPath[0]) dwMoveStatusFlags |= MOVE_PATHS_ON_DIF_VOL; /* move it */ do { TRACE ("Found file/directory: %s\n", debugstr_aw(findBuffer.cFileName)); nOverwrite = 1; dwMoveFlags = 0; dwMoveStatusFlags &= ~MOVE_DEST_IS_FILE & ~MOVE_DEST_IS_DIR & ~MOVE_SRC_CURRENT_IS_DIR & ~MOVE_DEST_EXISTS; _tcscpy(szFullSrcPath,szSrcDirPath); if(szFullSrcPath[_tcslen(szFullSrcPath) - 1] != _T('\\')) _tcscat (szFullSrcPath, _T("\\")); _tcscat(szFullSrcPath,findBuffer.cFileName); _tcscpy(szSrcPath, szFullSrcPath); if (IsExistingDirectory(szSrcPath)) { /* source is directory */ if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE) { dwMoveStatusFlags |= MOVE_SRC_CURRENT_IS_DIR; /* source is file but at the current round we found a directory */ continue; } TRACE ("Source is dir: %s\n", debugstr_aw(szSrcPath)); dwMoveFlags = MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED; } /* if source is file we don't need to do anything special */ if (IsExistingDirectory(szDestPath)) { /* destination is existing directory */ TRACE ("Destination is directory: %s\n", debugstr_aw(szDestPath)); dwMoveStatusFlags |= MOVE_DEST_IS_DIR; /*build the dest string(accounts for *)*/ _tcscpy (szFullDestPath, szDestPath); /*check to see if there is an ending slash, if not add one*/ if(szFullDestPath[_tcslen(szFullDestPath) - 1] != _T('\\')) _tcscat (szFullDestPath, _T("\\")); _tcscat (szFullDestPath, findBuffer.cFileName); if (IsExistingFile(szFullDestPath) || IsExistingDirectory(szFullDestPath)) dwMoveStatusFlags |= MOVE_DEST_EXISTS; dwMoveFlags |= MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED; } if (IsExistingFile(szDestPath)) { /* destination is a file */ TRACE ("Destination is file: %s\n", debugstr_aw(szDestPath)); dwMoveStatusFlags |= MOVE_DEST_IS_FILE | MOVE_DEST_EXISTS; _tcscpy (szFullDestPath, szDestPath); dwMoveFlags |= MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED; } TRACE ("Move Status Flags: 0x%X\n",dwMoveStatusFlags); if (dwMoveStatusFlags & MOVE_SOURCE_IS_DIR && dwMoveStatusFlags & MOVE_DEST_IS_DIR && dwMoveStatusFlags & MOVE_SOURCE_HAS_WILD) { /* We are not allowed to have existing source and destination dir when there is wildcard in source */ error_syntax(NULL); FindClose(hFile); freep(arg); return 1; } if (!(dwMoveStatusFlags & (MOVE_DEST_IS_FILE | MOVE_DEST_IS_DIR))) { /* destination doesn't exist */ _tcscpy (szFullDestPath, szDestPath); if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE) dwMoveStatusFlags |= MOVE_DEST_IS_FILE; if (dwMoveStatusFlags & MOVE_SOURCE_IS_DIR) dwMoveStatusFlags |= MOVE_DEST_IS_DIR; dwMoveFlags |= MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH | MOVEFILE_COPY_ALLOWED; } if (dwMoveStatusFlags & MOVE_SOURCE_IS_FILE && dwMoveStatusFlags & MOVE_DEST_IS_FILE && !OnlyOneFile) { /*source has many files but there is only one destination file*/ error_invalid_parameter_format(pszDest); FindClose(hFile); freep (arg); return 1; } /*checks to make sure user wanted/wants the override*/ if((dwFlags & MOVE_OVER_NO) && (dwMoveStatusFlags & MOVE_DEST_EXISTS)) continue; if(!(dwFlags & MOVE_OVER_YES) && (dwMoveStatusFlags & MOVE_DEST_EXISTS)) nOverwrite = MoveOverwrite (szFullDestPath); if (nOverwrite == PROMPT_NO || nOverwrite == PROMPT_BREAK) continue; if (nOverwrite == PROMPT_ALL) dwFlags |= MOVE_OVER_YES; ConOutPrintf (_T("%s => %s "), szSrcPath, szFullDestPath); /* are we really supposed to do something */ if (dwFlags & MOVE_NOTHING) continue; /*move the file*/ if (!(dwMoveStatusFlags & MOVE_SOURCE_IS_DIR && dwMoveStatusFlags & MOVE_PATHS_ON_DIF_VOL)) /* we aren't moving source folder to different drive */ MoveStatus = MoveFileEx (szSrcPath, szFullDestPath, dwMoveFlags); else { /* we are moving source folder to different drive */ _tcscpy(szMoveDest, szFullDestPath); _tcscpy(szMoveSrc, szSrcPath); DeleteFile(szMoveDest); MoveStatus = CreateDirectory(szMoveDest, NULL); /* we use default security settings */ if (MoveStatus) { _tcscat(szMoveDest,_T("\\")); _tcscat(szMoveSrc,_T("\\")); nDirLevel = 0; pszDestDirPointer = szMoveDest + _tcslen(szMoveDest); pszSrcDirPointer = szMoveSrc + _tcslen(szMoveSrc); _tcscpy(pszSrcDirPointer,_T("*.*")); hDestFile = FindFirstFile(szMoveSrc, &findDestBuffer); if (hDestFile == INVALID_HANDLE_VALUE) MoveStatus = FALSE; else { BOOL FirstTime = TRUE; FoundFile = TRUE; MoveStatus = FALSE; while(FoundFile) { if (FirstTime) FirstTime = FALSE; else FoundFile = FindNextFile (hDestFile, &findDestBuffer); if (!FoundFile) { /* Nothing to do in this folder so we stop working on it */ FindClose(hDestFile); (pszSrcDirPointer)--; (pszDestDirPointer)--; _tcscpy(pszSrcDirPointer,_T("")); _tcscpy(pszDestDirPointer,_T("")); if (nDirLevel > 0) { TCHAR szTempPath[MAX_PATH]; INT nDiff; FoundFile = TRUE; /* we need to continue our seek for files */ nDirLevel--; RemoveDirectory(szMoveSrc); GetDirectory(szMoveSrc,szTempPath,0); nDiff = _tcslen(szMoveSrc) - _tcslen(szTempPath); pszSrcDirPointer = pszSrcDirPointer - nDiff; _tcscpy(pszSrcDirPointer,_T("")); GetDirectory(szMoveDest,szTempPath,0); nDiff = _tcslen(szMoveDest) - _tcslen(szTempPath); pszDestDirPointer = pszDestDirPointer - nDiff; _tcscpy(pszDestDirPointer,_T("")); if(szMoveSrc[_tcslen(szMoveSrc) - 1] != _T('\\')) _tcscat (szMoveSrc, _T("\\")); if(szMoveDest[_tcslen(szMoveDest) - 1] != _T('\\')) _tcscat (szMoveDest, _T("\\")); pszDestDirPointer = szMoveDest + _tcslen(szMoveDest); pszSrcDirPointer = szMoveSrc + _tcslen(szMoveSrc); _tcscpy(pszSrcDirPointer,_T("*.*")); hDestFile = FindFirstFile(szMoveSrc, &findDestBuffer); if (hDestFile == INVALID_HANDLE_VALUE) continue; FirstTime = TRUE; } else { MoveStatus = TRUE; /* we moved everything so lets tell user about it */ RemoveDirectory(szMoveSrc); } continue; } /* if we find "." or ".." we'll skip them */ if (_tcscmp(findDestBuffer.cFileName,_T(".")) == 0 || _tcscmp(findDestBuffer.cFileName,_T("..")) == 0) continue; _tcscpy(pszSrcDirPointer, findDestBuffer.cFileName); _tcscpy(pszDestDirPointer, findDestBuffer.cFileName); if (IsExistingFile(szMoveSrc)) { FoundFile = CopyFile(szMoveSrc, szMoveDest, FALSE); if (!FoundFile) continue; DeleteFile(szMoveSrc); } else { FindClose(hDestFile); CreateDirectory(szMoveDest, NULL); _tcscat(szMoveDest,_T("\\")); _tcscat(szMoveSrc,_T("\\")); nDirLevel++; pszDestDirPointer = szMoveDest + _tcslen(szMoveDest); pszSrcDirPointer = szMoveSrc + _tcslen(szMoveSrc); _tcscpy(pszSrcDirPointer,_T("*.*")); hDestFile = FindFirstFile(szMoveSrc, &findDestBuffer); if (hDestFile == INVALID_HANDLE_VALUE) { FoundFile = FALSE; continue; } FirstTime = TRUE; } } } } } if (MoveStatus) ConOutResPrintf(STRING_MOVE_ERROR1); else ConOutResPrintf(STRING_MOVE_ERROR2); } while ((!OnlyOneFile || dwMoveStatusFlags & MOVE_SRC_CURRENT_IS_DIR ) && !(dwMoveStatusFlags & MOVE_SOURCE_IS_DIR) && FindNextFile (hFile, &findBuffer)); FindClose (hFile); freep (arg); return 0; }
INT CommandTimer (LPTSTR param) { // all timers are kept static DWORD clksT[10]; // timers status // set all the clocks off by default static BOOL clksS[10]={FALSE,FALSE,FALSE,FALSE, FALSE,FALSE,FALSE,FALSE,FALSE,FALSE}; // TRUE if /S in command line BOOL bS = FALSE; // avoid to set clk_n more than once BOOL bCanNSet = TRUE; INT NewClkStatus = NCS_NOT_SPECIFIED; // the clock number specified on the command line // 1 by default INT clk_n=1; // output format INT iFormat=1; // command line parsing variables INT argc; LPTSTR *p; INT i; if (_tcsncmp (param, _T("/?"), 2) == 0) { ConOutResPrintf(STRING_TIMER_HELP3, cTimeSeparator, cTimeSeparator, cDecimalSeparator); return 0; } nErrorLevel = 0; p = split (param, &argc, FALSE, FALSE); //read options for (i = 0; i < argc; i++) { //set timer on if (!(_tcsicmp(&p[i][0],_T("on"))) && NewClkStatus == NCS_NOT_SPECIFIED) { NewClkStatus = NCS_ON; continue; } //set timer off if (!(_tcsicmp(&p[i][0],_T("off"))) && NewClkStatus == NCS_NOT_SPECIFIED) { NewClkStatus = NCS_OFF; continue; } // other options if (p[i][0] == _T('/')) { // set timer number if (_istdigit(p[i][1]) && bCanNSet) { clk_n = p[i][1] - _T('0'); bCanNSet = FALSE; continue; } // set s(plit) option if (_totupper(p[i][1]) == _T('S')) { bS = TRUE; continue; } // specify format if (_totupper(p[i][1]) == _T('F')) { iFormat = p[i][2] - _T('0'); continue; } } } // do stuff (start/stop/read timer) if (NewClkStatus == NCS_ON) { cT=GetTickCount(); cS=TRUE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPuts(GetTimeString()); freep(p); return 0; } if (bS) { if (cS) { ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPrintf(_T("%s\n"), GetTimeString()); PrintElapsedTime(GetTickCount()-cT, iFormat); freep(p); return 0; } cT=GetTickCount(); cS=TRUE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPuts(GetTimeString()); freep(p); return 0; } if (NewClkStatus == NCS_NOT_SPECIFIED) { if (cS) { cS=FALSE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPrintf(_T("%s\n"), GetTimeString()); PrintElapsedTime(GetTickCount()-cT, iFormat); freep(p); return 0; } cT=GetTickCount(); cS=TRUE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPuts(GetTimeString()); freep(p); return 0; } if (NewClkStatus == NCS_OFF) { if (cS) { cS=FALSE; ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPrintf(_T("%s\n"), GetTimeString()); PrintElapsedTime(GetTickCount()-cT, iFormat); freep(p); return 0; } ConOutResPrintf (STRING_TIMER_TIME,clk_n,cS?_T("ON"):_T("OFF")); ConOutPuts(GetTimeString()); freep(p); return 0; } freep(p); return 0; }
/* * display shell version info internal command. */ INT cmd_ver (LPTSTR param) { INT i; nErrorLevel = 0; if (_tcsstr(param, _T("/?")) != NULL) { ConOutResPaging(TRUE,STRING_VERSION_HELP1); return 0; } ConOutResPrintf(STRING_CMD_SHELLINFO, _T(KERNEL_RELEASE_STR), _T(KERNEL_VERSION_BUILD_STR)); ConOutChar(_T('\n')); ConOutResPuts(STRING_VERSION_RUNNING_ON); PrintOSVersion(); /* Basic copyright notice */ if (param[0] != _T('\0')) { ConOutPuts(_T("\n\n")); ConOutPuts(_T("Copyright (C) 1994-1998 Tim Norman and others.\n")); ConOutPuts(_T("Copyright (C) 1998-") _T(COPYRIGHT_YEAR) _T(" ReactOS Team\n")); for (i = 0; param[i]; i++) { /* Skip spaces */ if (param[i] == _T(' ')) continue; if (param[i] == _T('/')) { /* Is this a lone '/' ? */ if (param[i + 1] == 0) { error_invalid_switch(_T(' ')); return 1; } continue; } if (_totupper(param[i]) == _T('W')) { /* Warranty notice */ ConOutResPuts(STRING_VERSION_HELP3); } else if (_totupper(param[i]) == _T('R')) { /* Redistribution notice */ ConOutResPuts(STRING_VERSION_HELP4); } else if (_totupper(param[i]) == _T('C')) { /* Developer listing */ ConOutResPuts(STRING_VERSION_HELP6); ConOutResPuts(STRING_FREEDOS_DEV); ConOutResPuts(STRING_VERSION_HELP7); ConOutResPuts(STRING_REACTOS_DEV); } else { error_invalid_switch(_totupper(param[i])); return 1; } } /* Bug report notice */ ConOutResPuts(STRING_VERSION_HELP5); } ConOutChar(_T('\n')); return 0; }