Monday, July 30, 2012

slackpkg does not work properly in 32-bit chroot environment under Slackware64

I am running Slackware64 13.37 as my main platform, since it is a pure 64-bit system, I run a chroot environment for Slackware to run some 32-bit programs.  But slackpkg does not work as expected.  It downloads the new lists, but when I do slackpkg upgrade-all, it does not found any upgrade packages.
After digging a little bit into slackpkg's source, I found that if I do not define the environment variable ARCH for current architecture, it will find the setting with uname -m, which in this chroot environment, it will be X86_64 and it is not the correct one.  Once I found out this, I issue the following command to get it working as expected:
ARCH=i486 slackpkg --upgrade-all

Source code syntax highlighting on blogger

My approach is quite different from other posts on the web, they are using some javascript engine to do the dynamic highlighting, I am making use of the hightlight program to do the actual highlighting staticly. As hightlight has different color theme, the color theme anotherdark matches my blog theme perferectly.

As hightlight is not as part of the default set of program in Slackware, I need to build it myself. Luckily, there is a build script in SlackBuilds.org.

Let's take my blog post Ada Unbounded String and Vector Container as examples.

First I have the program in ubt.adb, with the following command I will have ubt.htm

highlight -s anotherdark -i ubt.adb -o ubt.htm
You will also have a highlight.css file on the same output directory, wich difines the color theme:
/* Style definition file generated by highlight 3.9, http://www.andre-simon.de/ */

/* Highlighting theme: vim anotherdark */

body.hl { background-color:#333333; }
pre.hl { color:#dedede; background-color:#333333; font-size:10pt; font-family:'Courier New';}
.hl.num { color:#ffa0a0; }
.hl.esc { color:#ffddad; }
.hl.str { color:#ffa0a0; }
.hl.pps { color:#ffa0a0; }
.hl.slc { color:#ffa500; }
.hl.com { color:#ffa500; }
.hl.ppc { color:#5757ff; }
.hl.opt { color:#dedede; }
.hl.lin { color:#ffa500; }
.hl.kwa { color:#f0e68c; }
.hl.kwb { color:#bdb66b; }
.hl.kwc { color:#8b95f0; }
.hl.kwd { color:#f25252; }

First goto your blogger.com Template page, click on Customize to reach Blogger Template Designer, click on Advanced, then scroll the selection to Add CSS, then copy the content in hightlight.css start from pre.hl to the end, we don't need the body definition. Click on Apply to Blog to save it.

I also have the following CSS definition for the <pre> tag:

pre
{
background-color:#333333;
border: 1px dashed;
border-radius:5px;
padding: 2px;
white-space:pre-wrap;
}

The content of ubt.html is like this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>ubt.adb</title>
<link rel="stylesheet" type="text/css" href="highlight.css">
</head>
<body class="hl">
<pre class="hl"><span class="hl slc">-- test unbounded string with vector</span>

<span class="hl kwa">with</span> Ada<span class="hl opt">.</span>Text_IO<span class="hl opt">;</span> <span class="hl kwa">use</span> Ada<span class="hl opt">.</span>Text_IO<span class="hl opt">;</span>
<span class="hl kwa">with</span> Ada<span class="hl opt">.</span>Strings<span class="hl opt">.</span>Unbounded<span class="hl opt">;</span> <span class="hl kwa">use</span> Ada<span class="hl opt">.</span>Strings<span class="hl opt">.</span>Unbounded<span class="hl opt">;</span>
<span class="hl kwa">with</span> Ada<span class="hl opt">.</span>Containers<span class="hl opt">.</span>Vectors<span class="hl opt">;</span>
<span class="hl kwa">With</span> Ada<span class="hl opt">.</span>Text_IO<span class="hl opt">.</span>Unbounded_IO<span class="hl opt">;</span>
<span class="hl kwa">with</span> Ada<span class="hl opt">.</span>Command_Line<span class="hl opt">;</span> <span class="hl kwa">use</span> Ada<span class="hl opt">.</span>Command_Line<span class="hl opt">;</span>

<span class="hl kwa">procedure</span> ubt <span class="hl kwa">is</span>
   <span class="hl kwa">package</span> My_Vector <span class="hl kwa">is new</span> Ada<span class="hl opt">.</span>Containers<span class="hl opt">.</span>Vectors <span class="hl opt">(</span><span class="hl kwb">Natural</span><span class="hl opt">,</span>
     Unbounded_String<span class="hl opt">);</span>
   <span class="hl kwa">use</span> My_Vector<span class="hl opt">;</span>
   <span class="hl kwa">package</span> SUIO <span class="hl kwa">renames</span> Ada<span class="hl opt">.</span>Text_IO<span class="hl opt">.</span>Unbounded_IO<span class="hl opt">;</span>

   <span class="hl slc">-- read input file and add each line into str_pool till file end</span>
   <span class="hl kwa">procedure</span> read_input <span class="hl opt">(</span>str_pool <span class="hl opt">:</span> <span class="hl kwa">in out</span> My_Vector<span class="hl opt">.</span>Vector<span class="hl opt">;</span>
                         File     <span class="hl opt">:</span> File_Type<span class="hl opt">)</span> <span class="hl kwa">is</span>
   <span class="hl kwa">begin</span>
      <span class="hl kwa">loop</span>
         str_pool<span class="hl opt">.</span>Append <span class="hl opt">(</span>SUIO<span class="hl opt">.</span>Get_Line <span class="hl opt">(</span>File<span class="hl opt">));</span>
      <span class="hl kwa">end loop</span><span class="hl opt">;</span>
   <span class="hl kwa">exception</span>
      <span class="hl kwa">when</span> End_Error <span class="hl opt">=&gt;</span>
         <span class="hl kwa">null</span><span class="hl opt">;</span>
   <span class="hl kwa">end</span> read_input<span class="hl opt">;</span>

   File <span class="hl opt">:</span> File_Type<span class="hl opt">;</span>
   str_pool <span class="hl opt">:</span> My_Vector<span class="hl opt">.</span>Vector<span class="hl opt">;</span>
<span class="hl kwa">begin</span>
   Put_Line <span class="hl opt">(</span><span class="hl str">&quot;Argument 1 is : &quot;</span> <span class="hl opt">&amp;</span> Argument <span class="hl opt">(</span><span class="hl num">1</span><span class="hl opt">));</span>
   Open <span class="hl opt">(</span>File<span class="hl opt">,</span> In_File<span class="hl opt">,</span> Argument <span class="hl opt">(</span><span class="hl num">1</span><span class="hl opt">));</span>
   read_input <span class="hl opt">(</span>str_pool<span class="hl opt">,</span> File<span class="hl opt">);</span>
   Close <span class="hl opt">(</span>File<span class="hl opt">);</span>

   Put_Line <span class="hl opt">(</span><span class="hl str">&quot;Total line: &quot;</span> <span class="hl opt">&amp;</span> str_pool<span class="hl opt">.</span>Length<span class="hl kwd">'Img</span><span class="hl opt">);</span>
   Put_Line <span class="hl opt">(</span><span class="hl str">&quot;File content:&quot;</span><span class="hl opt">);</span>
   <span class="hl kwa">for</span> i <span class="hl kwa">in</span>  <span class="hl num">0</span> <span class="hl opt">..</span> <span class="hl kwb">Integer</span><span class="hl opt">(</span>str_pool<span class="hl opt">.</span>Length<span class="hl opt">) -</span> <span class="hl num">1</span> <span class="hl kwa">loop</span>
      SUIO<span class="hl opt">.</span>Put_Line <span class="hl opt">(</span>str_pool<span class="hl opt">.</span>Element<span class="hl opt">(</span><span class="hl kwb">Integer</span><span class="hl opt">(</span>i<span class="hl opt">)));</span>
   <span class="hl kwa">end loop</span><span class="hl opt">;</span>

   str_pool<span class="hl opt">.</span>Clear<span class="hl opt">;</span>
<span class="hl kwa">end</span> ubt<span class="hl opt">;</span>

</pre>
</body>
</html>
<!--HTML generated by highlight 3.9, http://www.andre-simon.de/-->
Copy the data between <pre> and </pre> to your blog entry. You will have the souce highligted.

Tuesday, July 24, 2012

nginx module reply with header only

When testing with a module written for nginx, I have only headers need to send back and no response body.  I set the content length to be zero and finished the module with the following line:
return ngx_http_send_header(r);
The browser was not receiving anything from the server and waiting till time out.  After digged through the nginx source, it seems nginx need to be informed data has been finished with a call to
ngx_http_send_special (r, NGX_HTTP_LAST);
After adding the necessary code and ended the module with a call to ngx_http_send_special(), it works as expected.

Friday, July 6, 2012

Dell's project Sputnik

Dell's project Sputnik now annouce for beta tester.

To participate in the beta program, you will need to fill in the forms.

Thursday, July 5, 2012

LaTeX to Lulu

Amy Brown from The Architecture of Open Source Applications wrote a seriese of blog post about what’s involved in going from LaTeX to a published book on Lulu.

Turn your Gigaset SE567 modem into a switch / bridge mode

Original article from (Turn your Gigaset SE567 modem into a wireless switch / bridge mode)
Follow these directions to turn your Gigaset (Siemens SE567) modem/wifi router combo into a wireless switch (bridge mode) that will work with any ISP/Ethernet uplink:
  1. First of all, reset your SE567 to its factory settings. Hold the button on the bottom in until the power light starts alternating green and red.
  2. After the SE567 reboots, connect to port 1 with your computer.
  3. Go to »192.168.1.254/ and log in (on the top right) using ID: admin, PW: telus
  4. Go through the Setup Wizard (or manually, your choice) and configure your security and any other settings the way you want them. When you are done you will be asked to reboot.
  5. Go to the above URL and log in once again.
  6. Go to the following URL to turn on bridge mode: »192.168.1.254/brgmode.htm This URL is not anywhere in the settings, you will have to go there manually. You will be asked to reboot the SE567 once again.
  7. After rebooting, unplug your computer from port 1 and plug your WAN connection into port 4. You should now be able to access the SE567 with your laptop and the security settings you applied to it.
Note, when in bridge mode, the SE567 will not function as the router it once did. It functions as a wireless switch and is not capable of assigning IP addresses and will only pass an IP to your computer from the WAN device it is connected to. The LAN ports on the back will not function, and you are unable to access the SE567's settings unless you reset it again. If you require multiple wireless connections, you can either have your ISP assign multiple IP addresses or you can plug the SE567 into an old wired router, which will also assign more than one IP address over the switch.
SE567's wireless is not very robust and sometimes I failed to get connection even just sit besides it. I turned off the wireless of the box completely and only use it as a switch connecting to my own wireless router.