Archive for the ‘C/C++’ Category

h1

Makefile Generator, version 2

June 24, 2009

genmake, the Not so Simple Makefile Generator Bash Script, is now hosted on Google Code (for older version, check this post).

The version 2 now supports:

  • executables, static libraries, and dynamic link libraries, based on the output file name format,
  • automatic increment of build number on each build (the header file including the version and build number is automatically generated; requires Awk),
  • several build targets – debug, debug profile, release, release profile,
  • easily specifying additional flags passed to compiler,
  • passing list of link libraries used for build,
  • selectively excluding files from build, and more…

Happy coding! :)

h1

Increase build number in C/C++ header (using Awk)

June 19, 2009

This trick works with most IDE’s that use pre-build step, but easiest I guess is to use it in a Makefile. Feel free to modify the “script” in any way it suites your purposes.

Suppose you have a build number defined as #define BuildNum 1 in BuildNum.h header.

All you have to do is add the following command in your make all section in Makefile ahead of other dependencies (it’s one line, broken here for visibility):

awk '$2 !~ /BuildNum/ {print} $2 ~ /BuildNum/ {print "#define BuildNum "$3+1}'\
    BuildNum.h > BuildNum.h~; mv BuildNum.h~ BuildNum.h

Yes, it’s a clumsy solution, but it does the work just fine… :D Sure, you can catch the lines in array, and afterwards print them one by one back to file, etc. … but it’s just not at all pretty bash script (enhancements and suggestions welcome!).

Notice that the command is pretty much dependent on the format of the line the BuildNum is defined on, and that “BuildNum” should not appear anywhere else as a second word on the line!

h1

Recommending – libmicrohttpd library

June 9, 2009

The GNU libmicrohttpd is a small, yet very powerful, C library that allows you to run HTTP 1.1 compliant server as part of another application.
Read the rest of this entry ?

h1

Recommending – SWILL library

February 19, 2009

SWILL is a simple and powerful C/C++ library that allows you to easily add web-server functionality to your C/C++ programs.

Read the rest of this entry ?

h1

Simple Makefile generator

January 10, 2009

Update: For a much more advanced version of this script, see Makefile Generator, version 2 post.

Presented here is a simple bash script for automatic Makefile generating.
This script simply takes all .c, .cpp, .c++ and .cxx files in the current folder, and generates Makefile that builds an executeable from all these sources.
Dependencies are generated using the gcc’s -MM functionality.

About the script

This script is provided under BSD-style license.

Of course, any comments, reports of use, and suggestions are very much welcome – just leave me a comment! It takes just a moment, and makes me know I didn’t put all the work in posting and updating this for nothing.

Read the rest of this entry ?

h1

How to convert UTF-8 to wchar_t (and back)

January 5, 2009

While this seems like re-inventing the wheel, it sure is hard to find this code for free on-line (believe me, I tried ;) ).
Of course, you might wanna use iconv for this, but it’s a bit too huge if all you want is UTF-8 <-> wchar_t.

Fortunately, Alexey Vatchenko has made the code available under BSD license, with a simple and clean interface.

Note: This code is converting UTF-8 to UCS-4-internal, thus it works properly only on systems, where size of wchar_t is 4 bytes (Linux/Unix, BSD, MacOS), but not on Windows, where wchar_t is only 2 bytes!

Happy coding!

h1

Recommending – DEELX “regex” library

December 28, 2008

DEELX is a simple (Perl compatible) regular expression engine coded in pure C++. It is a research project of RegExLab.

Read the rest of this entry ?

h1

Small guide to casting in C++

September 8, 2008

If you only want a guide to casting in C++, skip to the end of the article. If you want also a bit of technicalities for a better understanding of casting in C++, skip to the one but last section. If you want also a bit of my mind, read the article whole.

Read the rest of this entry ?

h1

How to Open Console Window in a Win32 Application

August 29, 2008

When you create a basic main()-based application, you get the console window implicitly; but a typical WinMain()-based application does not open a console window – you have to allocate the console and to connect the I/O streams yourself.

Yet, this is not a thing you find described in manuals. Fortunately, it’s simple to do, and the code presented here can be used as-is in all your projects.
Read the rest of this entry ?

h1

Simple Doxygen templates

July 29, 2008

This is a follow-up to previous tutorial, Simple guide to basic Doxygen usage.

Here are few simple templates that you might use for documenting your source; easiest use is with e.g. Visual Assist X, or any other tool that allows you to add predefined templates to your source code. I use these template with VAX and shortcut set to “/*!”, with short descriptive names, thus I don’t need to remember many shortcuts and have all at reach of 3 key-clicks. :D

And we finish off with a small list of simple tips.
Read the rest of this entry ?