4f1bd088c2c4a29a3ad77d70b790115019c16d76
[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-en.txt
10  *
11  */
12 /*--------------------------------------------------------------------------*/
13 #include <string.h>
14 #include "ConvertSlash.h"
15 /*--------------------------------------------------------------------------*/
16 #define UNIX_SEPATATOR '/'
17 #define WINDOWS_SEPATATOR '\\'
18 /*--------------------------------------------------------------------------*/
19 static BOOL convertSlash(char *path_in,char *path_out,BOOL slashToAntislash);
20 /*--------------------------------------------------------------------------*/
21 BOOL slashToAntislash(char *pathunix,char *pathwindows)
22 {
23         return convertSlash(pathunix,pathwindows,TRUE);
24 }
25 /*--------------------------------------------------------------------------*/
26 BOOL AntislashToSlash(char *pathwindows,char *pathunix)
27 {
28         return convertSlash(pathwindows,pathunix,FALSE);
29 }
30 /*--------------------------------------------------------------------------*/
31 static BOOL convertSlash(char *path_in,char *path_out,BOOL slashToAntislash)
32 {
33         BOOL bOK = FALSE;
34         if ( (path_in) && (path_out) )
35         {
36                 int i=0;
37                 strcpy(path_out,path_in);
38                 for (i=0;i<(int)strlen(path_out);i++)
39                 {
40                         if ( slashToAntislash )
41                         {
42                                 if (path_in[i] == UNIX_SEPATATOR) 
43                                 {
44                                         path_out[i] = WINDOWS_SEPATATOR;
45                                         bOK = TRUE;
46                                 }
47                         }
48                         else
49                         {
50                                 if (path_in[i] == WINDOWS_SEPATATOR) 
51                                 {
52                                         path_out[i] = UNIX_SEPATATOR;
53                                         bOK = TRUE;
54                                 }
55                         }
56                 }
57         }
58         else bOK = FALSE;
59
60         return bOK;
61 }
62 /*--------------------------------------------------------------------------*/