-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f48340d
commit e52ed4b
Showing
32 changed files
with
452 additions
and
18 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# GCC as library | ||
|
||
How to use GCC as a library, e.g. from another C program | ||
|
||
- <http://programmers.stackexchange.com/questions/189949/is-there-a-way-to-use-gcc-as-a-library> | ||
- <http://stackoverflow.com/questions/1735360/compiling-program-within-another-program-using-gcc> | ||
- <http://stackoverflow.com/questions/8144793/gcc-for-parsing-code> | ||
|
||
`libgccjit` from GCC 5 goes a long way. |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../Makefile |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
LIBS := -lcurses |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# curses | ||
|
||
1. [ncurses](ncurses.md) | ||
1. Examples | ||
1. [Hello world](hello.c) | ||
1. printw | ||
1. [printw newline](printw_newline.c) | ||
1. [printw twice](printw_twice.c) | ||
1. [printw newline screen height](printw_newline_screen_height.c) | ||
1. [clear](clear.c) | ||
1. [Check key pressed](check_key_pressed.c) | ||
1. Canonical. TODO. <http://www.gnu.org/software/libc/manual/html_node/Canonical-or-Not.html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
Check if a key was pressed in the last loop cycle: | ||
http://stackoverflow.com/questions/2984307/c-key-pressed-in-linux-console | ||
*/ | ||
|
||
#include "common.h" | ||
|
||
/* | ||
Return a character, on -1 if none was entered. | ||
*/ | ||
int getkey(void) { | ||
int character; | ||
int stdin_fileno; | ||
struct termios orig_term_attr; | ||
struct termios new_term_attr; | ||
|
||
stdin_fileno = fileno(stdin); | ||
|
||
/* Save old attributes. */ | ||
tcgetattr(stdin_fileno, &orig_term_attr); | ||
|
||
/* Set the terminal to raw mode. */ | ||
memcpy(&new_term_attr, &orig_term_attr, sizeof(struct termios)); | ||
/* TODO what are those parameters? */ | ||
new_term_attr.c_lflag &= ~(ECHO|ICANON); | ||
new_term_attr.c_cc[VTIME] = 0; | ||
new_term_attr.c_cc[VMIN] = 0; | ||
tcsetattr(stdin_fileno, TCSANOW, &new_term_attr); | ||
|
||
/* Read character. */ | ||
character = getchar(); | ||
while (getchar() != EOF); | ||
|
||
/* Restore the original terminal attributes. */ | ||
tcsetattr(stdin_fileno, TCSANOW, &orig_term_attr); | ||
|
||
return character; | ||
} | ||
|
||
int main(void) { | ||
int key; | ||
struct timespec sleep_cycle; | ||
sleep_cycle.tv_sec = 0; | ||
/* | ||
If we reduce this a lot and hold da key, `-1` shows all the time. | ||
When we hold a key, it it refreshed at a given low frequency it seems? | ||
*/ | ||
sleep_cycle.tv_nsec = 500000000L; | ||
initscr(); | ||
for (;;) { | ||
clear(); | ||
key = getkey(); | ||
printw("%d\n", key); | ||
refresh(); | ||
nanosleep(&sleep_cycle, NULL); | ||
} | ||
endwin(); | ||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* Second times overwrites the first. */ | ||
|
||
#include "common.h" | ||
#include "common_curses.h" | ||
|
||
int main(void) { | ||
int c; | ||
initscr(); | ||
printw("before clear\n"); | ||
clear(); | ||
printw("after clear\n"); | ||
refresh(); | ||
press_any_key_to_quit(); | ||
endwin(); | ||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../common.h |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#define ANY_KEY_TO_QUIT_MSG "press any key to quit\n" | ||
|
||
void press_any_key_to_quit() { | ||
printw(ANY_KEY_TO_QUIT_MSG); | ||
refresh(); | ||
getch(); | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <curses.h> | ||
|
||
int main(void) { | ||
/* Startup. */ | ||
initscr(); | ||
printw("hello world. Press any key to quit."); | ||
refresh(); | ||
/* Wait for use input. */ | ||
getch(); | ||
/* Teardown. */ | ||
endwin(); | ||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# ncurses | ||
|
||
Name of the dominant implementation. | ||
|
||
POSIX only talks about curses however. | ||
|
||
<http://stackoverflow.com/questions/1517756/whats-the-difference-between-lcurses-and-lncurses-when-compiling-c-using-ncur> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* Newlines do move the cursor down and to the beginning of the next line. */ | ||
|
||
#include "common.h" | ||
|
||
int main(void) { | ||
initscr(); | ||
printw("a\nb\npress any key to quit"); | ||
refresh(); | ||
getch(); | ||
endwin(); | ||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
Bad things happen: at the bottom of the screen, | ||
the cursor is imply not lowered anymore. | ||
*/ | ||
|
||
#include "common.h" | ||
#include "common_curses.h" | ||
|
||
int main(void) { | ||
int i; | ||
initscr(); | ||
for (i = 0; i < 1000; ++i) { | ||
printw("%d\n", i); | ||
} | ||
press_any_key_to_quit(); | ||
endwin(); | ||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* The current cursor position is unchanged. */ | ||
|
||
#include "common.h" | ||
#include "common_curses.h" | ||
|
||
int main(void) { | ||
initscr(); | ||
printw("first\n"); | ||
printw("second\n"); | ||
printw(ANY_KEY_TO_QUIT_MSG); | ||
refresh(); | ||
getch(); | ||
endwin(); | ||
return 0; | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
|
||
#include "common.h" | ||
|
||
int main() { | ||
int main(void) { | ||
int i = 0; | ||
while (1) { | ||
printf("%d\n", i); | ||
|
Oops, something went wrong.