Skip to content

Instantly share code, notes, and snippets.

@kdrnic
Created July 21, 2019 06:58
Show Gist options
  • Save kdrnic/a7f3c2bfcc31f6fd91d42808e91801ca to your computer and use it in GitHub Desktop.
Save kdrnic/a7f3c2bfcc31f6fd91d42808e91801ca to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <Windows.h>
const char prog[1024] = "\"C:\\Program Files (x86)\\Notepad++\\notepad++.exe\"";
DWORD GetNumCharsInConsoleBuffer()
{
CONSOLE_SCREEN_BUFFER_INFO buffer_info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &buffer_info);
return (DWORD)((buffer_info.dwSize.X * ( buffer_info.dwCursorPosition.Y + 1)) - (buffer_info.dwSize.X - (buffer_info.dwCursorPosition.X + 1)));
}
DWORD ReadConsoleBuffer(char* buffer, DWORD bufsize)
{
DWORD num_character_read = 0;
COORD first_char_to_read = {0};
ReadConsoleOutputCharacterA(GetStdHandle(STD_OUTPUT_HANDLE), buffer, bufsize, first_char_to_read, &num_character_read);
buffer[bufsize-1] = '\0';
return num_character_read;
}
struct errline
{
char file[256];
char err[256];
int row, col;
};
int main(int argc, char** argv)
{
DWORD bufsize = GetNumCharsInConsoleBuffer();
char* buffer = calloc(bufsize, 1);
ReadConsoleBuffer(buffer, bufsize);
int num_err = 0;
struct errline errline[999];
int i;
for(i = 0; i < bufsize; i++){
char *files, *rows, *cols, *errs;
if(buffer[i] == ' ') continue;
char *ch = files = buffer + i;
while(isalnum(*ch) || *ch == '/' || *ch == '.') ch++;
if(*ch != ':' || files == ch) continue;
*ch = 0; ch++;
rows = ch;
while(isdigit(*ch)) ch++;
if(*ch != ':' || rows == ch) continue;
*ch = 0; ch++;
cols = ch;
while(isdigit(*ch)) ch++;
if(*ch != ':' || cols == ch) continue;
*ch = 0; ch++;
errs = ch;
ch += 80 - 1 - (errs - files);
*ch = 0; i = ch - buffer;
strcpy(errline[num_err].file, files);
strcpy(errline[num_err].err, errs);
errline[num_err].col = atoi(cols);
errline[num_err].row = atoi(rows);
num_err++;
}
for(i = 0; i < num_err; i++){
printf("%d\t%-24s\t%d\t%d\n\t%s\n", i + 1, errline[i].file, errline[i].row, errline[i].col, errline[i].err + 1);
}
while(1){
puts("Select error (0 to quit):");
scanf("%d", &i);
if(i) i--;
else break;
char cmd[2048] = {};
sprintf(cmd, "%s -n%d -c%d %s", prog, errline[i].row, errline[i].col, errline[i].file);
system(cmd);
}
free(buffer);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment