Merge remote-tracking branch 'origin/master' into windows
[scilab.git] / scilab / modules / history_manager / sci_gateway / cpp / sci_loadhistory.cpp
1 /*
2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2011 - DIGITEO - Cedric DELAMARRE
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
17 #include "history_manager_gw.hxx"
18 #include "HistoryManager.hxx"
19 #include "function.hxx"
20 #include "string.hxx"
21
22 extern "C"
23 {
24 #include "sci_malloc.h"
25 #include "localization.h"
26 #include "Scierror.h"
27 #include "charEncoding.h"
28 #include "expandPathVariable.h"
29 }
30 /*--------------------------------------------------------------------------*/
31
32 types::Function::ReturnValue sci_loadhistory(types::typed_list &in, int _iRetCount, types::typed_list &out)
33 {
34     if (in.size() == 0)
35     {
36         char* pstFilename = HistoryManager::getInstance()->getFilename();
37         if (pstFilename)
38         {
39             BOOL bOK = HistoryManager::getInstance()->loadFromFile(pstFilename);
40             if (!bOK)
41             {
42                 Scierror(999, _("%s: loadScilabHistoryFromFile failed.\n"), "loadhistory");
43                 return types::Function::Error;
44             }
45             FREE(pstFilename);
46         }
47         else
48         {
49             Scierror(999, _("%s: getFilenameScilabHistory failed.\n"), "loadhistory");
50             return types::Function::Error;
51         }
52     }
53     else if (in.size() == 1)
54     {
55         if ((in[0]->isString() == false) || (in[0]->getAs<types::String>()->isScalar() == false))
56         {
57             Scierror(999, _("%s: Wrong type for input argument #%d: string expected.\n"), "loadhistory", 1);
58             return types::Function::Error;
59         }
60
61         char* pstFilename = expandPathVariable(in[0]->getAs<types::String>()->get(0));
62         BOOL bOK = HistoryManager::getInstance()->loadFromFile(pstFilename);
63         FREE(pstFilename);
64         if (!bOK)
65         {
66             Scierror(999, _("%s: Load Scilab history from file failed.\n"), "loadhistory");
67             return types::Function::Error;
68         }
69     }
70     else
71     {
72         Scierror(77, _("%s: Wrong number of input argument(s): %d to %d expected.\n"), "loadhistory", 0, 1);
73         return types::Function::Error;
74     }
75     return types::Function::OK;
76 }
77 /*--------------------------------------------------------------------------*/
78