What I Learned from Smoking Clover

I was browsing through the “The New Hackers Dictionary” (http://www.eps.mcgill.ca/jargon/jargon.html), a version of the “Jargon File” (https://en.wikipedia.org/wiki/Jargon_File) when I discovered a entry for Smoking Clover, a display hack attributed to Bill Gosper. I located a copy on SourceForge and downloaded it, and unzipped it into a src directory. Looked routine.

Not.


me@here:~/Projects/Graphics/SmokingClover$ cd src
me@here:~/Projects/Graphics/SmokingClover/src$ make
-g -Wall `gtk-config` --cflags -c -o clover.o clover.c
/bin/sh: 1: gtk-config: not found
In file included from clover.c:1:0:
clover.h:47:21: fatal error: gtk/gtk.h: No such file or directory
compilation terminated.
: recipe for target 'clover.o' failed
make: *** [clover.o] Error 1
me@here:~/Projects/Graphics/SmokingClover/src$/

make did not. The Makefile that comes with the Smoking Clover packages does not make the clover package. Why not?

Well, I know that gtk is installed. What’s wrong with this picture.

What’s in the Makefile?

me@here:~/Projects/Graphics/SmokingClover/src$ cat Makefile
CFLAGS = -g -Wall `gtk-config` --cflags
LIBS = `gtk-config` --libs

SRCS = README COPYING ChangeLog BUGS Makefile *.[ch]

CLOVER_OBJS = clover.o common.o direct.o true.o rgb.o
clover: $(CLOVER_OBJS)
$(CC) $(CFLAGS) -o clover $(CLOVER_OBJS) $(LIBS)
$(CLOVER_OBJS): clover.h Makefile

tar:
tar -cf - $(SRCS) | gzip > clover.tar.gz
clean:
rm -f *.o clover
me@here:~/Projects/Graphics/SmokingClover/src$

Maybe no path to gtk-config …

me@here:~/Projects/Graphics/SmokingClover/src$ locate gtk-config
/usr/share/icons/breeze/apps/32/preferences-gtk-config.svg
/usr/share/icons/breeze-dark/apps/32/preferences-gtk-config.svg

Not promising.

A google or two and still no real answer…

Let’s try something… executing gtk-config.

me@here:~/Projects/Graphics/SmokingClover/src$ gtk-config --cflags
No command 'gtk-config' found, did you mean:
Command 'gts-config' from package 'libgts-bin' (universe)
gtk-config: command not found
me@here:~/Projects/Graphics/SmokingClover/src$

Another google and a hit on StackOverflow provided a hint:

Use pkg-config instead of gtk-config. While the article in Stack Overflow did not say so, gtk-config was for GTK 1.0. GTK 2.0 changed that.

me@here:~/Projects/Graphics/SmokingClover/src$ pkg-config
Must specify package names on the command line

Now we are getting someplace.

me@here:~/Projects/Graphics/SmokingClover/src$ pkg-config gtk-2.0 --cflags
Package gtk-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk-2.0' found

Or better, spell gtk+-2.0 correctly.

me@here:~/Projects/Graphics/SmokingClover/src$ pkg-config gtk+-2.0 --cflags
-pthread -I/usr/include/gtk-2.0 -I/usr/lib/x86_64-linux-gnu/gtk-2.0/include -I/usr/include/gio-unix-2.0/ -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/libpng12 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng12 -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/freetype2

That’s better. Change the Makefile to include the pkg-config lines

me@here:~/Projects/Graphics/SmokingClover/src$ head Makefile -n 3
CFLAGS = -g -Wall 'pkg-config gtk+-2.0 --cflags`
LIBS = `pkg-config gtk+-2.0 --libs`

me@here:~/Projects/Graphics/SmokingClover/src$ make
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o clover.o clover.c
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o common.o common.c
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o direct.o direct.c
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o true.o true.c
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o rgb.o rgb.c
rgb.c: In function ‘rgb_init’:
rgb.c:28:31: warning: pointer targets in passing argument 1 of ‘gdk_rgb_cmap_new’ differ in signedness [-Wpointer-sign]
rgb_cmap = gdk_rgb_cmap_new (colors, 256);
^
In file included from /usr/include/gtk-2.0/gdk/gdkpixbuf.h:36:0,
from /usr/include/gtk-2.0/gdk/gdkcairo.h:28,
from /usr/include/gtk-2.0/gdk/gdk.h:33,
from /usr/include/gtk-2.0/gtk/gtk.h:32,
from clover.h:47,
from rgb.c:1:
/usr/include/gtk-2.0/gdk/gdkrgb.h:128:13: note: expected ‘guint32 * {aka unsigned int *}’ but argument is of type ‘gint32 * {aka int *}’
GdkRgbCmap *gdk_rgb_cmap_new (guint32 *colors,
^
rgb.c: In function ‘rgb_redraw’:
rgb.c:58:9: warning: pointer targets in assignment differ in signedness [-Wpointer-sign]
countp = counts;
^
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -o clover clover.o common.o direct.o true.o rgb.o `pkg-config gtk+-2.0 --libs`
/usr/bin/ld: direct.o: undefined reference to symbol 'floor@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
Makefile:8: recipe for target 'clover' failed
make: *** [clover] Error 1
me@here:~/Projects/Graphics/SmokingClover/src$

Close but no cigar.

Looking at the first error found, something called “floor” is undefined at link time. floor … looks like a math function, maybe not to you but I’ve had an interesting life.
A google hit includes the function ceil. A math function. The article suggests you add libm.

You are in a room … you see a libm. take libm

me@here:~/Projects/Graphics/SmokingClover/src$ head -n 3 Makefile
CFLAGS = -g -Wall `pkg-config gtk+-2.0 --cflags`
LIBS = `pkg-config gtk+-2.0 --libs` -lm


me@here:~/Projects/Graphics/SmokingClover/src$ make
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o clover.o clover.c
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o common.o common.c
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o direct.o direct.c
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o true.o true.c
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -c -o rgb.o rgb.c
rgb.c: In function ‘rgb_init’:
rgb.c:28:31: warning: pointer targets in passing argument 1 of ‘gdk_rgb_cmap_new’ differ in signedness [-Wpointer-sign]
rgb_cmap = gdk_rgb_cmap_new (colors, 256);
^
In file included from /usr/include/gtk-2.0/gdk/gdkpixbuf.h:36:0,
from /usr/include/gtk-2.0/gdk/gdkcairo.h:28,
from /usr/include/gtk-2.0/gdk/gdk.h:33,
from /usr/include/gtk-2.0/gtk/gtk.h:32,
from clover.h:47,
from rgb.c:1:
/usr/include/gtk-2.0/gdk/gdkrgb.h:128:13: note: expected ‘guint32 * {aka unsigned int *}’ but argument is of type ‘gint32 * {aka int *}’
GdkRgbCmap *gdk_rgb_cmap_new (guint32 *colors,
^
rgb.c: In function ‘rgb_redraw’:
rgb.c:58:9: warning: pointer targets in assignment differ in signedness [-Wpointer-sign]
countp = counts;
^
cc -g -Wall `pkg-config gtk+-2.0 --cflags` -o clover clover.o common.o direct.o true.o rgb.o `pkg-config gtk+-2.0 --libs` -lm
me@here:~/Projects/Graphics/SmokingClover/src$

WHOA!

make is made!

Smoking Clover now. Or more correctly, the clover executable has been created.

transparent 4 leaf clover in transparent green and magenta
Here is how clover executes on my system

Try it, you’ll like it.

Discussion:

This program is clearly ancient history. What I have discovered since is that gtk-config was the tool used in gtk-1.0 and was replaced in gtk+2.0. No hint of this was in any of the information that I found using the information that I had at the time. Young-in’s, no sense of history.
I also went down a false path (that I cannot seem to reproduce) that required that I add the names of the include files to some of the c header .h files. In reproducing my quest, this did not seem to be necessary. Go figure.

The pointer sign-ed-ness warning may or not be important. It should be fixed. In my experience warnings are there for a reason and the results may be unpredictable. I found some hints as to how to fix it but have not yet gotten to it.

The tag line “No smoke, no odor, not a sound” is from a radio commercial in the late 1960’s from the East Ohio Gas Company touting gas fired domestic incinerators. Refer to the Summary item 5. The jingle was very catchy and memorable. Additional interesting, related stuff

Security

Terrorists are in the news as is their wont. This has prompted a dither over what to do.

We need to keep doing what we have been doing and do it better. Since 9/11, our freedom continues to be eroded. This is just what the terrorists want.

My recommendation is that we continue to allow the NSA to monitor phone connections. And allow the encryption of phone content. A backdoor for the government is a backdoor for everyone as the government has demonstrated its lack of ability in keeping secrets.

We should continue the debate as to whether the NSA should share the data it collects with the FBI and others. I lean to “no sharing” of data without a court order. The NSA should be free to share findings of specific threats with other agencies.

Too Big To Fail?

Cleaning out my traveling bag, I found a clipping from Redmond Magazine, the Independent Voice of the Microsoft Community. The Editor, Jeffrey Schwartz comments in the November issue on large companies breaking up. This reminds me of a song that goes through my head from time to time (i.e. a couple of times per week). If you are an older person and have never heard it, I hope that you have saved heavily in non-debt, non-equity investments. A change is coming. If you are a younger person, keep going. You will prevail.
The fact of the matter is that too big to fail is too damn big. The anti-trust laws and the regulators are supposed to prevent this from happening. This is just additional evidence that the present and recent administrations are incompetent and, perhaps, corrupt.
But I digress. While Mr. Schartz’s astute editorial mentions HP, Symantec, and and Microsoft, IBM, and many large banks are also in this category. Please stand by. Adjust your set if you think it will help.

What’s the diff?

My problem was that my revised version of the Java program did not work as expected. While I believed that I had changed nothing but comments, the results were not the same. What had I changed?

“Oh, that’s easy” says I, “I’ll just diff the files and see what changed”. Well according to diff, EVERYTHING had changed. I used the regular options like -w, and -E, and -d, and -B and still no improvement.

“Duh”, he says, “it’s the encoding”. What is the diff option to compare two texts with different encoding? The short answer seems to be that there is no option.

But where there’s a will, there’s a way, particularly with Linux (and Unix). In Linux use the iconv command to do the conversion and pipe the output to diff for the compare.

If you do not know iconv, the short form is:

iconv -f from-file-encoding -t to-file-encoding from-file-name

Output to stdout.

Pipe it to diff and tell diff to pick up the input from the pipe with a dash – .

If you do not know the encoding of the files, use the file command to show you the encoding.

To find out if the encoding is supported (and spelled correctly), use

iconv -l

for a list of supported encodings.

The answer to the original question looks like:

iconv -f ISO-8859-1 -t UTF-8 ../x3-2.14/x3navaldv0.2.14/java/bateau/Bateau.java | diff -w - java/bateau/Bateau.java

I had changed only comments. Compiler difference? Compiler option difference?

FLTK – Fast Light Tool Kit

While working on an earlier project, I ran across a very good, portable window/widget tool kit. It goes by the name of FLTK (pronounced full-tick). A good tutorials exist here (note especially the “label pitfall”) and here which will teach you the basics. There are example programs in the full install found at the FLTK website along with an excellent programming manual. Documentation for previous releases is available. Ubuntu 10.4 LTS comes with FLTK 1.1.0.
When I began a new project, I decided to self-educate and used the second, pdf, tutorial above. I quickly worked through the examples until I got to 16. Handling mouse events part2 for the follow-the-mouse drawing program where I ran into a problem with the offscreenbuffer functions. I searched a bit for solutions. After reading more tutorials and more manuals, I discovered that the problem is that the example is omits several required includes. <stdlib.h> and <stdio.h>  are easy. A bit more difficult is #INCLUDE <FL/x.H>. This include provides environmental information for X11, in particular the definition for FL_Offscreen. These details are covered in Appendix F Operating System issues and briefly at “Drawing Things with FLTK” in the later on-line versions of the programming manual. But x.H may not be apparent at first glance. A corresponding win32.H also exists but including x.H will pick up the correct info if your environment variables are set.
With those three additions, the example 16 program compiles and runs.

Hacker Attire

Hacker in balaclava and black sweater using laptop
Hacker hacking
I was taking some “security training” for work. When they referred to “hackers”, the training showed “hackers” dressed in dark clothes and balaclava’s. I had seen this with other web sites. Since it is on the web and pervasive, it must be they way hackers really dress. I wondered why so I e-mailed my son who has degree in computer science and often is well informed on technical topics.

His response:

Dad,
This is a carryover from the days before surface mount technology, when computer hacking required the use of a soldering iron.

The jumpsuit protected the “hacker’s” body from stray molten solder. The balaclava, which you’ll note covers the nose and mouth, protected the individual’s lungs from harmful fumes that can be released during soldering, including lead, arsenic, organobromides and resin acid particulates. Some of these gases can also cause contact dermatitis, a risk that is also abated by the jumpsuit.

Of course, modern-day hackers can simply exploit operating system design flaws to perform their work. The dress is now ceremonial, though its use is required in the EU (some laws are slow to change!)

Hope this helps…

lex and yacc Continued

Follow the link for an excellent tutorial ref1 on lex and yacc with some sample code. I will refer to this as ref1 in comments below.

Another lex and yacc tutorial with sample code . This post is based substantially on this second tutorial and the examples in the sample code.

A number of examples are provided. For each example, a script, say example1.compile, is present after you gunzip and tar x-tract.
chmod 755 the *.compile files to make them executable.
cat or edit each example, example4.l is the lex file and example4.y is the yacc file.

I have never been a fan of exercise, either in the gym or on paper. Give me a real problem or a real event to contest any day. But exercise is sometimes a necessary preparation for building strength and agility. Recalling Harvey Wagner and the “Mind Expanding Exercises” in his textbook Principles of Operations Research let us call these:

Stretching Exercises

Note: Do all of the examples. Stretching exercises extend but do not replace the tutorial.

0. Download the sample code. Gunzip and expand it. Mark the executable *.compile scripts and execute the example1.compile script. Resolve any knowledge gaps.

1. Build example2 and test it. Now enhance it so that it prints “MIXED” if the input is alpha-numeric, “NUMIXED” if the input is alpha-numeric with leading digit, “NUMBER” if all digits, “TEXT” if all letters and if the input is EXIT, Return 0.
Did you get a message like ex2.l:9: warning, rule cannot be matched on the lex execution? Why might it occur? How can you fix it if it does?

2. Build example4 and test it. What usability problems would you fix? Suggest 3 usability or reliability improvements. Create a version that implements the improvements.

3. Now create a version of the example4.compile script that includes the yacc “-rall” switch. Execute it and examine the y.output file. Do you think that the “-rall” switch aids understanding? Debugging? Checking? Testing? Designing?

4. Review the tutorial at ref1. Repeat exercise 3.

5. Create a word counting program using lex (flex). Nobody expects the Inquistion. Compile and test it.

6. Run example4.compile. Examine y.tab.h.
rm y.output, lex.yy.c, y.tab.h and y.tab.c. Run example1.compile again. Which files are created? Make note of the size(s).
mv or cp lex.yy.c to preserve it.
Run example4.compile again. Which files are different?
diff the preserved version of lex.yy.c and the just created one. Are they more or less different than you expected?

7. Run example4. Use the following inputs (from the tutorial)
heat on
heat off
target temperature 22

What were the responses?

Try “heat foo” – what is the result?
Try “target temp 99” – what is the result?

Rate the generated program on a robustness scale of 0-3.
Rate the generated program on a user friendliness scale of 0-3.
Explain how this experience will influence your future program designs.
Explain how this experience will influence your future program testing.

8. Between earlier examples and example4, can you explain what changed that allowed the removal of -ll (libfl if flex how can that be?) from the link specification?
What did yacc provide that allowed this to happen?
In your intermediate files, can you find the line number?

9. diff example4.l and example5.l
diff examle4.y and example5.y
Demonstrate your understanding of yytext and yylval by explaining the origin of their content and when it is created.
Further explain yytext and yylval as “c” variables in the generated program.

10. diff example4.y and example6.y
Explain your understanding of the origin of variable $2
Explain your understanding of the origin of variable $3
Explain why the specifics of $1 $2 $3 etc. are not that important.
Explain why the shared usage of $1 $2 $3 is important to the shared, generated code.

10. Explain the lexyacc efficency trade-off on the choices made for HEAT ON and HEAT OFF.

11. Run example5.compile and provide inputs from 7 above.
Describe your user experience:
a. Program correct?
b. Program robustness, security, reliability, resistance to failure.
c. Program presentation/beauty/ease-of-use/understandability
d. Program efficiency.

12. As a user, rank the factors a-d above. Check with your associates. Ask visitors to your home to evaluate. Ask strangers to evalute the list.

13. Create a version of example5 that is more user friendly. Consider recovery from errors, ease of use, lack of training, carelessness.

Now that you are warmed up, Wikipedia [Bison] and ref1 present calculator programmes. Build each, test and evaluate, share a blog post that compares and contrasts the available examples.

lex and yacc

If you lift the lid on the engine compartment of your car (bonnet to English-speakers, hood to Americans), you see a complex arrangement of TUBES, wires, boxes, containers, and mysterious objects. Worse, they may be concealed by covers, bundles and conduits. If you have a friend or perhaps classroom instruction, with the help of a readable manual, you can find your way and check your fluids, look for damage, identify the source of a mysterious new noise.

Should you decide that there is a problem that you can fix yourself, you will go to your tool box to choose the right wrench (spanner) or screwdriver to fix the problem.

Linux is not different. And the tool box is vast.

Or perhaps you wish to make something new and different. Linux (and Unix, and all that goes before) provides a huge tool box (the USPTO pretending to not know (“I am not knowing” (has this been outsourced too?)). The great advantage of the Linux distributions is that they are free (as in freedom) and free or inexpensive (in cost). When you receive benefit, give back.

In my home tool box, I have a basin wrench . Cost per use $5. It allows one to reach into the inaccessable space between the wall and the basin to loosen or tighten the nut that holds the faucet to the basin or the supply-line to the faucet.

LEX and YACC are just such tools. Like many tools in the Unix/linux world, the have a specific application. And they are absolutely genius in what they do.

“Proper tool for the proper job”. Each tool does one thing very well. Something else? That is why there is | (pipe)

If you are not trying to create a programme or solve specific problem, you may already know every thing you need to know.

lex – a tool to generate (in conjunction with yacc) C code for a lexical scanner
yacc – a tool to generate (in conjunction with lex) C code for a grammer interpreter.

In naive terms, lex – what do I see, yacc – what do I do with it.

Think about this problem: You are trying to create program that “understands” specific input words and is able to act on them.
lex is the tool that can do this. The “shorthand” description to lex and the C compiler can create a program for Linux that scans the input stream for specific values, and generates specific results.

If the inputs are more complicated, you may need to have the program interpret as an example “what to do” “thing that it is done to”. This is where yacc come in.

To add to the confusion, lex is the classic Unix program, flex is the Linux equivalent. Mostly compatable but subtly different.

Similarly, yacc is a Unix program, bison is the linux equivalent. Fortunately, flex and bison have compatability so previous knowledge and program source is not rendered valueless.

More in a future post.

Error Errors

Error message:Bad Opaque
Error Message 1

I got this error message box again. Can anyone tell me what it means?

I actually sort of know what it means, where it originates, and why. But it is a good example of bad programming practice and poor program development management that an end user sees a message like this.

What is wrong with the message? “Bad Opaque”. Yep. This message is worse than opaque, it is a black hole that sucks energy into oblivion. “Bad Juju” (not to be confused with juju) would be just as appropriate and more comprehensible. Where did this message come from? The title on the box provides a clue “Failed to enter room”. I was in a “virtual room” a while ago but the meeting is over and I have closed all of the visible windows. The message box is “on top” and will will not release focus. So, even though it is NOT OK, I click OK because that is the only thing to do.
Some time later, I discover an all-gray window with a title “Failed to connect”. Yep. The programmer clearly failed to connect the “Bad Opaque” message with the application. At least I guess they should be connected as the 3 windows appear to occur around the same time among the 10-12 windows I typically have open on my desktop with no indication on the task bar or system tray.
So my interpretation of this, which may or may not be accurate, is that the meeting I was in has ended, the window-less program that makes the connection tried to re-enter the now closed virtual room. Failing that in an unexpected way pops the “Bad Opaque”.
Somehow the connector or the room-enterer did not get the message that the session was over.  A bit more transparency and better error messages would be helpful.

Some Microsoft products have gotten better about making it clear what the error is and what the consequences of “Cancel”, “End”, “OK”, etc are. But not everybody there has gotten the memo yet, or if they have they have not read it and taken it to heart.

Picture of: Uncorrectable Error has occured UpdateHandel:handle not allocated Press Enter to Abort
Uncorrectable
I like this one too.  It certainly gets your atten- tion.  I comp- lained about it to the system administrator for several years.  I am sure that it is no longer an issue because that account moved to Google Mail eliminating the application that was uncorrectable.  At least this message is clear about what it means and where it comes from.  The problem with this one is that while I may not be able to correct the error, the programmer who failed to anticipate the condition but was able to provide an error message could correct the code to make sure that the LookupHandle was allocated or perhaps provide a suggested corrective action to the user.  At the very least, the programmer could suggest the external cause, if that were the case, so that external corrective action could be taken, preferably before but in any case after “Abort”-ing the application.

But my all-time favorite is this one.

Windows message box Cannot quit Microsoft Office
Yes you can!

Typical of Microsoft’s lack of quality control, due to some unexplained condition, you fall into a routine where the debugging software has been left engaged. The good news is that you can use Open Office on Linux to eliminate this message, Microsoft Office, AND best-of-all eliminate Windows.