Adding new sites to the eclipse updater “hangs”
Just for the record: If adding a new site to your eclipse updater seems to hang/times out (entry is always “pending…”), its most probably not a problem with the update site itself but rather some firewall interfering. Make sure you have setup the appropriate proxies in eclipse (Window->Preferences->General->Network Connection).
Installing a gcc4.4 snapshot on Ubuntu
The upcoming gcc4.4 release adds a few more C++0x features (initializer lists, auto typed variables, defaulted and deleted functions, strongly typed enums, …) to the in this regard still very incomplete g++. To be able to play with it one has to compile a gcc-snapshot which turned out to be fairly easy.
- Download a copy of the gcc-core and the gcc-g++ snapshot from here. I used gcc-core-4.4-20090306.tar.bz2 and gcc-g++-4.4-20090306.tar.bz2
- Extract both archives into the same directory.
tar xvjf gcc-core-4.4-20090306.tar.bz2 && tar xvjf gcc-g++-4.4-20090306.tar.bz2 && cd gcc-4.4-20090306 - run
configure ./configure --prefix=$SOMEPLACEBe sure not to overwrite your default gcc-installation. If anything is missing configure will complain. - On my Ubuntu system i had to install libmpfr-dev to proceed.
sudo apt-get install libmpfr-dev - Now all it takes is time…
make && make install
To use it just put $SOMEPLACE in front of your $PATH. If you are using it to compile code which uses C++0x features (which is the whole point) you have to add -std=c++0x to your compiler command line. Bonus: If you are using Eclipse/CDT you can start it with the modified path and the builder will pickup the new gcc just fine.
Eclipse CDT 6 Milestone 5
The final release of CDT6 is still a few month ahead (scheduled for ~June) but there are already public milestone builds available. I haven’t played much with M5 but one thing that directly caught my attention is that you no longer have to manually setup all the include paths in your project. Eclipse will just use all the headers inside your workspace to resolve includes.
This is something i have been longing for for years. If you work inside a large projects tree with a lot of include directories (think public interfaces/private headers of N modules) its really painful to add all these to the project.
It will also enhance the out of the box experience for people importing their first project into eclipse. I know from experience that most people don’t know that they have to setup the include paths first (how should they? before CDT5 the default setup was not even outlining missing includes!). Without being able to resolve the includes the indexer will not work properly so all the advanced features are not available (go to definition, type hierarchy, global symbol lookup, macro expansion, include browser, etc…). Confronted with such a crippled project first timers might jump to the conclusion that eclipse has not much more to offer than their trusted editor of choice.
As always i am looking forward to the full release.
Elegant human readable enums
While reading the source of some FOSS project i noticed that the authors have come up with a nice way to get human readable enums through the use of the “stringification feature” of the C/C++ preprocessor. The trick is that the members of the enum are declared through a macro which can be expanded in different ways.
-
#include <iostream>
-
#include <cstdlib>
-
#include <cassert>
-
#include <time.h>
-
-
namespace MyStuff
-
{
-
enum Things {
-
#define THING(X) X,
-
#include "things.def"
-
MAX_THINGS
-
};
-
-
static const char* const ThingNames[] = {
-
#define THING(X) #X,
-
// ^ preprocessor stringification
-
#include "things.def"
-
NULL
-
};
-
-
const char *toString(Things t) {
-
assert(t >= 0 && t < MAX_THINGS);
-
return ThingNames[t];
-
}
-
}
-
-
int main(int argc, char **argv)
-
{
-
using namespace MyStuff;
-
std::srand(::time(NULL));
-
for (int i = 0; i < 4; ++i) {
-
Things aRandomThing =
-
static_cast<Things>(std::rand() % MAX_THINGS);
-
}
-
}
-
things.def:
-
-
#ifndef THING
-
#define THING
-
#endif
-
-
THING(CELLPHONE)
-
THING(NOTEBOOK)
-
THING(CUP_OF_TEA)
-
THING(MOUSE)
-
-
#undef THING
-
Time after time i am amazed what you can do with some of the advanced preprocessor features like “token pasting” or stringification.
Overload
I recently discover “Overload” - a publication done bi-monthly by the ACCU (Association of C & C++ Users). It’s focus is on C++ and software engineering in general. The overall quality of the articles is quite good and they also have some well known names like Kevlin Henney or Peter Sommerlad writing articles for them. In my opinion a worthy alternative to the dearly missed “C/C++ User Journal”. The complete archive can be found here. Highly recommended!
OpenWrt Gemini 0.2
Paolo Scaffardi just released version 0.2 of his OpenWrt port for SL3516 based devices. The main change from the 0.1 release is that he switched to the OpenWrt trunk as base. The great benefit of this decision is that there are a lot more packages available (over 940 new packages). The pre-compiled firmware images worked without problems with my NAS4220 device. YMMV!
Webif^2 tutorial part 02
Last time we created a simple “hello world” page. Not very useful. For our NAS box we need a way to input/select configuration data. Web interfaces implement user input using HTML forms. Webif^2 provides some features to make it easier to work with them.
The following example allows us to enter the name (text) and job description (selecting a predefined value) of the person you want to cheer. I start with my explanation at the end of the script.

On the lines 11 to 21 we use the function display_form to create the output you can see in the screen shot. display_form is at its heart an AWK script. AWK works on a line by line basis so every line till the EOF marker will be processed on its own. Processing means that the lines are expanded into fragments that will make up the final form.
start_form/end_form are doing exactly what you expect them to do. What about line 13? display_form is not only generating a form, it also embeds the form elements together with other elements into a table. “field” will put the text following it into a cell of this table. Line 14 creates a drop down box. The following two lines add two options to this drop down box. By passing the value of the variable FORM_job we can preselect a particular option. This allows us to remember user input between script invocations (albeit only on the browser side).
The input field to enter the name is created on line 18. As the last step before finishing the form we add a submit button so we can send the form back to the server for processing (line 19). The action associated with the form will be the embedding page.
-
#!/usr/bin/webif-page
-
<?
-
. /usr/lib/webif/webif.sh
-
-
header "Test" "Cheers" "Cheers" ” "$SCRIPT_NAME"
-
-
empty "$FORM_name" || empty "$FORM_job" || {
-
echo "cheers to $FORM_name the $FORM_job!</br>"
-
}
-
-
display_form <<EOF
-
start_form|Who is to be cheered?
-
field|Job description
-
select|job|$FORM_job
-
option|Code Simian|Code simian
-
option|Code Monkey|Code monkey
-
field|Name
-
text|name|$name
-
submit|button_set_name|Set
-
end_form
-
EOF
-
-
footer
-
?>
-
-
<!–
-
##WEBIF:name:Test:50:Cheers
-
–>
To wrap up this tutorial we now only have to do something with the data submitted through the form. On line 07 we check if $FORM_name or $FORM_job are empty. If both of them contain a value we display a customized greeting message.
Where do these variables come from? Haserl is parsing POST/GET requests and places form variables into the context of the script it currently exectues. The variables are always prefixed with “FORM_”.
This example wasn’t extensive of course. display_form provides a number of additional features to create radio buttons, check boxes, text areas, …. For a complete list you have to look up files/usr/lib/webif/form.awk.
The time we will extend this example to do some input validation.
Webif^2 tutorial part 01
This article tries to explain how you can extend Webif^2 with your own functionality. I am myself new to Webif^2. The reason i am writing this article is to get acquainted enough with the code so i can decide if i would like to use it to create some NAS specific functionality.
Webif^2 runs on devices with some severe CPU and memory limits. Given that using one of the mainstream web development platforms was apparently off the table. Instead a combination of shell/awk and sed is used to generate dynamic content. Basically the way your father would have done it back in the days (given that there had been a web to develop for…) Having done some work with Ruby on Rails recently i am not too excited by this prospect but lets see how it goes.
My first goal is to have some pages which are displaying friendly greeting messages. These pages should be grouped into a new category in the main menu. I assume that you have checked out a copy of webif^2. All path references are relative to trunk/package/webif/.
Step1: Adding a new category.
files/www/cgi-bin/webif/.categories contains the entries of the main menu. We just add our entry here (”Test”).
-
##WEBIF:category:Info
-
##WEBIF:category:Graphs
-
##WEBIF:category:Status
-
##WEBIF:category:Log
-
##WEBIF:category:-
-
##WEBIF:category:System
-
##WEBIF:category:Network
-
##WEBIF:category:VPN
-
##WEBIF:category:Test
-
##WEBIF:category:-
-
##WEBIF:category:Logout
If you now reload your web browser you should see a new category “Test”. The next step will be to add content to this category.
Step2: Putting content into the new category.
I add the file test-hello.sh in files/www/cgi-bin/webif. The name of the file doesn’t matter but the convention seems to be to name it $(category)-$(name).sh.
-
#!/usr/bin/webif-page
-
<?
-
. /usr/lib/webif/webif.sh
-
-
header "Test" "Hello" "@TR<<Hello>>" ” "$SCRIPT_NAME"
-
-
echo "hello openWrt"
-
-
footer ?>
-
-
<!–
-
##WEBIF:name:Test:0:Hello
-
–>
Webif^2 uses an interpreter called Haserl. It will parse html files and execute the shell fragments it finds enclosed by <? … ?> (basically like it is done by php/jsp/…). The documentation for it can be found here.
The first line tells the linux kernel which interpreter to use when trying to execute this file (webif-page is the actual haserl program). The lines 02 to 09 contain the actual program that will generate our page. 03 pulls in webif.sh which is a library containing the functions we will use. 05 calls the header function (found in webif.sh). It will generate the html header, the head section of page and also the main- and sub-menu. $SCRIPT_NAME is set by haserl. On line 07 we say “hello” to openWrt. The only thing left now is to finish the page. To accomplish this we call the footer function (also found in webif.sh). This function will generate the content you see in the bottom section (”Apply Changes”, “Clear Changes”, …). It will also close the HTML document.
The last three lines contain a strange HTML comment. Lets have a closer look. When the main menu is generated webif^2 scans all files in files/www/cgi-bin/webif/ having the .sh extensions, looking for this special marker. The marker tells it to put an entry “Hello” into the category “Test”. The number can be used to allow a non-alphabetical ordering of the entries. The entry with the lowest number comes first. It will also be the page being selected by default of you click on the category.
So far so good. Next time we try to use some forms.
Webif^2 on a NAS box
Webif^2 aka. X-Wrt is a kick ass web interface used on OpenWrt systems. I really like it but as the main focus of OpenWrt is routers and related devices it is missing a lot of functionality which would be needed for a NAS box. Still its a good starting point. It has all the basic functions you would also need for a NAS box. Another point to consider is that most NAS devices have USB so they can be very easily turned into an access point or router where all this standard Webif^2 features would be very handy.
Up and running!
I managed to build and install the 0.1 release of OpenWrt for SL3516 based devices. It needed some small tweaks to make it compile but nothing too serious. The only pitfall was that you need to change the gcc version from 4.2 (pre-selected) to 4.1.2. If you don’t do this there will be no init process at the and of the kernel boot. There is something wrong with the toolchain. The produced kernels are fine but the userspace programs are not working. Thanks to Paolo Scaffardi for the hint.
BusyBox v1.4.2 (2008-03-13 22:32:26 CET) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
KAMIKAZE (7.09) -----------------------------------
* 10 oz Vodka Shake well with ice and strain
* 10 oz Triple sec mixture into 10 shot glasses.
* 10 oz lime juice Salute!
---------------------------------------------------
root@OpenWrt:/# uname -a
Linux OpenWrt 2.6.15 #2 Tue Mar 11 22:54:29 CET 2008 armv4l unknown
root@OpenWrt:/#