]> err.no Git - sope/blob - gnustep-make/fixpath.sh.in
fixed mapping of 'method' attribute
[sope] / gnustep-make / fixpath.sh.in
1 #! /bin/sh
2 #
3 #   @configure_input@
4 #
5 #   Script for converting between windows and unix-style paths.
6 #
7 #   Copyright (C) 2001,2002 Free Software Foundation, Inc.
8 #
9 #   Author:  Stephen Brandon <stephen@brandonitconsulting.co.uk>
10 #   Modified by:  Richard Frith-Macdonald <rfm@gnu.org>
11 #
12 #   This file is part of the GNUstep Makefile Package.
13 #
14 #   This library is free software; you can redistribute it and/or
15 #   modify it under the terms of the GNU General Public License
16 #   as published by the Free Software Foundation; either version 2
17 #   of the License, or (at your option) any later version.
18 #   
19 #   You should have received a copy of the GNU General Public
20 #   License along with this library; see the file COPYING.LIB.
21 #   If not, write to the Free Software Foundation,
22 #   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 #
24
25 #
26 # Define CYGWIN to "yes" to force cygwin style path handling, or
27 # to anything else for MINGW32/MSYS style path handling.
28 #
29 CYGWIN="@CYGWIN@"
30
31 if [ ! $# -eq 2 ]; then
32   quit="yes"
33 fi
34
35 test "$1" = '-u' || test "$1" = '-w' || quit="yes"
36
37
38 if [ "$quit" = "yes" ]; then
39   echo "Usage: $0 (-u)|(-w) filename"
40   echo "Options:"
41   echo "   -u print Unix form of filename"
42   echo "   -w print Windows form of filename"
43   exit 1
44 fi
45
46 operation=$1
47 file=$2
48
49 if [ "$operation" = "-u" ]; then
50   #
51   # convert to Unix style file name
52   #
53   if [ "$CYGWIN" = "yes" ]; then
54     #
55     # drive:directory --> /cygdrive/drive/directory
56     #
57     echo $file | \
58     tr '\\' '/' | \
59     sed 's/^\([a-zA-Z]\):\(.*\)$/\/cygdrive\/\1\2/'
60   else
61     #
62     # drive:directory --> /drive/directory
63     #
64     echo $file | \
65     tr '\\' '/' | \
66     sed 's/^\([a-zA-Z]\):\(.*\)$/\/\1\2/' | \
67     sed 's/\/\//\//'
68   fi
69 else
70   #
71   # convert to Windows style file name
72   #
73   if [ "$CYGWIN" = "yes" ]; then
74     #
75     # /cygdrive/drive/directory --> drive:directory
76     #
77     echo $file | \
78     sed 's/^\(\/cygdrive\)\?\/\([a-zA-Z]\)\(\/.*\)$/\2:\3/' | \
79     tr '/' '\\'
80   else
81     #
82     # /drive/directory --> drive:directory
83     #
84     echo $file | \
85     sed 's/^\/\([a-zA-Z]\)\(\/.*\)$/\1:\2/' | \
86     tr '/' '\\'
87   fi
88 fi
89
90 exit 0
91
92