Created
February 26, 2023 11:29
-
-
Save anzz1/39f84c8f95168f4e3b4eae747745cde9 to your computer and use it in GitHub Desktop.
quickedit.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// quickedit.c | |
// cl /MD /Zl /O1 /Ob2 /Oi /GS- /kernel /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /c quickedit.c | |
// link kernel32.lib /entry:"main" /subsystem:console /pdb:none /machine:I386 /nodefaultlib /incremental:no /manifest:no /safeseh:no /emitpogophaseinfo /RELEASE /OPT:REF /OPT:ICF /OPT:NOWIN98 /MERGE:.rdata=.text quickedit.obj | |
#define WINVER 0x0501 | |
#define _WIN32_WINNT 0x0501 | |
#include <windows.h> | |
__forceinline static int ret(int n) | |
{ | |
DWORD u = 0; | |
char ret[1]; | |
ret[0] = n+48; | |
WriteFile(GetStdHandle(STD_OUTPUT_HANDLE), ret, 1, &u, 0); | |
return n; | |
} | |
int main(void) | |
{ | |
DWORD dwOldMode, dwNewMode; | |
HANDLE hConIn = GetStdHandle(STD_INPUT_HANDLE); | |
if (hConIn && hConIn != (HANDLE)-1 && GetConsoleMode(hConIn, &dwOldMode)) | |
{ | |
char* s; | |
int nState = -1; | |
s = GetCommandLineA(); | |
if (s && *s) { | |
if (*s == '"') { | |
++s; | |
while (*s) | |
if (*s++ == '"') | |
break; | |
} else { | |
while (*s && *s != ' ' && *s != '\t') | |
++s; | |
} | |
while (*s) { | |
if (*s == '0' || ( | |
(*s == 'O' || *s == 'o') && | |
(*(s+1) == 'F' || *(s+1) == 'f') && | |
(*(s+2) == 'F' || *(s+2) == 'f') | |
)) { nState = 0; break; } | |
else if (*s == '1' || ( | |
(*s == 'O' || *s == 'o') && | |
(*(s+1) == 'N' || *(s+1) == 'n') | |
)) { nState = 1; break; } | |
s++; | |
} | |
if (nState != -1) { | |
if (nState == 0) | |
dwNewMode = (dwOldMode | 0x80) & ~(0x40); // ENABLE_EXTENDED_FLAGS & ~ENABLE_QUICK_EDIT_MODE | |
else | |
dwNewMode = (dwOldMode | 0xC0); // ENABLE_EXTENDED_FLAGS | ENABLE_QUICK_EDIT_MODE | |
if (dwOldMode != dwNewMode) | |
return !SetConsoleMode(hConIn, dwNewMode); | |
else | |
return 0; | |
} | |
} | |
return ret((dwOldMode & 0x40) != 0); | |
} | |
return ret(-1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment