#577 GPVAL_SCRIPT

None
closed-accepted
nobody
None
5
2014-01-10
2012-02-07
No

We cannot use the script name in the script file since $0 means the first option. Attached patch may be for saving the script name to GPVAL_SCRIPT
to enable us to use the script name in the script as:

set title sprintf("made by %s",GPVAL_SCRIPT)

This feature is proposed on a Japanese BBS for gnuplot.

Discussion

  • Shigeharu TAKENO

    a patch to save the script name to GPVAL_SCRIPT

     
  • Ethan Merritt

    Ethan Merritt - 2012-02-07

    Hmm. I don't think this works.
    The variable GPVAL_SCRIPT will be over-written each time a script file is opened, but it is never restored when the script exits.
    So if you do:
    main: load "A"
    A: load "B"
    B: .... exit;
    At this point the program is back in A but GPVAL still says B.

     
  • Ethan Merritt

    Ethan Merritt - 2012-02-07

    Maybe it would be possible to instead load GPVAL_SCRIPT in the routines lf_push() and lf_pop()?

     
  • Shigeharu TAKENO

    > At this point the program is back in A but GPVAL still says B.

    Yes, you are right.

    > Maybe it would be possible to instead load GPVAL_SCRIPT in the routines
    > lf_push() and lf_pop()?

    Maybe.

    But I may admit the stack version and not stack version which
    can not follow the current script name correctly, because we may
    save the value GPVAL_SCRIPT to another variable before loading
    the next script B if we need the script name of A.

     
  • Shigeharu TAKENO

    I rewrote a patch for stack version and tested it.

    ----- test script (csh script) -----
    #! /bin/csh -f
    cat <<EOF > t@1.gp
    print sprintf("t@1.gp:1: %s\n",GPVAL_SCRIPT);
    load "t@2.gp"
    print sprintf("t@1.gp:2: %s\n",GPVAL_SCRIPT);
    EOF

    cat <<EOF > t@2.gp
    print sprintf("t@2.gp:1: %s\n",GPVAL_SCRIPT);
    load "t@3.gp"
    print sprintf("t@2.gp:2: %s\n",GPVAL_SCRIPT);
    EOF

    cat <<EOF > t@3.gp
    print sprintf("t@3.gp:1: %s\n",GPVAL_SCRIPT);
    EOF

    gnuplot t@1.gp

    ----- Result -----
    t@1.gp:1: t@1.gp

    t@2.gp:1: t@2.gp

    t@3.gp:1: t@3.gp

    t@2.gp:2: t@2.gp

    t@1.gp:2: t@1.gp

     
  • Ethan Merritt

    Ethan Merritt - 2014-01-10

    The name of the current script is now stored in ARG0. This is true for both "load" and "call" commands.

     
  • Ethan Merritt

    Ethan Merritt - 2014-01-10
    • status: open --> closed-accepted
    • Group: -->
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks