# Settings from the MH Profile

MH programs search for entries in the MH profile -- for instance, show uses the `show:` and `showproc:` entries. When you're writing a program, it can extract information like the `Draft-Folder:` name or the `Msg-Protect:` mode number from the MH profile. You can also store default options for a program of yours in the MH profile.

The latest versions of MH come with mhparam(1), a utility that reads the MH profile. The shell script called mhprofile, explained below, does many of the same things for earlier versions of MH. You can call mhparam or mhprofile to find the MH profile options you've set for a particular command. For example:

        % mhparam repl
        -query -nocc me -editor prompter.nopre -anno -inplace

mhparam will show the default value if you haven't set one in your MH profile. For example, without my own `showproc:` entry, I can still find:

        % mhparam showproc
        /usr/ucb/more

(The simple mhprofile script can't do that.)

Here's how a Bourne shell script you've written, named progname, could get any MH profile switches into a shell variable named progopts:

        myname="`basename $0`"
        progopts="`mhparam $myname`"
        allargs="$progopts $*"

If you've made links or versions of the script, the myname variable will contain the name the program was called with. You can make multiple profile entries to make the program's behavior depend on the name it was called with.

One very handy trick for programmers is to store the location of the MH library directory in an MH profile entry. I picked an entry named `library:`, but you can choose another one:

        library: /usr/local/lib/mh

Then you can get the library location from a program. You can do the same thing for the nmh etcetera directory, or you can also use the almost-undocumented command mhparam etcdir. (If you're installing MH on a new site, think about adding a `library:` profile entry to the default MH profile named mh.profile. It will be copied to new users' MH profiles by install-mh(8). If this is done on multiple hosts, the location of the library can become host-independent.)

Here's an example in Perl. It gets the library with mhparam and defaults to /usr/local/lib/mh if mhparam fails (returns a non-zero status):

        $mhlibdir = `mhparam library` || "/usr/local/lib/mh";

mhparam will also read the context file. For example, to find the most recent issue and volume numbers of the octopus-eaters digest:

        % mhparam digest-issue-octopus-eaters digest-volume-octopus-eaters
        digest-issue-octopus-eaters:    37
        digest-volume-octopus-eaters:   2

When you give mhparam more than one entry, it prints the entry names unless you add its -nocomponent switch.

If you don't have mhparam, the mhprofile shell script in this book's online archive will do the same basic things (with fewer features). It reads all lines with a certain entry name from the profile and writes them on its standard output. With the -b option it will also strip off the entry name, leaving just the value. For example:

        % cat .mh_profile
            ...
        myprog: -noverbose -sort
            ...
        % mhprofile myprog
        myprog: -noverbose -sort
        % mhprofile -b myprog
        -noverbose -sort

Your program could use lines such as the following to get its profile (`$profswch`) and command-line (`$*`) switches:

        myname="`basename $0`"
        # IF mhprofile FAILS, EXIT WITH ITS STATUS:
        profswch="`mhprofile -b $myname`" || exit
        for arg in $profswch $*
        do
            ...Parse switches...
        done

However, mhprofile uses grep to search for matching entries. Because grep doesn't understand MH's idea of continuation lines, mhprofile will only find the first line of an entry as in the following example:

        progname: -xxx 'blah blah blah' -yyy 'etc. etc. etc;'
           -zzz 'whatever else'

The easiest solution is to make your entry long and not split it.

If you need to search for multiline entries, either make mhprofile use something besides grep or put your patterns on multiple lines:

        progname: -xxx 'blah blah blah' -yyy 'etc. etc. etc;'
        progname: -zzz 'whatever else'

For most MH programs, that's not a problem.

Here is a description of the mhprofile program.