Older blog entries for aleix (starting at number 32)

Honeymoon and code poetry

code poetryDuring my honeymoon in Egypt (yes, I got married three weeks ago!) I had the chance to visit the new Bibliotheca Alexandrina. Before the guided tour, we spent some time walking around the different exhibitions inside the library building. In one of them, I found a set of punch cards and the great thing is what I could read in them:

“It gives a feeling of completeness”

“A great code is probably as rare as diamonds”

“Like a good poem, there are levels of insight to be gained at each reading”

“Beautiful software reflects a profound understanding of the world in some way”

“Like a good lecture, it leaves me with a desire to use what I’ve just learned”

I don’t know if this was a common behavior in the punch cards days or if people were used to it (if anyone knows I would be really interested in it). I found it really refreshing, it seems that in those days people loved what they were doing, they loved to write software.

Syndicated 2007-05-26 13:36:43 from axelio

Easy acronyms generation

At work, we needed a way to easily generate a list of acronyms of our documents, so I wrote an script (tex-acronyms.py) that parses the acronyms in a specified LaTeX file and tries to find a description (specified as a nomencl definition) in the files (*.tex) located in a directory. The script will create two files: one with acronyms and their descriptions and the other with conflicts, that is, acronyms with no or duplicate description.

The following example is a sample of an acronyms list file. Note that the LaTeX document must use the nomencl package, since the acronyms are defined using the nomencl syntax.

\nomenclature{ADDR}{Address}
\nomenclature{ANSI}{American National Standards Institute}
\nomenclature{API}{Application Programming Interface}
...

It is also possible to provide a list of words to be excluded in the exclude_acronyms.txt file, that must be located in the data directory by default (a different file can be specified using -x). For example:

CHAPTERS
CLOSED
DUPLICATE
FIRST
FIXED
BOTH
BUS
...

It is easy to find words to be excluded because they will be treated as errors (and written to the errors file) as no definition is available for them.

Finally, it is possible to parse the input files recursively passing the -r argument. This will parse all the files included with \input.

A possible program call could be:

tex-acronyms.py -r -d ~/acronyms -i article.tex -o acronyms.tex 
                -e acronyms.errors

where the acronyms found in the article.tex file (and its dependencies) will be matched against the acronyms found in ~/acronyms/*.tex. The matched acronyms will be written to acronyms.tex and the errors in acronyms.errors. Now, you just need to include acronyms.tex in your document.

Update 2007/02/23: GlossTeX does the same (and much more) but à la TeX way.

Syndicated 2007-02-22 15:01:50 from axelio

Designated initializers

Last year, I discovered, thanks to the book “C, A Reference Manual“, a great C99 feature: designated initializers. Designated initializers allow you to initialize components of an aggregate (structure, union or array) by specifying their names within an initializer list.

Arrays initialization

What most people normally use to initialize an array is the following idiom:

int v[4] = { 4, 2, 1, -5 };

in which you need to initialize each component of the array sequentially. Designated initializers allow you to specify which component of the array you want to initialize. Thus, we could write the line above as:

int v[4] = { [1] = 2, [2] = 1, [0] = 4, [3] = -5 };

Note that we have specified the component indexes which has allowed us to initialize the array with our desired order. If we do not initialize all the components, those not initialized will get 0 values. We can also mix both methods, so the line below would be also correct:

int v[4] = { [1] = 2, 1, [3] = -5 };

in which the component not referenced goes right after the named one.

A possible use of this kind of initializations would be a mapping between a list of identifiers and a list of strings.

// The public interface

typedef enum {
  id_one,
  id_two,
  id_three
} id_t;

extern char const* string_by_id (id_t id);

// The private implementation

static char const* strings[] =
{
  [id_one] = "identifier one",
  [id_two] = "identifier two",
  [id_three] = "identifier three"
};

char const*
string_by_id (id_t id)
{
  return strings[id];
}

Structures and unions initialization

Designated initializers are also useful to initialize components of structures and unions by their name. In this case, the component to be initialized takes the form .c, where c is the name of the component. So, suppose we have the following structure:

struct point { float x; float y; float z; };

we could initialize each component of a struct point variable like this:

struct point my_point =
{
  .x = 0.34,
  .y = 0.98,
  .z = 1.56
};

With unions, we will use the same method, so having the following union:

union integer
{
  unsigned char int_8;
  unsigned short int int_16;
  unsigned long int_32;
};

we can initialize it by any of its components:

union integer value = { .int_16 = 24000 };

Finally, we can merge both cases, so we can have arrays of structures or unions that can be initialized using designated initializers:

struct point pointvector[3] =
{
  [0].x = 0.34, [0].y = 1.78, [0].z = 3.18,
  [1] = { .x = 3.5, .y = 6.89 },
  [2] = { .y = 2.8, 1.23 }
};

Syndicated 2007-02-19 09:02:46 from axelio

Split directives into multiple files

Yesterday, I found out that I needed an application to split the virtual hosts of an Apache 1.3 configuration into separate files so I could use them in the sites-available/sites-enabled Debian’s Apache 2 way. I googled just a bit and I did not find anything so I did my own one (vhost-split.py).

Just pass it the configuration file and the script will generate a bunch of files named with the ServerName variable found in each virtual host. Note that repeated entries will generate separate files (www.mydomain.com, www.mydomain.com-1, …). The script will also report commented entries.

Syndicated 2007-02-15 18:57:09 from axelio

Unit Testing tools

Most of developers know how great and useful is unit testing. What is even greater is the bunch of libraries you can find out there for almost any language around (C, C++, Objective-C, Java, Pyhton, Perl…).

All these tools are great (I have used some of the ones I have mentioned), but what happens when you start working in a big and commercial project and your bosses have decided to buy a fantastic tool (I’m not going to mention the one I will talk about) which costs a lot of money and they have never try it? What happens is that you, the developer, start working in this fantastic tool and start feeling sort of depressing.

We started our project a year ago and by now, I have had to send so many e-mails to the unit testing software company that I can’t remember. The tool looked promising at first: unit testing, static analysis, user interfaces to speed up the process, cross platform (we use a cross compiler) and many other things. I started to use the GUI without much success, I don’t even remember how it looked like. After a couple of days we decided (we had it already in mind) to create the tests by hand (with help of some elisp code). After a month or so, we had our first problem: the parser for static analysis did not support some of the C99 syntax, first e-mail and first example to show the problem. It took like two months or more to fix the problem, this means that we had to code without using some of the syntax we wanted to use, and of course we had to remember it each time. After some months of tranquility, second problem: a header file provided by the unit testing software had some errors, so second e-mail with a fix suggestion. This time (or even before) I started thinking: “why have I to use this tool? I’m only using the basic macros all the free libraries already give me and no one in the company is looking at the metrics generated by the software”. Nevertheless, I kept on using the tool. A month ago (and after 6000 € paid for support), third problem: I got linking errors using the static analysis again. I prepared another test and sent it to the company again. They started by sending me an update that did not fix the C99 issue I mentioned above, and of course didn’t fix the current one. Then, I recognize it, I made a mistake and I saw a new issue when there really was no one, despite that the current problem was not fixed. This morning, I received a new version of the executables which were supposed to fix the problem. Again, no luck, no problem resolved. May be I made a mistake again, but no one has complained by now. Is any one trying the fix before they send it? Am I too exigent?

My conclusion is: whenever you can, avoid the tools you don’t know and use the ones you do. Commercial tools may not worth the money.

A co-worker told me that one can write its own code to perform unit testing, and his is totally right. If the problem is that the free libraries are not certified or whatever, write your own code and it will be certified as it will be the rest of the code.

Happy testing!

Syndicated 2006-11-09 18:26:52 from axelio

28 Oct 2003 (updated 11 Nov 2003 at 21:25 UTC) »

I'm glad to announce a new (but very small) free software project. It is gXMMS, a simple GNOME2 panel applet to control XMMS.

To those who like WePS, you'd like to know that I'm almost finished with the integration of the new user system and some other features. I think you'll really like it.

My plans now are finishing this version of WePS and release a new version of SCEW. And of course fix the bugs in gXMMS. And then focus all my attention in an other thing... I'll probably explain it in another entry.

22 Jul 2003 (updated 5 Aug 2004 at 11:20 UTC) »

I've been quite busy... Eventhough, I haven't been idle on my personal projects.

SCEW. Since the last post I have released three versions of SCEW, and I'm really happy for it. If you have ever used this library, you should have noticed many changes and improvements, some made by me and some made by contributors. Guys, I really appreciate your contributions. Thanks!

Wireless. I have also entered the wireless world. Right now, I'm just having some fun with it, playing with Linux HostAp, my Belkin PCMCIA cards and some other stuff. However, I don't have many time to play with it.

WePS. I have a contribution of a user system that I should have add some months ago, but I haven't. I'm very sad for this. May be this is one of the problems of Free Software: I have no time to update it, and I know that a lot of people is waiting for it... Well, may be it is really my problem, because I started other projects and stopped this one, which was probably the biggest... Please, be patience.

So long. Yes, my last post was on Jan 13. Many things occured in my life since then, but most of them are personal and boring things...so lets go to the interesting stuff. What about my contributions?

SCEW. I have just uploaded a new version (0.2.0) of SCEW (the Expat wrapper). This new release has almost been internally rewritten, but still keeps the same interface. It now supports XML tree creation and writing. Well, I'm happy for this new release but I'd like to have more time to code more free software...anyway...

WePS. What about it? Two weeks ago, two students from the Universitat Autonoma de Barcelona (where i get my degree in Computer Science), contributed a unix-like user/group system. Just let me say, that it is really cool, and is what everyone that uses WePS was waiting for. Thanks Cristina and Andres! I'll add this to the official WePS branch as soon as I can.
14 Jan 2003 (updated 14 Jan 2003 at 00:28 UTC) »
Free Software. Next friday a Free Software conference will be held in Barcelona (at the Universitat Pompeu Fabra). I'm really happy with this meeting. No need to say, that i will assist. Guess who is one of the lecturers (don't know if this is the right word in english)? Richard Stallman, in a few words: the father of the GNU/Free Software movement. Exciting!

Operating Systems. I finally formatted all my hard drive. By now, i just have FreeBSD installed on it. I will definitely install a Debian GNU/Linux for testing and a Debian GNU/Hurd system to play with. I'm trying to learn some more (i think i should say something instead of some more...anyway) about Operating Systems hacking and see if i can do some translators for the GNU/Hurd.

SCEW. I have just released SCEW 0.1.1 about an hour ago. This release includes two major bug fixes. If you use SCEW, just install it. If you don't, you are not my friend anymore! ;-)

As this post is getting too long and i don't feel like to write anything else, just a last thing:

Good night!
5 Dec 2002 (updated 5 Dec 2002 at 19:07 UTC) »
SCEW. I've released the first version of the Simple C Expat Wrapper. Check out the homepage!

Holidays. I'm going to Milan this weekend...Well, from friday to sunday night. My girlfriend works there during the week so we will enjoy the weekend there.

Bad luck. It seems that last month bad luck has come to my family. Someone stole my wallet in the subway, my mother fell down a horse and someone stole lots of money to my father... And guess what? I needed my identification card (that was in the wallet) to visit Italy... Is someone pulling my leg?

Anyway...

23 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!