Aller au contenu principal

replace

Replace current execution file.

REPLACE

NAME

replace - Replace current execution file.

SYNOPSIS

replace([keep_variables: bool, ct:"string",error:variable,textfile:binaryfile:file:compilefile:"file", …]);

DESCRIPTION

This function is used to replace current execution files.

At first, the current output buffer is clear, than the specify file is compile/run/read and the program stop.

If parameter textfile is used with a file, than the file is read.

If parameter binaryfile is used with a file, than the file is assumed to to be a compiled extenso file. The file is executed and the result return.

If parameter compilefile is used with a file, than the file is assumed to to be a source extenso file. The file is compile, executed and the result is return.

If parameter file is used with a file, or if only a file name is given, than there is 3 possibilities:

  • If the file extension is snc, the file is assumed to be a compiled extenso binary file. The file is executed and the result is return.
  • If the file extension is sn, the file is assumed to be a source extenso file. The file is compile, executed and the result is return.
  • All other extension are read

PARAMETERS

ct
Specify content-type for the file.
keep_variables
When executing the new file, a new virtual machine is set. This virtual machine does not keep the old variables. If you want to keep them, you have to set this parameter to true.
error
If an error occur while reading the file, the error variable will be set. If no error occured, this is useless since the program stop execution after replace. This variable is an hash array which contain the following:
res={_{ replace(error:t,"/html/oijfwi"); t;}}.

{"errmsg":"At line=1,errcode=20 Can't open file: /usr/local/website/v5/html/oijfwi: No such file or directory",
        "filename":"/usr/local/website/v5/html/tests/test.sn",
        "cfile":"exceptions.c",
        "errcode":20,
        "filefrom":"/usr/local/website/v5/html/tests/test.sn",
        "line":1,
        "cline":540,
        "compileuid":0,
        "date":"2013-09-19 07:57:43"}.

EXAMPLES

Note: In the followings examples, the _ between the { should be removed to make it work.

res={_{ replace("/html/oijfwi"); }}. return .*Can't open file.*
res={_{ replace("/html/oijfwi.sn"); }}. return .*Can't open file.*
res={_{ replace(error:t,"/html/oijfwi"); t.errcode;}}. return 20.
res={_{ replace(error:t,"/html/oijfwi.sn"); t.errcode}}. return 20.
res={_{ replace(error:t,"/html/replace1.html"); t}}. return simple text file
res={_{ replace(); }}. return
res={_{ replace("/html/replace1.html"); }}. return simple text file
res={_{ replace(ct:"text/xml","/html/replace1.html"); }}. return simple text file
res={_{
                remove("/tmp/tib.sn");
                write(data:"test 30",file:"/tmp/tib.sn");
                compile(error:t,src:"/tmp/tib.sn",dst:"/tmp/tib.snc");
                replace("/tmp/tib.snc");
                }}. return test 30
res={_{
                remove("/tmp/tib.sn");
                write(data:"test 30",file:"/tmp/tib.sn");
                compile(error:t,src:"/tmp/tib.sn",dst:"/tmp/tib.snc");
                replace(binaryfile:"/tmp/tib.snc");
                }}. return test 30
res={_{
                remove("/tmp/tib.sn");
                write(data:"test 30",file:"/tmp/tib.sn");
                replace(file:"/tmp/tib.sn");
                }}. return test 30
res={_{
                remove("/tmp/tib.sn");
                write(data:"test 30",file:"/tmp/tib.sn");
                replace("/tmp/tib.sn");
                }}. return test 30
res={_{
                remove("/tmp/tib.sn");
                write(data:"test 30",file:"/tmp/tib.sn");
                replace(compilefile:"/tmp/tib.sn");
                }}. return test 30

SEE ALSO

{{ include("includes/files.sn") }}

AUTHOR

Written by Pierre Laplante, <laplante@sednove.com>

MODIFICATIONS

1.0 2014-09-09 21:24:14 laplante@sednove.com

Edit

© 2024 extenso Inc. All rights reserved.