Fix Windows compilation after https://codereview.scilab.org/#/c/13227/
[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  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at
9  * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
10  *
11  */
12 /*--------------------------------------------------------------------------*/
13 #include <string.h>
14 #include "BOOL.h"
15 #include "dynlib_scilab_windows.h"
16 /*--------------------------------------------------------------------------*/
17 #define UNIX_SEPATATOR '/'
18 #define WINDOWS_SEPATATOR '\\'
19 /*--------------------------------------------------------------------------*/
20 static BOOL convertSlash(char *path_in, char *path_out, BOOL slashToAntislash);
21 /*--------------------------------------------------------------------------*/
22 SCILAB_WINDOWS_IMPEXP BOOL slashToAntislash(char *pathunix, char *pathwindows)
23 {
24     return convertSlash(pathunix, pathwindows, TRUE);
25 }
26 /*--------------------------------------------------------------------------*/
27 SCILAB_WINDOWS_IMPEXP BOOL AntislashToSlash(char *pathwindows, char *pathunix)
28 {
29     return convertSlash(pathwindows, pathunix, FALSE);
30 }
31 /*--------------------------------------------------------------------------*/
32 static BOOL convertSlash(char *path_in, char *path_out, BOOL slashToAntislash)
33 {
34     BOOL bOK = FALSE;
35     if ( (path_in) && (path_out) )
36     {
37         int i = 0;
38         int len_path_out = 0;
39         strcpy(path_out, path_in);
40         len_path_out = (int)strlen(path_out);
41
42         for (i = 0; i < len_path_out; i++)
43         {
44             if ( slashToAntislash )
45             {
46                 if (path_in[i] == UNIX_SEPATATOR)
47                 {
48                     path_out[i] = WINDOWS_SEPATATOR;
49                     bOK = TRUE;
50                 }
51             }
52             else
53             {
54                 if (path_in[i] == WINDOWS_SEPATATOR)
55                 {
56                     path_out[i] = UNIX_SEPATATOR;
57                     bOK = TRUE;
58                 }
59             }
60         }
61     }
62     else
63     {
64         return FALSE;
65     }
66
67     return bOK;
68 }
69 /*--------------------------------------------------------------------------*/