|
If you wish to use the mcc_add_applications.sh script
on ULTRIX, please replace /usr/mcc/mcc_system/mcc_add_applications.sh
with the shell script that appears in this reply after the
form feed. Use this new shell script to add applications
to the DECmcc resource file.
If you have used the mcc_add_applications.sh script which
was installed with the V1.2 kit on ULTRIX, please
refer to note 3486 in this conference. (We found that
there were cases where the V1.2 version may drop lines
from the end of the resource file.)
Sorry for any inconvenience this may cause.
Ulla Figwer
#!/bin/sh5
#=============================================================================
#
# Copyright (c) Digital Equipment Corporation, 1991 All Rights Reserved.
# Unpublished rights reserved under the copyright laws of the United States.
#
# The software contained on this media is proprietary to and embodies the
# confidential technology of Digital Equipment Corporation. Possession,
# use, duplication or dissemination of the software and media is authorized
# only pursuant to a valid written license from Digital Equipment Corporation.
#
#
# RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S.
# Government is subject to restrictions as set forth in Subparagraph
# (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable.
#
# Digital Equipment Corporation
#
#=============================================================================
# mcc_add_applications.sh V1.2.1 Page 1
#++
#
# FUNCTIONALITY:
#
# This command procedure will modify the mcc_resource.dat file
# specified in $3, to add application(s) to the DECmcc Iconic Map
# Applications menu, using a datafile specified in $2.
#
# INPUT:
#
# Parameter $1 :
#
# -a to add an application
# -d to delete an application
#
# Parameter $2 :
#
# The file name of the datafile which contains information about
# application(s) to add to the DECmcc Iconic Map Applications menu.
#
# File format:
#
# For each application to be added, specify a line which begins with
# the text "Application Name:" followed by the name of the application
# to appear in the DECmcc Iconic Map Applications menu.
#
# If the application is supported on an Ultrix system, add a line
# after the "Application Name:" line which starts with the text
# "<application name>.Ultrix Command:" (where <application name> is
# the name of the application specified in the "Application Name:"
# line), followed by the complete Ultrix command to invoke that
# application, all on the same line.
#
# If the application is supported on VMS create a new line
# that starts with "<application name>.VMS Command:" followed by
# the VMS command to invoke the application.
#
# Note the lines "<application name>.Ultrix Command:" and
# "<application name>.VMS Command:" should come after the
# "Application Name:" line and before the next "Application Name:"
# definition.
#
# Note that all searches for text are case-sensitive. Therefore,
# all labels must appear using the mixed case format described
# above. In addition, all instances of <application name> must
# be identical in this respect.
#
# The default application resource datafile is
# "MCC_COMMON:MCC_RESOURCE_APPL.DAT".
#
# Parameter $3 :
#
# The location of the mcc_resource.dat file to update.
#
# The default mcc_resource.dat file is
# DECW$SYSTEM_DEFAULTS:MCC_RESOURCE.DAT".
#
# OUTPUT:
#
# A new version of the file specified in $3, with the
# specified application(s) added.
#
#--
#
# MODIFICATION HISTORY
#
# 01-JUN-1992 UF Original version
# 05-JUN-1992 UF Added two echo statments in
# delete_applications() to print message when
# and application is deleted.
# V1.2.0 15-JUN-1992 UF Modified two statements in
# set_current_application() to do 'head -1'
# directly, instead of after a 'more' of the
# file.
# V1.2.1 31-JUL_1992 UF Modified delete_appl_and_commands() to
# delete application from the applications
# line using commands which depend on whether
# the application is at the end of the list or
# not.
#
# Modified for loop in mark_appl_line() and
# unmark_appl_line() :
# for (i = 1; i <= NR; i = i + 1)
# Use to read "i < NR". Was causing two
# lines to be dropped from mcc_resource.dat
# each time this command procedure was run
# with the -a option.
#=============================================================================
#
#-----------------------------------------------------------------------------
# cleanup()
#
# This routine is called each time the script exits. It is invoked
# as a result of the trap 'cleanup' 0 statement.
#
# Delete all temporary files. Exit with correct (good/bad) status,
# depending on whether there was an error.
#-----------------------------------------------------------------------------
cleanup()
{
if [ -r "$temp_resource_file" ]; then
rm $temp_resource_file
fi
if [ -r "$temp_resource_file2" ]; then
rm $temp_resource_file2
fi
if [ -r "$sed_command_file" ]; then
rm $sed_command_file
fi
if [ -r "$egrep_command_file" ]; then
rm $egrep_command_file
fi
if [ -r "$temp_appl_command_file" ]; then
rm $temp_appl_command_file
fi
if [ -r "$temp_appl_command_file2" ]; then
rm $temp_appl_command_file2
fi
if [ -r "/usr/tmp/mcc_temp_resource.dat" ]; then
rm /usr/tmp/mcc_temp_resource.dat
fi
if [ $error_occurred -eq 1 ]; then
exit 1
else
exit 0
fi
}
#
#-----------------------------------------------------------------------------
# trap_error()
#
# This routine is called if an error is trapped. It is invoked
# as a result of the trap 'trap_error' ... statement.
#
# Set error_occurred to 1 so that cleanup() will exit with error status.
#-----------------------------------------------------------------------------
trap_error()
{
echo ""
echo "mcc_add_applications: Error has occurred. No changes made to"
echo " resource file."
error_occurred=1
exit
}
#
#-----------------------------------------------------------------------------
# mark_appl_line()
#
# This routine is called during an add operation. It rewrites
# $mcc_resource_file to $temp_resource_file, marking the line which
# contains "mcc_pml.applications:". The first mark, "+-+-", is for
# substituting application names (see insert_appl()). The second mark,
# "+=+=", shows where to add lines for commands, using sed (see
# insert_appl_and_commands()).
#-----------------------------------------------------------------------------
mark_appl_line()
{
if [ -r "/usr/tmp/mcc_temp_resource.dat" ]; then
rm /usr/tmp/mcc_temp_resource.dat
fi
awk '{ line[NR] = $0 }
END { for (i = 1; i <= NR; i = i + 1)
if (index(line[i], "mcc_pml.applications:") != 0)
{
printf "%s%s\n%s\n", line[i], "+-+-", "+=+=" >>"/usr/tmp/mcc_temp_resource.dat"
}
else
{
printf "%s\n", line[i] >>"/usr/tmp/mcc_temp_resource.dat"
} }' $mcc_resource_file
mv /usr/tmp/mcc_temp_resource.dat $temp_resource_file
return
}
#
#-----------------------------------------------------------------------------
# set_current_application()
#
# This routine searches $temp_appl_command_file for all "Application Name:"'s
# and sets $current_application to the text of the first application. After
# this routine runs once, $temp_appl_command_file contains only lines
# which contain "Application Name:" (as opposed to the full application data
# file, $data_file).
#-----------------------------------------------------------------------------
set_current_application()
{
grep -i 'Application Name:' $temp_appl_command_file >"$temp_appl_command_file2"
rm $temp_appl_command_file
first_line=`head -1 $temp_appl_command_file2`
current_application=`head -1 $temp_appl_command_file2 | awk '{ start = index($0, ":") + 1 }
{ print substr($0, start, length($0) - start + 1) }'`
current_application=`echo $current_application | awk '{ print $0 }'`
echo "$first_line" >"$egrep_command_file"
egrep -fv $egrep_command_file $temp_appl_command_file2 >"$temp_appl_command_file"
rm $temp_appl_command_file2
rm $egrep_command_file
return
}
#
#-----------------------------------------------------------------------------
# unmark_appl_line()
#
# This routine reverses the marks made by mark_appl_line().
# $temp_resource_file is written to /usr/tmp/mcc_temp_resource.dat
# and then moved back to $temp_resource_file, without the marks
# "+-+-" and "+=+=".
#-----------------------------------------------------------------------------
unmark_appl_line()
{
if [ -r "/usr/tmp/mcc_temp_resource.dat" ]; then
rm /usr/tmp/mcc_temp_resource.dat
fi
awk '{ line[NR] = $0 }
END { for (i = 1; i <= NR; i = i + 1)
if (index(line[i], "+-+-") != 0)
{
end = index(line[i], "+-+-")
printf "%s\n", substr(line[i], 1, end-1) >>"/usr/tmp/mcc_temp_resource.dat"
}
else
if (index(line[i], "+=+=") == 0)
printf "%s\n", line[i] >>"/usr/tmp/mcc_temp_resource.dat"
}' $temp_resource_file
mv /usr/tmp/mcc_temp_resource.dat $temp_resource_file
return
}
#
#-----------------------------------------------------------------------------
# insert_appl()
#
# This routine uses sed to insert the application $current_application
# into $temp_recource_file, using the mark "+-+-" as a guide for
# where to insert the text. The mark "+-+-" is preserved, for the
# next time this routine is called.
#-----------------------------------------------------------------------------
insert_appl()
{
echo "s/+-+-/,${current_application}+-+-/" >"$sed_command_file"
sed -f $sed_command_file $temp_resource_file >"$temp_resource_file2"
mv $temp_resource_file2 $temp_resource_file
rm $sed_command_file
return
}
#
#-----------------------------------------------------------------------------
# insert_appl_and_commands()
#
# This routine searches $data_file for Ultrix and VMS commands for
# the application $current_application. If at least one command is
# found, $current_application is added to $temp_resource_file, along
# with the corresponding commands.
#-----------------------------------------------------------------------------
insert_appl_and_commands()
{
application_command_added=0
echo "${current_application}.Ultrix Command:" >"$egrep_command_file"
ultrix_command=`egrep -f $egrep_command_file $data_file| awk '{ start = index($0, ":") + 1 }
{ print substr($0, start, length($0) - start + 1) }'`
echo "${current_application}.VMS Command" >"$egrep_command_file"
vms_command=`egrep -f $egrep_command_file $data_file | awk '{ start = index($0, ":") + 1 }
{ print substr($0, start, length($0) - start + 1) }'`
rm $egrep_command_file
# If Ultrix command is found, add it to $temp_resource file.
if [ "$ultrix_command" ]; then
echo /+=+=/i\\ >"$sed_command_file"
echo "mcc_pml.applications.${current_application}.ultrix_command: ${ultrix_command}" >>"$sed_command_file"
sed -f $sed_command_file $temp_resource_file >"$temp_resource_file2"
mv $temp_resource_file2 $temp_resource_file
application_command_added=1
rm $sed_command_file
fi
# If VMS command is found, add it to $temp_resource file.
if [ "$vms_command" ]; then
echo /+=+=/i\\ >"$sed_command_file"
echo "mcc_pml.applications.${current_application}.vms_command: ${vms_command}" >>"$sed_command_file"
sed -f $sed_command_file $temp_resource_file >"$temp_resource_file2"
mv $temp_resource_file2 $temp_resource_file
application_command_added=1
rm $sed_command_file
fi
# If at least one command was added, add $current_application to the
# applications line of $temp_resource_file. Otherwise, print a message
# that no command were found and application will not be added.
if [ $application_command_added -eq 1 ]; then
global_application_added=1
insert_appl
echo ""
echo "mcc_add_applications: Added application '$current_application'."
else
echo ""
echo "mcc_add_applications: No commands for application"
echo " '$current_application'."
echo " No changes made to resource file."
fi
return
}
#
#-----------------------------------------------------------------------------
# add_applications()
#
# This routine is run when the -a option is selected.
#-----------------------------------------------------------------------------
add_applications()
{
#-----------------------------------------------------------------------------
# Mark the "mcc_pml.applications:" line in the resource file so
# that insert_appl() (called by insert_appl_and_commands()) will know
# where to insert text. mark_appl_line() creates temporary resource
# file $temp_resource_file.
#-----------------------------------------------------------------------------
mark_appl_line
#-----------------------------------------------------------------------------
# For each application in $data_file, add the ultrix and vms commands if
# they exist. Also add the application to the application line of
# the resource file.
#-----------------------------------------------------------------------------
cp $data_file $temp_appl_command_file
while [ -s "$temp_appl_command_file" ]
do
set_current_application
echo "$current_application" >"$egrep_command_file"
search_for_application=`more $mcc_resource_file | grep mcc_pml.applications: | egrep -f $egrep_command_file`
rm $egrep_command_file
if [ "$search_for_application" ]; then
echo ""
echo "mcc_add_applications: Application '$current_application'"
echo " already exists. No changes made to resource file."
else
insert_appl_and_commands
fi
done
#-----------------------------------------------------------------------------
# Unmark the "mcc_pml.applications:" line in the temporary resource file.
# Rename temporary file to $mcc_resource_file.
#-----------------------------------------------------------------------------
unmark_appl_line
if [ $global_application_added -eq 1 ]; then
cp $mcc_resource_file ${mcc_resource_file}_old
mv $temp_resource_file $mcc_resource_file
fi
return
}
#
#-----------------------------------------------------------------------------
# delete_appl_and_commands()
#
# This routine deletes $current_application from the applications line
# in $temp_resource_file and removes corresponding lines for commands.
#-----------------------------------------------------------------------------
delete_appl_and_commands()
{
# Delete application from the applications line.
# If application is at the end of the list, then delete the
# last comma and the application name. Otherwise delete
# the application name and the comma directly after the name.
# Note: This code will not handle the case where there is only one
# application listed. It is assumed that FCL will always be present.
echo "$current_application," >"$egrep_command_file"
search_for_application=`more $mcc_resource_file | grep mcc_pml.applications: | egrep -f $egrep_command_file`
rm $egrep_command_file
if [ "$search_for_application" ]; then
echo "/mcc_pml.applications:/s/${current_application},//" > "$sed_command_file"
sed -f $sed_command_file $temp_resource_file >"$temp_resource_file2"
mv $temp_resource_file2 $temp_resource_file
rm $sed_command_file
else
echo "/mcc_pml.applications:/s/,${current_application}//" > "$sed_command_file"
sed -f $sed_command_file $temp_resource_file >"$temp_resource_file2"
mv $temp_resource_file2 $temp_resource_file
rm $sed_command_file
fi
# If find Ultrix command line, delete the line.
echo "${current_application}.ultrix_command" >"$egrep_command_file"
string_found=`egrep -f $egrep_command_file $temp_resource_file`
rm $egrep_command_file
if [ "$string_found" ]; then
echo "/${current_application}.ultrix_command/d" >"$sed_command_file"
sed -f $sed_command_file $temp_resource_file >"$temp_resource_file2"
mv $temp_resource_file2 $temp_resource_file
rm $sed_command_file
fi
# If find VMS command line, delete the line.
echo "${current_application}.vms_command" >"$egrep_command_file"
string_found=`egrep -f $egrep_command_file $temp_resource_file`
rm $egrep_command_file
if [ "$string_found" ]; then
echo "/${current_application}.vms_command/d" >"$sed_command_file"
sed -f $sed_command_file $temp_resource_file >"$temp_resource_file2"
mv $temp_resource_file2 $temp_resource_file
rm $sed_command_file
fi
global_application_deleted=1
return
}
#
#-----------------------------------------------------------------------------
# delete_applications()
#
# This routine is run when the -d option is selected.
#-----------------------------------------------------------------------------
delete_applications()
{
#-----------------------------------------------------------------------------
# For each application in $data_file, delete the application from the
# application line of the resource file, and remove corresponding commands.
#-----------------------------------------------------------------------------
cp $data_file $temp_appl_command_file
cp $mcc_resource_file $temp_resource_file
while [ -s "$temp_appl_command_file" ]
do
set_current_application
echo "$current_application" >"$egrep_command_file"
search_for_application=`more $mcc_resource_file | grep mcc_pml.applications: | egrep -f $egrep_command_file`
rm $egrep_command_file
if [ "$search_for_application" ]; then
delete_appl_and_commands
echo ""
echo "mcc_add_applications: Deleted application '$current_application'."
else
echo ""
echo "mcc_add_applications: Application '$current_application'"
echo " does not exist. No changes made to resource file."
fi
done
#-----------------------------------------------------------------------------
# Rename temporary file to $mcc_resource_file.
#-----------------------------------------------------------------------------
if [ $global_application_deleted -eq 1 ]; then
cp $mcc_resource_file ${mcc_resource_file}_old
mv $temp_resource_file $mcc_resource_file
fi
return
}
#
#=============================================================================
# Script Start
#=============================================================================
#-----------------------------------------------------------------------------
# Set some variables
#-----------------------------------------------------------------------------
pid=$$
temp_resource_file="/usr/tmp/mcc_${pid}_resource.dat"
temp_resource_file2="/usr/tmp/mcc_${pid}_resource.dat2"
sed_command_file="/usr/tmp/mcc_${pid}_sed_commands.dat"
egrep_command_file="/usr/tmp/mcc_${pid}_egrep_commands.dat"
temp_appl_command_file="/usr/tmp/mcc_${pid}_appl_commands.dat"
temp_appl_command_file2="/usr/tmp/mcc_${pid}_appl_commands.dat2"
global_application_added=0
global_application_deleted=0
error_occurred=0
#-----------------------------------------------------------------------------
# Trap errors
#-----------------------------------------------------------------------------
trap 'cleanup' 0
trap 'trap_error' 1 2 3 15
#-----------------------------------------------------------------------------
# Set variables for filespecs using parameters if present. Otherwise
# use defaults:
#
# $2 = new application data file
# [/usr/lib/X11/app-defaults/mcc_resource_appl.dat]
#
# $3 = mcc_resource.dat
# [/usr/lib/X11/app-defaults/mcc_resource.dat]
#-----------------------------------------------------------------------------
if [ "$1" = "" ]; then
echo ""
echo " Usage: mcc_add_applications <option> [<appl-datafile>] [<mcc_resource file>]"
echo "Options: -a to add application(s)"
echo " -d to delete application(s)"
error_occurred=1
exit
fi
case "$1" in
-a) ;;
-d) ;;
*) echo ""
echo ""
echo " Usage: mcc_add_applications <option> [<appl-datafile>] [<mcc_resource file>]"
echo "Options: -a to add application(s)"
echo " -d to delete application(s)"
error_occurred=1
exit
;;
esac
if [ $2 ]; then
data_file=$2
else
data_file="/usr/lib/X11/app-defaults/mcc_resource_appl.dat"
fi
if [ $3 ]; then
mcc_resource_file=$3
else
mcc_resource_file="/usr/lib/X11/app-defaults/mcc_resource.dat"
fi
if [ ! -f "$data_file" ]; then
echo ""
echo "mcc_add_applications: Error opening the data file"
echo " $data_file."
echo " No changes made to resource file."
error_occurred=1
exit
fi
if [ ! -f "$mcc_resource_file" ]; then
echo ""
echo "mcc_add_applications: Error opening the data file"
echo " $mcc_resource_file."
echo " No changes made to resource file."
error_occurred=1
exit
fi
case "$1" in
-a) add_applications
;;
-d) delete_applications
;;
esac
#-----------------------------------------------------------------------------
# Remove all temporary files (cleanup) and exit. Cleanup done by trap 0.
#-----------------------------------------------------------------------------
echo ""
exit
#=============================================================================
# Script End
#=============================================================================
|