As of 2016-02-26, there will be no more posts for this blog. s/blog/pba/
Showing posts with label C. Show all posts


This is a note currently nothing about about the programming, but the use of C project.

1   $HOME/.local installation with Autotools

Normally, project with GNU Autotools, you can build and install to specified location, for example

% ./configure --prefix=$HOME/.local
% make
% make install

Which installs the files to $HOME/.local other than commonly default /usr/local. On most distributions, you shouldnt have issues with /usr/local installation, not just the executables, but also the libraries, pkg-config, linking, they all should be configured system-wide.

However, its not the case for user home installation, you will need to take some steps to ensure things can be found.

1.1   pkg-config

export LD_LIBRARY_PATH=$HOME/.local/lib
export PKG_CONFIG_PATH=$HOME/.local/lib/pkgconfig:/usr/lib64/pkgconfig

LD_LIBRARY_PATH makes sure any shared libraries are linked during the compilation can be found when you execute the program.

PKG_CONFIG_PATH isnt for additional paths, so you still need to provide the system pkg-config locations.

1.2   configure

When startup, continues sources prefix/share/, if found, prefix is either default or one you specify with --prefix. In my case, it is $HOME/.local/share/ and I have the following content:


They will make sure the header files can be found and linker knows there the shared libraries are stored.

hexedit is your typical standard hexadecimal editor that you would ever need.

hexedit 1.2.12 (2005-09), with --color

Click to watch some usages

It doesnt have any fancy UI, but it gets the job done. You can copy, paste, edit, truncate, search, etc.

I have been using it for six years, the same code is more than a decade code. Even the latest code is available for almost three years, I just dont feel the need of updating it.

hexedit was created by Pascal Rigaux on 1998-07-21, written in C under GPLv2, latest version is 1.2.13 (2013-03-01).

KOULES is a space action game, that you bump your enemies, the KOULES spheres, to death. Well, or the other way around.

Its an addictive game, you can play alone or with friends up to five for deathmatch or cooperative. For single player, it has 100 levels and 5 difficulty levels.

The game has 256-color mode in 640x480, monochrome, or black/white mode. It can also run a server and accept other players from clients. It can be played with keyboard, mouse, or joysticks.

The opening Star Wars crawl is interesting, so is the README and the official website. You may also want to read the Koules.FAQ.

KOULES was created by Jan Hubička in July, 1995, written in ANSI C with SVGAlib/X11, run on Unix-like or OS/2 Warp, under GPLv2, currently Debian version 1.4-23 (2015-05-02, post v1.4(1998-03-09)).

Back into Orbit is a fun shooter game in X Window, said a simple isometric shooter roguelike.

You shoot some black robots and green device which generates some kind of wave harming your health if you stay within the range. There is also different colors of cones that transport you to different locations. Some are really bad as you are ambushed.

Enemies and devices might drop coins, which might be used in a shop area. Never lived that long to try. The bigger robots shoot.

Back into Orbit was created on 2015-06-11, written in C with SDL2, GLEW, OpenGL 2.0+, and Assimp (Open Asset Import Library) under GPLv2, running on Linux and Windows, currently git-dc03083 (2016-01-21).

Pixel Knights provides your a virtual arena, you can have friends come in and fight.

The controls are WASD with IJKL for shooting bullets. You can eat ($) for points, chat with others. It is designed with client and server, so you will need to connect a server to play.

It has four map, the one above is default square map, there is also split, hall, and sniperArea. You can supply the map number when starting the server.

Pixel Knights was created by Markus Palonen on 2015-02-08, written in C (gnu99) under the MIT License, currently git-1064d62i (2016-01-21).

ASCII Flappy Bird! is yet another bird trying hard to flap through tiny gaps of endless obstacles.

It has a nice title screen and sad death screen. You know the drill, just Space to fly away.

ASCII Flappy Bird! was created by Hamik Mukelyan, writen in C with ncurses for terminal size 80x24+, under the MIT License, currently git-1c56b7b (2016-01-19).

nInvaders is a Space Invader clone, was made more than a decade ago, still runs even without any updates or patches for nearly 13 years.

Actual speed as recorded

Not sure if its by design or just outdated code, you will need to defeat the invaders in less than 20 seconds, which I dont believe thats plausible. Therefore, I edited the code, watch this video from 30 mark:

  • Time dilation devide: nInvader.c:L33 s/50/10/

  • Invisible Laser Destroyer: playerReloadMissile.c:L179 s/if/while/

  • Secret spell: UUDDLRLRBA

    echo -e '\e[31;1m*** CHEAT MODE ENABLED ***\e[0m'
    echo -e '- \e[34;1mTime dilation deviced\[0m    : \e[1;32mON\e[0m'
    echo -e '- \e[34;1mInvisible Laser Destroyer\[0m: \e[1;32mUPGRADED\e[0m'


Turns out, its a 13-year-old bug, and everyone had played it without knowing it or even questioning it. Ive forked it and patched the bug, you can get the updated nInvaders. (2016-01-21T08:29:10Z)

It has one command-line option for changing difficulty level, -l 0 for NIGHTMARE level and -l 9 for the easiest setting. There is also two builtin cheats, L for one more life and W to skip the level.

nInvaders was created by Thomas Dettbarn in 2002, written in C with ncurses under the GPLv2, currently version 0.1.1 (2003-05-08).

konsole_invaders is yet another clone, but it feels more action packed, because you have to keep tapping firing keys.

It supports WASD, HJKL, and arrow keys, plus Space for firing. It has scores, lives, and rockets. You get an extra life and rocket capacity once you clear a level or a wave of aliens. Detailed options for customize the gameplay, which can also be set with configuration file. Different types of alien ships, as deeper into levels, you get the stronger enemies.

Although, it looks good in many aspects, not so on other things. Such as big terminal size requirements, probably due to ASCII art of alien ships; and as you advance to later waves, you constantly have to press the firing key, if there was an auto-firing switch it would be much easier to play and for your wrist.

konsole_invaders was created by Fabian Ebner on 2011-08-17, written in C99 with terminal size 103x44+ under the GPLv3+, currently git-42b96db (2016-01-16)

Sudoku is a game, generator, solver, and statistics calculator. It has command-line options and well-documented manual page, plus nice UI to play.

In game, you can save or load board, request a hint which might even give you which digit to try, it can also solve the board if you have given up.

Sudoku was released in 2005-07 by Michael Kennett into public domain, continued by Peter Spiess-Knafl on 2015-02-12, written in C with ncurses, running on Windows and Unix-like, currently git-61e3f39 (2015-03-13, post v1.0.4 (2015-02-28)).

CursesBird is a simple side-scrolling game, you are the bird > and you are trying to flying through a tunnel, dont hit the wall. Well, that sounds more like a bat.

Anyway, the controls are basically Up/Down and Leff/Right to adjust speed. Also p pauses the game.

CursesBird was created on 2014-04-11, written in C with ncurses under New BSD License (3-clause), currently git-49a603c (2016-01-05).


This post is for GNU/Linux and POSIX systems.

Its quite often when I work on an old ANSI C/C89 code, if its using usleep and -Wall, then there would be a warning:

warning: implicit declaration of function 'usleep'

Since GNU C Library 2.12 (May 2010), you need to have right macros to have it, see usleep(3). I think the better way is to move onto nanosleep if its for POSIX systems, and every time I would have to copy from previous modified code. I think I will make a note for it.

1   usleep


2   nanosleep

#define _POSIX_C_SOURCE       199309L

#include <time.h>

struct timespec req = {
  .tv_sec = SLEEP / 1000000,
  .tv_nsec = SLEEP * 1000

nanosleep(&req, NULL);

Note that if SLEEP is for less than a second, then you can directly set .tv_sec to 0. Also _POSIX_C_SOURCE >= 199309L is required.

Wanderer (GitHub) is a Boulder Dash (1984) like game, originally written in K&R C now C99 for UNIX and released on Usenet in 1988. Later, it was ported to different systems, MS-DOS, Atari, Amiga, BBC Micro, and SCO-Unix. Some even in graphics mode.


To clear a level (screen) is to collect all the diamonds, stay alive, then head out through the WAYOUT.

boom (GitHub) is

A 2-player battle game made for Ludum Dare 28 (December 2013), for the theme you only get one.

The game goes like this, two players, each has many fake mine and one possibly real mine, but you never know if you get the real real mine until the detonation of the possibly real mine.

It can be played with keyboard or Xbox 360 controllers and it has sound.

You lay as many mines as you like, and hope your opponent will come close near the possibly real mine and you detonate the mines. If its real, you win. If its not, you can still play cool since your opponent has not yet deploy the real mine and still doesnt know that is a real deal. If your opponent detonates the real mine and doesnt blow you up, then you are the winner.

Its a fun game.

boom was created on 2013-12-13 by Joseph Lansdowne, written in Python 2/3 and C with Pygame under the GPLv3, currently git-a0fb8ac (2014-01-18).

I couldnt run vim-particle but the GIF from the project really is interesting.

It can only be run with GVim on Windows. Someone please at least ports it to Linux, and if possible, to Vim, although that could be very difficult. I wonder if you can do it within Vim, that is not drawing in X, but that would probably mess up the file being edited.

If you want to see another particle sparkling out and in terminal, try particle.cpp.

vim-particle was created by Yasuhiro Matsumoto, written in C and Vim script under the MIT License, currently git-37ecd82 (2015-12-01).

Cangkufan is a Sokoban clone with 50 puzzles by Hiroyuki Imabayashi.

The controls include mouse and keyboard, you can undo or redo, replay best pushes or steps, which are recorded. The Cangkufan is the Chinese Pinyi of the Japanese (Kanji) title, in short, the Chinese pronunciation of 倉庫番.

Cangkufan was created by Pluto Yang in 2003, written in C with GTK+2 under the GPLv2, currently version 0.2 (2010-09-17).

text2048 is a clone of that popular game 2048, which will be two years next March.

After this long time, 2048 is still sliding strong, a lot of people is still cloning it, making their own versions, even more A.I. popping up every a while with new ideas and algorithms.

It was even played in 18th Computer Olympiad (2015) for the first time.

As of this clone, the only thing differs it from others is the cells, the red color on the either edge of the cells of 2 2n+1.

text2048 was created by Christian Fiedler on 2015-08-09, written in C99 with ncurses under the MIT License, currently git-7b6cf12 (2015-11-11).

CPat is a Patience suite game, including 11 solitaire games:

FreeCell, Klondike, Spider, 40 Thieves, Bakers Dozen, Scorpion, Penguin, Yukon, Strategy, Canfield, Duchess.

(Watch this video for other screens and a bit of playing)

Since its all-in-one, you can have a unified controls, its all the same way to move a card, put into foundations, and so on. It also has help and rule screens to help you understand the card game.

There is also game statistics and high scores to keep records. There is one useful command-line option, -f, to speed up auto-moves, that is when you using free cells to move a stack of cards, it will move one by one to show the movements, but the default speed is too slow. -f can be used for multiple times, for example, -fff.

When move to the foundations, #pp or P will really be helpful since it doesnt do like some implementations will automatically move to the foundations for you, such as freecell.

CPat was created by Trevor Carey-Smith on 2006-02-16 (v0.1), based on Steve Levines code, written in C with ncurses, currently version 1.2.1 (2008-09-16).

mandelbrot-viewer is a simple and interactive viewer, you can zoom in and out with + and -.

The GIF screencast is of course sped up, somehow, it looks like something has been locked and the system is tracking down the subject like in sci-fi movie.

mandelbrot-viewer is written by David Ulrich in C with ncurses under the AGPLv3, based on Ken Perlins code snippet, currently git-a3f2762 (2015-10-30).

GNUjump is a clone of xjump aka. FALLING TOWER, it uses SDL and has a lot of more options, it also supports multiplayer.

GNUjump 1.0.8 with wincrash theme, watch in SDLjump theme

It has much more options, you can change game settings, such as FPS and trailing effect; video, such as using OpenGL and antialiasing; and sound volumes. Beside the must-have high scores, a replay feature, so you can watch other peoples playing.

The sound effect is hilarious, not your usual sounds, but someones vocals, watch the video and you will hear those.

Here are the four themes.

Canfield is part of BSD Games, a Patience/Solitaire game, also a gambling game.

Canfield: Instructions, Betting, Card counting

At first few plays, I could barely get a few into the foundations, I thought even I wasnt good at Patience game, but I couldnt be that bad, could I?

Finally, I looked up on Wikipedia and the first line it reads:

[] with a very low probability of winning. According to legend, it is originally a casino game, []. In England, it is known as Demon. [some emphases mine]