Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
117 lines (80 loc) · 2.39 KB

File metadata and controls

117 lines (80 loc) · 2.39 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*++
Copyright (c) 2014 by Antoni Sawicki
Module Name:
cmdsave.c
Abstract:
Dump contents of cmd.exe console window buffer to a file.
Version:
1.1 - crlf fix
Author:
Antoni Sawicki <as@tenoware.com>
License:
BSD
--*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
void ERRPT(char *msg, ...) {
va_list valist;
char vaBuff[1024];
char errBuff[1024];
DWORD err;
va_start(valist, msg);
_vsnprintf(vaBuff, sizeof(vaBuff), msg, valist);
va_end(valist);
printf("ERROR: %s\n", vaBuff);
err=GetLastError();
if(err) {
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), errBuff, sizeof(errBuff) , NULL );
printf("%08X : %s\n\n", err, errBuff);
}
ExitProcess(1);
}
int main(int argc, char **argv) {
HANDLE hConsole;
HANDLE hFile;
COORD start;
LPSTR buff;
CONSOLE_SCREEN_BUFFER_INFO cbi;
DWORD rchr, ochr, n;
LONG l;
if(argc!=2)
ERRPT("\rUsage: %s <filename>\n", argv[0]);
hConsole=GetStdHandle(STD_OUTPUT_HANDLE);
if(hConsole==INVALID_HANDLE_VALUE)
ERRPT("GetStdHandle" );
if(GetConsoleScreenBufferInfo(hConsole, &cbi)==0)
ERRPT("GetConsoleScreenBufferInfo");
buff=HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (cbi.dwSize.X+3)*sizeof(WCHAR));
if(buff==NULL)
ERRPT("HeapAlloc");
hFile=CreateFile(argv[1], GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile==INVALID_HANDLE_VALUE)
ERRPT("CreateFile %s", argv[1]);
start.X=0;
start.Y=0;
while(start.Y<cbi.dwSize.Y) {
if(ReadConsoleOutputCharacter(hConsole, buff, cbi.dwSize.X, start, &rchr)==0)
ERRPT("ReadConsoleOutputCharacter [rchr=%d, y:%d]", rchr, start.Y);
// trim horizontal
n=cbi.dwSize.X-1;
while(n && buff[n]==' ')
n--;
if(n==0)
n=-1;
buff[n+1]='\r';
buff[n+2]='\n';
buff[n+3]='\0';
if(WriteFile(hFile, buff, strlen(buff), &ochr, NULL)==0)
ERRPT("WriteFile");
// for vertical trim
if(buff[0]!='\r')
l=GetFileSize(hFile, NULL);
start.Y++;
}
// trim vertical
SetFilePointer(hFile, l, NULL, FILE_BEGIN);
SetEndOfFile(hFile);
CloseHandle(hFile);
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.