If I have a "Hello World" function (just prints that) and a similar "Goodbye World" function... is there a way (maybe a compiler option?) that I can get them to be executed directly as the absolute first and last things run in every function call.
So for example, the following code:
should print out:
I assume from this model, that a simple find&replace would work, even using something like grep/sed to add a call to hello() as the first call, and a goodbye() as the last thing before any return/function-exit... but is this doable without manually (including a sed script as "manual") modifying the code? IE, is there a pre-call/post-call function wrapper?...
You can actually use a sed script to replace lines beginning with "{" and "}" with preprocessor directives:
Now the sed scripts:
Compile and make sure it works. Once it does, you can change your macros so that FBEGIN and FEND call a function too, like something that logs to a file:
Last edited by otheus; 09-09-2008 at 10:23 AM..
Reason: fixed sed script
I am trying to capture the exit status of a parent shell
in a subshell.
I am using the trap .. Exit command in the subshell
I cant use the export command in the parent shell to
to export a variable with the exit status to the subshell.
I would have tooooo many parent shells to change.
... (2 Replies)
Hello friends,
Kindly help me in developing a script that asks user to enter a value and will wait for 5 seconds for the feedback. If there is no answer from the user the script will perform exit or it will continue doing something else
Ex: If yu have a multi OS system i believe while... (3 Replies)
Hi all,
My kshell code is not working, when I use a function to return something. But when I use the same function as without returning any values, it is working. Pls help me here.
Code1 :
func1 () {
y=`echo $x | grep XXX| cut -f 2 -d ' '`
if ; then
exit 100
... (2 Replies)
Hi All,
I have a scenario where I am executing some child shell scripts in background (using &)through a master parent script.
Is there a way I can capture the exit status of each individual child script after the execution is completed. (2 Replies)
Hi,
I just want to exit from function if some condition doesnt meet then control should go back to main program and start running from where it left..
When i used "exit" inside the function, its simply exited from entire script and it didnt run anymore.. Any idea how to do this..
Thanks... (3 Replies)
Hi,
Is there a way to exit from a subcommand, which is a function in my example below?
#!/bin/ksh
function exitFunction {
if ]; then
echo "success"
elif ]; then
echo "failed"
exit 1 # the exit problem
fi
exit 0
}
... (2 Replies)
Below is my script that is function properly per my conditions but I am facing one problem here that is when one function fails then Iy should not check other functions but it calls the other function too So anyone can help me how could i achieve this?
iNOUT i AM GIVING TO THE... (1 Reply)
Hi,
I have a sub function called pressEnter within my perl menu script which basically means that the script will await an interaction from the user before moving on.
Unfortunately when the script goes into pressEnter it just hangs (even if you press enter!!).
Any ideas on what could be... (4 Replies)
Hi
I am pretty confused in returning and capturing multiple values
i have defined a function which should return values "total, difference"
i have used as
#!/usr/bin/ksh
calc()
{
total=$1+$2
echo "$total"
diff=$2-$1
echo "$diff"
}
I have invoked this function as
calc 5 8
Now i... (2 Replies)
Hi All,
Good Day, seeking for your assistance on how to not perform my 2nd, 3rd,4th etc.. function if my 1st function is in else condition.
#Body
function1()
{
if
then
echo "exist"
else
echo "not exist"
}
#if not exist in function1 my all other function will not proceed.... (4 Replies)
Discussion started by: meister29
4 Replies
LEARN ABOUT SUSE
code
code(n) [incr Tcl] code(n)
__________________________________________________________________________________________________________________________________________________NAME
code - capture the namespace context for a code fragment
SYNOPSIS
itcl::code ?-namespace name? command ?arg arg ...?
_________________________________________________________________DESCRIPTION
Creates a scoped value for the specified command and its associated arg arguments. A scoped value is a list with three elements: the
"@scope" keyword, a namespace context, and a value string. For example, the command
namespace foo {
code puts "Hello World!"
}
produces the scoped value:
@scope ::foo {puts {Hello World!}}
Note that the code command captures the current namespace context. If the -namespace flag is specified, then the current context is
ignored, and the name string is used as the namespace context.
Extensions like Tk execute ordinary code fragments in the global namespace. A scoped value captures a code fragment together with its
namespace context in a way that allows it to be executed properly later. It is needed, for example, to wrap up code fragments when a Tk
widget is used within a namespace:
namespace foo {
private proc report {mesg} {
puts "click: $mesg"
}
button .b1 -text "Push Me" -command [code report "Hello World!"]
pack .b1
}
The code fragment associated with button .b1 only makes sense in the context of namespace "foo". Furthermore, the "report" procedure is
private, and can only be accessed within that namespace. The code command wraps up the code fragment in a way that allows it to be exe-
cuted properly when the button is pressed.
Also, note that the code command preserves the integrity of arguments on the command line. This makes it a natural replacement for the
list command, which is often used to format Tcl code fragments. In other words, instead of using the list command like this:
after 1000 [list puts "Hello $name!"]
use the code command like this:
after 1000 [code puts "Hello $name!"]
This not only formats the command correctly, but also captures its namespace context.
Scoped commands can be invoked like ordinary code fragments, with or without the eval command. For example, the following statements work
properly:
set cmd {@scope ::foo .b1}
$cmd configure -background red
set opts {-bg blue -fg white}
eval $cmd configure $opts
Note that scoped commands by-pass the usual protection mechanisms; the command:
@scope ::foo {report {Hello World!}}
can be used to access the "foo::report" proc from any namespace context, even though it is private.
KEYWORDS
scope, callback, namespace, public, protected, private
itcl 3.0 code(n)