1 | /* ***** BEGIN LICENSE BLOCK *****
|
---|
2 | * Version: CDDL 1.0/LGPL 2.1
|
---|
3 | *
|
---|
4 | * The contents of this file are subject to the COMMON DEVELOPMENT AND
|
---|
5 | * DISTRIBUTION LICENSE (CDDL) Version 1.0 (the "License"); you may not use
|
---|
6 | * this file except in compliance with the License. You may obtain a copy of
|
---|
7 | * the License at http://www.sun.com/cddl/
|
---|
8 | *
|
---|
9 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
11 | * for the specific language governing rights and limitations under the
|
---|
12 | * License.
|
---|
13 | *
|
---|
14 | * The Original Code is "NOM" Netlabs Object Model
|
---|
15 | *
|
---|
16 | * The Initial Developer of the Original Code is
|
---|
17 | * netlabs.org: Chris Wohlgemuth <cinc-ml@netlabs.org>.
|
---|
18 | * Portions created by the Initial Developer are Copyright (C) 2006-2007
|
---|
19 | * the Initial Developer. All Rights Reserved.
|
---|
20 | *
|
---|
21 | * Contributor(s):
|
---|
22 | *
|
---|
23 | * Alternatively, the contents of this file may be used under the terms of
|
---|
24 | * the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
|
---|
25 | * case the provisions of the LGPL are applicable instead of those above. If
|
---|
26 | * you wish to allow use of your version of this file only under the terms of
|
---|
27 | * the LGPL, and not to allow others to use your version of this file under
|
---|
28 | * the terms of the CDDL, indicate your decision by deleting the provisions
|
---|
29 | * above and replace them with the notice and other provisions required by the
|
---|
30 | * LGPL. If you do not delete the provisions above, a recipient may use your
|
---|
31 | * version of this file under the terms of any one of the CDDL or the LGPL.
|
---|
32 | *
|
---|
33 | * ***** END LICENSE BLOCK ***** */
|
---|
34 | /*
|
---|
35 | * And remember, phase 3 is near...
|
---|
36 | */
|
---|
37 | #ifndef NOM_NOMPath_IMPLEMENTATION_FILE
|
---|
38 | #define NOM_NOMPath_IMPLEMENTATION_FILE
|
---|
39 | #endif
|
---|
40 |
|
---|
41 | #define INCL_DOS
|
---|
42 | #include <os2.h>
|
---|
43 |
|
---|
44 | #include <nom.h>
|
---|
45 | #include <nomtk.h>
|
---|
46 |
|
---|
47 | #include <string.h>
|
---|
48 | #include <glib.h>
|
---|
49 |
|
---|
50 | #include "nomfilepath.ih"
|
---|
51 |
|
---|
52 | /**
|
---|
53 | Append a path to the string. A path separator will be added to the current path if necessary and the
|
---|
54 | given string appended. If the given string starts with a separator no additional separator will be
|
---|
55 | added to the path prior to appending. If the given string starts with a separator and the current
|
---|
56 | path ends with a separator the ending separator will be removed before appending.
|
---|
57 | If no input path is given only a separator is appended if necessary.
|
---|
58 |
|
---|
59 | Note that there's no check if the input string is an absolute path. So if an absolute path is given as
|
---|
60 | input the resulting path may not be valid.
|
---|
61 |
|
---|
62 | The method returns a new NOMPath after appending.
|
---|
63 | */
|
---|
64 | NOM_Scope PNOMPath NOMLINK impl_NOMPath_appendPath(NOMPath* nomSelf, const PNOMPath nomPath, CORBA_Environment *ev)
|
---|
65 | {
|
---|
66 | gchar* chrTemp;
|
---|
67 | PNOMPath np;
|
---|
68 |
|
---|
69 | if(!nomPath)
|
---|
70 | return (PNOMPath)NOMPath_appendSeparator(nomSelf, NULLHANDLE);
|
---|
71 |
|
---|
72 | if(0==NOMPath_length((NOMString*)nomPath, ev))
|
---|
73 | return NOMPath_appendSeparator(nomSelf, ev);
|
---|
74 |
|
---|
75 | /* This is not a copy */
|
---|
76 | chrTemp=NOMPath_queryCString(nomPath, NULLHANDLE);
|
---|
77 | if(G_DIR_SEPARATOR==chrTemp[0])
|
---|
78 | np=NOMPath_stripSeparator(nomSelf, ev);
|
---|
79 | else
|
---|
80 | np=NOMPath_appendSeparator(nomSelf, ev); /* Make sure current path has a separator */
|
---|
81 |
|
---|
82 | return (NOMPath*) NOMPath_append((NOMString*) np, (NOMString*)nomPath, NULLHANDLE);
|
---|
83 | }
|
---|
84 |
|
---|
85 | /**
|
---|
86 | Append a separator to the path. If the path already has a separator at the end this method does
|
---|
87 | nothing other than returning the path object. If the given path has zero length the path object
|
---|
88 | only holding a separator is returned.
|
---|
89 |
|
---|
90 | This method always returns a new instance of a NOMPath owned by the caller.
|
---|
91 | */
|
---|
92 | NOM_Scope PNOMPath NOMLINK impl_NOMPath_appendSeparator(NOMPath* nomSelf, CORBA_Environment *ev)
|
---|
93 | {
|
---|
94 | gchar* chrTemp;
|
---|
95 | gulong len;
|
---|
96 |
|
---|
97 | /* Return only a separator */
|
---|
98 | if((len=NOMPath_length((NOMString*)nomSelf, ev))==0)
|
---|
99 | return (NOMPath*)NOMPath_appendCString((NOMString*)nomSelf, G_DIR_SEPARATOR_S, ev);
|
---|
100 |
|
---|
101 | /* This is not a copy */
|
---|
102 | chrTemp=NOMPath_queryCString(nomSelf, NULLHANDLE);
|
---|
103 | /* Add a separator */
|
---|
104 | if(G_DIR_SEPARATOR!=chrTemp[len-1])
|
---|
105 | return (NOMPath*)NOMPath_appendCString( (NOMString*)nomSelf, G_DIR_SEPARATOR_S, ev);
|
---|
106 |
|
---|
107 | return nomSelf;
|
---|
108 | }
|
---|
109 |
|
---|
110 | /**
|
---|
111 | Strips the path separator from the end of a path if there's one.
|
---|
112 |
|
---|
113 | This method returns the same instance of a NOMPath.
|
---|
114 | */
|
---|
115 | NOM_Scope PNOMPath NOMLINK impl_NOMPath_stripSeparator(NOMPath* nomSelf, CORBA_Environment *ev)
|
---|
116 | {
|
---|
117 | gchar* chrTemp;
|
---|
118 | gulong len;
|
---|
119 |
|
---|
120 | if((len=NOMPath_length((NOMString*)nomSelf, NULLHANDLE))==0)
|
---|
121 | return nomSelf;
|
---|
122 |
|
---|
123 | /* This is not a copy */
|
---|
124 | chrTemp=NOMPath_queryCString((NOMString*)nomSelf, NULLHANDLE);
|
---|
125 |
|
---|
126 | if(chrTemp[len-1]==G_DIR_SEPARATOR)
|
---|
127 | return (NOMPath*)NOMPath_truncate( (NOMString*)nomSelf, len-1, NULLHANDLE);
|
---|
128 |
|
---|
129 | return nomSelf;
|
---|
130 | }
|
---|
131 |
|
---|
132 | /**
|
---|
133 | Returns TRUE if the given path is absolute.
|
---|
134 | On OS/2 this means it starts with a letter followed by a colon.
|
---|
135 | */
|
---|
136 | NOM_Scope CORBA_boolean NOMLINK impl_NOMPath_pathIsAbsolute(NOMPath* nomSelf, CORBA_Environment *ev)
|
---|
137 | {
|
---|
138 | /* NOMPathData* nomThis=NOMPathGetData(nomSelf); */
|
---|
139 | gchar* chrString;
|
---|
140 |
|
---|
141 | #ifndef __OS2__
|
---|
142 | #error !!!!! Only implemented for OS/2 !!!!!
|
---|
143 | #endif
|
---|
144 |
|
---|
145 | if(NOMPath_length(nomSelf, NULLHANDLE)<2)
|
---|
146 | return FALSE;
|
---|
147 |
|
---|
148 | chrString=NOMPath_queryCString(nomSelf, NULLHANDLE);
|
---|
149 |
|
---|
150 | if(!g_ascii_isalpha(chrString[0]) || chrString[1]!=':')
|
---|
151 | return FALSE;
|
---|
152 |
|
---|
153 | return TRUE;
|
---|
154 | }
|
---|
155 |
|
---|
156 | NOM_Scope PNOMPath NOMLINK impl_NOMPath_queryRoot(NOMPath* nomSelf, CORBA_Environment *ev)
|
---|
157 | {
|
---|
158 | /* NOMPathData* nomThis=NOMPathGetData(nomSelf); */
|
---|
159 | PNOMPath nomRetval=(PNOMPath)NOMPath_new(nomSelf, NULLHANDLE);
|
---|
160 | gchar os2Root[4]="a:"; /* includes padding */
|
---|
161 | gchar *chrTemp;
|
---|
162 |
|
---|
163 | #ifndef __OS2__
|
---|
164 | #error !!!!! Only implemented for OS/2 !!!!!
|
---|
165 | #endif
|
---|
166 |
|
---|
167 | if(!NOMPath_pathIsAbsolute(nomSelf, NULLHANDLE))
|
---|
168 | return nomRetval; /* Return a zero length string */
|
---|
169 |
|
---|
170 | chrTemp=NOMPath_queryCString(nomSelf, NULLHANDLE);
|
---|
171 |
|
---|
172 | os2Root[0]=chrTemp[0];
|
---|
173 | return (PNOMPath) NOMPath_assignCString(nomRetval, os2Root, NULLHANDLE);
|
---|
174 | }
|
---|
175 |
|
---|
176 | /**
|
---|
177 | This method strips all characters from the beginning of a path till the first
|
---|
178 | directory separator and also this first separator. If there's no separator in
|
---|
179 | the path a zero length path is returned.
|
---|
180 |
|
---|
181 | This method always returns a new instance of a NOMPath owned by the caller.
|
---|
182 | */
|
---|
183 | NOM_Scope PNOMPath NOMLINK impl_NOMPath_erasePathBegin(NOMPath* nomSelf, CORBA_Environment *ev)
|
---|
184 | {
|
---|
185 | /* NOMPathData* nomThis=NOMPathGetData(nomSelf); */
|
---|
186 | PNOMPath nomRetval=(PNOMPath) NOMPath_new(nomSelf, NULLHANDLE);
|
---|
187 | gchar *chrTemp;
|
---|
188 | g_message("In %s", __FUNCTION__);
|
---|
189 | chrTemp=NOMPath_queryCString(nomSelf, NULLHANDLE); /* Not a copy */
|
---|
190 |
|
---|
191 | while(*chrTemp!='\0' && *chrTemp!=G_DIR_SEPARATOR)
|
---|
192 | chrTemp++;
|
---|
193 |
|
---|
194 | if(*chrTemp==G_DIR_SEPARATOR)
|
---|
195 | chrTemp++;
|
---|
196 |
|
---|
197 | return (PNOMPath)NOMPath_assignCString(nomRetval, chrTemp, NULLHANDLE);
|
---|
198 | }
|
---|
199 |
|
---|
200 | /**
|
---|
201 | Returns the part of the path up to the first directory separator ('\' on OS/2).
|
---|
202 | If there's no directory separator the whole path is returned. This method does
|
---|
203 | not remove the part from the given path. Use erasePathBegin() to do that.
|
---|
204 | */
|
---|
205 | NOM_Scope PNOMPath NOMLINK impl_NOMPath_queryPathBegin(NOMPath* nomSelf, CORBA_Environment *ev)
|
---|
206 | {
|
---|
207 | /* NOMPathData* nomThis=NOMPathGetData(nomSelf); */
|
---|
208 | PNOMPath nomRetval=NOMPathNew();
|
---|
209 | gchar *chrTemp;
|
---|
210 | gchar *chrTemp2;
|
---|
211 |
|
---|
212 | chrTemp2 = chrTemp = NOMPath_copyCString(nomSelf, NULLHANDLE); /* This is a copy */
|
---|
213 |
|
---|
214 | while(*chrTemp!='\0' && *chrTemp!=G_DIR_SEPARATOR)
|
---|
215 | chrTemp++;
|
---|
216 | *chrTemp='\0';
|
---|
217 |
|
---|
218 | nomRetval=(PNOMPath)NOMPath_assignCString(nomRetval, chrTemp2, NULLHANDLE);
|
---|
219 |
|
---|
220 | g_free(chrTemp);
|
---|
221 | return (PNOMPath) nomRetval;
|
---|
222 | }
|
---|
223 |
|
---|