| 1 | // |
|---|
| 2 | // TxWin, Textmode Windowing Library |
|---|
| 3 | // |
|---|
| 4 | // Original code Copyright (c) 1995-2005 Fsys Software and Jan van Wijk |
|---|
| 5 | // |
|---|
| 6 | // ========================================================================== |
|---|
| 7 | // |
|---|
| 8 | // This file contains Original Code and/or Modifications of Original Code as |
|---|
| 9 | // defined in and that are subject to the GNU Lesser General Public License. |
|---|
| 10 | // You may not use this file except in compliance with the License. |
|---|
| 11 | // BY USING THIS FILE YOU AGREE TO ALL TERMS AND CONDITIONS OF THE LICENSE. |
|---|
| 12 | // A copy of the License is provided with the Original Code and Modifications, |
|---|
| 13 | // and is also available at http://www.dfsee.com/txwin/lgpl.htm |
|---|
| 14 | // |
|---|
| 15 | // This library is free software; you can redistribute it and/or modify |
|---|
| 16 | // it under the terms of the GNU Lesser General Public License as published |
|---|
| 17 | // by the Free Software Foundation; either version 2.1 of the License, |
|---|
| 18 | // or (at your option) any later version. |
|---|
| 19 | // |
|---|
| 20 | // This library is distributed in the hope that it will be useful, |
|---|
| 21 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 22 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
|---|
| 23 | // See the GNU Lesser General Public License for more details. |
|---|
| 24 | // |
|---|
| 25 | // You should have received a copy of the GNU Lesser General Public License |
|---|
| 26 | // along with this library; (lgpl.htm) if not, write to the Free Software |
|---|
| 27 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 28 | // |
|---|
| 29 | // Questions on TxWin licensing can be directed to: txwin@fsys.nl |
|---|
| 30 | // |
|---|
| 31 | // ========================================================================== |
|---|
| 32 | // |
|---|
| 33 | // TxLib filesystem functions, filename manipulations, base name |
|---|
| 34 | // |
|---|
| 35 | |
|---|
| 36 | #include <txlib.h> // TxLib interface |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | /*****************************************************************************/ |
|---|
| 40 | // Get base-name part from a path+filename string |
|---|
| 41 | /*****************************************************************************/ |
|---|
| 42 | char *TxGetBaseName // RET ptr to basename |
|---|
| 43 | ( |
|---|
| 44 | char *fname // IN path+filename string |
|---|
| 45 | ) |
|---|
| 46 | { |
|---|
| 47 | char *rc; |
|---|
| 48 | |
|---|
| 49 | if ((rc = strrchr( fname, FS_PATH_SEP)) != NULL) |
|---|
| 50 | { |
|---|
| 51 | rc++; // start of basename |
|---|
| 52 | } |
|---|
| 53 | else if ((rc = strrchr( fname, ':')) != NULL) // bare drive spec (x:file) |
|---|
| 54 | { |
|---|
| 55 | rc++; |
|---|
| 56 | } |
|---|
| 57 | else |
|---|
| 58 | { |
|---|
| 59 | rc = fname; // no path, use whole name |
|---|
| 60 | } |
|---|
| 61 | return( rc); |
|---|
| 62 | } // end 'TxGetBaseName' |
|---|
| 63 | /*---------------------------------------------------------------------------*/ |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | /*****************************************************************************/ |
|---|
| 67 | // Strip basename from path+filename string, leaving the PATH component only |
|---|
| 68 | /*****************************************************************************/ |
|---|
| 69 | char *TxStripBaseName // RET BaseName location, |
|---|
| 70 | ( // or NULL if not there |
|---|
| 71 | char *fname // IN path+filename string |
|---|
| 72 | ) // OUT path only string |
|---|
| 73 | { |
|---|
| 74 | char *rc = strrchr( fname, FS_PATH_SEP); |
|---|
| 75 | |
|---|
| 76 | if (rc != NULL) |
|---|
| 77 | { |
|---|
| 78 | *(rc++) = 0; // terminate at PATH_SEP loc |
|---|
| 79 | } // and advance to BaseName |
|---|
| 80 | return( rc); |
|---|
| 81 | } // end 'TxStripBaseName' |
|---|
| 82 | /*---------------------------------------------------------------------------*/ |
|---|