#!/usr/bin/env perl #-*- Mode: perl; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- # Functions for hacker debug. # # Copyright (C) 2000-2001 Ximian, Inc. # # Authors: Hans Petter Jansson # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Library General Public License as published # by the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program 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 Library General Public License for more details. # # You should have received a copy of the GNU Library General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. require "___scriptsdir___/general.pl"; require "___scriptsdir___/file.pl"; sub xst_debug_open_output_file { local *FILE; my $debug_path = &xst_file_get_debug_path () . "/$xst_name/1/$_[0]"; &xst_debug_rotate_try (); open (FILE, ">>$debug_path"); return *FILE; } sub xst_debug_print_string_to_file { my $debug_file; $debug_file = &xst_debug_open_output_file ($_[0]); print $debug_file $_[1]; close $debug_file; } sub xst_debug_print_string { if ($xst_debug) { print STDERR $_[0]; } &xst_debug_print_string_to_file ("debug", $_[0]); } sub xst_debug_print_line { &xst_debug_print_string ($_[0] . "\n"); } sub xst_debug_print_indent { my $indent = $_[0]; my $indent_string = ""; $indent_string = " " x $indent; &xst_debug_print_string ($indent_string); } sub xst_debug_print_indented_string { my ($indent, @string) = @_; &xst_debug_print_indent ($indent); &xst_debug_print_string (@string); } sub xst_debug_print_indented_line { my $indent = shift @_; my @line = @_; &xst_debug_print_indent ($indent); &xst_debug_print_line (@line); } sub xst_debug_print_struct { &xst_debug_print_struct_r (0, 0, @_); } sub xst_debug_print_struct_r { my ($indent) = $_[0]; my $is_hash_value = $_[1]; my $a = $_[2]; my $type; my @keys; my $elem; my $i; $type = ref $a; if (!$is_hash_value) { &xst_debug_print_indent ($indent); } if ($type eq "SCALAR") { &xst_debug_print_line ($$a); } elsif ($type eq "ARRAY") { &xst_debug_print_line ("[ARRAY]"); for ($i = 0; $i <= $#$a; $i++) { &xst_debug_print_struct_r ($indent, 0, $$a[$i]); } } elsif ($type eq "HASH") { @keys = sort keys (%$a); &xst_debug_print_line ("[HASH]"); foreach $i (@keys) { &xst_debug_print_indented_string ($indent + !$is_hash_value, $i . " -> "); &xst_debug_print_struct_r ($indent + !$is_hash_value + 1, 1, $$a{$i}); } } else { &xst_debug_print_line ($a); } } $xst_debug_dir_rotation_was_made = 0; sub xst_debug_rotate_try { my $debug_file = $_[0]; my $debug_tool_dir = &xst_file_get_debug_path () . "/$xst_name/"; # If this is the first debug created by this tool on this invocation, # rotate the debug directories and create a new, empty one. if (!$xst_debug_dir_rotation_was_made) { my $i; $xst_debug_dir_rotation_was_made = 1; if (stat ("$debug_tool_dir/9")) { &xst_file_run ("rm -Rf $debug_tool_dir/9"); } for ($i = 8; $i; $i--) { if (stat ("$debug_tool_dir/$i")) { &xst_file_run ("mv $debug_tool_dir/$i $debug_tool_dir/" . ($i+1)); } } &xst_file_create_path ("$debug_tool_dir/1"); } } 1;