#!/bin/sh

# `copyr $2`
# `state`

# Joseph Rosevear 100103 I wrote  this script.

# This script was made to solve a problem.  I first noticed the problem
# in relation to variable TERMCAP.  Doing a push and a pop causes it to
# get bigger with each push/pop use.  I tracked the problem down and
# found that my algorithm seemed to have a bug, although I still don't
# know why.

# In particular doing "declare -x" to make a file, then modifying that
# file by replacing "declare -x" with "export" to make another file,
# then sourcing that file... doesn't work.  (Actually I piped some of
# the above together.)

# As far as I know it works for all variables except for one, that is
# TERMCAP.  TERMCAP has a component called "kD" that has binary values. 
# Two of these values cause trouble.  They are (in base ten) 1 and 127
# or in base 8, 1 and 177.  The trouble is the algorithm I described
# above is a loop, and I assumed the loop could be looped (gone around)
# without things growing.  Not so.

# Here is a better statement of the loop.  In this let A be 1 and ? be
# 127 (both base ten).  I chose these names (A and ?), because they
# appear as A and ? (but with underlines) when viewed in editor JOE.

# Joseph Rosevear 120808 I changed the prgama back to #!/bin/sh,
# because due to changes in SAM the sh shell will work fine.



# Make a file (we'll call it <file>).

#   vvv
#   export HORSE="A?"
#   ^^^

# Here's the loop:

#    . <file>
#    declare -x > <file>
#    [in <file> replace "declare -x" with "export"]

# Looping through this causes

# ? -> A?
# A -> AA

# with each loop.  So I wrote the code below.  I use it in push.f to
# filter what comes out of "declare -x".

# This seems to work OK.  It keeps TERMCAP (and any other variable
# containing A or ?) from growing, and it doesn't seem to cause any
# trouble, although it is a bit early to be sure of that.

# Joseph Rosevear 110818 I replaced "source" with "." in the above
# comment section.  This is for improved POSIX compliance.

# Joseph Rosevear 111231 I changed #!/bin/sh to #!/bin/bash.



cat /dev/stdin | sed 's///g' | sed 's///g'
