7070c61d1c9eb6d240344e868db615e25300fe5c
[scilab.git] / scilab / modules / windows_tools / src / c / scilab_windows / ConvertSlash.c
1 /*\r
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab\r
3  * Copyright (C) 2008 - INRIA - Allan CORNET\r
4  * \r
5  * This file must be used under the terms of the CeCILL.\r
6  * This source file is licensed as described in the file COPYING, which\r
7  * you should have received as part of this distribution.  The terms\r
8  * are also available at    \r
9  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt\r
10  *\r
11  */\r
12 /*--------------------------------------------------------------------------*/\r
13 #include <string.h>\r
14 #include "ConvertSlash.h"\r
15 /*--------------------------------------------------------------------------*/\r
16 #define UNIX_SEPATATOR '/'\r
17 #define WINDOWS_SEPATATOR '\\'\r
18 /*--------------------------------------------------------------------------*/\r
19 static BOOL convertSlash(char *path_in,char *path_out,BOOL slashToAntislash);\r
20 /*--------------------------------------------------------------------------*/\r
21 BOOL slashToAntislash(char *pathunix,char *pathwindows)\r
22 {\r
23         return convertSlash(pathwindows,pathunix,TRUE);\r
24 }\r
25 /*--------------------------------------------------------------------------*/\r
26 BOOL AntislashToSlash(char *pathwindows,char *pathunix)\r
27 {\r
28         return convertSlash(pathwindows,pathunix,FALSE);\r
29 }\r
30 /*--------------------------------------------------------------------------*/\r
31 static BOOL convertSlash(char *path_in,char *path_out,BOOL slashToAntislash)\r
32 {\r
33         BOOL bOK = FALSE;\r
34         if ( (path_in) && (path_out) )\r
35         {\r
36                 int i=0;\r
37                 strcpy(path_out,path_in);\r
38                 for (i=0;i<(int)strlen(path_out);i++)\r
39                 {\r
40                         if ( slashToAntislash )\r
41                         {\r
42                                 if (path_in[i] == UNIX_SEPATATOR) \r
43                                 {\r
44                                         path_out[i] = WINDOWS_SEPATATOR;\r
45                                         bOK = TRUE;\r
46                                 }\r
47                         }\r
48                         else\r
49                         {\r
50                                 if (path_in[i] == WINDOWS_SEPATATOR) \r
51                                 {\r
52                                         path_out[i] = UNIX_SEPATATOR;\r
53                                         bOK = TRUE;\r
54                                 }\r
55                         }\r
56                 }\r
57         }\r
58         else bOK = FALSE;\r
59 \r
60         return bOK;\r
61 }\r
62 /*--------------------------------------------------------------------------*/\r