TinyURL widget - shorten your URL's for free!

Enter a long URL to make tiny:

Thursday, November 19, 2015

Ring Buffers in GNU C from Learn C The Hard Way



I took the ring buffers exercise from  http://c.learncodethehardway.org/book/
and I fixed it and expanded it. Not that it wasn't a good starting point but it was a good learning function list I didn't know how ring buffers worked.  I wanted to understand how ring buffers work and they do make sense for a lot of string reads and writes.

I had to fix some faulty logic in the functions, and I  took out the references to the bstring library in favour of GNU C and I put it all into an autotools format like I do.  In this way, one can expand and improve the code for open source applications. Of course then I open source the modified version and put in on GIT.



I had one comment about his code.


Note; one way to fool a compiler is to put function calls into define statements.  Example from his code:

#define RingBuffer_puts(B, D) RingBuffer_write((B), bdata((D)), blength((D)))


Now if this is the only reference to the bstring library, then it might be missed by compilers. GCC choked on this and missed it up until library linking. Otherwise it was a well written library function set.

My ringbuffers expand the original thinking.

 In Zed A. Shaw's original string of chars case the ring buffer is a conceptual ring of memory each one memory space wide.  Increase one memory increases one char.   But in my version there is an analog of a ring buffer of ROWS as the memory element in a ring where the row size and element size are arbitrary and determined by type. This allows one to conduct matrix and vector multiplications to them with pointers aimed at specific rows.


You can find my ringbuffers version here.  GNU Ring Buffers

Autoversion under Autoheader / Autoconf / Automake under git repositories


 https://www.gnu.org/graphics/heckert_gnu.small.png

There is a way to make the library update it's version number automagically is to use the

git describe --tags

function to get the current library version, the GPG signage, and store that value in a temporary file that you shouldn't track inside the repository.


In configure.ac:

AC_INIT([library], m4_esyscmd([build-aux/git-version-gen.sh .version]), [email@shaw.ca])
 Add this line to update the library version from a shell script. There is an unquoted version of m4_esyscmd_s that strips newlines but I found storing straight to file did not add any.

I got this from libqb's git repository but I modified their file to include git describe --tags rather than the original version.


Inside Makefile.am I added .phony targets unlike how libqb did with this:

.version:
    git describe --tags > build-aux/.version
dist-hook:
    git describe --tags  > $(distdir)/.tarball-version

.PHONY:  .version

commit:
    DATE='date'
    git commit -m  " $DATE "
    git push
    
.PHONY: commit

to make a version that then gets read by the autoheader when it sets up configure.

I added an auto commit as well but I may not use that. 

I added another shellscript to the top folder for priming the pump and inserting the first version number into the .version file.

#!/bin/sh
# uprev.sh - shell script to update the latest library tags.

git describe --tags > build-aux/.version

Friday, November 13, 2015

efunda: engineering fundamentals


I found this great website today, and used a couple of their java-script plotters to explain parametric equations. 

efunda stands for engineering fundamentals. 

Here is an excerpt from their website:

eFunda stands for engineering Fundamentals. Its mission is to create an online destination for the engineering community, where working professionals can quickly find concise and reliable information to meet the majority of their daily reference needs.
eFunda is all about the basics, for most part, that means college level material covered in engineering schools. If you practice engineering, more often than not you would find yourself searching for something you knew but could not quite remember. eFunda wants to be your reminder of these formulas. Not only that, eFunda wants to tell you exactly under what conditions those formulas apply, so you don't have to read an entire chapter of the good old textbook.

http://www.efunda.com/about/about.cfm


This is the java applet I was playing with.