[Cairo] The great renaming

Carl Worth cworth at east.isi.edu
Fri Jul 18 12:53:15 PDT 2003


There seems to be no complaint about the name Cairo.

I've just committed the first version of the source code to use the
new Cairo names. You may now checkout the "cairo" module from CVS,
(I've also tried to make sure that old checkouts will still work and
point to the new code, but do tell me if I missed something).

Here is the breakdown of changes:

Function names go from XrStudlyStyle to cairo_underscore_style:

	   XrSetLineJoin
	-> cairo_set_line_join

Symbolic values, (ie. enum values), go from StUdlY to ALL_CAPS:

	   XrLineJoinRound
	-> CAIRO_LINE_JOIN_ROUND

The convention for distinguising an enum/structure tag from a typedef
name changes from an '_' prefix on the tag to a "_t" suffix on the
typedef name:

	   typedef enum _XrLineJoin { ... } XrLineJoin;
	-> typedef enum cairo_line_join { ... } cairo_line_join_t;

And just for good measure, I took advantage of the chance to change a
couple of the names as well:

	XrState -> cairo_t
	XrCreateSurfaceNextTo -> cairo_create_surface_similar

The cairo/util directory contains a shell script, xr2cairo, which
makes it easy to convert any code using Xr to use the new Cairo naming
conventions.  I've attached a copy of the script as well.

The xr2cairo script handles all of the changes mentioned above. I've
run the script on Xr itself, as well as most of the code I've written
that uses Xr, (libxsvg, xsvg, xrtest, grrobot). But, just in case the
script really screws up, it first saves a backup with a .xr extension.

A very few tasks are left as exercises for the reader. Obviously one
will need to fix the build to link against libcairo rather than libXr.
Also, on a cosmetic note, it may be desired to change the name of the 
"xrs", (or whatever), identifier and fix whitespace issues caused by
the fact that the new names are almost all longer than the old ones.

Oh, and the script does require GNU sed, so go and get that if you
don't already have it, (but you really should have it already).

-Carl

-------------- next part --------------
#!/bin/sh
set -e

if [ $# -lt 1 ]; then
    argv0=`basename $0`
    echo "$argv0: Convert source code written for Xr to use Cairo instead." >&2
    echo "" >&2
    echo "Usage: $argv0 file [...]" >&2
    exit 1
fi

xr2cairo() {
	file=$1
	backup=$file.xr

	if [ -e $backup ]; then
		echo "Warning: Backup file $backup already exists --- not backing up this time." >&2
	else
		cp $file $backup
	fi
	sed -e '
		s/\(Xr[a-zA-Z]*\)RGB/\1Rgb/g
		s/\(Xr[a-zA-Z]*\)NextTo/\1Similar/g

		s/Xr\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z]\+\)/\Lcairo_\1_\2_\3_\4_\5\E/g
		s/Xr\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z]\+\)/\Lcairo_\1_\2_\3_\4\E/g
		s/Xr\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z]\+\)/\Lcairo_\1_\2_\3\E/g
		s/Xr\([A-Z]\+[a-z]\+\)\([A-Z]\+[a-z0-9]\+\)/\Lcairo_\1_\2\E/g
		s/Xr\([A-Z]\+[a-z]\+\)/\Lcairo_\1\E/g

		s/\(cairo_\(operator\|status\|fill_rule\|line_cap\|line_join\|filter\|format\)_[a-z0-9_]\{2,\}\)/\U\1/g

		s/cairo_\(fill_rule\|line_cap\|line_join\|format\|operator\|status\|filter\|surface\|matrix\)$/cairo_\1_t/g
		s/cairo_\(fill_rule\|line_cap\|line_join\|format\|operator\|status\|filter\|surface\|matrix\)\([^_]\)/cairo_\1_t\2/g
		s/_cairo_\(fill_rule\|line_cap\|line_join\|format\|operator\|status\|filter\|surface\|matrix\)_t/cairo_\1/g
		s/cairo_state/cairo_t/g
		s/_cairo_t/cairo/g

		s/Xr\.h/cairo.h/g

		' $backup > $file
}

while [ $# -gt 0 ]; do
	file=$1
	shift
	xr2cairo $file
done



More information about the cairo mailing list