extern VOIDSTAR
ck_malloc();
extern VOIDSTAR
init_buffer();
extern char *quote_copy_string();
extern char *get_buffer();
extern union record
*start_header();
extern struct stat hstat
; /* Stat struct corresponding */
/* Should use a hash table, etc. . */
struct mangled
*first_mangle
;
for(munge
=first_mangle
;munge
;munge
=munge
->next
)
if(!strcmp(name
,munge
->normal
))
void add_symlink_mangle(symlink
, linkto
, buffer
)
struct mangled
*munge
,*kludge
;
munge
=(struct mangled
*)ck_malloc(sizeof(struct mangled
)+strlen(symlink
)+strlen(linkto
)+2);
for(kludge
=first_mangle
;kludge
->next
;kludge
=kludge
->next
)
strcpy(munge
->normal
,symlink
);
munge
->linked_to
=munge
->normal
+strlen(symlink
)+1;
strcpy(munge
->linked_to
,linkto
);
sprintf(munge
->mangled
,"@@MaNgLeD.%d",mangled_num
++);
strncpy(buffer
,munge
->mangled
,NAMSIZ
);
add_mangle (name
, buffer
)
struct mangled
*munge
,*kludge
;
munge
=(struct mangled
*)ck_malloc(sizeof(struct mangled
)+strlen(name
));
for(kludge
=first_mangle
;kludge
->next
;kludge
=kludge
->next
)
strcpy(munge
->normal
,name
);
sprintf(munge
->mangled
,"@@MaNgLeD.%d",mangled_num
++);
strncpy(buffer
,munge
->mangled
,NAMSIZ
);
the_buffer
=init_buffer();
for(munge
=first_mangle
,size
=0;munge
;munge
=munge
->next
) {
ptr1
=quote_copy_string(munge
->normal
);
add_buffer(the_buffer
,"Symlink ",8);
add_buffer(the_buffer
,ptr1
,strlen(ptr1
));
add_buffer(the_buffer
," to ",4);
if(ptr2
=quote_copy_string(munge
->linked_to
)) {
add_buffer(the_buffer
,ptr2
,strlen(ptr2
));
add_buffer(the_buffer
,munge
->linked_to
,strlen(munge
->linked_to
));
add_buffer(the_buffer
,"Rename ",7);
add_buffer(the_buffer
,munge
->mangled
,strlen(munge
->mangled
));
add_buffer(the_buffer
," to ",4);
add_buffer(the_buffer
,ptr1
,strlen(ptr1
));
add_buffer(the_buffer
,"\n",1);
bzero(&hstat
,sizeof(struct stat
));
hstat
.st_atime
=hstat
.st_mtime
=hstat
.st_ctime
=time(0);
ptr1
=get_buffer(the_buffer
);
hstat
.st_size
=strlen(ptr1
);
header
=start_header("././@MaNgLeD_NaMeS",&hstat
);
header
->header
.linkflag
=LF_NAMES
;
bufsize
= endofrecs()->charptr
- header
->charptr
;
bcopy(ptr1
,header
->charptr
,bufsize
);
userec(header
+(bufsize
-1)/RECORDSIZE
);
bufsize
= endofrecs()->charptr
- header
->charptr
;
bcopy(ptr1
,header
->charptr
,size
);
bzero(header
->charptr
+size
,bufsize
-size
);
userec(header
+(size
-1)/RECORDSIZE
);
buf
=to
=ck_malloc(size
+1);
fromtape
=findrec()->charptr
;
msg("Unexpected EOF in mangled names!");
copied
=endofrecs()->charptr
-fromtape
;
bcopy(fromtape
,to
,copied
);
userec((union record
*)(fromtape
+copied
-1));
for(ptr
=buf
;*ptr
;ptr
=ptrend
) {
if(!strncmp(ptr
,"Rename ",7)) {
while(strncmp(nam1end
," to ",4)) {
nam1end
=index(nam1end
,' ');
un_quote_string(nam1end
+4);
if(rename(nam1
,nam1end
+4))
msg_perror("Can't rename %s to %s",nam1
,nam1end
+4);
msg("Renamed %s to %s",nam1
,nam1end
+4);
else if(!strncmp(ptr
,"Symlink ",8)) {
while(strncmp(nam1end
," to ",4)) {
nam1end
=index(nam1end
,' ');
un_quote_string(nam1end
+4);
if(symlink(nam1
,nam1end
+4) && (unlink(nam1end
+4) || symlink(nam1
,nam1end
+4)))
msg_perror("Can't symlink %s to %s",nam1
,nam1end
+4);
msg("Symlinkd %s to %s",nam1
,nam1end
+4);
msg("Unknown demangling command %s",ptr
);