Skip to content

Commit

Permalink
[azure-pipelines] add cpplint job. Fixes #140
Browse files Browse the repository at this point in the history
  • Loading branch information
Raffaello committed May 22, 2020
1 parent 41db00c commit f604401
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 224 deletions.
7 changes: 4 additions & 3 deletions azure-pipelines/analyzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,13 @@ stages:
pool:
vmImage: ${{ variables.mac_image }}
steps:
- script: chmod +x cpplint.sh && ./cpplint.sh
displayName: cpplint 2> cpplint.log
- script: pip install cpplint
displayName: install cpplint
- script: chmod +x cpplint.sh && ./cpplint.sh 2> cpplint.log || echo "-==*** ignoring linting warnings ***==-"
displayName: cpplint
continueOnError: true
# Publish (upload) a file or directory as a named artifact for the current run
- task: PublishPipelineArtifact@1
inputs:
targetPath: cpplint.log
artifactName: 'cpplint.log'

9 changes: 8 additions & 1 deletion cpplint.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#!/bin/bash

cpplint --recursive --linelength=120 --filter=-legal/copyright sdl2-vga-terminal/
cpplint --recursive --linelength=120 \
--exclude=sdl2-vga-terminal/src/vgapalette.h \
--filter=-legal/copyright,-build/include_order,-whitespace/braces\
,-whitespace/line_length,-build/include_subdir,-whitespace/indent\
,-whitespace/newline,-build/namespaces,-readability/braces,-build/c++11\
,-readability/todo,-whitespace/comments,-readability/utf8\
,-runtime/threadsafe_fn,-runtime/indentation_namespace \
sdl2-vga-terminal/
6 changes: 3 additions & 3 deletions sdl2-vga-terminal/examples/sdl2-tui-terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ int main(int argc, char* argv[])
SDL_Delay(10);
}

tui.drawSingleBorderDialog({ 30, 10, 20,3 }, 15, 1, "", "Press any key...");
tui.drawSingleBorderDialog({ 30, 10, 20, 3 }, 15, 1, "", "Press any key...");
tui.render();
//press a key...
// press a key...
SDL_Event event;
bool keypressed = false;
while (!keypressed) {
Expand All @@ -56,4 +56,4 @@ int main(int argc, char* argv[])

SDL_Quit();
return 0;
}
}
191 changes: 95 additions & 96 deletions sdl2-vga-terminal/examples/sdl2-vga-terminal-load-so.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,117 +39,116 @@ typedef VGA_Terminal* (__cdecl* PROCINIT)();

void win32()
{
const char* soname = TEXT(VGA_SO_NAME ".dll");
HINSTANCE hinstLib;
PROCINIT ProcAddInit = NULL;
PROCDESTROY ProcAddDestroy = NULL;
PROCWRITEXY ProcAddWriteXY = NULL;
PROCRENDER ProcAddRender = NULL;
BOOL fFreeResult;
BOOL fRunTimeLinkSuccess = SDL_FALSE;
printf("loading library: %s\n", soname);

hinstLib = LoadLibrary(soname);
if (hinstLib != NULL)
{
ProcAddInit = (PROCINIT)GetProcAddress(hinstLib, "VGA_TERMINAL_init");
ProcAddDestroy = (PROCDESTROY)GetProcAddress(hinstLib, "VGA_TERMINAL_destroy");
ProcAddWriteXY = (PROCWRITEXY)GetProcAddress(hinstLib, "VGA_TERMINAL_writeXY");
ProcAddRender = (PROCRENDER)GetProcAddress(hinstLib, "VGA_TERMINAL_render");

// If the function address is valid, call the function.

if (NULL != ProcAddInit && NULL != ProcAddDestroy && NULL != ProcAddWriteXY && NULL != ProcAddRender)
{
fRunTimeLinkSuccess = SDL_TRUE;
VGA_Terminal* term = ProcAddInit();
ProcAddWriteXY(term, 0, 0, "GREETINGS PROFESSOR FALKENS.", 10, 0);
ProcAddRender(term);
SDL_Delay(1000);
ProcAddDestroy(term);
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
if (!fFreeResult) {
fprintf(stderr, "unable to unload library\n");
}
else {
printf("library unloaded.\n");
}
}

// If unable to call the DLL function, use an alternative.
if (!fRunTimeLinkSuccess) {
DWORD dw = GetLastError();

fprintf(stderr, "failed to load the DLL. Error %lu\n", dw);
}
const char* soname = TEXT(VGA_SO_NAME ".dll");
HINSTANCE hinstLib;
PROCINIT ProcAddInit = NULL;
PROCDESTROY ProcAddDestroy = NULL;
PROCWRITEXY ProcAddWriteXY = NULL;
PROCRENDER ProcAddRender = NULL;
BOOL fFreeResult;
BOOL fRunTimeLinkSuccess = SDL_FALSE;

printf("loading library: %s\n", soname);

hinstLib = LoadLibrary(soname);
if (hinstLib != NULL)
{
ProcAddInit = (PROCINIT)GetProcAddress(hinstLib, "VGA_TERMINAL_init");
ProcAddDestroy = (PROCDESTROY)GetProcAddress(hinstLib, "VGA_TERMINAL_destroy");
ProcAddWriteXY = (PROCWRITEXY)GetProcAddress(hinstLib, "VGA_TERMINAL_writeXY");
ProcAddRender = (PROCRENDER)GetProcAddress(hinstLib, "VGA_TERMINAL_render");

// If the function address is valid, call the function.

if (NULL != ProcAddInit && NULL != ProcAddDestroy && NULL != ProcAddWriteXY && NULL != ProcAddRender)
{
fRunTimeLinkSuccess = SDL_TRUE;
VGA_Terminal* term = ProcAddInit();
ProcAddWriteXY(term, 0, 0, "GREETINGS PROFESSOR FALKENS.", 10, 0);
ProcAddRender(term);
SDL_Delay(1000);
ProcAddDestroy(term);
}
// Free the DLL module.
fFreeResult = FreeLibrary(hinstLib);
if (!fFreeResult) {
fprintf(stderr, "unable to unload library\n");
}
else {
printf("library unloaded.\n");
}
}

// If unable to call the DLL function, use an alternative.
if (!fRunTimeLinkSuccess) {
DWORD dw = GetLastError();

fprintf(stderr, "failed to load the DLL. Error %lu\n", dw);
}
}
#endif

#ifdef linux
void lnx()
{
const char* soname = "./lib" VGA_SO_NAME ".so";
void* handle = dlopen(soname, RTLD_NOW);

if (handle) {
char* error;

VGA_Terminal* (*init)(void);
void (*destroy)(VGA_Terminal*);
void (*writeXY)(VGA_Terminal*, uint8_t, uint8_t, char* str, uint8_t, uint8_t);

init = dlsym(handle, "VGA_TERMINAL_init");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}

destroy = dlsym(handle, "VGA_TERMINAL_destroy");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}

writeXY = dlsym(handle, "VGA_TERMINAL_writeXY");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}


VGA_Terminal* term = (*init)();
(*writeXY)(term, 0, 0, "test", 10, 0);
SDL_Delay(1000);
(*destroy)(term);


dlclose(handle);
}
else {
fprintf(stderr, "unable to load SO. Error %s\n", dlerror());
}

const char* soname = "./lib" VGA_SO_NAME ".so";
void* handle = dlopen(soname, RTLD_NOW);

if (handle) {
char* error;

VGA_Terminal* (*init)(void);
void (*destroy)(VGA_Terminal*);
void (*writeXY)(VGA_Terminal*, uint8_t, uint8_t, char* str, uint8_t, uint8_t);

init = dlsym(handle, "VGA_TERMINAL_init");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}

destroy = dlsym(handle, "VGA_TERMINAL_destroy");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}

writeXY = dlsym(handle, "VGA_TERMINAL_writeXY");
if ((error = dlerror()) != NULL) {
fputs(error, stderr);
exit(1);
}


VGA_Terminal* term = (*init)();
(*writeXY)(term, 0, 0, "test", 10, 0);
SDL_Delay(1000);
(*destroy)(term);


dlclose(handle);
}
else {
fprintf(stderr, "unable to load SO. Error %s\n", dlerror());
}
}
#endif

int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Unable to initialize SDL: %s", SDL_GetError());
return 1;
}
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Unable to initialize SDL: %s", SDL_GetError());
return 1;
}



#ifdef WIN32
win32();
win32();
#endif
#ifdef linux
lnx();
lnx();
#endif

SDL_Quit();
return 0;
SDL_Quit();
return 0;
}
67 changes: 33 additions & 34 deletions sdl2-vga-terminal/examples/sdl2-vga-terminal-so.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,46 @@
#include <stdio.h>

#ifdef WIN32
# include <Windows.h>
# include <delayimp.h>
# pragma comment(lib, "delayimp")
# include <Windows.h>
# include <delayimp.h>
# pragma comment(lib, "delayimp")
#endif


int main(int argc, char* argv[])
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Unable to initialize SDL: %s", SDL_GetError());
return 1;
}

VGA_Terminal* term = VGA_TERMINAL_init();

VGA_TERMINAL_writeXY(term, 0, 0, "GREETINGS PROFESSOR FALKEN.", 10, 0);
// emulating the main even loop few times
// just to show the cursor blinking....
int quit = 6;
SDL_Event e;
while (quit--) {
VGA_TERMINAL_render(term);
do {
SDL_WaitEvent(&e);
} while (e.type != SDL_USEREVENT && e.user.type != SDL_USEREVENT);

}

VGA_TERMINAL_destroy(term);
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) != 0) {
SDL_LogError(SDL_LOG_CATEGORY_SYSTEM, "Unable to initialize SDL: %s", SDL_GetError());
return 1;
}

VGA_Terminal* term = VGA_TERMINAL_init();

VGA_TERMINAL_writeXY(term, 0, 0, "GREETINGS PROFESSOR FALKEN.", 10, 0);
// emulating the main even loop few times
// just to show the cursor blinking....
int quit = 6;
SDL_Event e;
while (quit--) {
VGA_TERMINAL_render(term);
do {
SDL_WaitEvent(&e);
} while (e.type != SDL_USEREVENT && e.user.type != SDL_USEREVENT);
}

VGA_TERMINAL_destroy(term);

#ifdef WIN32
# ifndef NDEBUG
# define PFIX "d"
# else
# define PFIX ""
# endif
int t = __FUnloadDelayLoadedDLL2("vga-terminal" PFIX ".dll");
printf("unloaded? : %d\n", t);
getchar();
# ifndef NDEBUG
# define PFIX "d"
# else
# define PFIX ""
# endif
int t = __FUnloadDelayLoadedDLL2("vga-terminal" PFIX ".dll");
printf("unloaded? : %d\n", t);
getchar();
#endif // WIN32

SDL_Quit();
return 0;
SDL_Quit();
return 0;
}
9 changes: 4 additions & 5 deletions sdl2-vga-terminal/examples/sdl2-vga-terminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main(int argc, char* argv[])
term2.render();
SDL_Delay(1000);

VgaTerminal term1 = VgaTerminal("VgaTerminal",720,400, 0, -1, 0);
VgaTerminal term1 = VgaTerminal("VgaTerminal", 720, 400, 0, -1, 0);
if (SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2") == SDL_FALSE) {
cerr << "SetHint failed" << endl;
}
Expand Down Expand Up @@ -137,10 +137,10 @@ int main(int argc, char* argv[])
// at some point a better event name should be used
if (userevent.type == SDL_USEREVENT && userevent.code == 0) {
// the commented code below is intended as an example
//std::cout << "cursor event!" << endl;
// std::cout << "cursor event!" << endl;
}
else {
//cout << userevent.code << endl;
// cout << userevent.code << endl;
}
break;
}
Expand All @@ -150,7 +150,7 @@ int main(int argc, char* argv[])

term2.handler = f;
term2.cursor_time = 100;
//term2.setCursorSpeed(VgaTerminal::CURSOR_SPEED::CURSOR_SPEED_FAST);
// term2.setCursorSpeed(VgaTerminal::CURSOR_SPEED::CURSOR_SPEED_FAST);

string keyname;
while (!quit) {
Expand All @@ -172,7 +172,6 @@ int main(int argc, char* argv[])
}

switch (event.type) {

case SDL_QUIT:
quit = true;
break;
Expand Down
2 changes: 0 additions & 2 deletions sdl2-vga-terminal/src/TuiTerminal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ void TuiTerminal::drawDialog(const SDL_Rect& r, uint8_t col, uint8_t bgCol, cons
_drawHBorder(r.x + 1, r.y + r.h - 1, r.w, col, bgCol, 205);
_term.write(188, col, bgCol);
_drawShadow(r);

}

// progress [0, max]
Expand Down Expand Up @@ -263,7 +262,6 @@ void TuiTerminal::_drawBorder(const SDL_Rect& r, const uint8_t col, const uint8_
_term.gotoXY(r.x, r.y + r.h - 1);
_term.write(bc, col, bgCol);
_drawHBorder(r.x + 1, r.y + r.h - 1, r.w, col, bgCol, 205);

}

void TuiTerminal::_drawLeftBorder(const SDL_Rect& r, const uint8_t col, const uint8_t bgCol, const std::string& str)
Expand Down
Loading

0 comments on commit f604401

Please sign in to comment.