1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) DIGITEO - 2009 - Allan CORNET
4 *
5 * Copyright (C) 2012 - 2016 - Scilab Enterprises
6 *
7 * This file is hereby licensed under the terms of the GNU GPL v2.0,
8 * pursuant to article 5.3.4 of the CeCILL v.2.1.
9 * This file was originally licensed under the terms of the CeCILL v2.1,
10 * and continues to be available under such terms.
11 * For more information, see the COPYING file which you should have received
12 * along with this program.
13 *
14 */
15 /*--------------------------------------------------------------------------*/
16 #include "api_scilab.h"
17 #include "localization.h"
18 #include "Scierror.h"
19 #include "BOOL.h"
20 #include "freeArrayOfString.h"
21 #include "sci_malloc.h"
22 #include "getPartLine.h"
23 /*--------------------------------------------------------------------------*/
sci_getfilepartlevel(char * fname,void * pvApiCtx)24 int sci_getfilepartlevel(char *fname, void *pvApiCtx)
25 {
26 SciErr sciErr;
27 int* piAddr = NULL;
28 char* pcInput = NULL;
29 char* pcOutput = NULL;
30
31 CheckInputArgument(pvApiCtx, 1, 1);
32 CheckOutputArgument(pvApiCtx, 0, 1);
33
34 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
35 if (sciErr.iErr)
36 {
37 printError(&sciErr, 0);
38 return 1;
39 }
40
41 if (getAllocatedSingleString(pvApiCtx, piAddr, &pcInput))
42 {
43 Scierror(999, _("%s: Wrong type for argument #%d: A scalar string expected.\n"), fname, 1);
44 return 1;
45 }
46
47 pcOutput = getFilePartLevel(pcInput);
48 freeAllocatedSingleString(pcInput);
49
50 if (pcOutput == NULL)
51 {
52 createSingleString(pvApiCtx, *getNbInputArgument(pvApiCtx) + 1, "");
53 }
54 else
55 {
56 createSingleString(pvApiCtx, *getNbInputArgument(pvApiCtx) + 1, pcOutput);
57 FREE(pcOutput);
58 pcOutput = NULL;
59 }
60
61 AssignOutputVariable(pvApiCtx, 1) = 2; // rhs + 1
62 ReturnArguments(pvApiCtx);
63
64 return 0;
65 }
66 /*--------------------------------------------------------------------------*/
67