Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cygpath.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 2000, Brown University, Providence, RI.
00003  * 
00004  *                         All Rights Reserved
00005  * 
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  * 
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00022  */
00023 
00024 #include "std/strings.H"
00025 
00026 
00027 // this function changes occurances of /cygdrive/c/folder1/folder2/etc.. to
00028 // c:/folder1/folder2/etc.. when running in Windows.  paths coming from 
00029 // program arguments or environment variables will tend to take the
00030 // /cygdrive/<drive-letter>/ form when running under cygwin, but file
00031 // commands compiled with the MS Visual C++ compiler can't deal with paths
00032 // of this form.
00033 str_ptr
00034 decygify_path(Cstr_ptr in)
00035 {
00036 #ifdef WIN32
00037   char *startofcyg = strstr(**in,"/cygdrive");
00038   if (startofcyg) {
00039     int numpre = startofcyg - **in;
00040     char *precyg;
00041     precyg = new char[numpre+1];
00042     strncpy(precyg, **in, numpre);
00043     precyg[numpre] = '\0';
00044 
00045     char *endofcyg   = strstr(startofcyg+1,"/");
00046     char drive = endofcyg[1];
00047     char *rest = endofcyg+2;
00048 
00049     str_ptr newpath = str_ptr(precyg) + str_ptr(drive) + str_ptr(":") + 
00050       str_ptr(rest);
00051     delete [] precyg;
00052 
00053     // recursive call
00054     return decygify_path(newpath);
00055   }
00056   else {
00057     // no occurance of /cygdrive, return input unmodified
00058     return in;
00059   }
00060 #else
00061   return in;
00062 #endif
00063 }

Generated on Mon Sep 15 16:25:56 2003 for gluebase by doxygen1.2.18