2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4 * Copyright (C) DIGITEO - 2010 - Allan CORNET
6 * Copyright (C) 2012 - 2016 - Scilab Enterprises
8 * This file is hereby licensed under the terms of the GNU GPL v2.0,
9 * pursuant to article 5.3.4 of the CeCILL v.2.1.
10 * This file was originally licensed under the terms of the CeCILL v2.1,
11 * and continues to be available under such terms.
12 * For more information, see the COPYING file which you should have received
13 * along with this program.
16 /*--------------------------------------------------------------------------*/
21 #include "freeArrayOfString.h"
22 #include "sci_malloc.h"
23 /*--------------------------------------------------------------------------*/
25 /*--------------------------------------------------------------------------*/
26 int LineRead(int fd, char buf[], int n, int *cnt, int *nr)
28 int returnedInfo = READNEXTLINE_ERROR_ERROR_UNMANAGED;
29 int nbLinesToRead = 1;
30 int nbLinesReaded = 0;
31 int mgetIerr = MGETL_ERROR;
33 wchar_t **lines = mgetl(fd, nbLinesToRead, &nbLinesReaded, &mgetIerr);
34 char* line = wide_string_to_UTF8(lines[0]);
35 freeArrayOfWideString(lines, nbLinesReaded);
41 strcpy(buf, EMPTYSTR);
47 if (line && nbLinesReaded == 1)
49 /* current limitation (bsiz) of line readed by scilab */
50 if ((int)strlen(line) < bsiz)
53 returnedInfo = READNEXTLINE_ERROR_EOL;
57 strncpy(buf, line, bsiz);
58 returnedInfo = READNEXTLINE_ERROR_BUFFER_FULL;
63 returnedInfo = READNEXTLINE_ERROR_EOF_REACHED;
72 if (nbLinesReaded == 0)
74 returnedInfo = READNEXTLINE_ERROR_EOF_REACHED;
78 /* current limitation (bsiz) of line readed by scilab */
79 if ((int)strlen(line) >= bsiz)
82 returnedInfo = READNEXTLINE_ERROR_EOF_REACHED_AFTER_EOL;
86 strncpy(buf, line, bsiz);
87 returnedInfo = READNEXTLINE_ERROR_BUFFER_FULL;
93 returnedInfo = READNEXTLINE_ERROR_EOF_REACHED_BEFORE_EOL;
98 case MGETL_MEMORY_ALLOCATION_ERROR:
102 returnedInfo = READNEXTLINE_ERROR_ERROR_UNMANAGED;
107 *cnt = (int)strlen(buf) + 1;
117 /*--------------------------------------------------------------------------*/
118 void C2F(readnextline)(int *fd, char buf[], int *n, int *count, int *nr, int *ierr)
120 *ierr = LineRead(*fd, buf, *n, count, nr);
122 /*--------------------------------------------------------------------------*/