Home Software Documentation Stuff

                                  

                                  

                                  

                                  

Code Snippets

Here is some software I have written over the ages. It is all in the public domain. You may use the software any way you wish, I do not claim a copyright on any of it. You can remove my name and pass it off as your own if you'd like.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

If for any reason your jurisdiction does not recognize waiver of my copyright or the creation of public domain works, then use the CC0 1.0 Universal as a fallback.

Name Description
Makefile Makefile that can build everything here to use as a reference
args.c args.h args_test.c parser for command-line arguments.
3dsloader.c 3dsloader.h 3D model format file loader for Wavefront OBJ format. These files are needed:
byte_order.h fileio.c fileio.h logger.c logger.h model.c model.h test-3dsloader.c
base26.c A bijective base-26 numeration system (aka 26-adic). It is the base-26 that is used to label columns in spread sheet programs. It goes A..Z, AA..AZ, BA..BZ, ... This program can convert to the system and from the system. 'A' starts at 0, 'Z' is 25, 'AA' is 26, etc.
base85.c Encodes and decodes numbers in base85 using Ascii85/adobe or modifier RFC1924.
bdf.c bdf.h Loads BDF(Glyph Bitmap Distribution Format) font files to a data structure.
bitanon.c Example of using bitfields with anonymous struct and union. (GCC extension)
bitfield.h Macros to define bitfields of any size and manipulate them. example program: bitfield_test.c
bmp.c Primitive BMP bitmap image writing program. Only supports 8-bit grayscale images. (Example image)
buffer.c
buffer.h
I/O buffer library. supports a zero-copy API.
c99array.c Example of using C99 arrays to functions
carray.c dumps binary or text file into a C array. supports hexdump, character literals, string escapes, and decimal.
compiler.h Portability macros for various compiler and C99 extensions.
cccheck.c basic example of how a credit card works.
clock.c Simple curses based digital clock. build with -lncurses
config.c Parses a simple config file using wildcard matching
cp437utf8.c convert DOS CP-437 US Character set to UTF8 Unicode.
crc.c crc.h Calculates a CRC32 (ANSI X3.66) or CRC16 (Xmodem) on a block of data. [C99]
ctx.c ctx.h Loads Creativyst Table eXchange Format (CTX) files. Which are like "CSV" files.
cube_vbo.c Example of rendering an OpenGL cube using VBOs. (requires SDL2)
decimal.c converts an unsigned number into a decimal string without using sprintf.
d.c An example of using CURSES. (late 1990's)
demoserv.c One of the first TCP/IP socket programs I wrote.
dir.c Wrapper for Windows FindFirstFile()/FindNextFile() to implement a subset of POSIX opendir(), readdir(), closedir() and rewinddir().
dll.c dll.h dll_test.c dll_plugin1.c dll/shared-object loading for Windows and POSIX. Includes test code and an example plug-in.
errlog.c
errlog.h
Logging macros and function for C89 and C99.
fnt2bdf.c converts raw console fonts into X11 BDF fonts
freecell.c Generates Freecell boards based on Microsoft Freecell. Requires oldrand.c and oldrand.h
fileio.c A library to abstract binary file I/O in a slow but easy to read way.
funptr.c example of using function pointers
error.c Utility to look up errno values into symbolic names and error message strings.
gcd.c GCD calculator - Greatest Common Divisor
getaddrinfo.c example of using getaddrinfo and getnameinfo to do IPv4 and IPv6 look-ups transparently
grow.c dynamic arrays using realloc
heap.c example of a priority queue as a heap in an array holding a complete binary tree. Only a moderate amount of testing has gone into this.
ihash.c ihash.h Integer hash table. test/example program: test_ihash.c
ini.huge.c ini.huge.h demo.ini Old version of a library that loads windows-style INI configuration files. (ANSI C)
ini.medium.c ini.medium.h a medium sized .ini config file parser.
ini.small.c ini.small.h a minimalize INI config file parser using scanf
ipow.c ipow() is an integer power function for doing exponents.
list.h linked list macros without documentation. (ANSI C)
logger.c logger.h macros and library to log debug messages and status messages. test/example program: logger_test.c
macros.h a handful of useful macros for arrays, compiler options, tracing, and debuging.
makeext.c substitute one file extension for another. useful for handling command-line parameters.
map.c map.h associative array using string hashing
map2.c map2.h list.h macros.h version 2 of associative array hash table code
mapfile.c allows a file to mapped into memory (read-only) to be used as one big string. NOTE: the file is not null terminated. you must use the len parameter. On 32-bit systems you may have trouble loading very large files (like around 512M - 1GB, depending on your operating system and architecture). A more elegant solution would be to map around 1MB at a time and just move the map forward with a new offset.
maze.c the classic maze drawing algorithm. example
microthreads Pseudo-threads macros. See also "ot.h" below.
model.c model.h container for holding vertices for 3D objects. with some hacks for 3DS and OBJ file formats.
mkenum.c utilitiy that turns a list of strings into C source for an enum and optionally a table of strings.
moon.c moon.h Phase of the Moon, quick and dirty. With cool ASCII art. (build with -DUNIT_TEST to get a command-line program instead of a library)
myip.c Lists all of your computer's IP addresses. Supports IPv4 and IPv6
net.c net.h generic networking routines
netdump.c framework for writing diagnostic/debug/test code, outputs hex of a TCP socket in real time. easily modified for your tests.
objloader.c objloader.h 3D model format file loader for Wavefront OBJ format. These files are needed:
logger.c logger.h fileio.c fileio.h model.c model.h test-objloader.c
oldrand.c oldrand.h Implementations of old/obsolete random number generators. Including the generator used in Microsoft Visual C v4.0, the same one used for Microsoft Freecell game.
ot.h Pseudo-threads macros. See also "microthreads" above. Example: test-ot.c
hilbert.c draw a Hilbert's curve in ASCII. alternate versions: hilbert2.c hilberttiny.c
mren.c mren : mass rename using posix regular expression regex
parser.c A simple template for loading text files to parse.
pdline.c 3D and 2D line drawing routines using Bresenham's line algorithm the 2D line routine has an enhancement that does an inexpensive distance estimation. some stand-alone distance calculations are included for comparison with the distance estimate in line2d
pwgen.c Password generator. supports a variety of settings. also an [ugly] example of parsing command-line options without using getopt()
queue_test.c extensive test program for queue.h (see below)
rc4tiny.c inefficient and untested RC4 implementation. primarily for use as a pseudo-random number generator.
rc.c rc.h configuration file format parser. Example/test program
rickdate.c utility to encode and decode RickDate format. example: December 25, 2006 is 1JPCP. This format is useful for appending date information on filenames. There is a 3 and 4 letter version as well.
roundup2.c round up a number to next power of 2 in few loops
scrub.c A poor attempt at a program to strip comments and whitespace from C programs.
sha1.c inefficient and untested SHA-1 implementation
sha1tiny.c a smaller inefficient and untested SHA-1 implementation
showif.c finds all network interfaces and shows a little information about them. some operating systems list interfaces multiple times because of different flags, modes, etc. if you want to use this code you should be aware that duplicate interfaces is a possibility
strcmpn.c strcmpn.h function to do string comparison between a string and a series of chars.
stretch.c stretch.h generate tables useful for performing bit stretching
strtokex.c example of using the strtok() function
tcrypt.c Password hashing using TEA and XXT algorithms. Completely insecure, but short and simple.
telnet.c telnet.h arpa-telnet.h Telnet protocol parser (add your own network code). snapshot:telnet-jdm-20080523.tar.gz
tga.c Primitive TGA image writing program. Only supports 8-bit indexed color and grayscale images. (Example image)
texteditor.c Basic texteditor library using buffer-gap algorithm
udb.c udb.h tiny text file database API. can preprocess the first line into any sort of key (I use C function prototypes for the key in my udb database). I have an example file for when building the demo, grab dict.usb.gz and gunzip it to try the demo.
wav.c Simple WAV audio file exporter
xd.c Hexdump utility with lots of options. Can display hexdumps in real-time through a pipe, unlike most other utilities.
xgetopt.c xgetopt.h No-frills implementation of POSIX getopt(). Test program xgetopt-test.c
xrootbg.c Example of using Imlib2 to set the X wallpaper

Some examples of gas assembler

here is stuff I didn't write, but I enhanced or just find useful.

You can find more stuff in my found code section.