#include "esptool.h"
__declspec(noreturn)
void vFatal(const char*fmt,va_list va) {
vprintf(fmt,va);
putchar('\n');
ExitProcess(2);
}
__declspec(noreturn)
void _cdecl Fatal(const char*fmt,...) {
va_list va;
va_start(va,fmt);
vFatal(fmt,va);
}
static HINSTANCE ghInst;
static UINT consoleCP=CP_OEMCP;
Console tty={0,0,80,25};
autostring loadString(UINT id) {
HRSRC r=FindResource(ghInst,MAKEINTRESOURCE((id>>4)+1),RT_STRING);
if (!r) return (char*)0;
const WCHAR*p=reinterpret_cast<const WCHAR*>(LoadResource(ghInst,r));
for (id&=15; id; id--) {
p+=*p+1;
}
int need=WideCharToMultiByte(consoleCP,0,p+1,*p,0,0,0,0);
char*sbuf=new char[need+1];
WideCharToMultiByte(consoleCP,0,p+1,*p,sbuf,need,0,0);
sbuf[need]=0;
return sbuf;
}
__declspec(noreturn)
void _cdecl Fatal(UINT id,...) {
va_list va;
va_start(va,id);
vFatal(loadString(id).c_str(),va);
}
void _cdecl printf(unsigned id,...) {
va_list va;
va_start(va,id);
tty.x+=vprintf(loadString(id).c_str(),va);
va_end(va);
}
void _cdecl println(unsigned id,...) {
va_list va;
va_start(va,id);
vprintf(loadString(id).c_str(),va);
newline();
va_end(va);
}
void _cdecl println(const char*fmt,...) {
va_list va;
va_start(va,fmt);
vprintf(fmt,va);
newline();
va_end(va);
}
void newline() {
putchar('\n');
tty.x=0;
++tty.y;
}
void Console::init() {
if (SetConsoleOutputCP(CP_UTF8)) consoleCP=CP_UTF8;
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE),&csbi);
w=csbi.srWindow.Right-csbi.srWindow.Left+1;
h=csbi.srWindow.Bottom-csbi.srWindow.Top+1;
}
Detected encoding: ASCII (7 bit) | 2
|