Back to index

plt-scheme  4.2.1
Path.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: path- and filename manipulations
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #include "wx.h"
00028 
00029 #include <string.h>
00030 
00031 char *wxFileNameFromPath(char *path)
00032 {
00033     if (path) {
00034       int tcp, slen;
00035       
00036       tcp = slen = strlen(path);
00037       while (--tcp >= 0) {
00038        if (path[tcp] == '/') {
00039          char *naya;
00040          tcp++;
00041          naya = new WXGC_ATOMIC char[slen + 1 - tcp];
00042          memcpy(naya, path + tcp, slen + 1 - tcp);
00043          return naya;
00044        }
00045       }
00046     }
00047 
00048     return path;
00049 }
00050 
00051 char *wxPathOnly(char *path)
00052 {
00053   if (path) {
00054     int p, last_slash = 0;
00055     char *buf;
00056 
00057     buf = new WXGC_ATOMIC char[strlen(path) + 1];
00058     
00059     // copy path and keep the last slash or baskslash in mind
00060     for (p = 0; path[p]; p++) {
00061       buf[p] = path[p];
00062       if (buf[p] == '/')
00063        last_slash = p;
00064     }
00065     if (last_slash) {
00066       buf[last_slash] = 0;
00067       return buf;
00068     }
00069   }
00070 
00071   return NULL;
00072 }