Stefano on August 30th, 2008

To proceed further you will have to download an improved version of hello, from here.

Once you obtain the tar.gz file, unpack it so that the result is produced into a proper location where Chestnut can find it, for example by issuing

tar -xzv -C $HOME/Packages -f hello-1.1.0.package.tar.gz

Now you can check if the package is correctly installed by issuing

$ cnls -l hello-1.1.0
hello-1.1.0:
    Description: Contains utilities for various salutations
    Flags: xrdm
    Location: /Users/stefano/Packages/hello-1.1.0.package
    Executable entry points:
        bye  : Prints bye in the specified language
        hello (default) : Prints hello in the specified language
    Resource entry points:
        hello_translations : Translations for hello in various languages
        bye_translations : Translations for bye in various languages

Here things are different. We will now explain a little the terminology of Chestnut.

An entry point is a named access into the package. If a package is a street, the entry point is the house number. Normally, when you invoked cnrun earlier on, you did not specify an entry point, but Chestnut actually used the default one.

The above package has four entry points: bye, hello (which is set as the default), hello_translations and bye_translations. The first two are executable entry points, meaning that they are assigned to programs that can be executed by means of cnrun. The latter two are instead resource entry points, meaning that they are assigned to files carrying no executable meaning, like for example datafiles we want to make accessible. This package therefore contains both executable programs and data.

How do we use this package? We can execute it as before, using cnrun. This time, the program can provide salutation in different languages, by specifying the proper command line argument. We can get it in italian for example

$ cnrun hello-1.1.0 it
Running for Darwin-Power Macintosh
Current CN_ROOT_DIR is /Users/stefano/Packages/hello-1.1.0.package
ciao (on Darwin-Power Macintosh)

or in french

$ cnrun hello-1.1.0 fr
Running for Darwin-Power Macintosh
Current CN_ROOT_DIR is /Users/stefano/Packages/hello-1.1.0.package
salut (on Darwin-Power Macintosh)

With this invocation procedure we are currently executing the default executable entry point: hello. We can execute a different entry point with the following syntax

$ cnrun hello-1.1.0/bye it
Running for Darwin-Power Macintosh
Current CN_ROOT_DIR is /Users/stefano/Packages/hello-1.1.0.package
ci vediamo (on Darwin-Power Macintosh)

$ cnrun hello-1.1.0/bye fr
Running for Darwin-Power Macintosh
Current CN_ROOT_DIR is /Users/stefano/Packages/hello-1.1.0.package
au revoir (on Darwin-Power Macintosh)

As you can see, a different program is running now, the one associated to the bye entry point.

The default entry point is executed when no entry point is specified, so from all the practical point of view, there is no difference in using these two invocations:

cnrun hello-1.1.0 fr
cnrun hello-1.1.0/hello fr

If a default executable entry point is present, the package is said to be executable. If a package does not have a default executable entry point, then an entry point must always be specified explicitly. A package can also contain no executable entry points at all.

3.1 Resources and cnpath

What about resources, then ?

Resources have entry points as well, but they are used for a different task than execution (since you cannot execute resources, as they are normally data files). You can instead obtain the current absolute path of the resource with the program cnpath

$ cnpath hello-1.1.0/hello_translations
/Users/stefano/Packages/hello-1.1.0.package/Resources/Darwin-Power Macintosh/hello_translations

If you happen to move the package somewhere else, you will get the correct absolute path of the resource

$ mv Packages/hello-1.1.0.package /opt/Packages/                   
$ cnpath hello-1.1.0/hello_translations
/opt/Packages/hello-1.1.0.package/Resources/Darwin-Power Macintosh/hello_translations

Leave a Reply