Exemplo n.º 1
0
		  Int16u FNSplit (const char * pathP,
								char       * driveP,
								char       * dirP,
								char       * nameP,
								char       * extP)
		  {
				Int16u     Ret;

				//Set all string to default value zero
				Ret = 0;
				if (driveP)
					 *driveP = 0;
				if (dirP)
					 *dirP = 0;
				if (nameP)
					 *nameP = 0;
				if (extP)
					 *extP = 0;

				if (pathP == 0)
					 return 0;


				const char * cursor = pathP,
							  * dirStart = 0,
							  * lastSlash = 0;

//				if (StartsWithAnsi (cursor) && _istalpha (*cursor) &&
				if (StartsWithAnsi (cursor) && isAlpha (*cursor) &&
					 StartsWithAnsiChar (cursor + 1, ':'))
				{
					 // A drive letter presents.
					 if (driveP != 0)
						  StrCpyN (driveP, cursor, MAXDRIVE);

					 cursor += 2;
                Ret |= DRIVE;
            }

            dirStart = cursor;

            // now find the last slash
            while (*cursor != '\0')
            {
                if (StartsWithAnsiChar (cursor, '/') ||
                    StartsWithAnsiChar (cursor, '\\'))
                    lastSlash = cursor;

                cursor = AnsiNext (cursor);
            }

            if (lastSlash != 0)
            {
                // a slash was seen
                if (dirP != 0)
                {
                    Int16u bytesToCopy = lastSlash - dirStart
                                         + 1  // for '/'
                                         + 1; // for '\0'

                    if (bytesToCopy > MAXDIR)
                        bytesToCopy = MAXDIR;

                    StrCpyN (dirP, dirStart, bytesToCopy);
                }

                cursor = lastSlash + 1;

                Ret |= DIRECTORY;
            } else
                cursor = dirStart;

            // cursor now points to the start of the filename
            // check for wildcards
            if (AnsiStrChr (cursor, '*') != 0 ||
                AnsiStrChr (cursor, '?') != 0)
                Ret |= WILDCARDS;

            // now see if there's an extension
            const char * period = 0;

            for (const char * ptr = cursor; *ptr != '\0'; ptr = AnsiNext (ptr))
            {
                if (StartsWithAnsiChar (ptr, '.'))
                    period = ptr;
            }

            if (period != 0)
            {
                Int16u bytesToCopy = period - cursor + 1;  // for '\0'

                if (bytesToCopy > MAXFILE)
                    bytesToCopy = MAXFILE;

                if (bytesToCopy > 0)
                {
                    if (nameP != 0)
                        StrCpyN (nameP, cursor, bytesToCopy);

                    Ret |= FILENAME;
                }

                if (extP != 0)
                    StrCpyN (extP, period, MAXEXT);

                Ret |= EXTENSION;
            } else 
            {
                if (*cursor != '\0')
                {
                    if (nameP != 0)
                        StrCpyN (nameP, cursor, MAXFILE);

                    Ret |= FILENAME;
                }
            }

        #if defined (DEBUG_FNSPLIT)
            static char buffer [MAXPATH + MAXPATH + 32];

            wsprintf (buffer, 
                      "pathP:[%s]  driveP:[%s]  dirP:[%s]  nameP:[%s]  extP:[%s]",
                      pathP,
                      driveP != NULL ? driveP : "<NULL>",
                      dirP != NULL ? dirP : "<NULL>",
                      nameP != NULL ? nameP : "<NULL>",
                      extP != NULL ? extP : "<NULL>");
            MessageBox (GetActiveWindow (), buffer, "FNSplit", MB_OK);
        #endif //(DEBUG_FNSPLIT)

            return Ret;
        }
Exemplo n.º 2
0
inline char * AnsiStrChr (char * s, char c)
{
    return ((char *)AnsiStrChr ((const char *)s, c));
}