Skip to content

Commit

Permalink
move (almost) all stuff relevant for AppleDouble format and file name…
Browse files Browse the repository at this point in the history
… conventions to fileDouble.cpp
  • Loading branch information
autc04 committed Nov 19, 2017
1 parent a01cc7b commit 9cac2f0
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 196 deletions.
149 changes: 0 additions & 149 deletions src/fileAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ namespace Executor
PRIVATE OSErr PBLockUnlockRange(ParmBlkPtr, BOOLEAN, lockunlock_t);
PRIVATE VCB *vlookupbydrive(INTEGER);
PRIVATE char *dirindex(char *, LONGINT, BOOLEAN, struct stat *);
PRIVATE unsigned char tohex(unsigned char);
PRIVATE INTEGER Mac_to_UNIX7(unsigned char *, INTEGER, unsigned char *);
PRIVATE BOOLEAN myscandir(char *, char, char *, INTEGER);
PRIVATE LONGINT weasel(char *, struct stat *);
PRIVATE OSErr macopen(char *, short, LONGINT *, BOOLEAN, Byte *);
Expand Down Expand Up @@ -348,47 +346,6 @@ A0(PUBLIC, void, ROMlib_rewinddir)
cacheindex = 0x7fffffff;
}

/*
* Blech! I've finally caved in and am going to look for the magic
* number in the obnoxious case of a file that starts with %XX where XX
* are two upper case hex digits.
*/

PUBLIC BOOLEAN Executor::ROMlib_isresourcefork(const char *fullname)
{
LONGINT fd;
LONGINT magic;
BOOLEAN retval;
const char *filename;

/* netatalk_conventions_p means we never see resource forks, because
they're stored in a subdirectory */

if(netatalk_conventions_p)
retval = false;
else
{
filename = strrchr(fullname, '/');
if(!filename)
filename = fullname;
else
++filename;
if(filename[0] != '%')
retval = false;
else if(!isxdigit(filename[1]) || !isxdigit(filename[2]))
retval = true;
else
{
fd = -1;
retval = (fd = Uopen(fullname, O_BINARY | O_RDONLY, 0)) >= 0 && read(fd, (void *)&magic, sizeof(magic)) == sizeof(magic) && (magic == CLC(DOUBLEMAGIC).raw()
|| magic == DOUBLEMAGIC);
if(fd >= 0)
Uclose(fd);
}
}
return retval;
}

int Executor::ROMlib_no_dot_files = false;

static bool
Expand Down Expand Up @@ -485,66 +442,6 @@ A4(PRIVATE, char *, dirindex, char *, dir, LONGINT, index, BOOLEAN, nodirectorie
return dp ? dp->d_name : 0;
}

/*
* NOTE: we must use capital letters in tohex below. Code depends on it.
*/

A1(PRIVATE, unsigned char, tohex, unsigned char, c)
{
unsigned char retval;

retval = (unsigned char)(netatalk_conventions_p ? "0123456789abcdef"
: "0123456789ABCDEF")[c & 0xF];
return retval;
}

A3(PRIVATE, INTEGER, Mac_to_UNIX7, unsigned char *, name, INTEGER, length,
unsigned char *, out)
{
unsigned char c;
INTEGER retval;
bool last_character_was_colon;

retval = length;
last_character_was_colon = true;
while(--length >= 0)
{
c = *name++;
if(NEEDTOMAP(c))
{
*out++ = apple_double_quote_char;
*out++ = tohex(c >> 4);
*out++ = tohex(c);
retval += 2;
}
else if(c == ':')
{
if(last_character_was_colon)
{
*out++ = '.';
*out++ = '.';
retval += 2;
}
*out++ = '/';
}
else
*out++ = c;
last_character_was_colon = c == ':';
}
return retval;
}

A2(PUBLIC, char *, ROMlib_newunixfrommac, char *, ip, INTEGER, n)
{
char *retval;

if((retval = (char *)malloc(3 * n + 1))) /* worst case numbers */
retval[Mac_to_UNIX7((unsigned char *)ip, n,
(unsigned char *)retval)]
= 0;
return retval;
}

/*
* ROMlib_breakoutioname's role is to examine ioNamePtr and vRefNum
* to determine the vcbp, but since it has to look at ioNamePtr
Expand Down Expand Up @@ -958,52 +855,6 @@ A9(PUBLIC, OSErr, ROMlib_nami, ParmBlkPtr, pb, LONGINT, dir, /* INTERNAL */
return err;
}

/*
* Old algorithm:
*
* The new code is a little bit tricky; it would be just prepend a %, except
* if someone has a name that begins with two hex digits ("feed me") you would
* get something that could be a data fork, so we make sure that if the first
* char is a % and the next two are hex and the hex would make something that
* we would have wanted to map then we map the second character even though
* we normally wouldn't map it.
*
* New algorithm:
*
* We just prepend the bloody "%" -- We get into trouble with other providers
* of Apple Double if we do it differently. What a crock.
*/

#define ROOTS_PERCENT_FILE "%%2F"

A3(PUBLIC, char *, ROMlib_resname, char *, pathname, /* INTERNAL */
char *, filename, char *, endname)
{
int pathnamesize, filenamesize, newsize;
char *newname;

pathnamesize = filename - pathname;
filenamesize = endname - filename;
if(pathnamesize)
{
newsize = pathnamesize + filenamesize
+ apple_double_fork_prefix_length;
newname = (char *)malloc(newsize);
memcpy(newname, pathname, pathnamesize);
strcpy(&newname[pathnamesize], apple_double_fork_prefix);
memcpy(newname + pathnamesize + apple_double_fork_prefix_length,
filename, filenamesize);
}
else
{
/* "E:/" --> "E:/%%2F" */
newsize = filenamesize + sizeof(ROOTS_PERCENT_FILE);
newname = (char *)malloc(newsize);
sprintf(newname, "%s%s", filename, ROOTS_PERCENT_FILE);
}
return newname;
}

/*
* macopen opens the file using mac permissions, returning an OSErr
* the file descriptor of the opened file is filled in where fdp points
Expand Down
3 changes: 1 addition & 2 deletions src/fileCreate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@ A4(PRIVATE, OSErr, PBDeleteForD, ParmBlkPtr, pb, BOOLEAN, a,

rpathname = ROMlib_resname(pathname, filename, endname);
deletefailed = Uunlink(rpathname);
if(netatalk_conventions_p)
double_dir_op(pathname, rmdir_op);
double_dir_op(pathname, rmdir_op);
if(!deletefailed || errno == ENOTDIR || errno == ENOENT)
deletefailed = Uunlink(pathname);
if(deletefailed && ford == Directory)
Expand Down
Loading

0 comments on commit 9cac2f0

Please sign in to comment.