28
23
static char * expand_tilde(char * *path);
30
/* Pack a dirname ; Changes HOME to ~/ and current dev to ./ */
31
/* from is a dirname (from dirname() ?) ending with FN_LIBCHAR */
32
/* to may be == from */
34
void pack_dirname(char * to, const char *from)
37
size_t d_length,length,buff_length= 0;
41
(void) intern_filename(to,from); /* Change to intern name */
44
if ((start=strrchr(to,FN_DEVCHAR)) != 0) /* Skip device part */
50
if (!(cwd_err= my_getwd(buff,FN_REFLEN,MYF(0))))
52
buff_length= strlen(buff);
53
d_length= (size_t) (start-to);
55
(buff_length == d_length && !memcmp(buff,start,d_length))) &&
56
*start != FN_LIBCHAR && *start)
57
{ /* Put current dir before */
58
bchange((unsigned char*) to, d_length, (unsigned char*) buff, buff_length, strlen(to)+1);
62
if ((d_length= cleanup_dirname(to,to)) != 0)
67
length= strlen(home_dir);
68
if (home_dir[length-1] == FN_LIBCHAR)
69
length--; /* Don't test last '/' */
71
if (length > 1 && length < d_length)
72
{ /* test if /xx/yy -> ~/yy */
73
if (memcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR)
75
to[0]=FN_HOMELIB; /* Filename begins with ~ */
76
(void) strmov_overlapp(to+1,to+length);
80
{ /* Test if cwd is ~/... */
81
if (length > 1 && length < buff_length)
83
if (memcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR)
86
(void) strmov_overlapp(buff+1,buff+length);
89
if (is_prefix(to,buff))
93
(void) strmov_overlapp(to,to+length); /* Remove everything before */
96
to[0]= FN_CURLIB; /* Put ./ instead of cwd */
108
27
remove unwanted chars from dirname
142
61
if ((pos=strrchr(from_ptr,FN_DEVCHAR)) != 0)
143
62
{ /* Skip device part */
144
63
length=(size_t) (pos-from_ptr)+1;
145
start=my_stpncpy(buff,from_ptr,length); from_ptr+=length;
64
start= strncpy(buff,from_ptr,length);
65
start+= strlen(from_ptr);
149
70
parent[0]=FN_LIBCHAR;
150
length=(size_t) (my_stpcpy(parent+1,FN_PARENTDIR)-parent);
71
length= (size_t)((strcpy(parent+1,FN_PARENTDIR)+strlen(FN_PARENTDIR))-parent);
151
72
for (pos=start ; (*pos= *from_ptr++) != 0 ; pos++)
153
74
#ifdef BACKSLASH_MBTAIL
177
98
pos+=length+1; /* Don't unpack ~/.. */
180
pos=my_stpcpy(buff,home_dir)-1; /* Unpacks ~/.. */
101
pos= strcpy(buff,home_dir)+strlen(home_dir)-1; /* Unpacks ~/.. */
181
102
if (*pos == FN_LIBCHAR)
182
103
pos--; /* home ended with '/' */
184
105
if (*pos == FN_CURLIB && (pos == start || pos[-1] == FN_LIBCHAR))
186
if (my_getwd(curr_dir,FN_REFLEN,MYF(0)))
107
if (getcwd(curr_dir,FN_REFLEN))
188
109
pos+=length+1; /* Don't unpack ./.. */
191
pos=my_stpcpy(buff,curr_dir)-1; /* Unpacks ./.. */
112
pos= strcpy(buff,curr_dir)+strlen(curr_dir)-1; /* Unpacks ./.. */
192
113
if (*pos == FN_LIBCHAR)
193
114
pos--; /* home ended with '/' */
198
119
if (pos[1] == FN_HOMELIB || memcmp(pos,parent,length) == 0)
199
120
{ /* Don't remove ~user/ */
200
pos=my_stpcpy(end_parentdir+1,parent);
121
pos= strcpy(end_parentdir+1,parent)+strlen(parent);
226
(void) my_stpcpy(to,buff);
147
(void) strcpy(to,buff);
227
148
return((size_t) (pos-buff));
228
149
} /* cleanup_dirname */
232
153
On system where you don't have symbolic links, the following
233
code will allow you to create a file:
154
code will allow you to create a file:
234
155
directory-name.sym that should contain the real path
235
156
to the directory. This will be used if the directory name
251
172
char temp= *(--pos); /* May be "/" or "\" */
252
my_stpcpy(pos,".sym");
253
174
file= my_open(dir, O_RDONLY, MYF(0));
254
175
*pos++=temp; *pos=0; /* Restore old filename */
257
178
if ((length= my_read(file, buff, sizeof(buff), MYF(0))) > 0)
259
for (pos= buff + length ;
260
pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
263
/* Ensure that the symlink ends with the directory symbol */
264
if (pos == buff || pos[-1] != FN_LIBCHAR)
267
strmake(dir,buff, (size_t) (pos-buff));
180
for (pos= buff + length ;
181
pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
184
/* Ensure that the symlink ends with the directory symbol */
185
if (pos == buff || pos[-1] != FN_LIBCHAR)
188
strncpy(dir,buff, FN_REFLEN-1);
269
190
my_close(file, MYF(0));
321
242
if (tilde_expansion[h_length-1] == FN_LIBCHAR)
323
244
if (buff+h_length < suffix)
324
memcpy(buff+h_length, suffix, length);
245
memmove(buff+h_length, suffix, length);
326
247
bmove_upp((unsigned char*) buff+h_length+length, (unsigned char*) suffix+length, length);
327
memcpy(buff, tilde_expansion, h_length);
248
memmove(buff, tilde_expansion, h_length);
391
312
n_length=unpack_dirname(buff,buff);
392
313
if (n_length+strlen(from+length) < FN_REFLEN)
394
(void) my_stpcpy(buff+n_length,from+length);
315
(void) strcpy(buff+n_length,from+length);
395
316
length= system_filename(to,buff); /* Fix to usably filename */
407
328
size_t system_filename(char * to, const char *from)
409
330
#ifndef FN_C_BEFORE_DIR
410
return (size_t) (strmake(to,from,FN_REFLEN-1)-to);
331
return strlen(strncpy(to,from,FN_REFLEN-1));
413
334
/* change 'dev:lib/xxx' to 'dev:[lib]xxx' */
423
344
char buff[FN_REFLEN];
426
(void) my_stpcpy(buff,from); /* If to == from */
347
(void) strcpy(buff,from); /* If to == from */
428
349
if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skip device part */
431
to_pos=my_stpncpy(to,from_pos,(size_t) (pos-from_pos));
352
to_pos= strncpy(to,from_pos,(size_t) (pos-from_pos));
444
366
from_pos+=strlen(FN_ROOTDIR); /* Actually +1 but... */
445
367
if (! strchr(from_pos,FN_LIBCHAR))
446
368
{ /* No dir, use [000000] */
447
to_pos=my_stpcpy(to_pos,FN_C_ROOT_DIR);
369
to_pos= strcpy(to_pos,FN_C_ROOT_DIR)+strlen(FN_C_ROOT_DIR);
454
376
while ((pos=strchr(from_pos,FN_LIBCHAR)))
456
378
if (libchar_found++)
457
*(to_pos++)=FN_C_DIR_SEP; /* Add '.' between dirs */
379
*(to_pos++)=FN_C_DIR_SEP; /* Add '.' between dirs */
458
380
if (strstr(from_pos,FN_PARENTDIR) == from_pos &&
459
from_pos+strlen(FN_PARENTDIR) == pos)
460
to_pos=my_stpcpy(to_pos,FN_C_PARENT_DIR); /* Found '../' */
381
from_pos+strlen(FN_PARENTDIR) == pos) {
382
to_pos= strcpy(to_pos,FN_C_PARENT_DIR); /* Found '../' */
383
to_pos+= strlen(FN_C_PARENT_DIR);
462
to_pos=my_stpncpy(to_pos,from_pos,(size_t) (pos-from_pos));
387
to_pos= strncpy(to_pos,from_pos,(size_t) (pos-from_pos));
388
to_pos+= strlen(to_pos);
465
392
*(to_pos++)=FN_C_AFTER_DIR;
467
length= (size_t) (my_stpcpy(to_pos,from_pos)-to);
395
strcpy(to_pos, from_pos);
470
399
} /* system_filename */
478
407
char buff[FN_REFLEN];
480
409
{ /* Dirname may destroy from */
481
my_stpcpy(buff,from);
484
413
length= dirname_part(to, from, &to_length); /* Copy dirname & fix chars */
485
(void) my_stpcpy(to + to_length,from+length);
414
(void) strcpy(to + to_length,from+length);
487
416
} /* intern_filename */