23
23
static char * expand_tilde(char * *path);
25
/* Pack a dirname ; Changes HOME to ~/ and current dev to ./ */
26
/* from is a dirname (from dirname() ?) ending with FN_LIBCHAR */
27
/* to may be == from */
29
void pack_dirname(char * to, const char *from)
32
size_t d_length,length,buff_length= 0;
36
(void) intern_filename(to,from); /* Change to intern name */
39
if ((start=strrchr(to,FN_DEVCHAR)) != 0) /* Skip device part */
45
if (!(getcwd(buff, FN_REFLEN)))
48
buff_length= strlen(buff);
49
d_length= (size_t) (start-to);
51
(buff_length == d_length && !memcmp(buff,start,d_length))) &&
52
*start != FN_LIBCHAR && *start)
53
{ /* Put current dir before */
54
bchange((unsigned char*) to, d_length, (unsigned char*) buff, buff_length, strlen(to)+1);
58
if ((d_length= cleanup_dirname(to,to)) != 0)
63
length= strlen(home_dir);
64
if (home_dir[length-1] == FN_LIBCHAR)
65
length--; /* Don't test last '/' */
67
if (length > 1 && length < d_length)
68
{ /* test if /xx/yy -> ~/yy */
69
if (memcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR)
71
to[0]=FN_HOMELIB; /* Filename begins with ~ */
72
(void) strcpy(to+1,to+length);
76
{ /* Test if cwd is ~/... */
77
if (length > 1 && length < buff_length)
79
if (memcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR)
82
(void) strcpy(buff+1,buff+length);
85
if (is_prefix(to,buff))
89
(void) strcpy(to,to+length); /* Remove everything before */
92
to[0]= FN_CURLIB; /* Put ./ instead of cwd */
104
27
remove unwanted chars from dirname