/* * Processes a name match * dosname short dosname (ignored if is_primary) * * * Returns: * 2 if file is to be overwritten * 1 if file was renamed * 0 if it was skipped * * If a short name is involved, handle conversion between the 11-character * fixed-length record DOS name and a literal null-terminated name (e.g. * "COMMAND COM" (no null) <-> "COMMAND.COM" (null terminated)). * * Also, immediately copy the original name so that messages can use it. */ static __inline__ clash_action process_namematch(doscp_t *cp, dos_name_t *dosname, char *longname, int isprimary, ClashHandling_t *ch, int no_overwrite, int reason) { clash_action action; #if 0 fprintf(stderr, "process_namematch: name=%s, default_action=%d, ask=%d.\n", name, default_action, ch->ask); #endif action = ask_namematch(cp, dosname, longname, isprimary, ch, no_overwrite, reason); switch(action){ case NAMEMATCH_QUIT: got_signal = 1; return NAMEMATCH_SKIP; case NAMEMATCH_SKIP: return NAMEMATCH_SKIP; case NAMEMATCH_RENAME: case NAMEMATCH_PRENAME: /* We need to rename the file now. This means we must pass * back through the loop, a) ensuring there isn't a potential * new name collision, and b) finding a big enough VSE. * Change the name, so that it won't collide again. */ ask_rename(cp, ch, dosname, longname, isprimary); return action; case NAMEMATCH_AUTORENAME: /* Very similar to NAMEMATCH_RENAME, except that we need to * first generate the name. * TODO: Remember previous name so we don't * keep trying the same one. */ if (isprimary) { autorename_long(longname, 1); return NAMEMATCH_PRENAME; } else { autorename_short(dosname, 1); return NAMEMATCH_RENAME; } case NAMEMATCH_OVERWRITE: if(no_overwrite) return NAMEMATCH_SKIP; else return NAMEMATCH_OVERWRITE; default: return NAMEMATCH_NONE; } }
/* dos_name * * Convert a Unix-style filename to a legal MSDOS name and extension. * Will truncate file and extension names, will substitute * the character '~' for any illegal character(s) in the name. */ void dos_name(doscp_t *toDos, const char *name, int verbose UNUSEDP, int *mangled, dos_name_t *dn) { char *s, *ext; register int i; Case_t BaseCase, ExtCase; *mangled = 0; /* skip drive letter */ if (name[0] && name[1] == ':') name = &name[2]; /* zap the leading path */ name = (char *) _basename(name); if ((s = strrchr(name, '\\'))) name = s + 1; memset(dn, ' ', 11); /* skip leading dots and spaces */ i = strspn(name, ". "); if(i) { name += i; *mangled = 3; } ext = strrchr(name, '.'); /* main name */ TranslateToDos(toDos, name, dn->base, 8, ext, &BaseCase, mangled); if(ext) TranslateToDos(toDos, ext+1, dn->ext, 3, 0, &ExtCase, mangled); if(*mangled & 2) autorename_short(dn, 0); if(!*mangled) { if(BaseCase == LOWER) *mangled |= BASECASE; if(ExtCase == LOWER) *mangled |= EXTCASE; } }