[home]
phone: figure out how to dial phone numbers


Description

phone is a command that figures out how to dial a given phone number locally. It is intended to be used in conjunction with dialing scripts such as chat or wvdial, or in conjunction with fax software or other kind of software that keeps a database of phone numbers which may have to be called from different locations. But it can also be used as a simple phone book.

phone takes a fully qualified phone number and a locale specification and writes the local version of the phone number to standard output.

Downloading and Installing

The current version of phone can be downloaded as a gzipped tar archive from http://www.mathstat.dal.ca/~selinger/phone/phone-1.2.tar.gz. Unpack the archive by typing

        tar -zxf phone-1.2.tar.gz
This will create a directory phone-1.2 inside your current working directory. Change to this directory, and follow the instructions in the file INSTALL.

Usage

Usage: phone [options] phone-number
       phone [options] alias
       phone [options] -

Options and arguments: 
	 -h, --help      help
         -v              verbose
         -n              suppress newline
         -l locale       set locale string
         -f localename   set locale by name
         -d dialchars    set valid digits (default "+0123456789W@!,ABCD#*")
         -s              strip output of non-dialchars
         phone-number    a fully qualified phone number (starts with "+")
         alias           a nickname for a phone number
         -               run as a filter

Phone Numbers

A fully qualified phone number is a phone number in the international format: it begins with a "+", followed by the country code, followed by the remaining parts of the number. The input phone number can be either specified directly on the command line, or it can be read from an alias file if an alias is given. Alternatively, if the - option is specified, the input phone number is read from standard input.

Alias files. If a phone number is specified by an alias on the command line, then phone searches for the definition of the alias first in the file .phonebook in the user's home directory, and then in the system-wide file /etc/phonebook.sys. Each line of these files is assumed to be a pair

        alias phone-number
separated by white space. The phone number should be fully qualified. Typical lines of an alias file may look as follows:

        mom +1-734-555-1212
        gerhard +49-69-89551212
        isp   +1-888-555-1212
Lines starting with "#" are comments. Ill-formed lines are ignored. Leading and trailing blanks are removed.

Locales

A locale is a string of rules that specify how to dial phone numbers from a specific location. A locale consists of a colon-separated list of replacement rules of the form prefix=replacement. For instance, the locale

        +=011-:+1=1-:+1734=
specifies three replacement rules: any number can be dialed by replacing a leading "+" with "011-" (for international calls), or by replacing a leading "+1" with "1-" (for national calls other than local), or by replacing a leading "+1734" with "" (for local calls). I am in southern Michigan, where the area code is 734. As the example shows, a replacement string may be empty; the same is true for prefixes. If there is more than one matching replacement rule, the longest matching prefix is used. The following locale specifies that I wish to dial 1016868 before any long-distance call:

        +=1016868-011-:+1=1016868-1-:+1734=
The following locale is for my office. In my office, one has to dial "9" to reach an outside line. For internal calls, one can dial 3-xxxx and 6-xxx to reach the respective local numbers 763-xxxx and 476-xxxx.

        +=9-011-:+1=9-1-:+1734=9-:+1734763=3-:+1734476=6-
The following locale is for Darmstadt, Germany:

        +=00-:+49=0:+496151=

Note: if the locale has no rule that matches the given phone number, then phone prints a warning message and returns the unchanged input phone number. A frequent cause of this is a missing "+" at the beginning of the input phone number. To avoid this warning, add a "catchall" rule to the locale, which consists of an equality sign only.

The meaning of the replacement rules. To determine whether a replacement rule matches a given input phone number, first all non-dialchars are removed from the rule and from the phone number. If the left-hand-side of the rule is an initial piece of the phone number after this removal, then it is replaced by the right-hand-side of the rule. If more than one rule in a locale matches the given phone number, the rule that matches the most digits is used. If the -s option is given, phone strips all non-dialchars from the output. Otherwise, it retains as many non-dialchars as possible.

Locale files. If a localename is given with the -f option, phone searches for the definition of the locale in the file .phonelocale in the user's home directory, and then in the file /etc/phonelocale.sys. Similarly, if no -f or -l option is given, phone looks in these files for a locale named "default". The format of the locale files is similar to that of the alias files. Each line of a locale file is a pair

        localename locale
separated by white space. The following are some sample entries:

        default   +=011-:+1=1-:+1734=
        office    +=9-011-:+1=9-1-:+1734=9-:+1734763=3-:+1734476=6-
        darmstadt +=00-:+49=0:+496151=

Examples

        example% phone mom
        555-1212
        example% phone mom -f office
        9-555-1212
        example% phone mom -f office -s
        95551212
        example% phone gerhard
        011-49-69-89551212
        example% phone +49-69-89551212
        011-49-69-89551212
        example% phone gerhard -f darmstadt
        069-89551212
        example% phone mom -l '+=011-:+1=1-'
        1-734-555-1212

Version

1.2

Author

Copyright © 1999-2000 Peter Selinger.

License

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.


Back to Homepage: [home]


Peter Selinger / Department of Mathematics and Statistics / Dalhousie University
selinger@mathstat.dal.ca / PGP key
Updated December 18, 2000