summaryrefslogtreecommitdiff
path: root/lib/sbin/CSTUtils.pl
diff options
context:
space:
mode:
authorgoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>2004-08-17 18:30:19 +0000
committergoodale <goodale@17b73243-c579-4c4c-a9d2-2d5706c11dac>2004-08-17 18:30:19 +0000
commitfec387a8e2d38c46397a0cf32b17d61e50e48e76 (patch)
tree124c62aad641dee866d189fec09ef5cc5e56d36d /lib/sbin/CSTUtils.pl
parentf3c9aae0de05d708d1c1c257ac73243d8d33b6ad (diff)
More sophisticated comment removal - now does a better job with # in quoted
string. Patch from Yaakoub for PR 1086. git-svn-id: http://svn.cactuscode.org/flesh/trunk@3831 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/sbin/CSTUtils.pl')
-rw-r--r--lib/sbin/CSTUtils.pl96
1 files changed, 95 insertions, 1 deletions
diff --git a/lib/sbin/CSTUtils.pl b/lib/sbin/CSTUtils.pl
index ac733f4a..765b666b 100644
--- a/lib/sbin/CSTUtils.pl
+++ b/lib/sbin/CSTUtils.pl
@@ -110,7 +110,8 @@ sub read_file
chomp;
# Remove comments.
- $_ =~ s/\#.*//;
+ $_ = &RemoveComments($_);
+# $_ =~ s/\#.*//;
# Ignore empty lines.
next if(m/^\s*$/);
@@ -355,4 +356,97 @@ sub SplitWithStrings
}
+#/*@@
+# @routine RemoveComments
+# @date
+# @author Tom Goodale, Yaakoub El Khamra
+# @desc
+# Removes comments from lines
+# @enddesc
+# @calls
+# @calledby
+# @history
+#
+# @endhistory
+#
+# @var line
+# @vdesc line to remove comments from
+# @vtype string
+# @vio in
+# @endvar
+#
+# @returntype line
+# @returndesc
+# line without comments
+# @endreturndesc
+#@@*/
+sub RemoveComments
+{
+ my ($line) = @_;
+ my $nocomment = $line;
+ my $insstring = 0;
+ my $indstring = 0;
+ my $escaping = 0;
+ my $token="";
+
+ for $i (split(//,$line))
+ {
+
+ if($i eq '\\')
+ {
+ if($escaping)
+ {
+ $token .= $i;
+ }
+
+ $escaping = 1 - $escaping;
+ }
+ elsif($i eq '"' && ! $insstring && ! $escaping)
+ {
+ $token = "";
+ $indstring = 1 - $indstring;
+ }
+ elsif($i eq "'" && ! $indstring && ! $escaping)
+ {
+ $token = "";
+ $insstring = 1 - $insstring;
+ }
+ elsif($i =~ /^\s+$/ && ! $insstring && ! $indstring && ! $escaping)
+ {
+ $token = "";
+ }
+ elsif($i eq '=' && ! $insstring && ! $indstring && ! $escaping)
+ {
+ $token = "";
+ }
+ elsif($i eq '#' && ! $insstring && ! $indstring && ! $escaping)
+ {
+ $nocomment =~ s/\#.*//;
+ return $nocomment;
+ }
+ else
+ {
+ if($escaping)
+ {
+ $token .= "\\";
+ $escaping = 0;
+ }
+ $token .= "$i";
+ }
+ }
+
+ if($insstring || $indstring)
+ {
+ print "Error: Unterminated string while parsing interface for thorn : $thorn\n";
+ print $nocomment;
+ }
+
+ if($escaping)
+ {
+ $token .= '\\';
+ }
+
+ return $nocomment;
+}
+
1;