Minor CSS changes for code blocks

I made some minor changes to the default stylesheet to have blocks of code no longer overflow the edge of the page.

Changes were based on the stylesheet I found at
http://www.bigbold.com/snippets/stylesheets/posts.css.

I added in the following:

pre {
        border: 1px solid #333;
        padding: 6px;
        overflow: auto;
        margin: 0px 1%;
        width: 95%;
        }

Thanks to the Snippets public code repository.

Changes and suggestions welcome!

DYLD_LIBRARY_PATH

Anyhone has any clue why vast majority of the dynamic linkers out there (Solaris, Linux, BSD etc) all use LD_LIBRARY_PATH variable to specify where to load dynamic libraries from, yet Darwin/MacOS X uses DYLD_LIBRARY_PATH?

*grumble*

Compiling Alladin GhostScript 8.51 from source. It’s not hard, just quirky. Oh, and jpgsrc-6 and zlib-1.2.2 both need a config.sub from a recent package for configure to recognize Darwin/MacOS X.

Motorbike vs. Car

dAVE is complaining that all I write are boring technical articles, without any human touch. So the folowing is an experiment in blogging about “human” issues. Wish me luck…

Sunday night I were coming home, and noticed that the corner of Bronson and Gladstone was blocked off – in some directions a block away. Being curious, I wandered out there, and saw half the intersection closed off by “Do Not Cross” tape, lots of police, a car stopped half way through, and a motorcycle laying on it’s side.

From chatting with the bystanders, I learned the following:
A woman driver, going from west to east on Gladstone run a red light, and was hit by a motorbike going south to north on Bronson.
Bike rider was supposedly alive when he was taken to the hospital by an ambulance, but his right knee was totalled by a bike falling onto it.

In Soviet Russia bikes had roll cages. Even motorollers had leg protection. Statistics are against bikers – biker will fall at some point. However in North America bikes are considered to be a macho thing – people ride basically in shorts and tshirts, often without helmets.

I am as pro auto-darwination, as the next guy, however think of the police and ambulance workers that will have to scrape you off ashphalt – at least wear leather coat and pants, to keep the pieces together. Have roll cages – have you thought of the nurses? Do you know how bloody hard it is to bandage someone who has a smashed knee cup? Why make someone remember you with a curse, as you are moving on in the world?

*sigh*

As an aside, again, in Soviet Russia some bikers tended to wear really narrow thin knee high riding boots. They were a sort of indicator – during death body would relax, so quite often boots would fall off, no matter how tight fitting they were. In fact rescue/ambulance workers used that as an indicator to see if they should attempt to hospitalize a victim, or if they das alles tod.

(Above photos are licensed under licensed under the Creative Commons Attribution NonCommercial ShareAlike License v.2.5. If they make someone think before running a red light, I’ll be happy).

Shellscripts: Using ANSI colors or finding duplicate files in style

… or “ASCII stupid questions, get a stupid ANSI”….

I’ve been writing Evil Shell Scripts of Doom[tm] lately, got curious in highlighting parts of the output in different color.
As both Terminal.app and xterms in Apple shipped X11 support ANSI colors, it made sense to me.

There are excellent How to Change a Title of an Xterm and Bash Prompts HOWTOs out there, to which I’ll refere my gentle reader, and thus I will just paste some example code.

Bits that directly relate to ANSI color output are all the echo -e lines, with basic logic being that echo -ne “e[1;35m” turns ON purple color, and echo -ne “e[0;m” turns it off. Of course other numeric values will generate different colors, and colors will look different on different terminals. Please refere to HOWTOs above.

Please make sure that you BOTH understand what this does, and undertand that YOU are responsible for running this. If it breaks, you get to keep both pieces, and not cry in my shoulder. The following is copyright 2005 Stany, and is licensed under… *shrug* BSD 2 clause license, in hope that this will be useful to others

(This is just some internal code that in reality just externalizes a function out of a much larger script, however might be of use to others without revealing what exactly I were working on. Note that it will leave an md5sum.out file behind, and will generate a script called “killfile” to remove duplicate if they were detected. This script doesn’t do many sanity checks, as they were job of a larger script, and will barf if subdirectories are present and matched. )

#!/bin/bash
# Checks for duplicates.  Takes one argument (optional) of the file ending,
# eg: checkdupe.sh pdf
# $Id: checkdupe.sh,v 1.2 2005/09/06 06:56:11 stany Exp stany $
MD5SUM=/opt/gnu/bin/md5sum
BASENAME=`basename $0`

checkdupe()
{
for ii in *$1 ; do
        FILESUM=`$MD5SUM $ii | awk '{print $1}'`
        NUMFILES=`grep $FILESUM md5sum.out | wc -l`
        if [ $NUMFILES -gt 0 ]; then
                OTHERFILE=`grep $FILESUM md5sum.out | awk '{print $2}'`
                 echo -e "e[1;31m`date` $BASENAME: e[1;36m$ii e[1;32mis a duplicate of e[1;35m$OTHERFILE e[0;m"
                echo "rm $ii" >> killfile
        else
                $MD5SUM $ii >> md5sum.out
        fi
done
}

if [ -e killfile ] ; then
        rm killfile
fi

if [ -e md5sum.out ] ; then
        rm md5sum.out
fi
        touch md5sum.out

checkdupe $1

if [ -e killfile ] ; then
        echo -e "e[1;31m`date` $BASENAME: Duplicates found.  Run killfilee[0;m"
        echo -ne "e[1;35m"
        cat killfile
        echo -ne "e[0;m"

fi


Sample run:

stany@gilva:~[02:58 AM]$ mkdir test
stany@gilva:~[03:04 AM]$ cd test/
stany@gilva:~/test[03:04 AM]$ echo a >foo 
stany@gilva:~/test[03:04 AM]$ echo a >bar 
stany@gilva:~/test[03:04 AM]$ echo b > baz
stany@gilva:~/test[03:04 AM]$ ../checkdupe.sh 
Tue Sep  6 03:04:45 EDT 2005 checkdupe.sh: foo is a duplicate of bar 
Tue Sep  6 03:04:45 EDT 2005 checkdupe.sh: Duplicates found.  Run killfile
rm foo
stany@gilva:~/nature/test[03:04 AM]$ ls
bar             baz             foo             killfile        md5sum.out
stany@gilva:~/nature/test[03:04 AM]$ 

Oh, and checkdupe() can be trivially fixed so that it would take any shell expandable expression as an argument to the script, and work with that. I don’t even consider it an excercise 😛

MacOSX: Trimming fat from Mach-O fat files

MacOS X uses fat files.

A fat bundle contains data for different architectures. Here are some examples:

root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:03 AM]# file *
Terminal: Mach-O fat file with 2 architectures
Terminal (for architecture i386):       Mach-O executable i386
Terminal (for architecture ppc):        Mach-O executable ppc
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:03 AM]# 

or even:

stany@gilva:/System/Library/Frameworks/Accelerate.framework/Versions/A[02:07 AM]$ file Accelerate 
Accelerate: Mach-O fat file with 3 architectures
Accelerate (for architecture i386):     Mach-O dynamically linked shared library i386
Accelerate (for architecture ppc):      Mach-O dynamically linked shared library ppc
Accelerate (for architecture ppc64):    Mach-O 64-bit dynamically linked shared library ppc64
stany@gilva:/System/Library/Frameworks/Accelerate.framework/Versions/A[02:07 AM]$ 

In order to operate on fat bundles Apple provides a utility called lipo.

If you are in a situation where you are limited by processor architecture – for example, if you never expect to use internal hard drive of your iBook in firewire target mode to boot up an i386 system – it is possible to remove the extra “fat” from fat binaries, to save some disk space.

Here is an example:

root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:09 AM]# mv Terminal Terminal.bak 
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# ls
Terminal.bak
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]#lipo Terminal.bak -remove i386 -output Terminal
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# ls -la 
total 2296
drwxrwxr-x   4 root  admin     136 Sep  6 02:10 .
drwxrwxr-x   7 root  admin     238 Aug 31 00:07 ..
-rwxr-xr-x   1 root  admin  386472 Sep  6 02:10 Terminal
-rwxrwxr-x   1 root  admin  783784 May 14 22:22 Terminal.bak
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]# file *
Terminal:     Mach-O fat file with 1 architecture
Terminal (for architecture ppc):        Mach-O executable ppc
Terminal.bak: Mach-O fat file with 2 architectures
Terminal.bak (for architecture i386):   Mach-O executable i386
Terminal.bak (for architecture ppc):    Mach-O executable ppc
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:10 AM]#

A quick test confirms that Terminal.app continues to run as before, however to make sure that everything is kosher I would probably want to correct permissions on the new binary to match what it was on the original.

Disk space saving will not be big, as an average .app consists of many other objects besides the executable itself, so this is probably not a very big issue. If one tries to remove a non-existing architecture from a binary, lipo will complain:

root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:18 AM]# 
lipo Terminal.bak -remove ppc64 -output Terminal
lipo: -remove ppc64 specified but fat file: Terminal.bak does not contain that architecture
root@gilva:/Applications/Utilities/Terminal.app/Contents/MacOS[02:19 AM]#

Another interesting option to lipo is -detailed_info:

stany@gilva:~[02:22 AM]$ lipo -detailed_info /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate 
Fat header in: /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate
fat_magic 0xcafebabe
nfat_arch 3
architecture i386
    cputype CPU_TYPE_I386
    cpusubtype CPU_SUBTYPE_I386_ALL
    offset 4096
    size 8488
    align 2^12 (4096)
architecture ppc
    cputype CPU_TYPE_POWERPC
    cpusubtype CPU_SUBTYPE_POWERPC_ALL
    offset 16384
    size 8564
    align 2^12 (4096)
architecture ppc64
    cputype CPU_TYPE_POWERPC64
    cpusubtype CPU_SUBTYPE_POWERPC_ALL
    offset 28672
    size 8488
    align 2^12 (4096)
stany@gilva:~[02:22 AM]$ 

writing a script that processes the output of:

 find . -type f  -perm -55 -exec file {} ; | grep i386 | sed 's/.for arch.*$//g'

while stripping out the arch, AND not screwing up the system is left as an excercise for the reader. 😛

Rendering a manpage

This is more of a general unix hint, that is not really MacOS X specific.

If you have a manpage that you want to look at, that is not in $MANPATH, (Something that got installed by hand into a custom directory, for example something that was built and installed using
./configure –prefix=/opt/packagename && make install ), yet you know where it is (for example because you did run /usr/libexec/locate.updatedb as root at least once since and now can use locate), you can use nroff to render the man page into text:

stany@gilva:~[12:06 AM]$ ls -la /opt/gnu/man/man6/figlet.6 
-r--r--r--   1 root  501  21054 Sep  3 17:41 /opt/gnu/man/man6/figlet.6
stany@gilva:~[12:06 AM]$ nroff -man /opt/gnu/man/man6/figlet.6 | head -20
FIGLET(6)                                                            FIGLET(6)



NAME
       FIGlet - display large characters made up of ordinary screen characters


SYNOPSIS
       figlet [ -cklnoprstvxDELNRSWX ] [ -d fontdirectory ]
              [ -f fontfile ] [ -m layoutmode ]
              [ -w outputwidth ] [ -C controlfile ]
              [ -I infocode ] [ message ]


DESCRIPTION
       FIGlet prints its input using  large  characters  (called  ``FIGcharac-
       ters'')made  up  of  ordinary  screen  characters (called ``sub-charac-
       ters'').  FIGlet output is generally reminiscent of the sort of  ``sig-
       natures''  many people like to put at the end of e-mail and UseNet mes-
stany@gilva:~[12:06 AM]$