/* $Id: kLdrHlpPath.c 2944 2007-01-13 15:55:40Z bird $ */ /** @file * * kLdr - The Dynamic Loader, Path Helper Functions. * * Copyright (c) 2006-2007 knut st. osmundsen * * * This file is part of kLdr. * * kLdr is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * kLdr is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with kLdr; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ /******************************************************************************* * Header Files * *******************************************************************************/ #include #include "kLdrHlp.h" /** * Get the pointer to the filename part of the name. * * @returns Pointer to where the filename starts within the string pointed to by pszFilename. * @returns Pointer to the terminator char if no filename. * @param pszFilename The filename to parse. */ char *kldrHlpGetFilename(const char *pszFilename) { const char *pszLast = NULL; for (;;) { char ch = *pszFilename; #if defined(__OS2__) || defined(__WIN__) if (ch == '/' || ch == '\\' || ch == ':') { while ((ch = *++pszFilename) == '/' || ch == '\\' || ch == ':') /* nothing */; pszLast = pszFilename; } #else if (ch == '/') { while ((ch = *++pszFilename) == '/') /* betsuni */; pszLast = pszFilename; } #endif if (!ch) return (char *)(pszLast ? pszLast : pszFilename); pszFilename++; } } /** * Gets the filename suffix. * * @returns Pointer to where the suffix starts within the string pointed to by pszFilename. * @returns Pointer to the terminator char if no suffix. * @param pszFilename The filename to parse. */ char *kldrHlpGetSuff(const char *pszFilename) { const char *pszDot = NULL; pszFilename = kldrHlpGetFilename(pszFilename); for (;;) { char ch = *pszFilename; if (ch == '.') { while ((ch = *++pszFilename) == '.') /* nothing */; if (ch) pszDot = pszFilename - 1; } if (!ch) return (char *)(pszDot ? pszDot : pszFilename); pszFilename++; } } /** * Gets the filename extention. * * @returns Pointer to where the extension starts within the string pointed to by pszFilename. * @returns Pointer to the terminator char if no extension. * @param pszFilename The filename to parse. */ char *kldrHlpGetExt(const char *pszFilename) { char *psz = kldrHlpGetSuff(pszFilename); return *psz ? psz + 1 : psz; } /** * Checks if this is only a filename or if it contains any kind * of drive, directory, or server specs. * * @returns 1 if this is a filename only. * @returns 0 of it's isn't only a filename. * @param pszFilename The filename to parse. */ int kldrHlpIsFilenameOnly(const char *pszFilename) { for (;;) { const char ch = *pszFilename++; #if defined(__OS2__) || defined(__WIN__) if (ch == '/' || ch == '\\' || ch == ':') #else if (ch == '/') #endif return 0; if (!ch) return 1; } }