1#! /bin/sh
2#
3# newsyntax38 -- update a screenrc file from 3.3 to 3.8 syntax
4#
5# Please bring your scripts up to syntax level 3.3 before running this script.
6# Please check all comments after running this script and watch out 
7# for funny passages.
8#
9# * aka and shellaka are replaced by title and shelltitle.
10# 
11# * Pairs of termcap and terminfo commands are folded into a single 
12#   termcapinfo command where possible.
13#
14# * trailing blanks are zapped. Unintentionally.
15#
16# 12.10.95, jnweiger, use at your own risk.
17#
18if [ $# != 1 ]; then
19  echo "usage $0 screenrcfile"
20  echo ""
21  echo "The named file will be updated in place to the syntax of screen 3.8"
22  echo "A backup copy will be written to <screenrcfile>.bak"
23  exit 1;
24fi
25
26#Ultrix 4.2 /bin/sh does not handle "read a < $1" 
27#Dean Gaudet <dgaudet@watdragon.uwaterloo.ca>
28exec < $1
29read a
30
31if [ "$a" = "#3.8" ]; then
32  echo "$1 already updated"
33  exit 0
34fi
35
36rm -f $1.old $1.dups
37
38cp $1 $1.old
39echo "#3.8" > $1
40echo "# Do not remove the above line. This screen rc file was updated" >> $1
41echo "# by the newsyntax script." >> $1
42
43# termcap and terminfo lines can only be folded when there is no parameter
44# expansion in the codes. Parameters are denoted differently in 
45# termcap and termcap syntax. Everything else is identical, I assume.
46# Thus codes not containing '%' can be savely folded.
47
48sed < $1.old > $1.dups \
49-e 's/^\([	 #]*\)aka/\1title/' \
50-e 's/^\([	 #]*\)shellaka/\1shelltitle/' \
51-e 's/^\([	 #]*\)termcap[	 ][	 ]*\([^%]*$\)/\1termcapinfo \2/' \
52-e 's/^\([	 #]*\)terminfo[	 ][	 ]*\([^%]*$\)/\1termcapinfo \2/' \
53-e 's/\\/\\\\/g'
54
55# Oh, my bourne shell seems to gobble backslashes while reading.
56# Thus the sed above duplicates them in advance. 
57# Hope this is not just another silly bash featureism.
58# It still zaps trailing blanks. I do not know why. But that is nice.
59
60exec < $1.dups
61while read a ; do
62  if [ "$a" = "$b" ]; then
63    case "$a" in
64      *termcapinfo*) continue ;;
65    esac
66  fi
67  echo "$a" >> $1
68  b="$a"
69done
70
71rm -f $1.dups
72