RTPathParse.cpp.h revision cda4a68d59969f27d3063ff91c9c3f887d34c8f9
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * IPRT - RTPathParse - Code Template.
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * This file included multiple times with different path style macros.
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * Copyright (C) 2006-2013 Oracle Corporation
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * available from http://www.virtualbox.org. This file is free software;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * you can redistribute it and/or modify it under the terms of the GNU
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * General Public License (GPL) as published by the Free Software
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * The contents of this file may alternatively be used under the terms
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * of the Common Development and Distribution License Version 1.0
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * VirtualBox OSE distribution, in which case the provisions of the
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * CDDL are applicable instead of those of the GPL.
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * You may elect to license modified versions of this file under the
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * terms and conditions of either the GPL or the CDDL or both.
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * @copydoc RTPathParse
889f8d29a8325ed741d1466074c5371910a1fd63vboxsyncstatic int RTPATH_STYLE_FN(rtPathParse)(const char *pszPath, PRTPATHPARSED pParsed, size_t cbParsed, uint32_t fFlags)
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * Parse the root specification if present and initialize the parser state
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * (keep it on the stack for speed).
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync uint32_t const cMaxComps = cbParsed < RT_UOFFSETOF(RTPATHPARSED, aComps[0xfff0])
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync ? (cbParsed - RT_UOFFSETOF(RTPATHPARSED, aComps)) / sizeof(pParsed->aComps[0])
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync fProps = RTPATH_PROP_RELATIVE | RTPATH_PROP_EXTRA_SLASHES;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* UNC - skip to the end of the potential namespace or computer name. */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync while (!RTPATH_IS_SLASH(pszPath[offCur]) && pszPath[offCur])
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* If there is another slash, we considered it a valid UNC path, if
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync not it's just a root path with an extra slash thrown in. */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_UNC | RTPATH_PROP_ABSOLUTE;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_RELATIVE;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_RELATIVE;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync fProps = RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_ABSOLUTE;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync else if (RT_C_IS_ALPHA(pszPath[0]) && pszPath[1] == ':')
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync fProps = RTPATH_PROP_VOLUME | RTPATH_PROP_RELATIVE;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync fProps = RTPATH_PROP_VOLUME | RTPATH_PROP_ROOT_SLASH | RTPATH_PROP_ABSOLUTE;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* Add it to the component array . */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* Skip unnecessary slashes following the root-spec. */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * Parse the rest.
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* Find the end of the component. */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync while ((ch = pszPath[offCur]) != '\0' && !RTPATH_IS_SLASH(ch))
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* Add it. */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* Look for '.' and '..' references. */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync else if (cchComp == 2 && pszPath[offCur - 1] == '.' && pszPath[offCur - 2] == '.')
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync fProps |= RTPATH_PROP_DOTDOT_REFS | RTPATH_PROP_RELATIVE;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* Skip unnecessary slashes. Leave ch unchanged! */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* The end? */
cda4a68d59969f27d3063ff91c9c3f887d34c8f9vboxsync fProps |= RTPATH_PROP_DIR_SLASH; /* (not counted in component, but in cchPath) */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* look for an ? */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync uint32_t cchSuffix = offStart + cchComp - offSuffix;
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync /* No, not the end. Account for an separator before we restart the loop. */
889f8d29a8325ed741d1466074c5371910a1fd63vboxsync * Store the remainder of the state and we're done.