From 97cf5197cf5b882b2c689d8dc2b555f2edf8f418 Mon Sep 17 00:00:00 2001 From: Dave Wilson Date: Tue, 17 Mar 2015 19:50:07 -0700 Subject: Initial publish --- setup/devcon/devcon.cpp | 1162 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1162 insertions(+) create mode 100644 setup/devcon/devcon.cpp (limited to 'setup/devcon/devcon.cpp') diff --git a/setup/devcon/devcon.cpp b/setup/devcon/devcon.cpp new file mode 100644 index 00000000..d501dc1e --- /dev/null +++ b/setup/devcon/devcon.cpp @@ -0,0 +1,1162 @@ +/*++ + +Copyright (c) Microsoft Corporation. All rights reserved. + +Module Name: + + devcon.cpp + +Abstract: + + Device Console + command-line interface for managing devices + +--*/ + +#include "devcon.h" + +struct IdEntry { + LPCTSTR String; // string looking for + LPCTSTR Wild; // first wild character if any + BOOL InstanceId; +}; + +void FormatToStream(_In_ FILE * stream, _In_ DWORD fmt,...) +/*++ + +Routine Description: + + Format text to stream using a particular msg-id fmt + Used for displaying localizable messages + +Arguments: + + stream - file stream to output to, stdout or stderr + fmt - message id + ... - parameters %1... + +Return Value: + + none + +--*/ +{ + va_list arglist; + LPTSTR locbuffer = NULL; + DWORD count; + + va_start(arglist, fmt); + count = FormatMessage(FORMAT_MESSAGE_FROM_HMODULE|FORMAT_MESSAGE_ALLOCATE_BUFFER, + NULL, + fmt, + 0, // LANGID + (LPTSTR) &locbuffer, + 0, // minimum size of buffer + &arglist); + + if(locbuffer) { + if(count) { + int c; + int back = 0; + // + // strip any trailing "\r\n"s and replace by a single "\n" + // + while(((c = *CharPrev(locbuffer,locbuffer+count)) == TEXT('\r')) || + (c == TEXT('\n'))) { + count--; + back++; + } + if(back) { + locbuffer[count++] = TEXT('\n'); + locbuffer[count] = TEXT('\0'); + } + // + // now write to apropriate stream + // + _fputts(locbuffer,stream); + } + LocalFree(locbuffer); + } +} + +void Padding(_In_ int pad) +/*++ + +Routine Description: + + Insert padding into line before text + +Arguments: + + pad - number of padding tabs to insert + +Return Value: + + none + +--*/ +{ + int c; + + for(c=0;c