windows-nt/Source/XPSP1/NT/base/fs/ntfs/tests/bshell/tclose.c
2020-09-26 16:20:57 +08:00

212 lines
4.8 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "brian.h"
VOID
CloseIndex (
IN USHORT Index,
IN BOOLEAN DisplayParameters,
IN BOOLEAN VerboseResults
);
VOID
InputCloseIndex (
IN PCHAR ParamBuffer
)
{
BOOLEAN Verbose;
BOOLEAN HandleFound;
BOOLEAN DisplayParms;
ULONG ThisHandleIndex;
//
// Set the defaults.
//
Verbose = TRUE;
DisplayParms = FALSE;
HandleFound = FALSE;
//
// While there is more input, analyze the parameter and update the
// open flags.
//
while (TRUE) {
ULONG DummyCount;
//
// Swallow leading white spaces.
//
ParamBuffer = SwallowWhite( ParamBuffer, &DummyCount );
if (*ParamBuffer) {
//
// If the next parameter is legal then check the paramter value.
// Update the parameter value.
//
if((*ParamBuffer == '-'
|| *ParamBuffer == '/')
&& (ParamBuffer++, *ParamBuffer != '\0')) {
//
// Switch on the next character.
//
switch (*ParamBuffer) {
//
// Recover a handle.
//
case 'i' :
case 'I' :
//
// Move to the next character, as long as there
// are no white spaces continue analyzing letters.
// On the first bad letter, skip to the next
// parameter.
//
ParamBuffer++;
ThisHandleIndex = AsciiToInteger( ParamBuffer );
ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
HandleFound = TRUE;
break;
case 'v' :
case 'V' :
//
// Legal values for params are T/t or F/f.
//
ParamBuffer++;
if (*ParamBuffer == 'T'
|| *ParamBuffer == 't') {
Verbose = TRUE;
ParamBuffer++;
} else if (*ParamBuffer == 'F'
|| *ParamBuffer == 'f') {
Verbose = FALSE;
ParamBuffer++;
}
break;
case 'y' :
case 'Y' :
//
// Set the display parms flag and jump over this
// character.
//
DisplayParms = TRUE;
ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
break;
default :
//
// Swallow to the next white space and continue the
// loop.
//
ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
}
//
// Else the text is invalid, skip the entire block.
//
//
} else {
ParamBuffer = SwallowNonWhite( ParamBuffer, &DummyCount );
}
//
// Else break.
//
} else {
break;
}
}
//
// If the file name wasn't found, then display the syntax message
// and set verbose to FALSE.
//
if( !HandleFound ) {
printf( "\n Usage: cl [options]*\n" );
printf( "\n Options:" );
printf( "\n -i<index number> Input a index to close" );
printf( "\n -v[t|f] Verbose mode for subsequent handles" );
printf( "\n -y Display parameters before call" );
printf( "\n\n" );
} else {
CloseIndex( (USHORT) ThisHandleIndex,
DisplayParms,
Verbose );
}
return;
}
VOID
CloseIndex (
IN USHORT Index,
IN BOOLEAN DisplayParameters,
IN BOOLEAN VerboseResults
)
{
NTSTATUS Status;
//
// Display parameters if requested.
//
if (DisplayParameters) {
printf( "\nClose Index Parameters" );
printf( "\n\tIndex -> %04x", Index );
printf( "\n\n" );
}
if (Index >= MAX_HANDLES) {
printf( "\n\tClose Index: Invalid index value" );
Status = STATUS_INVALID_HANDLE;
} else if (!Handles[Index].Used) {
printf( "\n\tCloseIndex: Index is unused" );
Status = STATUS_INVALID_HANDLE;
} else {
Status = FreeIndex( Index );
if (VerboseResults) {
printf( "\n FreeIndex: Status -> %08lx\n\n", Status );
}
}
return;
}