Goto main content

read

Read a file.

READ

NAME

read - Reads a file.

SYNOPSIS

read([error:variable,]textfile:binaryfile:file:compilefile:"file", …);

DESCRIPTION

This function is used to read files. Cannot read PDF file.

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

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

If the "compilefile" parameter is used with a file, then the file is assumed to be a source extenso file. The file is compiled, executed and the result is returned.

If the "file" parameter is used with a file, or if only a file name is given, then there are 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 returned.
  • 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 returned.
  • All other extensions are read.

If the "error" parameter is used, errors will be stored in this variable. Error variables will contain:

{
        "errmsg":"Errcode=14 Can't open text file: ..."
        "filename":"/usr/local/website/v5/html/tests/test.sn",
        "cfile":"files.c",
        "errcode":14,
        "filefrom":"/usr/local/website/v5/html/tests/test.sn",
        "line":4,"error":"Can't open text file: /usr/local/website/v5/html/tests/areiuhgiwuerhgiew: No such file or directory",
        "cline":2622,
        "compileuid":0,
        "date":"2014-03-26 11:36:12"
}.

If there is no error, errcode will be zero.

EXAMPLES

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

res={_{ read("/xyxyx"); }}. return .*No such file or directory.*

res={_{ void generate(compile:true,file:"/tests/test-read-generate.snc",template:"/tests/test-read-generate.sn");
        a=read("/tests/test-read-generate.snc"); a; }}. return res=res from sample = 512 11.
code later:
This will be executed later11.
.

res={_{ a=read("/tests/test-read-generate.snc"); a; }}. return res=res from sample = 512 11.
code later:
This will be executed later11.
.

res={_{ a=read(binaryfile:"/tests/test-read-generate.snc"); a; }}. return res=res from sample = 512 11.
code later:
This will be executed later11.
.

res={_{ a=read("/tests/sample.sn"); a; UWRITE;}}. return res=res from sample = 512 11.undefined.

res={_{ a=read(compilefile:"/tests/sample.sn"); a; UWRITE;}}. return res=res from sample = 512 11.undefined.

res={_{ a=read("/tests/testread",textfile:"/includes/extenso.sn"); a =~ "GWRITE"; a=~"multiline";}}. return res=truetrue.

res={_{ a=read("/tests/testread",textfile:"/includes/extenso.sn"); a =~ "GWRITE"; a =~[i] "Multiline";}}. return res=truetrue.

res={_{ a=read("/tests/testread",textfile:"/includes/extenso.sn"); a =~ "GWRITE"; a =~"Multiline";}}. return res=truefalse.

res={_{ a=read("/tests/testread",textfile:"/includes/extenso.sn"); a =~ "GWRITE"; a !~"Multiline";}}. return res=truetrue.

res={_{ a=read("/tests/testread",textfile:"/includes/extenso.sn"); a =~ "GWRITE"; a !~[i]"Multiline";}}. return res=truefalse.

res={_{ a=read("/tests/testread",textfile:"/includes/extenso.sn"); a =~[xi]"
        # Match the keywork Multiline
        Multiline";}}. return res=true.

SEE ALSO

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

AUTHOR

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

MODIFICATIONS

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

Edit

© 2021 extenso Inc. All rights reserved.