]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/m2/tools-src/calcpath
3 # calcpath return a path which is $1/$2/$3 when $2 is relative and $2/$3 if absolute.
5 # Copyright (C) 2021-2024 Free Software Foundation, Inc.
6 # Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
8 # This file is part of GNU Modula-2.
10 # GNU Modula-2 is free software; you can redistribute it and/or modify it under
11 # the terms of the GNU General Public License as published by the Free
12 # Software Foundation; either version 3, or (at your option) any later
15 # GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
20 # You should have received a copy of the GNU General Public License along
21 # with gm2; see the file COPYING. If not, write to the Free Software
22 # Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *)
27 Usage: $0 pathcomponent1 pathcomponent2 subdir
28 if pathcomponent2 is relative then pathcomponent1/pathcompinent2/subdir is returned
29 otherwise pathcomponent2/subdir is returned
30 the path is checked for legality in subdir.
35 printf "calcpath: error: %s\n" "$1" >&2
41 /*) the_path
="$2/$3" ;;
42 *) the_path
="$1/$2/$3" ;;
44 cd "$3" || die
"could not access $3"
45 if ( cd "$the_path" ); then
46 printf '%s\n' "${the_path}"
48 die
"${the_path} is not a valid path in subdirectory $3"