detecting .m file name

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

detecting .m file name

wkim+
I'm using Octave 2.0.13 for OS/2.

Can I know .m file name when it is running?  (like program_name)
I want to detect which .m file is running, for a batch job.

Thanks.

//--------------------------------------------------------------------
// Wonkoo Kim ([hidden email])


Reply | Threaded
Open this post in threaded view
|

detecting .m file name

John W. Eaton-6
On 21-Jun-1998, Wonkoo Kim <[hidden email]> wrote:

| I'm using Octave 2.0.13 for OS/2.
|
| Can I know .m file name when it is running?  (like program_name)
| I want to detect which .m file is running, for a batch job.

It's not clear to me exactly what you want.  Can you give an example?

If it is to get the name of a script file while it is running,
program_name gives you that provided that you are running it with

  octave script.m

or

  ./script.m

(by using the `#!' hack on Unixy systems and making the file script.m
executable).

jwe


Reply | Threaded
Open this post in threaded view
|

Re: detecting .m file name

wkim+
In reply to this post by wkim+
> Date: Mon, 22 Jun 98 23:53:18 -0500
> From: "John W. Eaton" <[hidden email]>
> Subject: detecting .m file name
>
> On 21-Jun-1998, Wonkoo Kim <[hidden email]> wrote:
>
> | I'm using Octave 2.0.13 for OS/2.
> |
> | Can I know .m file name when it is running?  (like program_name)
> | I want to detect which .m file is running, for a batch job.
>
> It's not clear to me exactly what you want.  Can you give an example?

Oh, sorry.  

Suppose "foo.m" has a line:

  eval(sprintf("gset output \"%s.ps\"", this_script_name));

and I want the above line does

  gset output "foo.ps"  (or, gset output "foo.m.ps")

when I run it from Octave.

> If it is to get the name of a script file while it is running,
> program_name gives you that provided that you are running it with
>
>   octave script.m
>
> or
>
>   ./script.m
>
> (by using the `#!' hack on Unixy systems and making the file script.m
> executable).

If I put 'program_name' in foo.m, I got

octave:2>foo
program_name = octave.exe

but I want "foo" or "foo.m".

Thanks.

//--------------------------------------------------------------------
// Wonkoo Kim ([hidden email])


Reply | Threaded
Open this post in threaded view
|

Re: detecting .m file name

John W. Eaton-6
On 23-Jun-1998, Wonkoo Kim <[hidden email]> wrote:

| Suppose "foo.m" has a line:
|
|   eval(sprintf("gset output \"%s.ps\"", this_script_name));
|
| and I want the above line does
|
|   gset output "foo.ps"  (or, gset output "foo.m.ps")
|
| when I run it from Octave.

Please try the following patch.

Thanks,

jwe


Tue Jun 23 15:09:54 1998  John W. Eaton  <[hidden email]>

        * variables.cc (clear_current_script_file_name): New function.
        (parse_fcn_file): Bind current_script_file_name while script is
        executing.  Use unwind_protect to clear it once the script is
        finished.


*** src/variables.cc~ Wed May 13 22:49:15 1998
--- src/variables.cc Tue Jun 23 15:49:46 1998
***************
*** 636,641 ****
--- 636,647 ----
      fclose ((FILE *) f);
  }
 
+ static void
+ clear_current_script_file_name (void *)
+ {
+   bind_builtin_variable ("current_script_file_name", octave_value ());
+ }
+
  int
  parse_fcn_file (const string& ff, bool exec_script, bool force_script)
  {
***************
*** 732,737 ****
--- 738,747 ----
 
   Vsaving_history = 0;
   reading_script_file = 1;
+
+  add_unwind_protect (clear_current_script_file_name, 0);
+
+  bind_builtin_variable ("current_script_file_name", ff);
 
   parse_and_execute (ffile, 1);