1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
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 extern "C" {
17 #include "gw_gui.h"
18 #include "api_scilab.h"
19 #include "Scierror.h"
20 #include "localization.h"
21 #include "createGraphicObject.h"
22 #include "getGraphicObjectProperty.h"
23 #include "graphicObjectProperties.h"
24 #include "HandleManagement.h"
25 #include "FileExist.h"
26 #include "expandPathVariable.h"
27 }
28
sci_loadGui(char * fname,void * pvApiCtx)29 int sci_loadGui(char *fname, void* pvApiCtx)
30 {
31 SciErr sciErr;
32 int* piAddr = NULL;
33 char* pstFile = NULL;
34 char* pstFullFile = NULL;
35
36 int iRhs = nbInputArgument(pvApiCtx);
37
38 CheckInputArgument(pvApiCtx, 1, 1);
39 CheckOutputArgument(pvApiCtx, 0, 1);
40
41 sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddr);
42 if (sciErr.iErr)
43 {
44 printError(&sciErr, 0);
45 return 1;
46 }
47
48 if (isStringType(pvApiCtx, piAddr) == 0 || isScalar(pvApiCtx, piAddr) == 0)
49 {
50 Scierror(999, _("%s: Wrong size for input argument #%d: string expected.\n"), fname, 1);
51 return 1;
52 }
53
54
55 if (getAllocatedSingleString(pvApiCtx, piAddr, &pstFile))
56 {
57 if (pstFile)
58 {
59 freeAllocatedSingleString(pstFile);
60 }
61
62 Scierror(202, _("%s: Wrong type for argument #%d: string expected.\n"), fname, 1);
63 return 1;
64 }
65
66 pstFullFile = expandPathVariable(pstFile);
67 if (!FileExist(pstFullFile))
68 {
69 Scierror(999, _("%s: This file %s does not exist.\n"), fname, pstFile);
70 freeAllocatedSingleString(pstFile);
71 freeAllocatedSingleString(pstFullFile);
72 return 0;
73 }
74
75 int iFig = xmldomload(pstFullFile);
76 if (iFig < 1)
77 {
78 Scierror(999, _("%s: can not read file %s.\n"), fname, pstFile);
79 freeAllocatedSingleString(pstFile);
80 freeAllocatedSingleString(pstFullFile);
81 return 0;
82 }
83
84 freeAllocatedSingleString(pstFile);
85
86 long long h = (long long)getHandle(iFig);
87 createScalarHandle(pvApiCtx, iRhs + 1, h);
88 AssignOutputVariable(pvApiCtx, 1) = iRhs + 1;
89 ReturnArguments(pvApiCtx);
90 return 0;
91 }
92