S010's homepage

 


Tags:
c, cwm for linux, fun, game, interpreter, kernel, lan card, linux, lisp, low level programming, openbsd, patch, programming, system programming, utility, windows

cwm(1)

ctime:2009-11-11 02:00:07
mtime:2009-11-11 02:02:29

I decided to start using OpenBSD's calmwm(1) at work, where I have a Linux box. So I checked out the latest source and naturally it didn't compile straight away. Here it is if you're a linuxoid and you want to try cwm out too and you don't want to waste a few hours playing with Makefile, searching for missing files and implementing several lacking library functions: http://s010.lv/files/cwm_linux_20091109.tar.gz

lisp

ctime:2009-11-10 12:22:06
mtime:2009-11-11 01:49:47

lisp -- is a small LISP interpreter written in C. I wrote it to see if I could, and because LISP seems to be a very peculiar programming language, I feel that I should look into it.

I used Paul Graham's paper The Roots of Lisp as a language definition.

The currently supported operators are: quote, atom, eq, car, cdr, cons, cond, defun, list, null, and, not, exec. Their meanings and workings are described in the README file.

A few run examples:

s@d400:0:lisp$ ./lisp -e "(cdr '(a b c))" ( b c ) s@d400:0:lisp$ ./lisp -e "(atom (cdr '(a b c)))" () s@d400:0:lisp$ ./lisp -e "(atom (car (cdr '(a b c))))" t s@d400:0:lisp$ ./lisp -e "(defun fn (x) (cond ((atom x) 'x) ('t (cdr x)))) (fn '(a b c))" () ( b c ) s@d400:0:lisp$

Of course, it can interpret files as well. There is a file included in the archive, test.lisp, there are some usage examples in it and I also use it as a regression test.

lisp.tar.gz

pcspkr_play

ctime:2009-11-10 12:22:06
mtime:2009-11-11 01:18:50

pcspkr_play is a little fun program I wrote in C. It reads a file with notes, and plays them on the PC speaker.

I've tested it only on my laptop which runs OpenBSD 4.5 at the moment, my Linux box doesn't have a PC speaker unfortunately. I would be very glad if someone would tell me if it works in Linux or not (my email is in the first section of the site).

pcspkr_play comes with one melody, The Blue Danube by Johann Strauss. The Blue Danube can be heard in a beautiful space scene of Stanley Kubrick's movie, 2001: A Space Odyssey. Here is an example of how the note file might look like:

... octave 5 c6 200 c6 p 100 g 200 g ...

octave obviously sets the current octave. A character from a to g is the note to play, the current octave can be overridden by adding the octave number immediately after the note char. The optional number on the right -- is for how long to play the note in milliseconds. If you don't specify the length, the value you used most recently is assumed. p -- is a special note char, which denotes a pause when no sound is produced.

Compile on OpenBSD like this: cc -DOPENBSD -o pcspkr_play pcspkr_play.c -li386
on Linux: cc -o pcspkr_play pcspkr_play.c
The program must be run from root because it directly accesses the hardware, i.e. the I/O ports.

pcspkr_play.tar.gz

OpenBSD kernel patch for DELL Latitude D400

ctime:2009-11-10 12:22:06
mtime:2009-11-11 01:52:27

This is a trivial patch for OpenBSD 4.5 release kernel which makes CardBus (basically, the PCMCIA slot) work on DELL Latitude D400 laptop (the older one, which was silver-metallic, had a Pentium M 1400 Mhz ...).

To apply the patch, download the kernel sources and unpack them, then put bios.c.patch into sys directory, the root directory of kernel's source tree, and run patch < bios.c.patch. Then compile the kernel, instructions on how to do this can be found on OpenBSD's website, in FAQs.

tnamed

ctime:2009-11-10 12:22:06
mtime:2009-11-11 01:19:52

tnamed or trivial name daemon, is a UNIX daemon that allows computers on a local network to recognize each other by names. It's intended as a zero-configuration daemon so it needs no conf files or command line options.

I can never remember what IP addresses comps on my LAN have, an obvious solution is to add ip->hostname mappings to /etc/hosts file. But wtf, the computer should make my life easier not add more problems. And then you'll have to use static IP addresses or tell DHCP server to always assign the same IPs for certain MACs.

When you run tnamed, it:

  1. acquires the list of IP address that the machine has
  2. for each of the IP addresses, it broadcasts to the subnet 255.255.255.0 a message telling that it's located at that IP address :D Makes no sense, right? Example: a machine has a hostname of "slowpoke" and IP addresses 192.168.0.1, 89.191.97.180, then it will broadcast a message "slowpoke@192.168.0.1" to every host in 192.168.0 and "slowpoke@89.191.97.180" to every host in 89.191.97
  3. It then broadcasts a request for other hosts to announce themselves to the subnets the computer is connected to
  4. Then it goes into an endless loop waiting for incoming messages; when it gets a request to announce self, it does (1); when it gets other host's announcment, it adds an entry to /etc/hosts file
    The hosts file may look something like this after tnamed:
    127.0.0.1 slowpoke# Following entries added by tnamed192.168.0.11 x2192.168.0.10 d400
  5. When you kill tnamed, it restores the original /etc/hosts file

tnamed is intended as a zero-configuration daemon, it doesn't need any conf files or command line options. To use it, simply run it from root, on all the participating machines.
Say, you have three machines on you LAN, "host1", "host2" and "host3". Run tnamed on each of the comps. And then, being logged in on one of these comps, you can address the other two by names, liek ping host2

tnamed.c -- current version is somewhere like 0.5, the code is a little rough and I have one other thing I want to add for great justice =)

On BSD, compile like: cc -DBSD -o tnamed tnamed.c
on Linux: cc -o tnamed tnamed.c