1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) XXXX-2008 - INRIA
3 // Copyright (C) 2008-2011 - DIGITEO - Allan CORNET
5 // This file must be used under the terms of the CeCILL.
6 // This source file is licensed as described in the file COPYING, which
7 // you should have received as part of this distribution. The terms
8 // are also available at
9 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
12 function varargout = fscanf(fil, frmt)
14 // fscanf - Emulator of C language fscanf
16 warnobsolete("mfscanf","5.5.0");
21 error(999, msprintf(gettext("%s: Wrong number of input arguments: %d expected.\n"),"fscanf", 2));
26 error(999, msprintf(gettext("%s: Wrong number of output argument(s).\n"),"fscanf"));
29 if type(fil)<>10 & type(fil)<> 1 then
30 error(999, msprintf(gettext("%s: Wrong type for input argument #%d: A file descriptor expected.\n"),"fscanf",1));
33 if size(fil,"*")<>1 then
34 error(999, msprintf(gettext("%s: Wrong size for input argument #%d: A file descriptor expected.\n")),"fscanf",1);
37 if type(frmt)<>10 then
38 error(999, msprintf(gettext("%s: Wrong type for input argument #%d: String expected.\n"),"fscanf",2));
41 if size(frmt,"*")<>1 then
42 error(999, msprintf(gettext("%s: Wrong size for input argument #%d: A string expected.\n")),"fscanf",2);
46 if type(fil) == 1 then
48 if ~or(fids == fil) then
49 error(999, msprintf(gettext("%s: Wrong value for input argument #%d: A valid file descriptor expected.\n"), "fscanf", 1));
55 args = strcat( v(ones(lhs, 1)) + string(1:lhs)', ",");
57 if (type(fil) == 1) then
58 [id, typ, fn] = file(fil);
60 buf = read(fil, 1, 1, "(a)");
68 execstr("[v0," + args + "] = msscanf(buf, frmt);"); // v0 is the number of data raed
69 execstr("varargout = list(" + args + ");");