Archive for September, 2009

Bash Job Control

September 24th, 2009 subogero Comments off

Having already explored theĀ  possibilities of starting parallel processes using the Gnome window-manager, as described on my go page, it was high time to immerse myself, being the keyboard-addicted geek that I am, into doing the same by using just a simple terminal.

But what’s the point? In my case, it was a commit process with a revision-control system called foo. The commit is done with a script, and I wanted to make sure the project compiles OK before the actual commit.

This involves two quite long processes, which could nicely run parallel, one is composing the commit-message with an editor, and the other is the compilation. We shall go on with the commit after BOTH are finished. Oh, I nearly forgot, the commit shall be canceled, if the compilation fails!

I studied bash job-control a bit and then:

# The '&' character runs the command in the background
# which in turn becomes job number 1, later referred to as %1.
make &

# Compose the commit-message in the foreground
foo-status > CommitMessage
mcedit CommitMessage

# Wait for the make (job 1, alias %1) to complete,
# check its exit status and abort if it's failed.
# The 'wait' command's exit status is the same as the job's we wait for
wait %1
if [ $? -ne 0 ]; then exit 1; fi

# Do the commit
foo-commit --message=CommitMessage
rm CommitMessage

Try this with batch-files on Windows. Actually, you can do it with Cygwin. I’m sure Richard Stallman calls this platform GNU/Windows.

Bash is cool. Bourne Again Shell for Born Again Christians, that’s what I always say. Or as Master Foo put it once:

“There is more Unix-nature in one line of shell script than there is in ten thousand lines of C.”

Categories: Uncategorized Tags: ,

Compile on Linux for Win32

September 12th, 2009 subogero Comments off

This is perverse. I’ve just compiled a native Win32 application on Linux. What’s even more perverse it runs on Linux too with Wine.

To cut a long story short I needed a command line tool to send emails using the MAPI protocol, the only language spoken by Outlook and MS Exchange. Don’t ask me why. It’s by the way my first ever Win32 application using the Win32 API. Or `mapi.h’, to be precise.

I started developing it on a Win32-cygwin platform with gcc, but I wanted to control the sources with git. Which prefers Linux. So I ended up rebooting the box a few times to change between the two. But I’m extremely lazy, so I soon googled for a way to cross-compile Win32 programs on a Linux host. It did not take long. I summarize my findings in a few lines:

What to install:

sudo apt-get install mingw32

How to compile:

i586-mingw32msvc-gcc -L/usr/i586-mingw32msvc/lib \
  -I/usr/i586-mingw32msvc/include -o foo.exe foo.c

The result? See the mapis page.

Categories: Uncategorized Tags: , , ,

Midnight Commander and Cursor Beyond End of Line

September 7th, 2009 subogero 2 comments

Two weeks ago I had a short glance at the Midnight Commander’s Roadmap and found that 4.7.0-pre2 was to be relased end of August. Looking through the tickets what do I see? Cursor beyond end of line in the built-in editor.

I’ve just arrived from the world of those glassed openings on walls, which should illuminate the inside of buildings during the working hours. In this world, I was obviously the victim of evil (and rude) monopolies, that should not be named in polite company. But even these despotic dictatorships have advantages. The oppressed subordinates may enjoy the cursor going beyond the end of line in all text-editors that are worth mentioning (step forward, Far-manager).

Having arrived in the free world, I received one nasty shock after another every time I wanted to go up two lines to the same position in text-editors. If the line in between was shorter or empty, the cursor endeavoured to jump back and stay there. Just like… erm… I have to say it, Notepad.

Gedit is like that. Emacs is like that. Midnight Commander’s editor is like that. Or has been, until now.

Having returned from a week long cycling trip from the Italian Alps, my life has become completely meaningless, at least in the eye of the Master Programmer, as in the absence of computers I had to abstain from programming for more than the official limit of 3 days. To restore my form, the first thing was to download mc-4.7.0-pre2.

Binaries are not provided, only sources, so I had to configure the makefile and compile it. The configure script disliked my Ubuntu-installation in a marked manner. It raised its eyebrows, pursed its lips and refused to produce any usable makefile. Some obscure gmodule-2.0 was missing. But after a considerable amount of googling, synaptic-package-managing and trying I had a running MC with the editor allowing the cursor to go beyond the end of line.

For the benefit of the general public I now kindly publish the major milestones that helped me achieve this majestic goal:

sudo apt-get install build-essential
sudo apt-get install libglib2.0-dev
sudo apt-get install libslang2-dev
sudo apt-get install gettext
sudo apt-get install libtool
./configure --with-samba
sudo make install