Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/mysqlfs/tel.rc

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

rfork en

host=vm-slp-is-data
lookup=user

fn user {
	query='
		SELECT 
			u.firstname,
			u.lastname,
			u.extension,
			d.friendly,
			s.name
				FROM users AS u, departments AS d, sites AS s
				WHERE ( 
					( u.dept = d.mitel AND u.site_code = s.site_code )
				AND 
					( u.firstname LIKE ''%'^$1^'%'' OR u.lastname LIKE ''%'^$1^'%'' )
				)
	'

	{
		d=$mnt^/^`{cat}
	
		echo use intranet_phonesearch > $d/ctl
		echo $query > $d/query
		sed '
			s/R&D/R\&D    /g
		' $d/data
	} < $mnt^/clone
}

fn site {
	query='
		SELECT 
			name, 
			address1,
			address2,
			town,
			country,
			postcode,
			reception,
			fax,
			country_prefix 
			FROM sites
				WHERE name LIKE ''%'^$1^'%''
	'
	{
		d=$mnt^/^`{cat}
	
		echo delimited > $d/ctl
		echo use intranet_phonesearch > $d/ctl
		echo $query > $d/query
		awk -F '|' '
			{
				if(hit++ > 0)
					printf("\n");
				printf("Name:         %s\n", $1);
				printf("Address:      %s, %s\n", $2, $3);
				printf("Town:         %s\n", $4);
				printf("Country:      %s\n", $5);
				printf("Postcode:     %s\n", $6);
				printf("Reception:    %s\n", $7);
				printf("FAX:          %s\n", $8);
				printf("Country code: %s\n", $9);
			} 
		' $d/data
	} < $mnt^/clone
}

fn usage {
	echo 'usage: tel person' >[1=2]
	echo 'or     tel -s site' >[1=2]
	exit 'usage'
}

while(! ~ $#* 0 && ~ $1 -* && ! ~ $1 --){
	switch($1){
	case -s
		lookup=site
		shift
	case -*
		usage
	}
}

what=$1
if(~ $#what 0)
	what=''

mnt=/n/phonebook
mysqlfs -m $mnt $host
$lookup $what

exit ''

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].