INT cmd_shift (LPTSTR param) { INT i = 0; TRACE ("cmd_shift: (\'%s\')\n", debugstr_aw(param)); if (!_tcsncmp (param, _T("/?"), 2)) { ConOutResPaging(TRUE,STRING_SHIFT_HELP); return 0; } nErrorLevel = 0; if (bc == NULL) { /* not in batch - error!! */ nErrorLevel = 1; return 1; } if (!_tcsicmp (param, _T("down"))) { if (bc->shiftlevel[0]) for (; i <= 9; i++) bc->shiftlevel[i]--; } else /* shift up */ { if (*param == _T('/')) { if (param[1] < '0' || param[1] > '9') { error_invalid_switch(param[1]); return 1; } i = param[1] - '0'; } for (; i < 9; i++) bc->shiftlevel[i] = bc->shiftlevel[i + 1]; bc->shiftlevel[i]++; } return 0; }
/* * DirReadParameters * * Parse the parameters and switches of the command line and exports them */ static BOOL DirReadParam(LPTSTR Line, /* [IN] The line with the parameters & switches */ LPTSTR** params, /* [OUT] The parameters after parsing */ LPINT entries, /* [OUT] The number of parameters after parsing */ LPDIRSWITCHFLAGS lpFlags) /* [IN/OUT] The flags after calculating switches */ { TCHAR cCurSwitch; /* The current switch */ TCHAR cCurChar; /* Current examing character */ TCHAR cCurUChar; /* Current upper examing character */ BOOL bNegative; /* Negative switch */ BOOL bPNegative; /* Negative switch parameter */ BOOL bIntoQuotes; /* A flag showing if we are in quotes (") */ LPTSTR ptrStart; /* A pointer to the first character of a parameter */ LPTSTR ptrEnd; /* A pointer to the last character of a parameter */ BOOL bOrderByNoPar; /* A flag to indicate /O with no switch parameter */ LPTSTR temp; /* Initialize parameter array */ *params = NULL; *entries = 0; /* Initialize variables; */ cCurSwitch = _T(' '); bNegative = FALSE; bPNegative = FALSE; /* We suppose that switch parameters were given to avoid setting them to default if the switch was not given */ bOrderByNoPar = FALSE; /* Main Loop (see README_DIR.txt) */ /* scan the command line char per char, and we process its char */ while (*Line) { /* we save current character as it is and its upper case */ cCurChar = *Line; cCurUChar = _totupper(*Line); /* 1st section (see README_DIR.txt) */ /* When a switch is expecting */ if (cCurSwitch == _T('/')) { while (*Line == _T(' ')) Line++; bNegative = (*Line == _T('-')); Line += bNegative; cCurChar = *Line; cCurUChar = _totupper(*Line); if ((cCurUChar == _T('A')) ||(cCurUChar == _T('T')) || (cCurUChar == _T('O'))) { /* If positive, prepare for parameters... if negative, reset to defaults */ switch (cCurUChar) { case _T('A'): lpFlags->stAttribs.dwAttribVal = 0L; lpFlags->stAttribs.dwAttribMask = 0L; if (bNegative) lpFlags->stAttribs.dwAttribMask = FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM; break; case _T('T'): if (bNegative) lpFlags->stTimeField.eTimeField = TF_MODIFIEDDATE; break; case _T('O'): bOrderByNoPar = !bNegative; lpFlags->stOrderBy.sCriteriaCount = 0; break; } if (!bNegative) { /* Positive switch, so it can take parameters. */ cCurSwitch = cCurUChar; Line++; /* Skip optional leading colon */ if (*Line == _T(':')) Line++; continue; } } else if (cCurUChar == _T('L')) lpFlags->bLowerCase = ! bNegative; else if (cCurUChar == _T('B')) lpFlags->bBareFormat = ! bNegative; else if (cCurUChar == _T('C')) lpFlags->bTSeperator = ! bNegative; else if (cCurUChar == _T('W')) lpFlags->bWideList = ! bNegative; else if (cCurUChar == _T('D')) lpFlags->bWideListColSort = ! bNegative; else if (cCurUChar == _T('N')) lpFlags->bNewLongList = ! bNegative; else if (cCurUChar == _T('P')) lpFlags->bPause = ! bNegative; else if (cCurUChar == _T('Q')) lpFlags->bUser = ! bNegative; else if (cCurUChar == _T('S')) lpFlags->bRecursive = ! bNegative; else if (cCurUChar == _T('X')) lpFlags->bShortName = ! bNegative; else if (cCurChar == _T('4')) lpFlags->b4Digit = ! bNegative; else if (cCurChar == _T('?')) { DirHelp(); return FALSE; } else { error_invalid_switch ((TCHAR)_totupper (*Line)); return FALSE; } /* Make sure there's no extra characters at the end of the switch */ if (Line[1] && Line[1] != _T('/') && Line[1] != _T(' ')) { error_parameter_format(Line[1]); return FALSE; } cCurSwitch = _T(' '); } else if (cCurSwitch == _T(' ')) { /* 2nd section (see README_DIR.txt) */ /* We are expecting parameter or the unknown */ if (cCurChar == _T('/')) cCurSwitch = _T('/'); else if (cCurChar == _T(' ')) /* do nothing */; else { /* This is a file/directory name parameter. Find its end */ ptrStart = Line; bIntoQuotes = FALSE; while (*Line) { if (!bIntoQuotes && (*Line == _T('/') || *Line == _T(' '))) break; bIntoQuotes ^= (*Line == _T('"')); Line++; } ptrEnd = Line; /* Copy it to the entries list */ temp = cmd_alloc((ptrEnd - ptrStart + 1) * sizeof (TCHAR)); if(!temp) return FALSE; memcpy(temp, ptrStart, (ptrEnd - ptrStart) * sizeof (TCHAR)); temp[ptrEnd - ptrStart] = _T('\0'); StripQuotes(temp); if(!add_entry(entries, params, temp)) { cmd_free(temp); freep(*params); return FALSE; } cmd_free(temp); continue; } } else { /* 3rd section (see README_DIR.txt) */ /* We are waiting for switch parameters */ /* Check if there are no more switch parameters */ if ((cCurChar == _T('/')) || ( cCurChar == _T(' '))) { /* Wrong desicion path, reprocess current character */ cCurSwitch = _T(' '); continue; } /* Process parameter switch */ switch(cCurSwitch) { case _T('A'): /* Switch parameters for /A (attributes filter) */ if(cCurChar == _T('-')) bPNegative = TRUE; else if(cCurUChar == _T('D')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_DIRECTORY; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_DIRECTORY; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_DIRECTORY; } else if(cCurUChar == _T('R')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_READONLY; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_READONLY; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_READONLY; } else if(cCurUChar == _T('H')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_HIDDEN; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_HIDDEN; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_HIDDEN; } else if(cCurUChar == _T('A')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_ARCHIVE; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_ARCHIVE; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_ARCHIVE; } else if(cCurUChar == _T('S')) { lpFlags->stAttribs.dwAttribMask |= FILE_ATTRIBUTE_SYSTEM; if (bPNegative) lpFlags->stAttribs.dwAttribVal &= ~FILE_ATTRIBUTE_SYSTEM; else lpFlags->stAttribs.dwAttribVal |= FILE_ATTRIBUTE_SYSTEM; } else { error_parameter_format((TCHAR)_totupper (*Line)); return FALSE; } break; case _T('T'): /* Switch parameters for /T (time field) */ if(cCurUChar == _T('C')) lpFlags->stTimeField.eTimeField= TF_CREATIONDATE ; else if(cCurUChar == _T('A')) lpFlags->stTimeField.eTimeField= TF_LASTACCESSEDDATE ; else if(cCurUChar == _T('W')) lpFlags->stTimeField.eTimeField= TF_MODIFIEDDATE ; else { error_parameter_format((TCHAR)_totupper (*Line)); return FALSE; } break; case _T('O'): /* Switch parameters for /O (order) */ /* Ok a switch parameter was given */ bOrderByNoPar = FALSE; if(cCurChar == _T('-')) bPNegative = TRUE; else if(cCurUChar == _T('N')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_NAME; } else if(cCurUChar == _T('S')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_SIZE; } else if(cCurUChar == _T('G')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_DIRECTORY; } else if(cCurUChar == _T('E')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_EXTENSION; } else if(cCurUChar == _T('D')) { if (lpFlags->stOrderBy.sCriteriaCount < 3) lpFlags->stOrderBy.sCriteriaCount++; lpFlags->stOrderBy.bCriteriaRev[lpFlags->stOrderBy.sCriteriaCount - 1] = bPNegative; lpFlags->stOrderBy.eCriteria[lpFlags->stOrderBy.sCriteriaCount - 1] = ORDER_TIME; } else { error_parameter_format((TCHAR)_totupper (*Line)); return FALSE; } } /* We check if we calculated the negative value and realese the flag */ if ((cCurChar != _T('-')) && bPNegative) bPNegative = FALSE; } Line++; } /* /O with no switch parameters acts like /O:GN */ if (bOrderByNoPar) { lpFlags->stOrderBy.sCriteriaCount = 2; lpFlags->stOrderBy.eCriteria[0] = ORDER_DIRECTORY; lpFlags->stOrderBy.bCriteriaRev[0] = FALSE; lpFlags->stOrderBy.eCriteria[1] = ORDER_NAME; lpFlags->stOrderBy.bCriteriaRev[1] = FALSE; } return TRUE; }
/* * 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; }
/* * 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; }