1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2007 - INRIA - Allan CORNET
4  * ...
5  *
6  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
8  * This file is hereby licensed under the terms of the GNU GPL v2.0,
9  * pursuant to article 5.3.4 of the CeCILL v.2.1.
10  * This file was originally licensed under the terms of the CeCILL v2.1,
11  * and continues to be available under such terms.
12  * For more information, see the COPYING file which you should have received
13  * along with this program.
14  *
15  */
16 /*--------------------------------------------------------------------------*/
17 #include <string.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include "URIFileToFilename.h"
21 #include "sci_malloc.h"
22 #include "os_string.h"
23 /*--------------------------------------------------------------------------*/
24 #if _MSC_VER
25 #define strnicmp _strnicmp
26 #else
27 #define strnicmp strncasecmp
28 #endif
29 /*--------------------------------------------------------------------------*/
30 #define URI_BEGIN "file://"
31 /*--------------------------------------------------------------------------*/
URIFileToFilename(char * uri)32 char *URIFileToFilename(char *uri)
33 {
34     char *filename = NULL;
35 
36     if (uri)
37     {
38         if (isURIFile(uri))
39         {
40             int pos = (int) strlen(URI_BEGIN);
41             filename = os_strdup(&uri[pos]);
42         }
43         else
44         {
45             filename = os_strdup(uri);
46         }
47     }
48     return filename;
49 }
50 /*--------------------------------------------------------------------------*/
isURIFile(char * uri)51 BOOL isURIFile(char *uri)
52 {
53     BOOL bOK = FALSE;
54     if (uri)
55     {
56         if (strlen(uri) > strlen(URI_BEGIN))
57         {
58             if ( strnicmp(uri, URI_BEGIN, strlen(URI_BEGIN)) == 0)
59             {
60                 bOK = TRUE;
61             }
62         }
63     }
64     return bOK;
65 }
66 /*--------------------------------------------------------------------------*/
67