Lessons learnt from Oracle

Lesson number 1: "how to handle temporary files".

$ rm tp*
$ proc code=cpp lines=yes dba_vm.pc

Pro*C/C++: Release 10.2.0.1.0 - Production on Wed Sep 30 11:10:00 2009

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

System default option values taken from: /usr/local/oracle/10.2.01/db_1/precomp/admin/pcscfg.cfg

$ echo $?
0
$ ls tp*
tpoHRjc8  tpqkU4Cp  tpY5Eo4G
$

Today we learn this: for every successful compilation of a single source file, it is a Good Thing to leave three temporary files around as a tribute to the Holy Trinity who bestowed upon us the grace of seeing our prayers fulfilled and our work rewarded.

For those illiterate of us who do not want to learn from the Market Leaders, and do not want to put a rm -f tp* in their makefiles just to avoid in the future to see hours of work on tpl_support.cc disappear at the first invocation of make, here's the Yokel's Wrapper:

#!/bin/sh -ue

if [ $# -ne 2 ]
then
        echo "Usage: $0 infile outfile" >&2
        exit 1
fi

DIR=`mktemp -d`

cleanup() {
        rm -rf "$DIR"
}

trap cleanup EXIT

cp "$1" "$DIR"
(
        cd $DIR
        proc code=cpp lines=yes "$1"
        mv `basename "$1" .pc`.c "$2"
)
mv "$DIR/$2" .

exit 0