Menu

[0c50c7]: / lib / journal.sh  Maximize  Restore  History

Download this file

82 lines (71 with data), 2.5 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- shell-script -*-
# Things related to variable journaling.
#
# Copyright (C) 2002, 2003, 2004, 2006, 2008, 2009,
# 2010, 2011 Rocky Bernstein <rocky@gnu.org>
#
# This program 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 2, 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
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, 59 Temple Place, Suite 330, Boston,
# MA 02111 USA.
# We use a journal file to save variable state so that we can pass
# values set in a subshell or nested shell back. This typically
# includes debugger information, e.g. breakpoints and state. This file
# is just code (usually assignment statements) that get eval'd.
# The file to save the journal information.
typeset _Dbg_journal=$(_Dbg_tempname journal)
# append a command into journal file and then run the command.
_Dbg_write_journal_eval() {
_Dbg_write_journal "$@"
eval "$@"
}
# append a command into journal file and then run the command.
_Dbg_write_journal_var() {
typeset var_name="$1"
typeset val
typeset val_cmd="val='\${$var_name}'"
eval "$val_cmd"
_Dbg_write_journal "${var_name}='${val}'"
}
_Dbg_write_journal_avar() {
typeset decl_str; decl_str=$(declare -p $1)
typeset -a decl_a
decl_a=($decl_str)
typeset -a decl_a2
decl_a2=${decl_a[@]:2}
_Dbg_write_journal ${decl_a2[@]}
}
# Append a command into journal file. But we only need to do
# if we are in a subshell.
_Dbg_write_journal() {
if (( BASH_SUBSHELL != 0 )) ; then
echo "$@" >> ${_Dbg_journal} 2>/dev/null
fi
# return $?
}
# Remove all journal files.
_Dbg_erase_journals() {
[[ -f $_Dbg_journal ]] && rm ${_Dbg_journal} 2>/dev/null
return $?
}
# read in or "source" in journal file which will set variables.
_Dbg_source_journal() {
if [ -r $_Dbg_journal ] ; then
. "$_Dbg_journal"
(( BASH_SUBSHELL == 0 )) && _Dbg_erase_journals
fi
}
if [ ! -f _Dbg_journal ] ; then
typeset -i _Dbg_QUIT_LEVELS=0
_Dbg_write_journal "_Dbg_QUIT_LEVELS=0"
fi
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.