License Header change: Removed the LICENSE_END before beta
[scilab.git] / scilab / modules / windows_tools / src / c / scilab_windows / ConvertSlash.c
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2008 - INRIA - 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 <string.h>
17 #include "BOOL.h"
18 #include "dynlib_scilab_windows.h"
19 /*--------------------------------------------------------------------------*/
20 #define UNIX_SEPATATOR '/'
21 #define WINDOWS_SEPATATOR '\\'
22 /*--------------------------------------------------------------------------*/
23 static BOOL convertSlash(char *path_in, char *path_out, BOOL slashToAntislash);
24 /*--------------------------------------------------------------------------*/
25 SCILAB_WINDOWS_IMPEXP BOOL slashToAntislash(char *pathunix, char *pathwindows)
26 {
27     return convertSlash(pathunix, pathwindows, TRUE);
28 }
29 /*--------------------------------------------------------------------------*/
30 SCILAB_WINDOWS_IMPEXP BOOL AntislashToSlash(char *pathwindows, char *pathunix)
31 {
32     return convertSlash(pathwindows, pathunix, FALSE);
33 }
34 /*--------------------------------------------------------------------------*/
35 static BOOL convertSlash(char *path_in, char *path_out, BOOL slashToAntislash)
36 {
37     BOOL bOK = FALSE;
38     if ( (path_in) && (path_out) )
39     {
40         int i = 0;
41         int len_path_out = 0;
42         strcpy(path_out, path_in);
43         len_path_out = (int)strlen(path_out);
44
45         for (i = 0; i < len_path_out; i++)
46         {
47             if ( slashToAntislash )
48             {
49                 if (path_in[i] == UNIX_SEPATATOR)
50                 {
51                     path_out[i] = WINDOWS_SEPATATOR;
52                     bOK = TRUE;
53                 }
54             }
55             else
56             {
57                 if (path_in[i] == WINDOWS_SEPATATOR)
58                 {
59                     path_out[i] = UNIX_SEPATATOR;
60                     bOK = TRUE;
61                 }
62             }
63         }
64     }
65     else
66     {
67         return FALSE;
68     }
69
70     return bOK;
71 }
72 /*--------------------------------------------------------------------------*/