diff options
Diffstat (limited to 'lib/sbin/CSTUtils.pl')
-rw-r--r-- | lib/sbin/CSTUtils.pl | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/sbin/CSTUtils.pl b/lib/sbin/CSTUtils.pl index 743186ad..e56a85e0 100644 --- a/lib/sbin/CSTUtils.pl +++ b/lib/sbin/CSTUtils.pl @@ -43,5 +43,97 @@ sub CST_error } + +#/*@@ +# @routine read_file +# @date Wed Sep 16 11:54:38 1998 +# @author Tom Goodale +# @desc +# Reads a file deleting comments and blank lines. +# @enddesc +# @calls +# @calledby +# @history +# @hdate Fri Sep 10 10:25:47 1999 @hauthor Tom Goodale +# @hdesc Allows a \ to escape the end of a line. +# @endhistory +#@@*/ + +sub read_file +{ + local($file) = @_; + local(@indata); + local($line); + + open(IN, "<$file") || die("Can't open $file\n"); + + $line = ""; + + while(<IN>) + { + $_ =~ s/\#.*//; + + next if(m/^\s+$/); + + &chompme($_); + + # Add to the currently processed line. + $line .= $_; + + # Check the line for line-continuation + if(m:[^\\]\\$:) + { + $line =~ s:\\$::; + } + else + { + push(@indata, $line); + $line = ""; + } + } + + # Make sure to dump out the last line, even if it ends in a \ + if($line ne "") + { + push(@indata, $line); + } + close IN; + + return @indata; +} + + +#/*@@ +# @routine chompme +# @date Mon 26th April 1999 +# @author Gabrielle Allen +# @desc +# Implements a version of the perl5 chomp function, +# returning the string passed in with the last character +# removed unless it is a newline +# @enddesc +# @calls +# @calledby +# @history +# +# @endhistory +#@@*/ + +sub chompme +{ + local($in) = @_; + + $lastchar = chop($in); + if ($lastchar == "\n") + { + return $_; + } + else + { + return $in; + } +} + + 1; |