Friday, November 13, 2015

Running i3 under HiDPI display

I recently got a MacbookPro (early 2015) with retina display for work.  I installed a fresh Slackware64-current on to it with rEFInd as the boot loader.  The process was quite smooth, I used a USB boot image then network install (with a thunderbolt gigabyte adapter).  Some devices/functions are not fully functional but usable for me. Console font is using the kernel built in SUN12x22 font with kernel option "fbcon:font=SUN12x22".

Since this laptop has a 2560x1600 on a 13" display, roughly 227DI, my old setting for i3 did not work well, although I already using xft font for status bar display.  After a few search, I found out xorg server always set DPI 96, that is a bad move in my opinion, as it makes previous valid DPI calculation wrong and still wrong for those cases that the calculation do not fit.  And I have to add a line
xrandr --fbmm 286x179
in .xinitrc file in order to let i3 pick up the correct DPI setting.  OK, now the i3 status bar display fine.  The default dmenu I initially installed does not support xft font, so it looks really small.  Luckily there is a dmenu2 which merged the xft patched.  Remove the old dmenu package and install the dmenu2 package, then add the font parameter to the dmenu_run command in i3's config Latest dmenu works with xft font now. Everything works fine.

I have the following settings in my .Xresources file.
Xft.dpi : 227
Xft.antialias: false
Xft.rgba: rgb

URxvt.scrollstyle: xterm
URxvt.background: black
URxvt.foreground: gray
URxvt.preeditType: Root
URxvt.scrollBar_right: true
URxvt.jumpScroll: true
URxvt.perl-ext-common:  tabbed
URxvt.tabbed.tabbar-fg: 2
URxvt.tabbed.tabbar-bg: 0    3    0
URxvt.termName: rxvt
URxvt.geometry: 83x27
urxvt.font: xft:DejaVuSansMono:size=8

Xpdf*fontList: -adobe-helvetica-bold-r-normal--0-0-0-0-p-0-iso8859-1
Xpdf.initialZoom: 200

Xcursor.size: 64

With the following, the width should be $((11*COLUMNS+13)) pixels;
! in contrast, the fixed = 6x13 bitmap font is typically used on a
! low-definition screen, giving a width of $((6*COLUMNS+13)) pixels.
XTerm*faceName:  Monospace
XTerm*faceSize:  10
! For xterm menus. This font is large enough, but a bit ugly.
XTerm*font:  -adobe-helvetica-bold-r-normal--0-0-0-0-p-0-iso8859-1
My default terminal is rxvt-unicode, so it works fine. You may notice I have turn antialias off, the font looks sharp, you may see zigzag when looking really close, but for 227DPI, it's very clear without it already.  Most of the document on line regarding GTK+3's HiDPI support is by setting
export GDK_SCALE=2
export GDK_DPI_SCALE=05
I found the program behave a little strange when this kind of scaling in effect.  Font is a little blur than none scale one. For the Gnat Programing Studio (GPS), with the scaling effect, the menu display strangely:
compare with the one without scaling:
I am not sure whether its GTK3' fault or GPS's fault.  I would hope for a GDK_IMAGE_SCALE and only scale image, maybe that will work better.

P.S. After upgrade to kernel 4.4, all the special keys (fn+Fx) works as expected (with pommed-light)

Thursday, October 1, 2015

Using mutool to repair a PDF file that has corrupted xref table

Someone send me a PDF and I could not opened it on my Nexus 5 with Adobe's PDF reader (It suits me the best for a PDF viewer in the android phone).  But both XPDF and muPDF under Linux could opened it with some error message saying the xref table is corrupted and try to rebuild it. 

How could I repair the pdf file?  The first tool comes in my mind is pdftk, it failed to read the corrupted file and give exception.  Then I try pdf2ps, it failed either. 

Google shows me some one saying mutool from muPDF could repair it.  I have using muPDF for some time, it is the default PDF viewer in my Slackware desktop.  But I never take attention to the little tools come along with it, after man mutool, the following command save me:
mutool clean corrupted.pdf clean.pdf
The repaired PDF file is in clean.pdf.

P.S. muPDF does not come with Slackware, but it has a SlackBuild script.  For Windows user, muPDF provide windows version too.

Thursday, September 24, 2015

gnatpp could not align exception declaration properly

I normally use the GNAT Pretty-Printer gnatpp to format my Ada code.  The output of it is not perfect but acceptable and make my code look consistent.

It has a small alignment bug, for exception declaration, it could not handle it properly.  For this specification
package Align_Test is
    Index: Integer;
    Number_Test : Integer;

    Bad_File : exception;
    Bad_Argument : exception;
end Align_Test;
gnatpp -r will produce:
package Align_Test is
   Index       : Integer;
   Number_Test : Integer;

   Bad_File : exception;
   Bad_Argument : exception;
end Align_Test;
I have to manually align the declaration and add specific comments to fence it from gnatpp to change my alignment in future. 
package Align_Test is
   Index       : Integer;
   Number_Test : Integer;

   --!pp off
   Bad_File     : exception;
   Bad_Argument : exception;
   --!pp on
end Align_Test;
It does not look good, but acceptable.  Wish next version of gnatpp could solve this problem.

P.S. Hooray, today (May. 19, 2016) AdaCore fixed the alignment problem. It will properly show up in GNAT GPL 2016.

Wednesday, September 16, 2015

Where/when is my next laptop purchase

My fastest computer in my home right now is a MacBook from 2009.  It's hard disk has been replaced by a SSD and runs smoothly with the latest OS X and Slackware with some minor glitches (web-camera not working, occasionally system have USB bus error, result in non usable system without keyboard, have to reboot back to OS X to fix it).  I have been searching for my next laptop for some time, but still don't find a perfect one that suites my particular requirements:
  • With 13"/14" screen resolution must be high DPI, the higher the better, minimum 3200x1800.
  • Must have optical digital sound output, be it dedicated TOSLINK connector or combo with head phone jack (this has been standard for MacBook for years).
  • Be lightweight and have longer battery life (>= 8 hours)
  • Must be Linux friendly.
Actually, Dell's XPS 13 almost meets the requirement, except for the optical digital sound output.  Apple's MacBook Pro comes close but it is not Linux friendly, and screen resolution is lower than Dell's.  All of Lenovo's offers lack optical digital sound output, X1 carbon does not have high resolution screen, Yoga Pro does not have enough CPU power.

Maybe I should wait one or two more years, then Intel's new 3D XPoint maybe used for storage, oh my, maybe I will never buy a new one ... ...

Tuesday, September 15, 2015

Microsoft is downloading Windows 10 to your machine 'just in case'

Oh, Microsoft is doing his "smart" again. Now it will silently download Windows 10 image to your machine regardless you want it or not.

News from Inquirer confirmed it with Microsoft.

It is time to turn off automatically update if you still want to keep running it, or better wipe it out with a Linux distribution (Slackware, should you ask for recommendation). ^_^

Thursday, September 10, 2015

Getting Started with GtkAda - Content

This is the content for my previous Getting Started with GtkAda blogs.

Building Ada programming environment with GCC 5 and GNAT GPL 2015

I would like to rebuild the Ada programming environment based on GCC 5 and GNAT GPL 2015 in Slackware64 14.1, as Ada 2012 support is more mature in GCC 5.

The FSF GCC compiler

At the writing, the latest release of GCC is 5.2.0.  First I update the build script to matched what's in the current tree.  I would to like to replace the stock Slackware64 14.1's compiler with the new one, but GCC changed the default standard C++ library ABI since 5.1.0.  To make it compatible with GCC 4, a configure switch (--with-default-libstdcxx-abi=gcc4-compatible) was added to the build script.  Also, I have changed the build directory to a fixed location to avoid the random location in the original script.  As it is needed for gnat_util build, a fixed location is easier for the script to find the right files.  I had problem on i586 platform, which I had to explicitly add the --disable-multilib switch to the configuration and remove the conditional test for it.  Built and install without problem.

P.S. Due to GPRBuild will look for GNAT's runtime library as in stead of, build script was modified to create the softlink when packaging the GNAT compiler.  Also created from


For XMLAda GPL 2015, the default build process is making use of gprbuild, which depends on XMLAda.  I followed what was done on Arch Linux and created a custom Makefile.SlackBuild.  But I installed the package with the following scheme, similar to what GNAT GPL 2015 is doing but with sub-directories for each sub-module:
             |- input
             |- unicode
           |- input
           |  |- static
           |  `- relocatable
           |- unicode
           |  |- static
           |  `- relocatable
The document build requires Sphinx, as provides all necessary build scripts, it is a matter of installing the relevant packages and dependencies.


The 2015 version of gprbuild required gprbuild itself.  So Similar to XMLAda, a custom Makefile was borrowed from the Arch Linux project and modified to suite the needs of Slackware.  My first build was without error, but it failed to build when trying it for gnat_uitl, complained about:
gnat_util.gpr:21:09: warning: no compiler specified for language "C", ignoring all its sources
gnat_util.gpr:21:09: warning: no compiler specified for language "Ada", ignoring all its sources
Further investigation showed that the default target for gprconfig was wrong, it was set to "Slackware" when generating in my build script, due to not fully understand what it means.  After set it to "$ARCH-slackare-linux", it still failed on linking, looking for GNAT's runtime library, which does not exist for a standard GCC build, as it only has  After created a soft link from, it builds and working.


The GNAT Util Library provides access to GNAT compiler internals for AdaCore utilities.  The latest release is 5.1.0, since there are no changes on Ada part of the GCC for 5.2.0, it is sufficient for us.  The build went well except for the initial gprbuild target problem.


GTKAda require Gtk+3 version after 3.8.3, the stock version in Slackware 14.1 is 3.8.2, need to upgrade to a latter version.  The version in Slackware current tree is too new, I settled on the latest 3.8 release 3.8.9 and rebuild the GTK+3 package.  The GL support is turned on for this version, but when building test program, it complained:
gtkada-gpl-2015-src/src/lib/gtkada_gl/static/libgtkada_gl.a(gdkgl.o): undefined reference to symbol 'XFree'
/usr/lib/ error adding symbols: DSO missing from command line
After patching the testgtk.gpr with linker option to link with -lX11 -lm, it built and run fine.


Aunit's build script needed to adapt to gprinstall command, other than that, it built smoothly.


GNATColl compiled OK, with minor problem with


The IDE compiler could be compiled now given all dependencies had been built.  The build did not go smoothly related to some xmlada library issues, back and forth a few times, finally got it compiled.  When running GPS, it gave python script warning about pep8 and jedi, after install those two from, everything is working fine.


The florist library changed to use gprinstall, which breaks the install process.  After adjust the build script and patched the generated proper project file for used with others, it built and install fine.


Asis has little problem for installing to correct path, some patch needed to be re-do, after that, everything built and installed correctly.

Gnatmem and Ahven

Gnatmem gave no trouble when compiled for the 2015 version.  Ahven's 2.6 version changed the build process and I had to create a gpr file for it.  Other than that, there is no big problems.

Where are the build scripts

All build scripts are available at GitHub.

Wednesday, August 19, 2015

Ref: Interview with Brian Kernighan

An interview done by Computerphile. Early days of C by Brian Kernighan.

Wednesday, July 29, 2015

Setup guacamole server on Slackware

I encountered the need to access some ssh/telnet/vns server through a client-less HTML5 web app.

Gooling gave me the best product and it is free, the guacamole server.  Looking at the building requirement of it at, I found Slackware by default does not come with all the components needed.  Follow the build procedure in the document, I started with building guacamole-server.

Building guacamole-server

I tried to build all the dependency in except for PulseAudio.  After look through the supported list of needed libraries, FreeRDP, libssh2, have build script at, and libtelnet does not.  After installed FreeRDP and libssh2, I wrote build script for libtelnet, it built and installed without problem.

After I had all the libraries installed, I downloaded the server code guacamole-server-0.9.7.tar.gz.  The package does not come with a ready to use configure command, and have to use autoreconf -fi to bootstrap it.  The configure failed for not finding OSSP UUID library.  Slackware already comes with a uuid library from the util-linux package and it is better than the OSSP one.  So I developed a patched to use the uuid library from util-linux and it works without problem.

Building guacamole-client

The guacamole-client needs to be run under a Java Servlet server.  Luckily, has all I need.  After installed the latest jdk, apache-ant, commons-daemon, apache-tomcat with sbopkg, I had a tomcat server up and running.  I still need to configured /etc/tomcat/tomcat-users.xml to allow to to use the manager GUI. I added the following line to it (of course the user name and password are not the real one I am using ^_^):
<user password="manager" roles="manager-gui" username="manager">
Guacamole-client needs Apache Maven to build, and has a script for maven.  After installed maven, and with the command mvn package guacamole-client was built and a war file was created in guacamole/target/guacamole-0.9.7.war.  I made it install to /usr/share/lib/guacamole/guacamole-0.9.7.war and had it symbolic links to /var/lib/tomcat/webapps/guacamole.war.  Now I could saw it from Tomcat's manger GUI, accessing it with url http://localhost:8080/guacamole I got a blank screen :(, that was not good.  I have the impression that it should be very easy to setup, now it failed on me.  After reading the documentation again, and again, I realized I failed to setup a user-mapping.xml in /etc/guacamole/.  After follow the example, voila! it showed me the login page, after logged in, I was presented with the entries I had setup earlier in user-mapping.xml.  Links with remote servers are working great!

I am preparing scipts to submit, should not wait too long for them to show up.

Tuesday, June 23, 2015

Protection for Text Messaging SPAM (For Rogers customer)

Sometimes I received spam SMS message, and just found out it could be reported to Rogers and get the credit back.
For protection against unsolicited and unwanted “spam” text messages, send us a text message with the 10-digit wireless number of the spam message to 7726 (SPAM). We will credit your account $0.15 for each reported SPAM message and it’s free to report SPAM. Premium messages (i.e. alerts, contests and promotions) that you have prompted will not be credited. You will not be charged for administrative (such as roaming, data alerts and service messages) or marketing messages that you receive from Rogers and therefore, those messages are not eligible for a credit.


Tuesday, May 5, 2015

The Code: Story of Linux documentary

The Code: Story of Linux documentary is a very nice documentary about Linux.  You will see the early days of Linux and young 'Linus' and all the important people for the development of it. ^_^

Monday, May 4, 2015

Building Ada promgramming enviroment for Slackware

Slackware has finally upgraded the system GCC to 4.9.2 in current. Here I presented my work to compile GPS using FSF's GCC 4.9.2. It is based on my previous attempt to build the environment with GCC 4.7.0. This time lots of things have changed, new GCC and GNAT GPL released and they make the attempt much more easier than previous one. GCC 5.1 has just been released, but Slackware use 4.9.2 in the current branch for now, so we stick with 4.9.2.

The Compiler

There is no need to change the build script any more, but we need some of the compiler internal files. So run the standard build script for GCC.


For this one, I am using the xmlada-for-gps-6.0.1-src.tgz from GNAT GPL 2014, in stead of xmlada-gpl-2014-src.tar.gz. They are almost exactly the same with minor changes.


I am using the gprbuild-gpl-2014-src.tar.gz. GPRbuild expected some support functions that are not in the FSF GNAT compiler. Namely the "GNAT.Rewrite_Data" package and some low level support functions in os_lib.c. I gather the missing functions from the GNAT GPL 2014 version and make up some packages for it. Then it builds without problem.


This GNAT Util Library provides access to GNAT compiler internals for AdaCore utilities. It makes the previous effort of trying to mimic what Debian do redundant. In the build script, the source and build directory of the GCC compiler needs to be specified for it to work correctly.
I am using the 4.9.1 one from the sourceforge project. For there is no 4.9.2 version and there are basically no differences for the generation of gnat_util.


With the standard gtkada-gpl-3.8.2-src.tgz, there is nothing special, it builds without problem. One may have to note that currently it does not support GL.


Aunit GPL 2014 also builds without too much problem.


GNATcoll compile without problem with some patches.


Oh, finally, we could build the IDE. It depends on pygobject3, which could be build using's supply script.

Florist, ASIS, GNATMEM, Ahven

The rests are relatively easy and build fine with the build script. For gnatmem, we need to rebuild the binutils and specified the directory in gnatmem build script.

Other experimental scripts

I have tried to build the Ada-RM, GNAT RM, GNAT user guide to integrated with GPS, it seems working for me.

Where are the build scripts

All build scripts are available at GitHub.

Monday, April 27, 2015

A built in Javascript code beautifier in Firefox

From time to time, I need to look at Javascript code from some web site.  As most of the script files have been minimized to a form that is unreadable by human being.  A good Javascript code beautifier is needed. There are various tools I found in the web, some are local some are on the web. But sometime I forgot the URL or could not find the tools in the system.

Then I came a cross this Scratchpad built into Firefox itself. I was not aware of this tool for all the time I am using FireBug for debugging. And I found this Scratchpad has a "Pretty Print" button. ^_^ How nice, a code beautifier is right there!

The output is good and I don't need to remember anything, except the shortcut "Shift+F4", I think I will use it a lot!

Friday, April 10, 2015

Creating a muli-processes DTLS server.

I need to create an UDP server working with multiple clients over DTLS.  I found one note about net-snmp's DTLS Implementation Notes which almost has the same requirement as mime.  But it seems it falls back to use memory BIO and cache the data, and Campgnol VPN's solution is making use of NAT traversal technique that open each new connection with a new UDP port, which does not fit my requirement to only use one UDP port for server.

From the notes, I notice the author is almost succeeded with peeking the incoming traffic except the "Packets Pile Up" problem.  I think that is the right direction for me.

I tried on a single process server first. With recvmsg() with MSG_PEEK, I could get the client's address and port number, from which I could select the right context for the DTLS link.  I realized that I need a custom BIO module to avoid the"Packets Pile Up" problem.

I made a copy of crypto/bio/bss_dgram.c from OpenSSL's source and renamed it to my_udp.c, then stripped away anything unrelated to my usage, basically removed all platform specific and SCTP code except for Linux.  Then further removed all code related to connected filed flag.  Then changed the reading function to peek the packet first and compare the source IP and port number to the current one.  If it is not the current one, then fake an EAGAIN error.

Since server is listening on multiple interfaces, when sending data out, it needs to set its source address correspondingly.  But UDP does not directly give the local address used for the data.  With socket option IP_PKTINFO turn on for UDP server socket, local server address could be found with recvmsg() together with MSG_PEEK.  It is then set in my custom UDP BIO to be used when sending out data.  This seems to work fine with single server process.

But then I was facing the challenge to serve client on multiple processes on the same UDP port. After some tried and errors, I settled on the following method:

The parent creates socketpair() with each child for communication.  For the start, only the first child would listen on the UDP server port.  After peeking from the incoming data, calculate a child index from the client address and port. If the child index is its own, it proceeds to process the data, if not, it stops monitoring the server port for incoming data and send a command to parent and inform parent that the other child should handle the incoming data.  When parent receives the command, it will send the information to the other child, the other child gets the message and start monitoring server port and process incoming data and so on.

It seems working, but have not test out the performance, whether it is worth the trouble to have multiple processes.

Monday, March 9, 2015

MIT open course for Ada

MIT offers one open course for Ada programming (it is based on Ada 95):
Unified Engineering I, II, III, & IV » Comps./Programming

Tuesday, January 20, 2015

Ref: Git: Using Different User Emails for Different Repositories

A good solution for the problem is here.

Simply by putting "(none") under .gitconfig.

 name = Your Name
 email = "(none)"
Then git config in each repository.