0023426: Tool to compare two runs of tests on the same station
[occt.git] / src / Xw / Xw_get_filename.cxx
CommitLineData
b311480e 1// Copyright (c) 1999-2012 OPEN CASCADE SAS
2//
3// The content of this file is subject to the Open CASCADE Technology Public
4// License Version 6.5 (the "License"). You may not use the content of this file
5// except in compliance with the License. Please obtain a copy of the License
6// at http://www.opencascade.org and read it completely before using this file.
7//
8// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
10//
11// The Original Code and all software distributed under the License is
12// distributed on an "AS IS" basis, without warranty of any kind, and the
13// Initial Developer hereby disclaims all such warranties, including without
14// limitation, any warranties of merchantability, fitness for a particular
15// purpose or non-infringement. Please see the License for the specific terms
16// and conditions governing the rights and limitations under the License.
17
7fd59977 18/* PRO12499 OPTIMISATION & DEBUG GG_100398
19// Utiliser plutot une variable statique que allouer de
20 la memoire.
21*/
22
23#define IMP010200 /* GG
24 Add protection when NO extension is defined
25 and the path contains a '.'
26*/
27
28#include <Xw_Extension.h>
29#include <string.h>
30
31 /* ifdef then trace on */
32#ifdef TRACE
33#define TRACE_GET_FILENAME
34#endif
35
36/*
37 char* Xw_get_filename (filename,extension):
38 char *filename Filename to translate
39 char *extension File extension
40
41 Translate Filename depending of environment and extension
42
43 Returns Updated Filename depending of environment and extension
44 or Returns NULL is translating can't be done
45
46 NOTE: Filename can be given under the forms :
47
48 1) xxxxxx.ext
49 2) xxxxxx (.extension is added)
50 3) /usr/..../xxxxxx.ext
51 4) $XXXXX/yyyyyy.ext ($XXXXX symbol is get and insert
52
53*/
54#define MAXSTRING 512
55static char string1[MAXSTRING];
56static char string2[MAXSTRING];
57
58#ifdef XW_PROTOTYPE
59char* Xw_get_filename (char* filename,const char* extension)
60#else
61char* Xw_get_filename (filename,extension)
62char *filename ;
63const char *extension ;
64#endif /*XW_PROTOTYPE*/
65{
66char *pname,*pext,*pslash;
67
68 if( !filename || strlen(filename) > MAXSTRING ) {
69 printf (" *TOO BIG PATH*Xw_get_filename('%s','%s')\n",
70 filename,extension) ;
71 return (NULL) ;
72 }
73
74 pname = strcpy(string1,filename) ;
75
76 if( *pname == '$' ) {
77 pname = (char*) strchr(string1,'/') ;
78 if( pname ) { /* Filename is $XXXX/yyyyy */
79 XW_STATUS status;
80 *pname = '\0' ;
81 status = Xw_get_env(&string1[1],string2,MAXSTRING) ;
82 *pname = '/' ;
83 if( status ) {
84 if( (strlen(string2) + strlen(pname) + 1) < MAXSTRING ) {
85 pname = strcat(string2,pname) ;
86 } else {
87 printf (" *TOO BIG SYMBOL PATH*Xw_get_filename('%s','%s')\n",
88 filename,extension) ;
89 return NULL;
90 }
91 }
92 }
93 }
94
95 pext = strrchr(pname,'.') ;
96#ifdef IMP010200
97 pslash = strrchr(pname,'/') ;
98 if( pext && (pslash > pext) ) pext = NULL;
99#endif
100
101 if( !pext ) { /* Add file extension ".extension" */
102 if( (strlen(pname) + strlen(extension) + 2) < MAXSTRING ) {
103 strcat(pname,".") ;
104 strcat(pname,extension) ;
105 } else {
106 printf (" *TOO BIG EXTENSION*Xw_get_filename('%s','%s')\n",
107 filename,extension) ;
108 return NULL;
109 }
110 }
111
112#ifdef TRACE_GET_FILENAME
113if( Xw_get_trace() > 1 ) {
114 printf (" '%s'= Xw_get_filename('%s','%s')\n",pname,filename,extension) ;
115}
116#endif
117
118 return (pname);
119}