#!/bin/sh

# slice
# Copyright (C) 2010, 2011, 2012 Joseph Rosevear, San Diego CA, USA.

# This file is part of The SAM Kernel.

# The SAM Kernel 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 3 of the
# License, or (at your option) any later version.

# The SAM Kernel 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, see <http://www.gnu.org/licenses/>.



# JHR 100103

# 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.

# JHR 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.

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

# JHR 111231 I changed #!/bin/sh to #!/bin/bash.



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