@@ -139,7 +139,17 @@ void SySetGapRootPath(const Char * string)
139139 path = MakeString ("./" );
140140 // TODO: insert output of getcwd??
141141 } else {
142- path = MakeStringWithLen (p , q - p );
142+ if (* p == '~' ) {
143+ const char * userhome = getenv ("HOME" );
144+ if (!userhome )
145+ userhome = "" ;
146+ path = MakeString (userhome );
147+ p ++ ;
148+ AppendCStr (path , p , q - p );
149+ }
150+ else {
151+ path = MakeStringWithLen (p , q - p );
152+ }
143153
144154 Char * r = CSTR_STRING (path );
145155 #ifdef SYS_IS_CYGWIN32
@@ -172,28 +182,6 @@ void SySetGapRootPath(const Char * string)
172182 pos ++ ;
173183#endif
174184 }
175-
176- #if 0
177- // TODO: add this code back in
178-
179- // replace leading tilde ~ by HOME environment variable
180- // TODO; instead of iterating over all entries each time, just
181- // do this for the new entries
182- char * userhome = getenv ("HOME" );
183- if (!userhome || !* userhome )
184- return ;
185- const UInt userhomelen = strlen (userhome );
186- for (i = 0 ; i < MAX_GAP_DIRS && SyGapRootPaths [i ][0 ]; i ++ ) {
187- const UInt pathlen = strlen (SyGapRootPaths [i ]);
188- if (SyGapRootPaths [i ][0 ] == '~' &&
189- userhomelen + pathlen < sizeof (SyGapRootPaths [i ])) {
190- SyMemmove (SyGapRootPaths [i ] + userhomelen ,
191- // don't copy the ~ but the trailing '\0'
192- SyGapRootPaths [i ] + 1 , pathlen );
193- memcpy (SyGapRootPaths [i ], userhome , userhomelen );
194- }
195- }
196- #endif
197185}
198186
199187
0 commit comments