├── .github └── workflows │ └── makefile.yml ├── .gitignore ├── COPYRIGHT ├── EXCLUDE ├── Makefile.in ├── README.md ├── VERSION ├── aclocal.m4 ├── config.guess ├── config.sub ├── configure.ac ├── duti.1 ├── duti.c ├── handler.c ├── handler.h ├── install-sh ├── pkg-resources ├── Description.plist ├── Info.plist ├── License.rtf ├── ReadMe.rtf └── Welcome.rtf ├── plist.c ├── plist.h ├── util.c ├── util.h └── version.c.in /.github/workflows/makefile.yml: -------------------------------------------------------------------------------- 1 | name: Makefile CI 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: macos-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | 17 | - name: configure 18 | run: autoreconf -i && ./configure 19 | 20 | - name: Install dependencies 21 | run: make 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile 2 | a.out 3 | autom4te.cache 4 | /config.h 5 | config.log 6 | config.status 7 | configure 8 | version.c 9 | *.o 10 | -------------------------------------------------------------------------------- /COPYRIGHT: -------------------------------------------------------------------------------- 1 | duti is free software released into the public domain by Andrew Mortensen, 2008. 2 | It is provided as is without warranties of any kind. 3 | 4 | You may do anything you like with this software. If you incorporate some or all 5 | of the source into a project, I'd appreciate a credit for the work I've done, 6 | but that's all. Enjoy. 7 | -------------------------------------------------------------------------------- /EXCLUDE: -------------------------------------------------------------------------------- 1 | .cvsignore 2 | .gitignore 3 | .git 4 | CVS 5 | EXCLUDE 6 | Makefile 7 | config.log 8 | config.status 9 | -------------------------------------------------------------------------------- /Makefile.in: -------------------------------------------------------------------------------- 1 | SHELL = /bin/sh 2 | 3 | srcdir = @srcdir@ 4 | VPATH = @srcdir@ 5 | 6 | prefix=@prefix@ 7 | exec_prefix=@exec_prefix@ 8 | datarootdir=@datarootdir@ 9 | datadir=@datadir@ 10 | BINDIR=@bindir@ 11 | MANDIR=@mandir@ 12 | 13 | DUTI_BUILD_DATE=@build_date@ 14 | 15 | CC= @CC@ 16 | FRAMEWORKS= -framework ApplicationServices -framework CoreFoundation 17 | OPTOPTS= -isysroot @macosx_sdk@ \ 18 | @macosx_arches@ \ 19 | -mmacosx-version-min=@macosx_dep_target@ \ 20 | @OPTOPTS@ 21 | 22 | LIBS= @LIBS@ 23 | LDFLAGS= @LDFLAGS@ ${LIBS} 24 | CFLAGS= ${OPTOPTS} @CFLAGS@ 25 | INSTALL= @INSTALL@ 26 | 27 | TARGETS= duti 28 | MAN1TARGETS= duti.1 29 | MANTARGETS= ${MAN1TARGETS} 30 | 31 | DUTI_OBJ= version.o util.o plist.o handler.o duti.o 32 | 33 | all : ${TARGETS} 34 | 35 | version.o : version.c 36 | ${CC} ${CFLAGS} -c ${srcdir}/version.c 37 | 38 | duti.o : duti.c 39 | ${CC} ${CFLAGS} -c ${srcdir}/duti.c 40 | 41 | handler.o : handler.c 42 | ${CC} ${CFLAGS} -c ${srcdir}/handler.c 43 | 44 | plist.o : plist.c 45 | ${CC} ${CFLAGS} -c ${srcdir}/plist.c 46 | 47 | util.o : util.c 48 | ${CC} ${CFLAGS} -c ${srcdir}/util.c 49 | 50 | duti : ${DUTI_OBJ} 51 | ${CC} ${FRAMEWORKS} ${CFLAGS} -o duti ${DUTI_OBJ} ${LDFLAGS} 52 | 53 | VERSION=$(shell date +%Y%m%d) 54 | DISTDIR=duti-${VERSION} 55 | 56 | dist : distclean 57 | mkdir ../${DISTDIR} 58 | tar -h -c -f - -X EXCLUDE . | tar xpf - -C ../${DISTDIR} 59 | echo ${VERSION} > ../${DISTDIR}/VERSION 60 | sed -e "s@INTERNAL@${VERSION}@" \ 61 | < configure.ac > ../${DISTDIR}/configure.ac 62 | (cd "../${DISTDIR}"; autoconf; rm -rf autom4te.cache) 63 | for i in ${MANTARGETS}; do \ 64 | sed -e 's@_DUTI_BUILD_DATE@${DUTI_BUILD_DATE}@g' \ 65 | ../${DISTDIR}/$$i > ../${DISTDIR}/$$i.tmp; \ 66 | mv -f ../${DISTDIR}/$$i.tmp ../${DISTDIR}/$$i; \ 67 | done 68 | (cd .. && tar cvfz ${DISTDIR}.tar.gz ${DISTDIR}) 69 | for c in sha1 rmd160 md5; do \ 70 | (cd .. && openssl $$c ${DISTDIR}.tar.gz); \ 71 | done 72 | 73 | install : all 74 | -mkdir -p ${DESTDIR}${BINDIR} 75 | ${INSTALL} -m 0755 -c ${TARGETS} ${DESTDIR}${BINDIR}/ 76 | -mkdir -p ${DESTDIR}${MANDIR}/man1 77 | ${INSTALL} -m 0644 -c ${MAN1TARGETS} ${DESTDIR}${MANDIR}/man1/ 78 | 79 | PKGNAME= duti-${VERSION} 80 | PKGDIR= tmp/duti-installer 81 | PKGRSRC= $(wildcard pkg-resources/*.rtf) 82 | PKGINFODIR= tmp/Info 83 | PKGINFO= pkg-resources/Description.plist pkg-resources/Info.plist 84 | DEVUTILS= /Developer/Applications/Utilities 85 | PKGMKR= ${DEVUTILS}/PackageMaker.app/Contents/MacOS/packagemaker 86 | 87 | packageroot : all 88 | -mkdir -p -m 0755 ${PKGDIR}/${BINDIR} 89 | for i in ${TARGETS}; do \ 90 | ${INSTALL} -m 0755 -c $$i ${PKGDIR}/${BINDIR}/; \ 91 | done 92 | -mkdir -p -m 0755 ${PKGDIR}/${MANDIR} 93 | -mkdir -p -m 0755 ${PKGDIR}/${MANDIR}/man1 94 | for i in ${MANTARGETS}; do \ 95 | ${INSTALL} -m 0644 $$i ${PKGDIR}/${MANDIR}/man1/; \ 96 | sed -e 's@_DUTI_BUILD_DATE@${DUTI_BUILD_DATE}@g' \ 97 | ${PKGDIR}/${MANDIR}/man1/$$i > \ 98 | ${PKGDIR}/${MANDIR}/man1/$$i.tmp; \ 99 | mv -f ${PKGDIR}/${MANDIR}/man1/$$i.tmp \ 100 | ${PKGDIR}/${MANDIR}/man1/$$i; \ 101 | done 102 | -mkdir -p -m 0755 ${PKGINFODIR} 103 | for i in ${PKGINFO}; do \ 104 | sed -e 's@_DUTI_VERSION@${VERSION}@g' $$i \ 105 | > ${PKGINFODIR}/`basename $$i`; \ 106 | done 107 | for i in ${PKGRSRC}; do \ 108 | ${INSTALL} -m 0644 -c $$i ${PKGINFODIR}/`basename $$i`; \ 109 | done 110 | sudo chown -R root:wheel ${PKGDIR} 111 | sudo chgrp admin ${PKGDIR} 112 | 113 | pkgmaker : packageroot 114 | ${PKGMKR} -build -p ../${PKGNAME}.pkg \ 115 | -f ${PKGDIR} -r ${PKGINFODIR} \ 116 | -i ${PKGINFODIR}/Info.plist \ 117 | -d ${PKGINFODIR}/Description.plist 118 | (cd .. && tar cvfz ${PKGNAME}.pkg.tar.gz ${PKGNAME}.pkg) 119 | sudo rm -rf tmp 120 | for c in sha1 rmd160 md5; do \ 121 | (cd ..; openssl $$c ${PKGNAME}.pkg.tar.gz); \ 122 | done 123 | 124 | pkgbld : packageroot 125 | pkgbuild --root ${PKGDIR} \ 126 | --identifier public-domain.mortensen.duti-installer \ 127 | --version ${VERSION} \ 128 | ../${PKGNAME}.pkg 129 | 130 | pkgbldsigned : pkgbld 131 | /bin/mv ../${PKGNAME}.pkg ../${PKGNAME}-unsigned.pkg 132 | productsign --timestamp --sign "${INST_KEY}" ../${PKGNAME}-unsigned.pkg ../${PKGNAME}.pkg 133 | 134 | pkgcln : 135 | (cd .. && tar cvfz ${PKGNAME}.pkg.tar.gz ${PKGNAME}.pkg) 136 | sudo rm -rf tmp 137 | for c in sha1 rmd160 md5; do \ 138 | (cd ..; openssl $$c ${PKGNAME}.pkg.tar.gz); \ 139 | done 140 | 141 | pkg : pkgbld pkgcln 142 | 143 | pkgsigned : pkgbldsigned pkgcln 144 | 145 | clean : 146 | rm -f *.o a.out core 147 | rm -f ${TARGETS} 148 | rm -rf tmp 149 | 150 | distclean : clean 151 | rm -f config.log config.status config.cache Makefile version.c 152 | rm -rf autom4te.cache 153 | rm -rf .#* 154 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | duti 2 | ==== 3 | 4 | duti is a command-line utility capable of setting default applications for 5 | various document types on [macOS](https://www.apple.com/macos/), using Apple's 6 | [Uniform Type 7 | Identifiers](https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_intro/understand_utis_intro.html) 8 | (UTI). A UTI is a unique string describing the format of a file's content. For 9 | instance, a Microsoft Word document has a UTI of `com.microsoft.word.doc`. Using 10 | `duti`, the user can change which application acts as the default handler for a 11 | given UTI. 12 | 13 | 14 | Compiling 15 | --------- 16 | 17 | autoreconf -i 18 | ./configure 19 | make 20 | sudo make install 21 | 22 | 23 | Usage 24 | ----- 25 | 26 | `duti` can read settings from four different sources: 27 | 28 | 1. standard input 29 | 30 | 1. a settings file 31 | 32 | 1. an XML [property list](https://en.wikipedia.org/wiki/Property_list) (plist) 33 | 34 | 1. command-line arguments. 35 | 36 | A settings line, as read in cases 1 and 2, consists of an application's bundle 37 | ID, a UTI, and a string describing what role the application handles for the 38 | given UTI. The process is similar when `duti` processes a plist. If the path 39 | given to `duti` on the command-line is a directory, `duti` will apply settings 40 | from all valid settings files in that directory, excluding files whose names 41 | begin with `.` (single dot). 42 | 43 | `duti` can also print out the default application information for a given 44 | extension (`-x`). This feature is based on public domain source code posted 45 | by Keith Alperin on the heliumfoot.com blog. 46 | 47 | See the man page for additional usage details. 48 | 49 | 50 | Examples 51 | -------- 52 | 53 | * Set Safari as the default handler for HTML documents: 54 | 55 | ```sh 56 | duti -s com.apple.Safari public.html all 57 | ``` 58 | 59 | * Set TextEdit as the default handler for Word documents: 60 | 61 | ```sh 62 | echo 'com.apple.TextEdit com.microsoft.word.doc all' | duti 63 | ``` 64 | 65 | * Set Finder as the default handler for ftp:// URLs: 66 | 67 | ```sh 68 | duti -s com.apple.Finder ftp 69 | ``` 70 | 71 | * Get default application information for .jpg files: 72 | 73 | ```sh 74 | duti -x jpg 75 | 76 | # Output 77 | Preview 78 | /Applications/Preview.app 79 | com.apple.Preview 80 | ``` 81 | 82 | Support 83 | ------- 84 | 85 | `duti` is unsupported. You can submit bug reports and feature requests at 86 | the duti [GitHub project page](https://github.com/moretension). 87 | 88 | Related 89 | ------- 90 | [dutis](https://github.com/tsonglew/dutis) is a wrapper around duti, providing an 91 | interactive interface to select default applications. 92 | 93 | License 94 | ------- 95 | 96 | `duti` was originally released into the public domain by Andrew Mortensen 97 | in 2008. It's provided as is without warranties of any kind. You can do 98 | anything you want with it. If you incorporate some or all of the code into 99 | another project, I'd appreciate credit for the work I've done, but that's all. 100 | 101 | Andrew Mortensen 102 | April 2018 103 | -------------------------------------------------------------------------------- /VERSION: -------------------------------------------------------------------------------- 1 | internal 2 | -------------------------------------------------------------------------------- /aclocal.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([DUTI_CHECK_SDK], 2 | [ 3 | AC_MSG_CHECKING(which SDK to use) 4 | AC_ARG_WITH(macosx-sdk, 5 | AC_HELP_STRING([--with-macosx-sdk=DIR], [path to SDK]), 6 | macosx_sdk="$withval") 7 | 8 | sdk_path="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs" 9 | macosx_arches="-arch i386 -arch x86_64" 10 | 11 | case "${host_os}" in 12 | darwin8*) 13 | sdk_path="/Developer/SDKs/MacOSX10.4u.sdk" 14 | macosx_arches="" 15 | ;; 16 | 17 | darwin9*) 18 | sdk_path="/Developer/SDKs/MacOSX10.5.sdk" 19 | ;; 20 | 21 | darwin10*) 22 | sdk_path="/Developer/SDKs/MacOSX10.6.sdk" 23 | ;; 24 | 25 | darwin11*) 26 | sdk_path="${sdk_path}/MacOSX10.7.sdk" 27 | ;; 28 | 29 | darwin12*) 30 | sdk_path="${sdk_path}/MacOSX10.8.sdk" 31 | ;; 32 | 33 | darwin13*) 34 | sdk_path="${sdk_path}/MacOSX10.9.sdk" 35 | macosx_arches="" 36 | ;; 37 | 38 | darwin14*) 39 | sdk_path="${sdk_path}/MacOSX10.10.sdk" 40 | macosx_arches="" 41 | ;; 42 | 43 | darwin15*|darwin16*|darwin17*|darwin18*) 44 | sdk_path="${sdk_path}/MacOSX.sdk" 45 | macosx_arches="" 46 | ;; 47 | 48 | darwin19*) 49 | sdk_path="${sdk_path}/MacOSX.sdk" 50 | macosx_arches="-arch x86_64" 51 | ;; 52 | 53 | darwin20*|darwin21*|darwin22*) 54 | sdk_path="${sdk_path}/MacOSX.sdk" 55 | macosx_arches="-arch x86_64 -arch arm64" 56 | ;; 57 | 58 | *) 59 | AC_MSG_ERROR([${host_os} is not a supported system]) 60 | esac 61 | 62 | if test -z "$macosx_sdk"; then 63 | macosx_sdk=$sdk_path 64 | fi 65 | 66 | AC_SUBST(macosx_arches) 67 | AC_SUBST(macosx_sdk) 68 | AC_MSG_RESULT($macosx_sdk) 69 | ]) 70 | 71 | AC_DEFUN([DUTI_CHECK_DEPLOYMENT_TARGET], 72 | [ 73 | AC_MSG_CHECKING(Mac OS X deployment target) 74 | 75 | AC_ARG_WITH(macosx-deployment-target, 76 | AC_HELP_STRING([--with-macosx-deployment-target=VERSION], 77 | [OS version]), macosx_dep_target="$withval") 78 | 79 | case "${host_os}" in 80 | darwin8*) 81 | dep_target="10.4" 82 | ;; 83 | 84 | darwin9*) 85 | dep_target="10.5" 86 | ;; 87 | 88 | darwin10*) 89 | dep_target="10.6" 90 | ;; 91 | 92 | darwin11*) 93 | dep_target="10.7" 94 | ;; 95 | 96 | darwin12*) 97 | dep_target="10.8" 98 | ;; 99 | 100 | darwin13*) 101 | dep_target="10.9" 102 | ;; 103 | 104 | darwin14*) 105 | dep_target="10.10" 106 | ;; 107 | 108 | darwin15*) 109 | dep_target="10.11" 110 | ;; 111 | 112 | darwin16*) 113 | dep_target="10.12" 114 | ;; 115 | 116 | darwin17*) 117 | dep_target="10.13" 118 | ;; 119 | 120 | darwin18*) 121 | dep_target="10.14" 122 | ;; 123 | 124 | darwin19*) 125 | dep_target="10.15" 126 | ;; 127 | 128 | darwin20*) 129 | dep_target="11" 130 | ;; 131 | 132 | darwin21*) 133 | dep_target="12" 134 | ;; 135 | 136 | darwin22*) 137 | dep_target="13" 138 | ;; 139 | 140 | esac 141 | 142 | if test -z "$macosx_dep_target"; then 143 | macosx_dep_target=$dep_target 144 | fi 145 | 146 | AC_SUBST(macosx_dep_target) 147 | AC_MSG_RESULT($macosx_dep_target) 148 | ]) 149 | -------------------------------------------------------------------------------- /config.guess: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Attempt to guess a canonical system name. 3 | # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 4 | # 2000, 2001, 2002 Free Software Foundation, Inc. 5 | 6 | timestamp='2002-10-21' 7 | 8 | # This file is free software; you can redistribute it and/or modify it 9 | # under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation; either version 2 of the License, or 11 | # (at your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 21 | # 22 | # As a special exception to the GNU General Public License, if you 23 | # distribute this file as part of a program that contains a 24 | # configuration script generated by Autoconf, you may include it under 25 | # the same distribution terms that you use for the rest of that program. 26 | 27 | # Originally written by Per Bothner . 28 | # Please send patches to . Submit a context 29 | # diff and a properly formatted ChangeLog entry. 30 | # 31 | # This script attempts to guess a canonical system name similar to 32 | # config.sub. If it succeeds, it prints the system name on stdout, and 33 | # exits with 0. Otherwise, it exits with 1. 34 | # 35 | # The plan is that this can be called by configure scripts if you 36 | # don't specify an explicit build system type. 37 | 38 | me=`echo "$0" | sed -e 's,.*/,,'` 39 | 40 | usage="\ 41 | Usage: $0 [OPTION] 42 | 43 | Output the configuration name of the system \`$me' is run on. 44 | 45 | Operation modes: 46 | -h, --help print this help, then exit 47 | -t, --time-stamp print date of last modification, then exit 48 | -v, --version print version number, then exit 49 | 50 | Report bugs and patches to ." 51 | 52 | version="\ 53 | GNU config.guess ($timestamp) 54 | 55 | Originally written by Per Bothner. 56 | Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 57 | Free Software Foundation, Inc. 58 | 59 | This is free software; see the source for copying conditions. There is NO 60 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." 61 | 62 | help=" 63 | Try \`$me --help' for more information." 64 | 65 | # Parse command line 66 | while test $# -gt 0 ; do 67 | case $1 in 68 | --time-stamp | --time* | -t ) 69 | echo "$timestamp" ; exit 0 ;; 70 | --version | -v ) 71 | echo "$version" ; exit 0 ;; 72 | --help | --h* | -h ) 73 | echo "$usage"; exit 0 ;; 74 | -- ) # Stop option processing 75 | shift; break ;; 76 | - ) # Use stdin as input. 77 | break ;; 78 | -* ) 79 | echo "$me: invalid option $1$help" >&2 80 | exit 1 ;; 81 | * ) 82 | break ;; 83 | esac 84 | done 85 | 86 | if test $# != 0; then 87 | echo "$me: too many arguments$help" >&2 88 | exit 1 89 | fi 90 | 91 | trap 'exit 1' 1 2 15 92 | 93 | # CC_FOR_BUILD -- compiler used by this script. Note that the use of a 94 | # compiler to aid in system detection is discouraged as it requires 95 | # temporary files to be created and, as you can see below, it is a 96 | # headache to deal with in a portable fashion. 97 | 98 | # Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still 99 | # use `HOST_CC' if defined, but it is deprecated. 100 | 101 | # This shell variable is my proudest work .. or something. --bje 102 | 103 | set_cc_for_build='tmpdir=${TMPDIR-/tmp}/config-guess-$$ ; 104 | (old=`umask` && umask 077 && mkdir $tmpdir && umask $old && unset old) 105 | || (echo "$me: cannot create $tmpdir" >&2 && exit 1) ; 106 | dummy=$tmpdir/dummy ; 107 | files="$dummy.c $dummy.o $dummy.rel $dummy" ; 108 | trap '"'"'rm -f $files; rmdir $tmpdir; exit 1'"'"' 1 2 15 ; 109 | case $CC_FOR_BUILD,$HOST_CC,$CC in 110 | ,,) echo "int x;" > $dummy.c ; 111 | for c in cc gcc c89 c99 ; do 112 | if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then 113 | CC_FOR_BUILD="$c"; break ; 114 | fi ; 115 | done ; 116 | rm -f $files ; 117 | if test x"$CC_FOR_BUILD" = x ; then 118 | CC_FOR_BUILD=no_compiler_found ; 119 | fi 120 | ;; 121 | ,,*) CC_FOR_BUILD=$CC ;; 122 | ,*,*) CC_FOR_BUILD=$HOST_CC ;; 123 | esac ; 124 | unset files' 125 | 126 | # This is needed to find uname on a Pyramid OSx when run in the BSD universe. 127 | # (ghazi@noc.rutgers.edu 1994-08-24) 128 | if (test -f /.attbin/uname) >/dev/null 2>&1 ; then 129 | PATH=$PATH:/.attbin ; export PATH 130 | fi 131 | 132 | UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown 133 | UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown 134 | UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown 135 | UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown 136 | 137 | # Note: order is significant - the case branches are not exclusive. 138 | 139 | case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in 140 | *:NetBSD:*:*) 141 | # NetBSD (nbsd) targets should (where applicable) match one or 142 | # more of the tupples: *-*-netbsdelf*, *-*-netbsdaout*, 143 | # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently 144 | # switched to ELF, *-*-netbsd* would select the old 145 | # object file format. This provides both forward 146 | # compatibility and a consistent mechanism for selecting the 147 | # object file format. 148 | # 149 | # Note: NetBSD doesn't particularly care about the vendor 150 | # portion of the name. We always set it to "unknown". 151 | sysctl="sysctl -n hw.machine_arch" 152 | UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \ 153 | /usr/sbin/$sysctl 2>/dev/null || echo unknown)` 154 | case "${UNAME_MACHINE_ARCH}" in 155 | armeb) machine=armeb-unknown ;; 156 | arm*) machine=arm-unknown ;; 157 | sh3el) machine=shl-unknown ;; 158 | sh3eb) machine=sh-unknown ;; 159 | *) machine=${UNAME_MACHINE_ARCH}-unknown ;; 160 | esac 161 | # The Operating System including object format, if it has switched 162 | # to ELF recently, or will in the future. 163 | case "${UNAME_MACHINE_ARCH}" in 164 | arm*|i386|m68k|ns32k|sh3*|sparc|vax) 165 | eval $set_cc_for_build 166 | if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \ 167 | | grep __ELF__ >/dev/null 168 | then 169 | # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout). 170 | # Return netbsd for either. FIX? 171 | os=netbsd 172 | else 173 | os=netbsdelf 174 | fi 175 | ;; 176 | *) 177 | os=netbsd 178 | ;; 179 | esac 180 | # The OS release 181 | release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'` 182 | # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM: 183 | # contains redundant information, the shorter form: 184 | # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used. 185 | echo "${machine}-${os}${release}" 186 | exit 0 ;; 187 | amiga:OpenBSD:*:*) 188 | echo m68k-unknown-openbsd${UNAME_RELEASE} 189 | exit 0 ;; 190 | arc:OpenBSD:*:*) 191 | echo mipsel-unknown-openbsd${UNAME_RELEASE} 192 | exit 0 ;; 193 | hp300:OpenBSD:*:*) 194 | echo m68k-unknown-openbsd${UNAME_RELEASE} 195 | exit 0 ;; 196 | mac68k:OpenBSD:*:*) 197 | echo m68k-unknown-openbsd${UNAME_RELEASE} 198 | exit 0 ;; 199 | macppc:OpenBSD:*:*) 200 | echo powerpc-unknown-openbsd${UNAME_RELEASE} 201 | exit 0 ;; 202 | mvme68k:OpenBSD:*:*) 203 | echo m68k-unknown-openbsd${UNAME_RELEASE} 204 | exit 0 ;; 205 | mvme88k:OpenBSD:*:*) 206 | echo m88k-unknown-openbsd${UNAME_RELEASE} 207 | exit 0 ;; 208 | mvmeppc:OpenBSD:*:*) 209 | echo powerpc-unknown-openbsd${UNAME_RELEASE} 210 | exit 0 ;; 211 | pmax:OpenBSD:*:*) 212 | echo mipsel-unknown-openbsd${UNAME_RELEASE} 213 | exit 0 ;; 214 | sgi:OpenBSD:*:*) 215 | echo mipseb-unknown-openbsd${UNAME_RELEASE} 216 | exit 0 ;; 217 | sun3:OpenBSD:*:*) 218 | echo m68k-unknown-openbsd${UNAME_RELEASE} 219 | exit 0 ;; 220 | wgrisc:OpenBSD:*:*) 221 | echo mipsel-unknown-openbsd${UNAME_RELEASE} 222 | exit 0 ;; 223 | *:OpenBSD:*:*) 224 | echo ${UNAME_MACHINE}-unknown-openbsd${UNAME_RELEASE} 225 | exit 0 ;; 226 | alpha:OSF1:*:*) 227 | if test $UNAME_RELEASE = "V4.0"; then 228 | UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'` 229 | fi 230 | # A Vn.n version is a released version. 231 | # A Tn.n version is a released field test version. 232 | # A Xn.n version is an unreleased experimental baselevel. 233 | # 1.2 uses "1.2" for uname -r. 234 | eval $set_cc_for_build 235 | cat <$dummy.s 236 | .data 237 | \$Lformat: 238 | .byte 37,100,45,37,120,10,0 # "%d-%x\n" 239 | 240 | .text 241 | .globl main 242 | .align 4 243 | .ent main 244 | main: 245 | .frame \$30,16,\$26,0 246 | ldgp \$29,0(\$27) 247 | .prologue 1 248 | .long 0x47e03d80 # implver \$0 249 | lda \$2,-1 250 | .long 0x47e20c21 # amask \$2,\$1 251 | lda \$16,\$Lformat 252 | mov \$0,\$17 253 | not \$1,\$18 254 | jsr \$26,printf 255 | ldgp \$29,0(\$26) 256 | mov 0,\$16 257 | jsr \$26,exit 258 | .end main 259 | EOF 260 | $CC_FOR_BUILD -o $dummy $dummy.s 2>/dev/null 261 | if test "$?" = 0 ; then 262 | case `$dummy` in 263 | 0-0) 264 | UNAME_MACHINE="alpha" 265 | ;; 266 | 1-0) 267 | UNAME_MACHINE="alphaev5" 268 | ;; 269 | 1-1) 270 | UNAME_MACHINE="alphaev56" 271 | ;; 272 | 1-101) 273 | UNAME_MACHINE="alphapca56" 274 | ;; 275 | 2-303) 276 | UNAME_MACHINE="alphaev6" 277 | ;; 278 | 2-307) 279 | UNAME_MACHINE="alphaev67" 280 | ;; 281 | 2-1307) 282 | UNAME_MACHINE="alphaev68" 283 | ;; 284 | 3-1307) 285 | UNAME_MACHINE="alphaev7" 286 | ;; 287 | esac 288 | fi 289 | rm -f $dummy.s $dummy && rmdir $tmpdir 290 | echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[VTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` 291 | exit 0 ;; 292 | Alpha\ *:Windows_NT*:*) 293 | # How do we know it's Interix rather than the generic POSIX subsystem? 294 | # Should we change UNAME_MACHINE based on the output of uname instead 295 | # of the specific Alpha model? 296 | echo alpha-pc-interix 297 | exit 0 ;; 298 | 21064:Windows_NT:50:3) 299 | echo alpha-dec-winnt3.5 300 | exit 0 ;; 301 | Amiga*:UNIX_System_V:4.0:*) 302 | echo m68k-unknown-sysv4 303 | exit 0;; 304 | *:[Aa]miga[Oo][Ss]:*:*) 305 | echo ${UNAME_MACHINE}-unknown-amigaos 306 | exit 0 ;; 307 | *:[Mm]orph[Oo][Ss]:*:*) 308 | echo ${UNAME_MACHINE}-unknown-morphos 309 | exit 0 ;; 310 | *:OS/390:*:*) 311 | echo i370-ibm-openedition 312 | exit 0 ;; 313 | arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*) 314 | echo arm-acorn-riscix${UNAME_RELEASE} 315 | exit 0;; 316 | SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*) 317 | echo hppa1.1-hitachi-hiuxmpp 318 | exit 0;; 319 | Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*) 320 | # akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE. 321 | if test "`(/bin/universe) 2>/dev/null`" = att ; then 322 | echo pyramid-pyramid-sysv3 323 | else 324 | echo pyramid-pyramid-bsd 325 | fi 326 | exit 0 ;; 327 | NILE*:*:*:dcosx) 328 | echo pyramid-pyramid-svr4 329 | exit 0 ;; 330 | DRS?6000:UNIX_SV:4.2*:7*) 331 | case `/usr/bin/uname -p` in 332 | sparc) echo sparc-icl-nx7 && exit 0 ;; 333 | esac ;; 334 | sun4H:SunOS:5.*:*) 335 | echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 336 | exit 0 ;; 337 | sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*) 338 | echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 339 | exit 0 ;; 340 | i86pc:SunOS:5.*:*) 341 | echo i386-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 342 | exit 0 ;; 343 | sun4*:SunOS:6*:*) 344 | # According to config.sub, this is the proper way to canonicalize 345 | # SunOS6. Hard to guess exactly what SunOS6 will be like, but 346 | # it's likely to be more like Solaris than SunOS4. 347 | echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 348 | exit 0 ;; 349 | sun4*:SunOS:*:*) 350 | case "`/usr/bin/arch -k`" in 351 | Series*|S4*) 352 | UNAME_RELEASE=`uname -v` 353 | ;; 354 | esac 355 | # Japanese Language versions have a version number like `4.1.3-JL'. 356 | echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'` 357 | exit 0 ;; 358 | sun3*:SunOS:*:*) 359 | echo m68k-sun-sunos${UNAME_RELEASE} 360 | exit 0 ;; 361 | sun*:*:4.2BSD:*) 362 | UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null` 363 | test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3 364 | case "`/bin/arch`" in 365 | sun3) 366 | echo m68k-sun-sunos${UNAME_RELEASE} 367 | ;; 368 | sun4) 369 | echo sparc-sun-sunos${UNAME_RELEASE} 370 | ;; 371 | esac 372 | exit 0 ;; 373 | aushp:SunOS:*:*) 374 | echo sparc-auspex-sunos${UNAME_RELEASE} 375 | exit 0 ;; 376 | # The situation for MiNT is a little confusing. The machine name 377 | # can be virtually everything (everything which is not 378 | # "atarist" or "atariste" at least should have a processor 379 | # > m68000). The system name ranges from "MiNT" over "FreeMiNT" 380 | # to the lowercase version "mint" (or "freemint"). Finally 381 | # the system name "TOS" denotes a system which is actually not 382 | # MiNT. But MiNT is downward compatible to TOS, so this should 383 | # be no problem. 384 | atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*) 385 | echo m68k-atari-mint${UNAME_RELEASE} 386 | exit 0 ;; 387 | atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*) 388 | echo m68k-atari-mint${UNAME_RELEASE} 389 | exit 0 ;; 390 | *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*) 391 | echo m68k-atari-mint${UNAME_RELEASE} 392 | exit 0 ;; 393 | milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*) 394 | echo m68k-milan-mint${UNAME_RELEASE} 395 | exit 0 ;; 396 | hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*) 397 | echo m68k-hades-mint${UNAME_RELEASE} 398 | exit 0 ;; 399 | *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*) 400 | echo m68k-unknown-mint${UNAME_RELEASE} 401 | exit 0 ;; 402 | powerpc:machten:*:*) 403 | echo powerpc-apple-machten${UNAME_RELEASE} 404 | exit 0 ;; 405 | RISC*:Mach:*:*) 406 | echo mips-dec-mach_bsd4.3 407 | exit 0 ;; 408 | RISC*:ULTRIX:*:*) 409 | echo mips-dec-ultrix${UNAME_RELEASE} 410 | exit 0 ;; 411 | VAX*:ULTRIX*:*:*) 412 | echo vax-dec-ultrix${UNAME_RELEASE} 413 | exit 0 ;; 414 | 2020:CLIX:*:* | 2430:CLIX:*:*) 415 | echo clipper-intergraph-clix${UNAME_RELEASE} 416 | exit 0 ;; 417 | mips:*:*:UMIPS | mips:*:*:RISCos) 418 | eval $set_cc_for_build 419 | sed 's/^ //' << EOF >$dummy.c 420 | #ifdef __cplusplus 421 | #include /* for printf() prototype */ 422 | int main (int argc, char *argv[]) { 423 | #else 424 | int main (argc, argv) int argc; char *argv[]; { 425 | #endif 426 | #if defined (host_mips) && defined (MIPSEB) 427 | #if defined (SYSTYPE_SYSV) 428 | printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0); 429 | #endif 430 | #if defined (SYSTYPE_SVR4) 431 | printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0); 432 | #endif 433 | #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD) 434 | printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0); 435 | #endif 436 | #endif 437 | exit (-1); 438 | } 439 | EOF 440 | $CC_FOR_BUILD -o $dummy $dummy.c \ 441 | && $dummy `echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` \ 442 | && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0 443 | rm -f $dummy.c $dummy && rmdir $tmpdir 444 | echo mips-mips-riscos${UNAME_RELEASE} 445 | exit 0 ;; 446 | Motorola:PowerMAX_OS:*:*) 447 | echo powerpc-motorola-powermax 448 | exit 0 ;; 449 | Motorola:*:4.3:PL8-*) 450 | echo powerpc-harris-powermax 451 | exit 0 ;; 452 | Night_Hawk:*:*:PowerMAX_OS) 453 | echo powerpc-harris-powermax 454 | exit 0 ;; 455 | Night_Hawk:Power_UNIX:*:*) 456 | echo powerpc-harris-powerunix 457 | exit 0 ;; 458 | m88k:CX/UX:7*:*) 459 | echo m88k-harris-cxux7 460 | exit 0 ;; 461 | m88k:*:4*:R4*) 462 | echo m88k-motorola-sysv4 463 | exit 0 ;; 464 | m88k:*:3*:R3*) 465 | echo m88k-motorola-sysv3 466 | exit 0 ;; 467 | AViiON:dgux:*:*) 468 | # DG/UX returns AViiON for all architectures 469 | UNAME_PROCESSOR=`/usr/bin/uname -p` 470 | if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ] 471 | then 472 | if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \ 473 | [ ${TARGET_BINARY_INTERFACE}x = x ] 474 | then 475 | echo m88k-dg-dgux${UNAME_RELEASE} 476 | else 477 | echo m88k-dg-dguxbcs${UNAME_RELEASE} 478 | fi 479 | else 480 | echo i586-dg-dgux${UNAME_RELEASE} 481 | fi 482 | exit 0 ;; 483 | M88*:DolphinOS:*:*) # DolphinOS (SVR3) 484 | echo m88k-dolphin-sysv3 485 | exit 0 ;; 486 | M88*:*:R3*:*) 487 | # Delta 88k system running SVR3 488 | echo m88k-motorola-sysv3 489 | exit 0 ;; 490 | XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3) 491 | echo m88k-tektronix-sysv3 492 | exit 0 ;; 493 | Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD) 494 | echo m68k-tektronix-bsd 495 | exit 0 ;; 496 | *:IRIX*:*:*) 497 | echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'` 498 | exit 0 ;; 499 | ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX. 500 | echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id 501 | exit 0 ;; # Note that: echo "'`uname -s`'" gives 'AIX ' 502 | i*86:AIX:*:*) 503 | echo i386-ibm-aix 504 | exit 0 ;; 505 | ia64:AIX:*:*) 506 | if [ -x /usr/bin/oslevel ] ; then 507 | IBM_REV=`/usr/bin/oslevel` 508 | else 509 | IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} 510 | fi 511 | echo ${UNAME_MACHINE}-ibm-aix${IBM_REV} 512 | exit 0 ;; 513 | *:AIX:2:3) 514 | if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then 515 | eval $set_cc_for_build 516 | sed 's/^ //' << EOF >$dummy.c 517 | #include 518 | 519 | main() 520 | { 521 | if (!__power_pc()) 522 | exit(1); 523 | puts("powerpc-ibm-aix3.2.5"); 524 | exit(0); 525 | } 526 | EOF 527 | $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0 528 | rm -f $dummy.c $dummy && rmdir $tmpdir 529 | echo rs6000-ibm-aix3.2.5 530 | elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then 531 | echo rs6000-ibm-aix3.2.4 532 | else 533 | echo rs6000-ibm-aix3.2 534 | fi 535 | exit 0 ;; 536 | *:AIX:*:[45]) 537 | IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'` 538 | if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then 539 | IBM_ARCH=rs6000 540 | else 541 | IBM_ARCH=powerpc 542 | fi 543 | if [ -x /usr/bin/oslevel ] ; then 544 | IBM_REV=`/usr/bin/oslevel` 545 | else 546 | IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE} 547 | fi 548 | echo ${IBM_ARCH}-ibm-aix${IBM_REV} 549 | exit 0 ;; 550 | *:AIX:*:*) 551 | echo rs6000-ibm-aix 552 | exit 0 ;; 553 | ibmrt:4.4BSD:*|romp-ibm:BSD:*) 554 | echo romp-ibm-bsd4.4 555 | exit 0 ;; 556 | ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and 557 | echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to 558 | exit 0 ;; # report: romp-ibm BSD 4.3 559 | *:BOSX:*:*) 560 | echo rs6000-bull-bosx 561 | exit 0 ;; 562 | DPX/2?00:B.O.S.:*:*) 563 | echo m68k-bull-sysv3 564 | exit 0 ;; 565 | 9000/[34]??:4.3bsd:1.*:*) 566 | echo m68k-hp-bsd 567 | exit 0 ;; 568 | hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*) 569 | echo m68k-hp-bsd4.4 570 | exit 0 ;; 571 | 9000/[34678]??:HP-UX:*:*) 572 | HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` 573 | case "${UNAME_MACHINE}" in 574 | 9000/31? ) HP_ARCH=m68000 ;; 575 | 9000/[34]?? ) HP_ARCH=m68k ;; 576 | 9000/[678][0-9][0-9]) 577 | if [ -x /usr/bin/getconf ]; then 578 | sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null` 579 | sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null` 580 | case "${sc_cpu_version}" in 581 | 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0 582 | 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1 583 | 532) # CPU_PA_RISC2_0 584 | case "${sc_kernel_bits}" in 585 | 32) HP_ARCH="hppa2.0n" ;; 586 | 64) HP_ARCH="hppa2.0w" ;; 587 | '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20 588 | esac ;; 589 | esac 590 | fi 591 | if [ "${HP_ARCH}" = "" ]; then 592 | eval $set_cc_for_build 593 | sed 's/^ //' << EOF >$dummy.c 594 | 595 | #define _HPUX_SOURCE 596 | #include 597 | #include 598 | 599 | int main () 600 | { 601 | #if defined(_SC_KERNEL_BITS) 602 | long bits = sysconf(_SC_KERNEL_BITS); 603 | #endif 604 | long cpu = sysconf (_SC_CPU_VERSION); 605 | 606 | switch (cpu) 607 | { 608 | case CPU_PA_RISC1_0: puts ("hppa1.0"); break; 609 | case CPU_PA_RISC1_1: puts ("hppa1.1"); break; 610 | case CPU_PA_RISC2_0: 611 | #if defined(_SC_KERNEL_BITS) 612 | switch (bits) 613 | { 614 | case 64: puts ("hppa2.0w"); break; 615 | case 32: puts ("hppa2.0n"); break; 616 | default: puts ("hppa2.0"); break; 617 | } break; 618 | #else /* !defined(_SC_KERNEL_BITS) */ 619 | puts ("hppa2.0"); break; 620 | #endif 621 | default: puts ("hppa1.0"); break; 622 | } 623 | exit (0); 624 | } 625 | EOF 626 | (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy` 627 | if test -z "$HP_ARCH"; then HP_ARCH=hppa; fi 628 | rm -f $dummy.c $dummy && rmdir $tmpdir 629 | fi ;; 630 | esac 631 | echo ${HP_ARCH}-hp-hpux${HPUX_REV} 632 | exit 0 ;; 633 | ia64:HP-UX:*:*) 634 | HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'` 635 | echo ia64-hp-hpux${HPUX_REV} 636 | exit 0 ;; 637 | 3050*:HI-UX:*:*) 638 | eval $set_cc_for_build 639 | sed 's/^ //' << EOF >$dummy.c 640 | #include 641 | int 642 | main () 643 | { 644 | long cpu = sysconf (_SC_CPU_VERSION); 645 | /* The order matters, because CPU_IS_HP_MC68K erroneously returns 646 | true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct 647 | results, however. */ 648 | if (CPU_IS_PA_RISC (cpu)) 649 | { 650 | switch (cpu) 651 | { 652 | case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break; 653 | case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break; 654 | case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break; 655 | default: puts ("hppa-hitachi-hiuxwe2"); break; 656 | } 657 | } 658 | else if (CPU_IS_HP_MC68K (cpu)) 659 | puts ("m68k-hitachi-hiuxwe2"); 660 | else puts ("unknown-hitachi-hiuxwe2"); 661 | exit (0); 662 | } 663 | EOF 664 | $CC_FOR_BUILD -o $dummy $dummy.c && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0 665 | rm -f $dummy.c $dummy && rmdir $tmpdir 666 | echo unknown-hitachi-hiuxwe2 667 | exit 0 ;; 668 | 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* ) 669 | echo hppa1.1-hp-bsd 670 | exit 0 ;; 671 | 9000/8??:4.3bsd:*:*) 672 | echo hppa1.0-hp-bsd 673 | exit 0 ;; 674 | *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*) 675 | echo hppa1.0-hp-mpeix 676 | exit 0 ;; 677 | hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* ) 678 | echo hppa1.1-hp-osf 679 | exit 0 ;; 680 | hp8??:OSF1:*:*) 681 | echo hppa1.0-hp-osf 682 | exit 0 ;; 683 | i*86:OSF1:*:*) 684 | if [ -x /usr/sbin/sysversion ] ; then 685 | echo ${UNAME_MACHINE}-unknown-osf1mk 686 | else 687 | echo ${UNAME_MACHINE}-unknown-osf1 688 | fi 689 | exit 0 ;; 690 | parisc*:Lites*:*:*) 691 | echo hppa1.1-hp-lites 692 | exit 0 ;; 693 | C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*) 694 | echo c1-convex-bsd 695 | exit 0 ;; 696 | C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*) 697 | if getsysinfo -f scalar_acc 698 | then echo c32-convex-bsd 699 | else echo c2-convex-bsd 700 | fi 701 | exit 0 ;; 702 | C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*) 703 | echo c34-convex-bsd 704 | exit 0 ;; 705 | C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*) 706 | echo c38-convex-bsd 707 | exit 0 ;; 708 | C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*) 709 | echo c4-convex-bsd 710 | exit 0 ;; 711 | CRAY*Y-MP:*:*:*) 712 | echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 713 | exit 0 ;; 714 | CRAY*[A-Z]90:*:*:*) 715 | echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \ 716 | | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \ 717 | -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \ 718 | -e 's/\.[^.]*$/.X/' 719 | exit 0 ;; 720 | CRAY*TS:*:*:*) 721 | echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 722 | exit 0 ;; 723 | CRAY*T3D:*:*:*) 724 | echo alpha-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 725 | exit 0 ;; 726 | CRAY*T3E:*:*:*) 727 | echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 728 | exit 0 ;; 729 | CRAY*SV1:*:*:*) 730 | echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/' 731 | exit 0 ;; 732 | F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*) 733 | FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'` 734 | FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'` 735 | FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'` 736 | echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}" 737 | exit 0 ;; 738 | i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*) 739 | echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE} 740 | exit 0 ;; 741 | sparc*:BSD/OS:*:*) 742 | echo sparc-unknown-bsdi${UNAME_RELEASE} 743 | exit 0 ;; 744 | *:BSD/OS:*:*) 745 | echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE} 746 | exit 0 ;; 747 | *:FreeBSD:*:*) 748 | # Determine whether the default compiler uses glibc. 749 | eval $set_cc_for_build 750 | sed 's/^ //' << EOF >$dummy.c 751 | #include 752 | #if __GLIBC__ >= 2 753 | LIBC=gnu 754 | #else 755 | LIBC= 756 | #endif 757 | EOF 758 | eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` 759 | rm -f $dummy.c && rmdir $tmpdir 760 | echo ${UNAME_MACHINE}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`${LIBC:+-$LIBC} 761 | exit 0 ;; 762 | i*:CYGWIN*:*) 763 | echo ${UNAME_MACHINE}-pc-cygwin 764 | exit 0 ;; 765 | i*:MINGW*:*) 766 | echo ${UNAME_MACHINE}-pc-mingw32 767 | exit 0 ;; 768 | i*:PW*:*) 769 | echo ${UNAME_MACHINE}-pc-pw32 770 | exit 0 ;; 771 | x86:Interix*:3*) 772 | echo i386-pc-interix3 773 | exit 0 ;; 774 | i*:Windows_NT*:* | Pentium*:Windows_NT*:*) 775 | # How do we know it's Interix rather than the generic POSIX subsystem? 776 | # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we 777 | # UNAME_MACHINE based on the output of uname instead of i386? 778 | echo i386-pc-interix 779 | exit 0 ;; 780 | i*:UWIN*:*) 781 | echo ${UNAME_MACHINE}-pc-uwin 782 | exit 0 ;; 783 | p*:CYGWIN*:*) 784 | echo powerpcle-unknown-cygwin 785 | exit 0 ;; 786 | prep*:SunOS:5.*:*) 787 | echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'` 788 | exit 0 ;; 789 | *:GNU:*:*) 790 | echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-gnu`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'` 791 | exit 0 ;; 792 | i*86:Minix:*:*) 793 | echo ${UNAME_MACHINE}-pc-minix 794 | exit 0 ;; 795 | arm*:Linux:*:*) 796 | echo ${UNAME_MACHINE}-unknown-linux-gnu 797 | exit 0 ;; 798 | ia64:Linux:*:*) 799 | echo ${UNAME_MACHINE}-unknown-linux-gnu 800 | exit 0 ;; 801 | m68*:Linux:*:*) 802 | echo ${UNAME_MACHINE}-unknown-linux-gnu 803 | exit 0 ;; 804 | mips:Linux:*:*) 805 | eval $set_cc_for_build 806 | sed 's/^ //' << EOF >$dummy.c 807 | #undef CPU 808 | #undef mips 809 | #undef mipsel 810 | #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL) 811 | CPU=mipsel 812 | #else 813 | #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB) 814 | CPU=mips 815 | #else 816 | CPU= 817 | #endif 818 | #endif 819 | EOF 820 | eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^CPU=` 821 | rm -f $dummy.c && rmdir $tmpdir 822 | test x"${CPU}" != x && echo "${CPU}-pc-linux-gnu" && exit 0 823 | ;; 824 | ppc:Linux:*:*) 825 | echo powerpc-unknown-linux-gnu 826 | exit 0 ;; 827 | ppc64:Linux:*:*) 828 | echo powerpc64-unknown-linux-gnu 829 | exit 0 ;; 830 | alpha:Linux:*:*) 831 | case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in 832 | EV5) UNAME_MACHINE=alphaev5 ;; 833 | EV56) UNAME_MACHINE=alphaev56 ;; 834 | PCA56) UNAME_MACHINE=alphapca56 ;; 835 | PCA57) UNAME_MACHINE=alphapca56 ;; 836 | EV6) UNAME_MACHINE=alphaev6 ;; 837 | EV67) UNAME_MACHINE=alphaev67 ;; 838 | EV68*) UNAME_MACHINE=alphaev68 ;; 839 | esac 840 | objdump --private-headers /bin/sh | grep ld.so.1 >/dev/null 841 | if test "$?" = 0 ; then LIBC="libc1" ; else LIBC="" ; fi 842 | echo ${UNAME_MACHINE}-unknown-linux-gnu${LIBC} 843 | exit 0 ;; 844 | parisc:Linux:*:* | hppa:Linux:*:*) 845 | # Look for CPU level 846 | case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in 847 | PA7*) echo hppa1.1-unknown-linux-gnu ;; 848 | PA8*) echo hppa2.0-unknown-linux-gnu ;; 849 | *) echo hppa-unknown-linux-gnu ;; 850 | esac 851 | exit 0 ;; 852 | parisc64:Linux:*:* | hppa64:Linux:*:*) 853 | echo hppa64-unknown-linux-gnu 854 | exit 0 ;; 855 | s390:Linux:*:* | s390x:Linux:*:*) 856 | echo ${UNAME_MACHINE}-ibm-linux 857 | exit 0 ;; 858 | sh*:Linux:*:*) 859 | echo ${UNAME_MACHINE}-unknown-linux-gnu 860 | exit 0 ;; 861 | sparc:Linux:*:* | sparc64:Linux:*:*) 862 | echo ${UNAME_MACHINE}-unknown-linux-gnu 863 | exit 0 ;; 864 | x86_64:Linux:*:*) 865 | echo x86_64-unknown-linux-gnu 866 | exit 0 ;; 867 | i*86:Linux:*:*) 868 | # The BFD linker knows what the default object file format is, so 869 | # first see if it will tell us. cd to the root directory to prevent 870 | # problems with other programs or directories called `ld' in the path. 871 | # Set LC_ALL=C to ensure ld outputs messages in English. 872 | ld_supported_targets=`cd /; LC_ALL=C ld --help 2>&1 \ 873 | | sed -ne '/supported targets:/!d 874 | s/[ ][ ]*/ /g 875 | s/.*supported targets: *// 876 | s/ .*// 877 | p'` 878 | case "$ld_supported_targets" in 879 | elf32-i386) 880 | TENTATIVE="${UNAME_MACHINE}-pc-linux-gnu" 881 | ;; 882 | a.out-i386-linux) 883 | echo "${UNAME_MACHINE}-pc-linux-gnuaout" 884 | exit 0 ;; 885 | coff-i386) 886 | echo "${UNAME_MACHINE}-pc-linux-gnucoff" 887 | exit 0 ;; 888 | "") 889 | # Either a pre-BFD a.out linker (linux-gnuoldld) or 890 | # one that does not give us useful --help. 891 | echo "${UNAME_MACHINE}-pc-linux-gnuoldld" 892 | exit 0 ;; 893 | esac 894 | # Determine whether the default compiler is a.out or elf 895 | eval $set_cc_for_build 896 | sed 's/^ //' << EOF >$dummy.c 897 | #include 898 | #ifdef __ELF__ 899 | # ifdef __GLIBC__ 900 | # if __GLIBC__ >= 2 901 | LIBC=gnu 902 | # else 903 | LIBC=gnulibc1 904 | # endif 905 | # else 906 | LIBC=gnulibc1 907 | # endif 908 | #else 909 | #ifdef __INTEL_COMPILER 910 | LIBC=gnu 911 | #else 912 | LIBC=gnuaout 913 | #endif 914 | #endif 915 | EOF 916 | eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep ^LIBC=` 917 | rm -f $dummy.c && rmdir $tmpdir 918 | test x"${LIBC}" != x && echo "${UNAME_MACHINE}-pc-linux-${LIBC}" && exit 0 919 | test x"${TENTATIVE}" != x && echo "${TENTATIVE}" && exit 0 920 | ;; 921 | i*86:DYNIX/ptx:4*:*) 922 | # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there. 923 | # earlier versions are messed up and put the nodename in both 924 | # sysname and nodename. 925 | echo i386-sequent-sysv4 926 | exit 0 ;; 927 | i*86:UNIX_SV:4.2MP:2.*) 928 | # Unixware is an offshoot of SVR4, but it has its own version 929 | # number series starting with 2... 930 | # I am not positive that other SVR4 systems won't match this, 931 | # I just have to hope. -- rms. 932 | # Use sysv4.2uw... so that sysv4* matches it. 933 | echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION} 934 | exit 0 ;; 935 | i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*) 936 | UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'` 937 | if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then 938 | echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL} 939 | else 940 | echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL} 941 | fi 942 | exit 0 ;; 943 | i*86:*:5:[78]*) 944 | case `/bin/uname -X | grep "^Machine"` in 945 | *486*) UNAME_MACHINE=i486 ;; 946 | *Pentium) UNAME_MACHINE=i586 ;; 947 | *Pent*|*Celeron) UNAME_MACHINE=i686 ;; 948 | esac 949 | echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION} 950 | exit 0 ;; 951 | i*86:*:3.2:*) 952 | if test -f /usr/options/cb.name; then 953 | UNAME_REL=`sed -n 's/.*Version //p' /dev/null >/dev/null ; then 956 | UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')` 957 | (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486 958 | (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \ 959 | && UNAME_MACHINE=i586 960 | (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \ 961 | && UNAME_MACHINE=i686 962 | (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \ 963 | && UNAME_MACHINE=i686 964 | echo ${UNAME_MACHINE}-pc-sco$UNAME_REL 965 | else 966 | echo ${UNAME_MACHINE}-pc-sysv32 967 | fi 968 | exit 0 ;; 969 | i*86:*DOS:*:*) 970 | echo ${UNAME_MACHINE}-pc-msdosdjgpp 971 | exit 0 ;; 972 | pc:*:*:*) 973 | # Left here for compatibility: 974 | # uname -m prints for DJGPP always 'pc', but it prints nothing about 975 | # the processor, so we play safe by assuming i386. 976 | echo i386-pc-msdosdjgpp 977 | exit 0 ;; 978 | Intel:Mach:3*:*) 979 | echo i386-pc-mach3 980 | exit 0 ;; 981 | paragon:*:*:*) 982 | echo i860-intel-osf1 983 | exit 0 ;; 984 | i860:*:4.*:*) # i860-SVR4 985 | if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then 986 | echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4 987 | else # Add other i860-SVR4 vendors below as they are discovered. 988 | echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4 989 | fi 990 | exit 0 ;; 991 | mini*:CTIX:SYS*5:*) 992 | # "miniframe" 993 | echo m68010-convergent-sysv 994 | exit 0 ;; 995 | mc68k:UNIX:SYSTEM5:3.51m) 996 | echo m68k-convergent-sysv 997 | exit 0 ;; 998 | M68*:*:R3V[567]*:*) 999 | test -r /sysV68 && echo 'm68k-motorola-sysv' && exit 0 ;; 1000 | 3[34]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0) 1001 | OS_REL='' 1002 | test -r /etc/.relid \ 1003 | && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid` 1004 | /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ 1005 | && echo i486-ncr-sysv4.3${OS_REL} && exit 0 1006 | /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \ 1007 | && echo i586-ncr-sysv4.3${OS_REL} && exit 0 ;; 1008 | 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*) 1009 | /bin/uname -p 2>/dev/null | grep 86 >/dev/null \ 1010 | && echo i486-ncr-sysv4 && exit 0 ;; 1011 | m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*) 1012 | echo m68k-unknown-lynxos${UNAME_RELEASE} 1013 | exit 0 ;; 1014 | mc68030:UNIX_System_V:4.*:*) 1015 | echo m68k-atari-sysv4 1016 | exit 0 ;; 1017 | i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.0*:*) 1018 | echo i386-unknown-lynxos${UNAME_RELEASE} 1019 | exit 0 ;; 1020 | TSUNAMI:LynxOS:2.*:*) 1021 | echo sparc-unknown-lynxos${UNAME_RELEASE} 1022 | exit 0 ;; 1023 | rs6000:LynxOS:2.*:*) 1024 | echo rs6000-unknown-lynxos${UNAME_RELEASE} 1025 | exit 0 ;; 1026 | PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.0*:*) 1027 | echo powerpc-unknown-lynxos${UNAME_RELEASE} 1028 | exit 0 ;; 1029 | SM[BE]S:UNIX_SV:*:*) 1030 | echo mips-dde-sysv${UNAME_RELEASE} 1031 | exit 0 ;; 1032 | RM*:ReliantUNIX-*:*:*) 1033 | echo mips-sni-sysv4 1034 | exit 0 ;; 1035 | RM*:SINIX-*:*:*) 1036 | echo mips-sni-sysv4 1037 | exit 0 ;; 1038 | *:SINIX-*:*:*) 1039 | if uname -p 2>/dev/null >/dev/null ; then 1040 | UNAME_MACHINE=`(uname -p) 2>/dev/null` 1041 | echo ${UNAME_MACHINE}-sni-sysv4 1042 | else 1043 | echo ns32k-sni-sysv 1044 | fi 1045 | exit 0 ;; 1046 | PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort 1047 | # says 1048 | echo i586-unisys-sysv4 1049 | exit 0 ;; 1050 | *:UNIX_System_V:4*:FTX*) 1051 | # From Gerald Hewes . 1052 | # How about differentiating between stratus architectures? -djm 1053 | echo hppa1.1-stratus-sysv4 1054 | exit 0 ;; 1055 | *:*:*:FTX*) 1056 | # From seanf@swdc.stratus.com. 1057 | echo i860-stratus-sysv4 1058 | exit 0 ;; 1059 | *:VOS:*:*) 1060 | # From Paul.Green@stratus.com. 1061 | echo hppa1.1-stratus-vos 1062 | exit 0 ;; 1063 | mc68*:A/UX:*:*) 1064 | echo m68k-apple-aux${UNAME_RELEASE} 1065 | exit 0 ;; 1066 | news*:NEWS-OS:6*:*) 1067 | echo mips-sony-newsos6 1068 | exit 0 ;; 1069 | R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*) 1070 | if [ -d /usr/nec ]; then 1071 | echo mips-nec-sysv${UNAME_RELEASE} 1072 | else 1073 | echo mips-unknown-sysv${UNAME_RELEASE} 1074 | fi 1075 | exit 0 ;; 1076 | BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only. 1077 | echo powerpc-be-beos 1078 | exit 0 ;; 1079 | BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only. 1080 | echo powerpc-apple-beos 1081 | exit 0 ;; 1082 | BePC:BeOS:*:*) # BeOS running on Intel PC compatible. 1083 | echo i586-pc-beos 1084 | exit 0 ;; 1085 | SX-4:SUPER-UX:*:*) 1086 | echo sx4-nec-superux${UNAME_RELEASE} 1087 | exit 0 ;; 1088 | SX-5:SUPER-UX:*:*) 1089 | echo sx5-nec-superux${UNAME_RELEASE} 1090 | exit 0 ;; 1091 | SX-6:SUPER-UX:*:*) 1092 | echo sx6-nec-superux${UNAME_RELEASE} 1093 | exit 0 ;; 1094 | Power*:Rhapsody:*:*) 1095 | echo powerpc-apple-rhapsody${UNAME_RELEASE} 1096 | exit 0 ;; 1097 | *:Rhapsody:*:*) 1098 | echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE} 1099 | exit 0 ;; 1100 | *:Darwin:*:*) 1101 | echo `uname -p`-apple-darwin${UNAME_RELEASE} 1102 | exit 0 ;; 1103 | *:procnto*:*:* | *:QNX:[0123456789]*:*) 1104 | UNAME_PROCESSOR=`uname -p` 1105 | if test "$UNAME_PROCESSOR" = "x86"; then 1106 | UNAME_PROCESSOR=i386 1107 | UNAME_MACHINE=pc 1108 | fi 1109 | echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE} 1110 | exit 0 ;; 1111 | *:QNX:*:4*) 1112 | echo i386-pc-qnx 1113 | exit 0 ;; 1114 | NSR-[DGKLNPTVW]:NONSTOP_KERNEL:*:*) 1115 | echo nsr-tandem-nsk${UNAME_RELEASE} 1116 | exit 0 ;; 1117 | *:NonStop-UX:*:*) 1118 | echo mips-compaq-nonstopux 1119 | exit 0 ;; 1120 | BS2000:POSIX*:*:*) 1121 | echo bs2000-siemens-sysv 1122 | exit 0 ;; 1123 | DS/*:UNIX_System_V:*:*) 1124 | echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE} 1125 | exit 0 ;; 1126 | *:Plan9:*:*) 1127 | # "uname -m" is not consistent, so use $cputype instead. 386 1128 | # is converted to i386 for consistency with other x86 1129 | # operating systems. 1130 | if test "$cputype" = "386"; then 1131 | UNAME_MACHINE=i386 1132 | else 1133 | UNAME_MACHINE="$cputype" 1134 | fi 1135 | echo ${UNAME_MACHINE}-unknown-plan9 1136 | exit 0 ;; 1137 | i*86:OS/2:*:*) 1138 | # If we were able to find `uname', then EMX Unix compatibility 1139 | # is probably installed. 1140 | echo ${UNAME_MACHINE}-pc-os2-emx 1141 | exit 0 ;; 1142 | *:TOPS-10:*:*) 1143 | echo pdp10-unknown-tops10 1144 | exit 0 ;; 1145 | *:TENEX:*:*) 1146 | echo pdp10-unknown-tenex 1147 | exit 0 ;; 1148 | KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*) 1149 | echo pdp10-dec-tops20 1150 | exit 0 ;; 1151 | XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*) 1152 | echo pdp10-xkl-tops20 1153 | exit 0 ;; 1154 | *:TOPS-20:*:*) 1155 | echo pdp10-unknown-tops20 1156 | exit 0 ;; 1157 | *:ITS:*:*) 1158 | echo pdp10-unknown-its 1159 | exit 0 ;; 1160 | i*86:XTS-300:*:STOP) 1161 | echo ${UNAME_MACHINE}-unknown-stop 1162 | exit 0 ;; 1163 | i*86:atheos:*:*) 1164 | echo ${UNAME_MACHINE}-unknown-atheos 1165 | exit 0 ;; 1166 | esac 1167 | 1168 | #echo '(No uname command or uname output not recognized.)' 1>&2 1169 | #echo "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" 1>&2 1170 | 1171 | eval $set_cc_for_build 1172 | cat >$dummy.c < 1175 | # include 1176 | #endif 1177 | main () 1178 | { 1179 | #if defined (sony) 1180 | #if defined (MIPSEB) 1181 | /* BFD wants "bsd" instead of "newsos". Perhaps BFD should be changed, 1182 | I don't know.... */ 1183 | printf ("mips-sony-bsd\n"); exit (0); 1184 | #else 1185 | #include 1186 | printf ("m68k-sony-newsos%s\n", 1187 | #ifdef NEWSOS4 1188 | "4" 1189 | #else 1190 | "" 1191 | #endif 1192 | ); exit (0); 1193 | #endif 1194 | #endif 1195 | 1196 | #if defined (__arm) && defined (__acorn) && defined (__unix) 1197 | printf ("arm-acorn-riscix"); exit (0); 1198 | #endif 1199 | 1200 | #if defined (hp300) && !defined (hpux) 1201 | printf ("m68k-hp-bsd\n"); exit (0); 1202 | #endif 1203 | 1204 | #if defined (NeXT) 1205 | #if !defined (__ARCHITECTURE__) 1206 | #define __ARCHITECTURE__ "m68k" 1207 | #endif 1208 | int version; 1209 | version=`(hostinfo | sed -n 's/.*NeXT Mach \([0-9]*\).*/\1/p') 2>/dev/null`; 1210 | if (version < 4) 1211 | printf ("%s-next-nextstep%d\n", __ARCHITECTURE__, version); 1212 | else 1213 | printf ("%s-next-openstep%d\n", __ARCHITECTURE__, version); 1214 | exit (0); 1215 | #endif 1216 | 1217 | #if defined (MULTIMAX) || defined (n16) 1218 | #if defined (UMAXV) 1219 | printf ("ns32k-encore-sysv\n"); exit (0); 1220 | #else 1221 | #if defined (CMU) 1222 | printf ("ns32k-encore-mach\n"); exit (0); 1223 | #else 1224 | printf ("ns32k-encore-bsd\n"); exit (0); 1225 | #endif 1226 | #endif 1227 | #endif 1228 | 1229 | #if defined (__386BSD__) 1230 | printf ("i386-pc-bsd\n"); exit (0); 1231 | #endif 1232 | 1233 | #if defined (sequent) 1234 | #if defined (i386) 1235 | printf ("i386-sequent-dynix\n"); exit (0); 1236 | #endif 1237 | #if defined (ns32000) 1238 | printf ("ns32k-sequent-dynix\n"); exit (0); 1239 | #endif 1240 | #endif 1241 | 1242 | #if defined (_SEQUENT_) 1243 | struct utsname un; 1244 | 1245 | uname(&un); 1246 | 1247 | if (strncmp(un.version, "V2", 2) == 0) { 1248 | printf ("i386-sequent-ptx2\n"); exit (0); 1249 | } 1250 | if (strncmp(un.version, "V1", 2) == 0) { /* XXX is V1 correct? */ 1251 | printf ("i386-sequent-ptx1\n"); exit (0); 1252 | } 1253 | printf ("i386-sequent-ptx\n"); exit (0); 1254 | 1255 | #endif 1256 | 1257 | #if defined (vax) 1258 | # if !defined (ultrix) 1259 | # include 1260 | # if defined (BSD) 1261 | # if BSD == 43 1262 | printf ("vax-dec-bsd4.3\n"); exit (0); 1263 | # else 1264 | # if BSD == 199006 1265 | printf ("vax-dec-bsd4.3reno\n"); exit (0); 1266 | # else 1267 | printf ("vax-dec-bsd\n"); exit (0); 1268 | # endif 1269 | # endif 1270 | # else 1271 | printf ("vax-dec-bsd\n"); exit (0); 1272 | # endif 1273 | # else 1274 | printf ("vax-dec-ultrix\n"); exit (0); 1275 | # endif 1276 | #endif 1277 | 1278 | #if defined (alliant) && defined (i860) 1279 | printf ("i860-alliant-bsd\n"); exit (0); 1280 | #endif 1281 | 1282 | exit (1); 1283 | } 1284 | EOF 1285 | 1286 | $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null && $dummy && rm -f $dummy.c $dummy && rmdir $tmpdir && exit 0 1287 | rm -f $dummy.c $dummy && rmdir $tmpdir 1288 | 1289 | # Apollos put the system type in the environment. 1290 | 1291 | test -d /usr/apollo && { echo ${ISP}-apollo-${SYSTYPE}; exit 0; } 1292 | 1293 | # Convex versions that predate uname can use getsysinfo(1) 1294 | 1295 | if [ -x /usr/convex/getsysinfo ] 1296 | then 1297 | case `getsysinfo -f cpu_type` in 1298 | c1*) 1299 | echo c1-convex-bsd 1300 | exit 0 ;; 1301 | c2*) 1302 | if getsysinfo -f scalar_acc 1303 | then echo c32-convex-bsd 1304 | else echo c2-convex-bsd 1305 | fi 1306 | exit 0 ;; 1307 | c34*) 1308 | echo c34-convex-bsd 1309 | exit 0 ;; 1310 | c38*) 1311 | echo c38-convex-bsd 1312 | exit 0 ;; 1313 | c4*) 1314 | echo c4-convex-bsd 1315 | exit 0 ;; 1316 | esac 1317 | fi 1318 | 1319 | cat >&2 < in order to provide the needed 1331 | information to handle your system. 1332 | 1333 | config.guess timestamp = $timestamp 1334 | 1335 | uname -m = `(uname -m) 2>/dev/null || echo unknown` 1336 | uname -r = `(uname -r) 2>/dev/null || echo unknown` 1337 | uname -s = `(uname -s) 2>/dev/null || echo unknown` 1338 | uname -v = `(uname -v) 2>/dev/null || echo unknown` 1339 | 1340 | /usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null` 1341 | /bin/uname -X = `(/bin/uname -X) 2>/dev/null` 1342 | 1343 | hostinfo = `(hostinfo) 2>/dev/null` 1344 | /bin/universe = `(/bin/universe) 2>/dev/null` 1345 | /usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null` 1346 | /bin/arch = `(/bin/arch) 2>/dev/null` 1347 | /usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null` 1348 | /usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null` 1349 | 1350 | UNAME_MACHINE = ${UNAME_MACHINE} 1351 | UNAME_RELEASE = ${UNAME_RELEASE} 1352 | UNAME_SYSTEM = ${UNAME_SYSTEM} 1353 | UNAME_VERSION = ${UNAME_VERSION} 1354 | EOF 1355 | 1356 | exit 1 1357 | 1358 | # Local variables: 1359 | # eval: (add-hook 'write-file-hooks 'time-stamp) 1360 | # time-stamp-start: "timestamp='" 1361 | # time-stamp-format: "%:y-%02m-%02d" 1362 | # time-stamp-end: "'" 1363 | # End: 1364 | -------------------------------------------------------------------------------- /config.sub: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Configuration validation subroutine script. 3 | # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 4 | # 2000, 2001, 2002 Free Software Foundation, Inc. 5 | 6 | timestamp='2002-09-05' 7 | 8 | # This file is (in principle) common to ALL GNU software. 9 | # The presence of a machine in this file suggests that SOME GNU software 10 | # can handle that machine. It does not imply ALL GNU software can. 11 | # 12 | # This file is free software; you can redistribute it and/or modify 13 | # it under the terms of the GNU General Public License as published by 14 | # the Free Software Foundation; either version 2 of the License, or 15 | # (at your option) any later version. 16 | # 17 | # This program is distributed in the hope that it will be useful, 18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 | # GNU General Public License for more details. 21 | # 22 | # You should have received a copy of the GNU General Public License 23 | # along with this program; if not, write to the Free Software 24 | # Foundation, Inc., 59 Temple Place - Suite 330, 25 | # Boston, MA 02111-1307, USA. 26 | 27 | # As a special exception to the GNU General Public License, if you 28 | # distribute this file as part of a program that contains a 29 | # configuration script generated by Autoconf, you may include it under 30 | # the same distribution terms that you use for the rest of that program. 31 | 32 | # Please send patches to . Submit a context 33 | # diff and a properly formatted ChangeLog entry. 34 | # 35 | # Configuration subroutine to validate and canonicalize a configuration type. 36 | # Supply the specified configuration type as an argument. 37 | # If it is invalid, we print an error message on stderr and exit with code 1. 38 | # Otherwise, we print the canonical config type on stdout and succeed. 39 | 40 | # This file is supposed to be the same for all GNU packages 41 | # and recognize all the CPU types, system types and aliases 42 | # that are meaningful with *any* GNU software. 43 | # Each package is responsible for reporting which valid configurations 44 | # it does not support. The user should be able to distinguish 45 | # a failure to support a valid configuration from a meaningless 46 | # configuration. 47 | 48 | # The goal of this file is to map all the various variations of a given 49 | # machine specification into a single specification in the form: 50 | # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM 51 | # or in some cases, the newer four-part form: 52 | # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM 53 | # It is wrong to echo any other type of specification. 54 | 55 | me=`echo "$0" | sed -e 's,.*/,,'` 56 | 57 | usage="\ 58 | Usage: $0 [OPTION] CPU-MFR-OPSYS 59 | $0 [OPTION] ALIAS 60 | 61 | Canonicalize a configuration name. 62 | 63 | Operation modes: 64 | -h, --help print this help, then exit 65 | -t, --time-stamp print date of last modification, then exit 66 | -v, --version print version number, then exit 67 | 68 | Report bugs and patches to ." 69 | 70 | version="\ 71 | GNU config.sub ($timestamp) 72 | 73 | Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 74 | Free Software Foundation, Inc. 75 | 76 | This is free software; see the source for copying conditions. There is NO 77 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE." 78 | 79 | help=" 80 | Try \`$me --help' for more information." 81 | 82 | # Parse command line 83 | while test $# -gt 0 ; do 84 | case $1 in 85 | --time-stamp | --time* | -t ) 86 | echo "$timestamp" ; exit 0 ;; 87 | --version | -v ) 88 | echo "$version" ; exit 0 ;; 89 | --help | --h* | -h ) 90 | echo "$usage"; exit 0 ;; 91 | -- ) # Stop option processing 92 | shift; break ;; 93 | - ) # Use stdin as input. 94 | break ;; 95 | -* ) 96 | echo "$me: invalid option $1$help" 97 | exit 1 ;; 98 | 99 | *local*) 100 | # First pass through any local machine types. 101 | echo $1 102 | exit 0;; 103 | 104 | * ) 105 | break ;; 106 | esac 107 | done 108 | 109 | case $# in 110 | 0) echo "$me: missing argument$help" >&2 111 | exit 1;; 112 | 1) ;; 113 | *) echo "$me: too many arguments$help" >&2 114 | exit 1;; 115 | esac 116 | 117 | # Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any). 118 | # Here we must recognize all the valid KERNEL-OS combinations. 119 | maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'` 120 | case $maybe_os in 121 | nto-qnx* | linux-gnu* | freebsd*-gnu* | storm-chaos* | os2-emx* | windows32-* | rtmk-nova*) 122 | os=-$maybe_os 123 | basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'` 124 | ;; 125 | *) 126 | basic_machine=`echo $1 | sed 's/-[^-]*$//'` 127 | if [ $basic_machine != $1 ] 128 | then os=`echo $1 | sed 's/.*-/-/'` 129 | else os=; fi 130 | ;; 131 | esac 132 | 133 | ### Let's recognize common machines as not being operating systems so 134 | ### that things like config.sub decstation-3100 work. We also 135 | ### recognize some manufacturers as not being operating systems, so we 136 | ### can provide default operating systems below. 137 | case $os in 138 | -sun*os*) 139 | # Prevent following clause from handling this invalid input. 140 | ;; 141 | -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \ 142 | -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \ 143 | -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \ 144 | -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\ 145 | -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \ 146 | -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \ 147 | -apple | -axis) 148 | os= 149 | basic_machine=$1 150 | ;; 151 | -sim | -cisco | -oki | -wec | -winbond) 152 | os= 153 | basic_machine=$1 154 | ;; 155 | -scout) 156 | ;; 157 | -wrs) 158 | os=-vxworks 159 | basic_machine=$1 160 | ;; 161 | -chorusos*) 162 | os=-chorusos 163 | basic_machine=$1 164 | ;; 165 | -chorusrdb) 166 | os=-chorusrdb 167 | basic_machine=$1 168 | ;; 169 | -hiux*) 170 | os=-hiuxwe2 171 | ;; 172 | -sco5) 173 | os=-sco3.2v5 174 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 175 | ;; 176 | -sco4) 177 | os=-sco3.2v4 178 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 179 | ;; 180 | -sco3.2.[4-9]*) 181 | os=`echo $os | sed -e 's/sco3.2./sco3.2v/'` 182 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 183 | ;; 184 | -sco3.2v[4-9]*) 185 | # Don't forget version if it is 3.2v4 or newer. 186 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 187 | ;; 188 | -sco*) 189 | os=-sco3.2v2 190 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 191 | ;; 192 | -udk*) 193 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 194 | ;; 195 | -isc) 196 | os=-isc2.2 197 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 198 | ;; 199 | -clix*) 200 | basic_machine=clipper-intergraph 201 | ;; 202 | -isc*) 203 | basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'` 204 | ;; 205 | -lynx*) 206 | os=-lynxos 207 | ;; 208 | -ptx*) 209 | basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'` 210 | ;; 211 | -windowsnt*) 212 | os=`echo $os | sed -e 's/windowsnt/winnt/'` 213 | ;; 214 | -psos*) 215 | os=-psos 216 | ;; 217 | -mint | -mint[0-9]*) 218 | basic_machine=m68k-atari 219 | os=-mint 220 | ;; 221 | esac 222 | 223 | # Decode aliases for certain CPU-COMPANY combinations. 224 | case $basic_machine in 225 | # Recognize the basic CPU types without company name. 226 | # Some are omitted here because they have special meanings below. 227 | 1750a | 580 \ 228 | | a29k \ 229 | | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \ 230 | | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \ 231 | | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr \ 232 | | clipper \ 233 | | d10v | d30v | dlx | dsp16xx \ 234 | | fr30 | frv \ 235 | | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \ 236 | | i370 | i860 | i960 | ia64 \ 237 | | ip2k \ 238 | | m32r | m68000 | m68k | m88k | mcore \ 239 | | mips | mipsbe | mipseb | mipsel | mipsle \ 240 | | mips16 \ 241 | | mips64 | mips64el \ 242 | | mips64vr | mips64vrel \ 243 | | mips64orion | mips64orionel \ 244 | | mips64vr4100 | mips64vr4100el \ 245 | | mips64vr4300 | mips64vr4300el \ 246 | | mips64vr5000 | mips64vr5000el \ 247 | | mipsisa32 | mipsisa32el \ 248 | | mipsisa64 | mipsisa64el \ 249 | | mipsisa64sb1 | mipsisa64sb1el \ 250 | | mipsisa64sr71k | mipsisa64sr71kel \ 251 | | mipstx39 | mipstx39el \ 252 | | mn10200 | mn10300 \ 253 | | ns16k | ns32k \ 254 | | openrisc | or32 \ 255 | | pdp10 | pdp11 | pj | pjl \ 256 | | powerpc | powerpc64 | powerpc64le | powerpcle | ppcbe \ 257 | | pyramid \ 258 | | sh | sh[1234] | sh3e | sh[34]eb | shbe | shle | sh[1234]le | sh3ele \ 259 | | sh64 | sh64le \ 260 | | sparc | sparc64 | sparc86x | sparclet | sparclite | sparcv9 | sparcv9b \ 261 | | strongarm \ 262 | | tahoe | thumb | tic80 | tron \ 263 | | v850 | v850e \ 264 | | we32k \ 265 | | x86 | xscale | xstormy16 | xtensa \ 266 | | z8k) 267 | basic_machine=$basic_machine-unknown 268 | ;; 269 | m6811 | m68hc11 | m6812 | m68hc12) 270 | # Motorola 68HC11/12. 271 | basic_machine=$basic_machine-unknown 272 | os=-none 273 | ;; 274 | m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k) 275 | ;; 276 | 277 | # We use `pc' rather than `unknown' 278 | # because (1) that's what they normally are, and 279 | # (2) the word "unknown" tends to confuse beginning users. 280 | i*86 | x86_64) 281 | basic_machine=$basic_machine-pc 282 | ;; 283 | # Object if more than one company name word. 284 | *-*-*) 285 | echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 286 | exit 1 287 | ;; 288 | # Recognize the basic CPU types with company name. 289 | 580-* \ 290 | | a29k-* \ 291 | | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \ 292 | | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \ 293 | | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \ 294 | | arm-* | armbe-* | armle-* | armeb-* | armv*-* \ 295 | | avr-* \ 296 | | bs2000-* \ 297 | | c[123]* | c30-* | [cjt]90-* | c4x-* | c54x-* \ 298 | | clipper-* | cydra-* \ 299 | | d10v-* | d30v-* | dlx-* \ 300 | | elxsi-* \ 301 | | f30[01]-* | f700-* | fr30-* | frv-* | fx80-* \ 302 | | h8300-* | h8500-* \ 303 | | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \ 304 | | i*86-* | i860-* | i960-* | ia64-* \ 305 | | ip2k-* \ 306 | | m32r-* \ 307 | | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \ 308 | | m88110-* | m88k-* | mcore-* \ 309 | | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \ 310 | | mips16-* \ 311 | | mips64-* | mips64el-* \ 312 | | mips64vr-* | mips64vrel-* \ 313 | | mips64orion-* | mips64orionel-* \ 314 | | mips64vr4100-* | mips64vr4100el-* \ 315 | | mips64vr4300-* | mips64vr4300el-* \ 316 | | mips64vr5000-* | mips64vr5000el-* \ 317 | | mipsisa32-* | mipsisa32el-* \ 318 | | mipsisa64-* | mipsisa64el-* \ 319 | | mipsisa64sb1-* | mipsisa64sb1el-* \ 320 | | mipsisa64sr71k-* | mipsisa64sr71kel-* \ 321 | | mipstx39 | mipstx39el \ 322 | | none-* | np1-* | ns16k-* | ns32k-* \ 323 | | orion-* \ 324 | | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \ 325 | | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* | ppcbe-* \ 326 | | pyramid-* \ 327 | | romp-* | rs6000-* \ 328 | | sh-* | sh[1234]-* | sh3e-* | sh[34]eb-* | shbe-* \ 329 | | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \ 330 | | sparc-* | sparc64-* | sparc86x-* | sparclet-* | sparclite-* \ 331 | | sparcv9-* | sparcv9b-* | strongarm-* | sv1-* | sx?-* \ 332 | | tahoe-* | thumb-* | tic30-* | tic4x-* | tic54x-* | tic80-* | tron-* \ 333 | | v850-* | v850e-* | vax-* \ 334 | | we32k-* \ 335 | | x86-* | x86_64-* | xps100-* | xscale-* | xstormy16-* \ 336 | | xtensa-* \ 337 | | ymp-* \ 338 | | z8k-*) 339 | ;; 340 | # Recognize the various machine names and aliases which stand 341 | # for a CPU type and a company and sometimes even an OS. 342 | 386bsd) 343 | basic_machine=i386-unknown 344 | os=-bsd 345 | ;; 346 | 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc) 347 | basic_machine=m68000-att 348 | ;; 349 | 3b*) 350 | basic_machine=we32k-att 351 | ;; 352 | a29khif) 353 | basic_machine=a29k-amd 354 | os=-udi 355 | ;; 356 | adobe68k) 357 | basic_machine=m68010-adobe 358 | os=-scout 359 | ;; 360 | alliant | fx80) 361 | basic_machine=fx80-alliant 362 | ;; 363 | altos | altos3068) 364 | basic_machine=m68k-altos 365 | ;; 366 | am29k) 367 | basic_machine=a29k-none 368 | os=-bsd 369 | ;; 370 | amdahl) 371 | basic_machine=580-amdahl 372 | os=-sysv 373 | ;; 374 | amiga | amiga-*) 375 | basic_machine=m68k-unknown 376 | ;; 377 | amigaos | amigados) 378 | basic_machine=m68k-unknown 379 | os=-amigaos 380 | ;; 381 | amigaunix | amix) 382 | basic_machine=m68k-unknown 383 | os=-sysv4 384 | ;; 385 | apollo68) 386 | basic_machine=m68k-apollo 387 | os=-sysv 388 | ;; 389 | apollo68bsd) 390 | basic_machine=m68k-apollo 391 | os=-bsd 392 | ;; 393 | aux) 394 | basic_machine=m68k-apple 395 | os=-aux 396 | ;; 397 | balance) 398 | basic_machine=ns32k-sequent 399 | os=-dynix 400 | ;; 401 | c90) 402 | basic_machine=c90-cray 403 | os=-unicos 404 | ;; 405 | convex-c1) 406 | basic_machine=c1-convex 407 | os=-bsd 408 | ;; 409 | convex-c2) 410 | basic_machine=c2-convex 411 | os=-bsd 412 | ;; 413 | convex-c32) 414 | basic_machine=c32-convex 415 | os=-bsd 416 | ;; 417 | convex-c34) 418 | basic_machine=c34-convex 419 | os=-bsd 420 | ;; 421 | convex-c38) 422 | basic_machine=c38-convex 423 | os=-bsd 424 | ;; 425 | cray | j90) 426 | basic_machine=j90-cray 427 | os=-unicos 428 | ;; 429 | crds | unos) 430 | basic_machine=m68k-crds 431 | ;; 432 | cris | cris-* | etrax*) 433 | basic_machine=cris-axis 434 | ;; 435 | da30 | da30-*) 436 | basic_machine=m68k-da30 437 | ;; 438 | decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn) 439 | basic_machine=mips-dec 440 | ;; 441 | decsystem10* | dec10*) 442 | basic_machine=pdp10-dec 443 | os=-tops10 444 | ;; 445 | decsystem20* | dec20*) 446 | basic_machine=pdp10-dec 447 | os=-tops20 448 | ;; 449 | delta | 3300 | motorola-3300 | motorola-delta \ 450 | | 3300-motorola | delta-motorola) 451 | basic_machine=m68k-motorola 452 | ;; 453 | delta88) 454 | basic_machine=m88k-motorola 455 | os=-sysv3 456 | ;; 457 | dpx20 | dpx20-*) 458 | basic_machine=rs6000-bull 459 | os=-bosx 460 | ;; 461 | dpx2* | dpx2*-bull) 462 | basic_machine=m68k-bull 463 | os=-sysv3 464 | ;; 465 | ebmon29k) 466 | basic_machine=a29k-amd 467 | os=-ebmon 468 | ;; 469 | elxsi) 470 | basic_machine=elxsi-elxsi 471 | os=-bsd 472 | ;; 473 | encore | umax | mmax) 474 | basic_machine=ns32k-encore 475 | ;; 476 | es1800 | OSE68k | ose68k | ose | OSE) 477 | basic_machine=m68k-ericsson 478 | os=-ose 479 | ;; 480 | fx2800) 481 | basic_machine=i860-alliant 482 | ;; 483 | genix) 484 | basic_machine=ns32k-ns 485 | ;; 486 | gmicro) 487 | basic_machine=tron-gmicro 488 | os=-sysv 489 | ;; 490 | go32) 491 | basic_machine=i386-pc 492 | os=-go32 493 | ;; 494 | h3050r* | hiux*) 495 | basic_machine=hppa1.1-hitachi 496 | os=-hiuxwe2 497 | ;; 498 | h8300hms) 499 | basic_machine=h8300-hitachi 500 | os=-hms 501 | ;; 502 | h8300xray) 503 | basic_machine=h8300-hitachi 504 | os=-xray 505 | ;; 506 | h8500hms) 507 | basic_machine=h8500-hitachi 508 | os=-hms 509 | ;; 510 | harris) 511 | basic_machine=m88k-harris 512 | os=-sysv3 513 | ;; 514 | hp300-*) 515 | basic_machine=m68k-hp 516 | ;; 517 | hp300bsd) 518 | basic_machine=m68k-hp 519 | os=-bsd 520 | ;; 521 | hp300hpux) 522 | basic_machine=m68k-hp 523 | os=-hpux 524 | ;; 525 | hp3k9[0-9][0-9] | hp9[0-9][0-9]) 526 | basic_machine=hppa1.0-hp 527 | ;; 528 | hp9k2[0-9][0-9] | hp9k31[0-9]) 529 | basic_machine=m68000-hp 530 | ;; 531 | hp9k3[2-9][0-9]) 532 | basic_machine=m68k-hp 533 | ;; 534 | hp9k6[0-9][0-9] | hp6[0-9][0-9]) 535 | basic_machine=hppa1.0-hp 536 | ;; 537 | hp9k7[0-79][0-9] | hp7[0-79][0-9]) 538 | basic_machine=hppa1.1-hp 539 | ;; 540 | hp9k78[0-9] | hp78[0-9]) 541 | # FIXME: really hppa2.0-hp 542 | basic_machine=hppa1.1-hp 543 | ;; 544 | hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893) 545 | # FIXME: really hppa2.0-hp 546 | basic_machine=hppa1.1-hp 547 | ;; 548 | hp9k8[0-9][13679] | hp8[0-9][13679]) 549 | basic_machine=hppa1.1-hp 550 | ;; 551 | hp9k8[0-9][0-9] | hp8[0-9][0-9]) 552 | basic_machine=hppa1.0-hp 553 | ;; 554 | hppa-next) 555 | os=-nextstep3 556 | ;; 557 | hppaosf) 558 | basic_machine=hppa1.1-hp 559 | os=-osf 560 | ;; 561 | hppro) 562 | basic_machine=hppa1.1-hp 563 | os=-proelf 564 | ;; 565 | i370-ibm* | ibm*) 566 | basic_machine=i370-ibm 567 | ;; 568 | # I'm not sure what "Sysv32" means. Should this be sysv3.2? 569 | i*86v32) 570 | basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` 571 | os=-sysv32 572 | ;; 573 | i*86v4*) 574 | basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` 575 | os=-sysv4 576 | ;; 577 | i*86v) 578 | basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` 579 | os=-sysv 580 | ;; 581 | i*86sol2) 582 | basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'` 583 | os=-solaris2 584 | ;; 585 | i386mach) 586 | basic_machine=i386-mach 587 | os=-mach 588 | ;; 589 | i386-vsta | vsta) 590 | basic_machine=i386-unknown 591 | os=-vsta 592 | ;; 593 | iris | iris4d) 594 | basic_machine=mips-sgi 595 | case $os in 596 | -irix*) 597 | ;; 598 | *) 599 | os=-irix4 600 | ;; 601 | esac 602 | ;; 603 | isi68 | isi) 604 | basic_machine=m68k-isi 605 | os=-sysv 606 | ;; 607 | m88k-omron*) 608 | basic_machine=m88k-omron 609 | ;; 610 | magnum | m3230) 611 | basic_machine=mips-mips 612 | os=-sysv 613 | ;; 614 | merlin) 615 | basic_machine=ns32k-utek 616 | os=-sysv 617 | ;; 618 | mingw32) 619 | basic_machine=i386-pc 620 | os=-mingw32 621 | ;; 622 | miniframe) 623 | basic_machine=m68000-convergent 624 | ;; 625 | *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*) 626 | basic_machine=m68k-atari 627 | os=-mint 628 | ;; 629 | mips3*-*) 630 | basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'` 631 | ;; 632 | mips3*) 633 | basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown 634 | ;; 635 | mmix*) 636 | basic_machine=mmix-knuth 637 | os=-mmixware 638 | ;; 639 | monitor) 640 | basic_machine=m68k-rom68k 641 | os=-coff 642 | ;; 643 | morphos) 644 | basic_machine=powerpc-unknown 645 | os=-morphos 646 | ;; 647 | msdos) 648 | basic_machine=i386-pc 649 | os=-msdos 650 | ;; 651 | mvs) 652 | basic_machine=i370-ibm 653 | os=-mvs 654 | ;; 655 | ncr3000) 656 | basic_machine=i486-ncr 657 | os=-sysv4 658 | ;; 659 | netbsd386) 660 | basic_machine=i386-unknown 661 | os=-netbsd 662 | ;; 663 | netwinder) 664 | basic_machine=armv4l-rebel 665 | os=-linux 666 | ;; 667 | news | news700 | news800 | news900) 668 | basic_machine=m68k-sony 669 | os=-newsos 670 | ;; 671 | news1000) 672 | basic_machine=m68030-sony 673 | os=-newsos 674 | ;; 675 | news-3600 | risc-news) 676 | basic_machine=mips-sony 677 | os=-newsos 678 | ;; 679 | necv70) 680 | basic_machine=v70-nec 681 | os=-sysv 682 | ;; 683 | next | m*-next ) 684 | basic_machine=m68k-next 685 | case $os in 686 | -nextstep* ) 687 | ;; 688 | -ns2*) 689 | os=-nextstep2 690 | ;; 691 | *) 692 | os=-nextstep3 693 | ;; 694 | esac 695 | ;; 696 | nh3000) 697 | basic_machine=m68k-harris 698 | os=-cxux 699 | ;; 700 | nh[45]000) 701 | basic_machine=m88k-harris 702 | os=-cxux 703 | ;; 704 | nindy960) 705 | basic_machine=i960-intel 706 | os=-nindy 707 | ;; 708 | mon960) 709 | basic_machine=i960-intel 710 | os=-mon960 711 | ;; 712 | nonstopux) 713 | basic_machine=mips-compaq 714 | os=-nonstopux 715 | ;; 716 | np1) 717 | basic_machine=np1-gould 718 | ;; 719 | nsr-tandem) 720 | basic_machine=nsr-tandem 721 | ;; 722 | op50n-* | op60c-*) 723 | basic_machine=hppa1.1-oki 724 | os=-proelf 725 | ;; 726 | or32 | or32-*) 727 | basic_machine=or32-unknown 728 | os=-coff 729 | ;; 730 | OSE68000 | ose68000) 731 | basic_machine=m68000-ericsson 732 | os=-ose 733 | ;; 734 | os68k) 735 | basic_machine=m68k-none 736 | os=-os68k 737 | ;; 738 | pa-hitachi) 739 | basic_machine=hppa1.1-hitachi 740 | os=-hiuxwe2 741 | ;; 742 | paragon) 743 | basic_machine=i860-intel 744 | os=-osf 745 | ;; 746 | pbd) 747 | basic_machine=sparc-tti 748 | ;; 749 | pbb) 750 | basic_machine=m68k-tti 751 | ;; 752 | pc532 | pc532-*) 753 | basic_machine=ns32k-pc532 754 | ;; 755 | pentium | p5 | k5 | k6 | nexgen | viac3) 756 | basic_machine=i586-pc 757 | ;; 758 | pentiumpro | p6 | 6x86 | athlon | athlon_*) 759 | basic_machine=i686-pc 760 | ;; 761 | pentiumii | pentium2) 762 | basic_machine=i686-pc 763 | ;; 764 | pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*) 765 | basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'` 766 | ;; 767 | pentiumpro-* | p6-* | 6x86-* | athlon-*) 768 | basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` 769 | ;; 770 | pentiumii-* | pentium2-*) 771 | basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'` 772 | ;; 773 | pn) 774 | basic_machine=pn-gould 775 | ;; 776 | power) basic_machine=power-ibm 777 | ;; 778 | ppc) basic_machine=powerpc-unknown 779 | ;; 780 | ppc-*) basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'` 781 | ;; 782 | ppcle | powerpclittle | ppc-le | powerpc-little) 783 | basic_machine=powerpcle-unknown 784 | ;; 785 | ppcle-* | powerpclittle-*) 786 | basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'` 787 | ;; 788 | ppc64) basic_machine=powerpc64-unknown 789 | ;; 790 | ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'` 791 | ;; 792 | ppc64le | powerpc64little | ppc64-le | powerpc64-little) 793 | basic_machine=powerpc64le-unknown 794 | ;; 795 | ppc64le-* | powerpc64little-*) 796 | basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'` 797 | ;; 798 | ps2) 799 | basic_machine=i386-ibm 800 | ;; 801 | pw32) 802 | basic_machine=i586-unknown 803 | os=-pw32 804 | ;; 805 | rom68k) 806 | basic_machine=m68k-rom68k 807 | os=-coff 808 | ;; 809 | rm[46]00) 810 | basic_machine=mips-siemens 811 | ;; 812 | rtpc | rtpc-*) 813 | basic_machine=romp-ibm 814 | ;; 815 | s390 | s390-*) 816 | basic_machine=s390-ibm 817 | ;; 818 | s390x | s390x-*) 819 | basic_machine=s390x-ibm 820 | ;; 821 | sa29200) 822 | basic_machine=a29k-amd 823 | os=-udi 824 | ;; 825 | sb1) 826 | basic_machine=mipsisa64sb1-unknown 827 | ;; 828 | sb1el) 829 | basic_machine=mipsisa64sb1el-unknown 830 | ;; 831 | sequent) 832 | basic_machine=i386-sequent 833 | ;; 834 | sh) 835 | basic_machine=sh-hitachi 836 | os=-hms 837 | ;; 838 | sparclite-wrs | simso-wrs) 839 | basic_machine=sparclite-wrs 840 | os=-vxworks 841 | ;; 842 | sps7) 843 | basic_machine=m68k-bull 844 | os=-sysv2 845 | ;; 846 | spur) 847 | basic_machine=spur-unknown 848 | ;; 849 | st2000) 850 | basic_machine=m68k-tandem 851 | ;; 852 | stratus) 853 | basic_machine=i860-stratus 854 | os=-sysv4 855 | ;; 856 | sun2) 857 | basic_machine=m68000-sun 858 | ;; 859 | sun2os3) 860 | basic_machine=m68000-sun 861 | os=-sunos3 862 | ;; 863 | sun2os4) 864 | basic_machine=m68000-sun 865 | os=-sunos4 866 | ;; 867 | sun3os3) 868 | basic_machine=m68k-sun 869 | os=-sunos3 870 | ;; 871 | sun3os4) 872 | basic_machine=m68k-sun 873 | os=-sunos4 874 | ;; 875 | sun4os3) 876 | basic_machine=sparc-sun 877 | os=-sunos3 878 | ;; 879 | sun4os4) 880 | basic_machine=sparc-sun 881 | os=-sunos4 882 | ;; 883 | sun4sol2) 884 | basic_machine=sparc-sun 885 | os=-solaris2 886 | ;; 887 | sun3 | sun3-*) 888 | basic_machine=m68k-sun 889 | ;; 890 | sun4) 891 | basic_machine=sparc-sun 892 | ;; 893 | sun386 | sun386i | roadrunner) 894 | basic_machine=i386-sun 895 | ;; 896 | sv1) 897 | basic_machine=sv1-cray 898 | os=-unicos 899 | ;; 900 | symmetry) 901 | basic_machine=i386-sequent 902 | os=-dynix 903 | ;; 904 | t3d) 905 | basic_machine=alpha-cray 906 | os=-unicos 907 | ;; 908 | t3e) 909 | basic_machine=alphaev5-cray 910 | os=-unicos 911 | ;; 912 | t90) 913 | basic_machine=t90-cray 914 | os=-unicos 915 | ;; 916 | tic4x | c4x*) 917 | basic_machine=tic4x-unknown 918 | os=-coff 919 | ;; 920 | tic54x | c54x*) 921 | basic_machine=tic54x-unknown 922 | os=-coff 923 | ;; 924 | tx39) 925 | basic_machine=mipstx39-unknown 926 | ;; 927 | tx39el) 928 | basic_machine=mipstx39el-unknown 929 | ;; 930 | toad1) 931 | basic_machine=pdp10-xkl 932 | os=-tops20 933 | ;; 934 | tower | tower-32) 935 | basic_machine=m68k-ncr 936 | ;; 937 | udi29k) 938 | basic_machine=a29k-amd 939 | os=-udi 940 | ;; 941 | ultra3) 942 | basic_machine=a29k-nyu 943 | os=-sym1 944 | ;; 945 | v810 | necv810) 946 | basic_machine=v810-nec 947 | os=-none 948 | ;; 949 | vaxv) 950 | basic_machine=vax-dec 951 | os=-sysv 952 | ;; 953 | vms) 954 | basic_machine=vax-dec 955 | os=-vms 956 | ;; 957 | vpp*|vx|vx-*) 958 | basic_machine=f301-fujitsu 959 | ;; 960 | vxworks960) 961 | basic_machine=i960-wrs 962 | os=-vxworks 963 | ;; 964 | vxworks68) 965 | basic_machine=m68k-wrs 966 | os=-vxworks 967 | ;; 968 | vxworks29k) 969 | basic_machine=a29k-wrs 970 | os=-vxworks 971 | ;; 972 | w65*) 973 | basic_machine=w65-wdc 974 | os=-none 975 | ;; 976 | w89k-*) 977 | basic_machine=hppa1.1-winbond 978 | os=-proelf 979 | ;; 980 | windows32) 981 | basic_machine=i386-pc 982 | os=-windows32-msvcrt 983 | ;; 984 | xps | xps100) 985 | basic_machine=xps100-honeywell 986 | ;; 987 | ymp) 988 | basic_machine=ymp-cray 989 | os=-unicos 990 | ;; 991 | z8k-*-coff) 992 | basic_machine=z8k-unknown 993 | os=-sim 994 | ;; 995 | none) 996 | basic_machine=none-none 997 | os=-none 998 | ;; 999 | 1000 | # Here we handle the default manufacturer of certain CPU types. It is in 1001 | # some cases the only manufacturer, in others, it is the most popular. 1002 | w89k) 1003 | basic_machine=hppa1.1-winbond 1004 | ;; 1005 | op50n) 1006 | basic_machine=hppa1.1-oki 1007 | ;; 1008 | op60c) 1009 | basic_machine=hppa1.1-oki 1010 | ;; 1011 | romp) 1012 | basic_machine=romp-ibm 1013 | ;; 1014 | rs6000) 1015 | basic_machine=rs6000-ibm 1016 | ;; 1017 | vax) 1018 | basic_machine=vax-dec 1019 | ;; 1020 | pdp10) 1021 | # there are many clones, so DEC is not a safe bet 1022 | basic_machine=pdp10-unknown 1023 | ;; 1024 | pdp11) 1025 | basic_machine=pdp11-dec 1026 | ;; 1027 | we32k) 1028 | basic_machine=we32k-att 1029 | ;; 1030 | sh3 | sh4 | sh3eb | sh4eb | sh[1234]le | sh3ele) 1031 | basic_machine=sh-unknown 1032 | ;; 1033 | sh64) 1034 | basic_machine=sh64-unknown 1035 | ;; 1036 | sparc | sparcv9 | sparcv9b) 1037 | basic_machine=sparc-sun 1038 | ;; 1039 | cydra) 1040 | basic_machine=cydra-cydrome 1041 | ;; 1042 | orion) 1043 | basic_machine=orion-highlevel 1044 | ;; 1045 | orion105) 1046 | basic_machine=clipper-highlevel 1047 | ;; 1048 | mac | mpw | mac-mpw) 1049 | basic_machine=m68k-apple 1050 | ;; 1051 | pmac | pmac-mpw) 1052 | basic_machine=powerpc-apple 1053 | ;; 1054 | *-unknown) 1055 | # Make sure to match an already-canonicalized machine name. 1056 | ;; 1057 | *) 1058 | echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2 1059 | exit 1 1060 | ;; 1061 | esac 1062 | 1063 | # Here we canonicalize certain aliases for manufacturers. 1064 | case $basic_machine in 1065 | *-digital*) 1066 | basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'` 1067 | ;; 1068 | *-commodore*) 1069 | basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'` 1070 | ;; 1071 | *) 1072 | ;; 1073 | esac 1074 | 1075 | # Decode manufacturer-specific aliases for certain operating systems. 1076 | 1077 | if [ x"$os" != x"" ] 1078 | then 1079 | case $os in 1080 | # First match some system type aliases 1081 | # that might get confused with valid system types. 1082 | # -solaris* is a basic system type, with this one exception. 1083 | -solaris1 | -solaris1.*) 1084 | os=`echo $os | sed -e 's|solaris1|sunos4|'` 1085 | ;; 1086 | -solaris) 1087 | os=-solaris2 1088 | ;; 1089 | -svr4*) 1090 | os=-sysv4 1091 | ;; 1092 | -unixware*) 1093 | os=-sysv4.2uw 1094 | ;; 1095 | -gnu/linux*) 1096 | os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'` 1097 | ;; 1098 | # First accept the basic system types. 1099 | # The portable systems comes first. 1100 | # Each alternative MUST END IN A *, to match a version number. 1101 | # -sysv* is not here because it comes later, after sysvr4. 1102 | -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \ 1103 | | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ 1104 | | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ 1105 | | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ 1106 | | -aos* \ 1107 | | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ 1108 | | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ 1109 | | -hiux* | -386bsd* | -netbsd* | -openbsd* | -freebsd* | -riscix* \ 1110 | | -lynxos* | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \ 1111 | | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \ 1112 | | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \ 1113 | | -chorusos* | -chorusrdb* \ 1114 | | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \ 1115 | | -mingw32* | -linux-gnu* | -uxpv* | -beos* | -mpeix* | -udk* \ 1116 | | -interix* | -uwin* | -rhapsody* | -darwin* | -opened* \ 1117 | | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \ 1118 | | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \ 1119 | | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \ 1120 | | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* | -powermax*) 1121 | # Remember, each alternative MUST END IN *, to match a version number. 1122 | ;; 1123 | -qnx*) 1124 | case $basic_machine in 1125 | x86-* | i*86-*) 1126 | ;; 1127 | *) 1128 | os=-nto$os 1129 | ;; 1130 | esac 1131 | ;; 1132 | -nto*) 1133 | os=-nto-qnx 1134 | ;; 1135 | -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \ 1136 | | -windows* | -osx | -abug | -netware* | -os9* | -beos* \ 1137 | | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*) 1138 | ;; 1139 | -mac*) 1140 | os=`echo $os | sed -e 's|mac|macos|'` 1141 | ;; 1142 | -linux*) 1143 | os=`echo $os | sed -e 's|linux|linux-gnu|'` 1144 | ;; 1145 | -sunos5*) 1146 | os=`echo $os | sed -e 's|sunos5|solaris2|'` 1147 | ;; 1148 | -sunos6*) 1149 | os=`echo $os | sed -e 's|sunos6|solaris3|'` 1150 | ;; 1151 | -opened*) 1152 | os=-openedition 1153 | ;; 1154 | -wince*) 1155 | os=-wince 1156 | ;; 1157 | -osfrose*) 1158 | os=-osfrose 1159 | ;; 1160 | -osf*) 1161 | os=-osf 1162 | ;; 1163 | -utek*) 1164 | os=-bsd 1165 | ;; 1166 | -dynix*) 1167 | os=-bsd 1168 | ;; 1169 | -acis*) 1170 | os=-aos 1171 | ;; 1172 | -atheos*) 1173 | os=-atheos 1174 | ;; 1175 | -386bsd) 1176 | os=-bsd 1177 | ;; 1178 | -ctix* | -uts*) 1179 | os=-sysv 1180 | ;; 1181 | -nova*) 1182 | os=-rtmk-nova 1183 | ;; 1184 | -ns2 ) 1185 | os=-nextstep2 1186 | ;; 1187 | -nsk*) 1188 | os=-nsk 1189 | ;; 1190 | # Preserve the version number of sinix5. 1191 | -sinix5.*) 1192 | os=`echo $os | sed -e 's|sinix|sysv|'` 1193 | ;; 1194 | -sinix*) 1195 | os=-sysv4 1196 | ;; 1197 | -triton*) 1198 | os=-sysv3 1199 | ;; 1200 | -oss*) 1201 | os=-sysv3 1202 | ;; 1203 | -svr4) 1204 | os=-sysv4 1205 | ;; 1206 | -svr3) 1207 | os=-sysv3 1208 | ;; 1209 | -sysvr4) 1210 | os=-sysv4 1211 | ;; 1212 | # This must come after -sysvr4. 1213 | -sysv*) 1214 | ;; 1215 | -ose*) 1216 | os=-ose 1217 | ;; 1218 | -es1800*) 1219 | os=-ose 1220 | ;; 1221 | -xenix) 1222 | os=-xenix 1223 | ;; 1224 | -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) 1225 | os=-mint 1226 | ;; 1227 | -none) 1228 | ;; 1229 | *) 1230 | # Get rid of the `-' at the beginning of $os. 1231 | os=`echo $os | sed 's/[^-]*-//'` 1232 | echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2 1233 | exit 1 1234 | ;; 1235 | esac 1236 | else 1237 | 1238 | # Here we handle the default operating systems that come with various machines. 1239 | # The value should be what the vendor currently ships out the door with their 1240 | # machine or put another way, the most popular os provided with the machine. 1241 | 1242 | # Note that if you're going to try to match "-MANUFACTURER" here (say, 1243 | # "-sun"), then you have to tell the case statement up towards the top 1244 | # that MANUFACTURER isn't an operating system. Otherwise, code above 1245 | # will signal an error saying that MANUFACTURER isn't an operating 1246 | # system, and we'll never get to this point. 1247 | 1248 | case $basic_machine in 1249 | *-acorn) 1250 | os=-riscix1.2 1251 | ;; 1252 | arm*-rebel) 1253 | os=-linux 1254 | ;; 1255 | arm*-semi) 1256 | os=-aout 1257 | ;; 1258 | # This must come before the *-dec entry. 1259 | pdp10-*) 1260 | os=-tops20 1261 | ;; 1262 | pdp11-*) 1263 | os=-none 1264 | ;; 1265 | *-dec | vax-*) 1266 | os=-ultrix4.2 1267 | ;; 1268 | m68*-apollo) 1269 | os=-domain 1270 | ;; 1271 | i386-sun) 1272 | os=-sunos4.0.2 1273 | ;; 1274 | m68000-sun) 1275 | os=-sunos3 1276 | # This also exists in the configure program, but was not the 1277 | # default. 1278 | # os=-sunos4 1279 | ;; 1280 | m68*-cisco) 1281 | os=-aout 1282 | ;; 1283 | mips*-cisco) 1284 | os=-elf 1285 | ;; 1286 | mips*-*) 1287 | os=-elf 1288 | ;; 1289 | or32-*) 1290 | os=-coff 1291 | ;; 1292 | *-tti) # must be before sparc entry or we get the wrong os. 1293 | os=-sysv3 1294 | ;; 1295 | sparc-* | *-sun) 1296 | os=-sunos4.1.1 1297 | ;; 1298 | *-be) 1299 | os=-beos 1300 | ;; 1301 | *-ibm) 1302 | os=-aix 1303 | ;; 1304 | *-wec) 1305 | os=-proelf 1306 | ;; 1307 | *-winbond) 1308 | os=-proelf 1309 | ;; 1310 | *-oki) 1311 | os=-proelf 1312 | ;; 1313 | *-hp) 1314 | os=-hpux 1315 | ;; 1316 | *-hitachi) 1317 | os=-hiux 1318 | ;; 1319 | i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent) 1320 | os=-sysv 1321 | ;; 1322 | *-cbm) 1323 | os=-amigaos 1324 | ;; 1325 | *-dg) 1326 | os=-dgux 1327 | ;; 1328 | *-dolphin) 1329 | os=-sysv3 1330 | ;; 1331 | m68k-ccur) 1332 | os=-rtu 1333 | ;; 1334 | m88k-omron*) 1335 | os=-luna 1336 | ;; 1337 | *-next ) 1338 | os=-nextstep 1339 | ;; 1340 | *-sequent) 1341 | os=-ptx 1342 | ;; 1343 | *-crds) 1344 | os=-unos 1345 | ;; 1346 | *-ns) 1347 | os=-genix 1348 | ;; 1349 | i370-*) 1350 | os=-mvs 1351 | ;; 1352 | *-next) 1353 | os=-nextstep3 1354 | ;; 1355 | *-gould) 1356 | os=-sysv 1357 | ;; 1358 | *-highlevel) 1359 | os=-bsd 1360 | ;; 1361 | *-encore) 1362 | os=-bsd 1363 | ;; 1364 | *-sgi) 1365 | os=-irix 1366 | ;; 1367 | *-siemens) 1368 | os=-sysv4 1369 | ;; 1370 | *-masscomp) 1371 | os=-rtu 1372 | ;; 1373 | f30[01]-fujitsu | f700-fujitsu) 1374 | os=-uxpv 1375 | ;; 1376 | *-rom68k) 1377 | os=-coff 1378 | ;; 1379 | *-*bug) 1380 | os=-coff 1381 | ;; 1382 | *-apple) 1383 | os=-macos 1384 | ;; 1385 | *-atari*) 1386 | os=-mint 1387 | ;; 1388 | *) 1389 | os=-none 1390 | ;; 1391 | esac 1392 | fi 1393 | 1394 | # Here we handle the case where we know the os, and the CPU type, but not the 1395 | # manufacturer. We pick the logical manufacturer. 1396 | vendor=unknown 1397 | case $basic_machine in 1398 | *-unknown) 1399 | case $os in 1400 | -riscix*) 1401 | vendor=acorn 1402 | ;; 1403 | -sunos*) 1404 | vendor=sun 1405 | ;; 1406 | -aix*) 1407 | vendor=ibm 1408 | ;; 1409 | -beos*) 1410 | vendor=be 1411 | ;; 1412 | -hpux*) 1413 | vendor=hp 1414 | ;; 1415 | -mpeix*) 1416 | vendor=hp 1417 | ;; 1418 | -hiux*) 1419 | vendor=hitachi 1420 | ;; 1421 | -unos*) 1422 | vendor=crds 1423 | ;; 1424 | -dgux*) 1425 | vendor=dg 1426 | ;; 1427 | -luna*) 1428 | vendor=omron 1429 | ;; 1430 | -genix*) 1431 | vendor=ns 1432 | ;; 1433 | -mvs* | -opened*) 1434 | vendor=ibm 1435 | ;; 1436 | -ptx*) 1437 | vendor=sequent 1438 | ;; 1439 | -vxsim* | -vxworks* | -windiss*) 1440 | vendor=wrs 1441 | ;; 1442 | -aux*) 1443 | vendor=apple 1444 | ;; 1445 | -hms*) 1446 | vendor=hitachi 1447 | ;; 1448 | -mpw* | -macos*) 1449 | vendor=apple 1450 | ;; 1451 | -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*) 1452 | vendor=atari 1453 | ;; 1454 | -vos*) 1455 | vendor=stratus 1456 | ;; 1457 | esac 1458 | basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"` 1459 | ;; 1460 | esac 1461 | 1462 | echo $basic_machine$os 1463 | exit 0 1464 | 1465 | # Local variables: 1466 | # eval: (add-hook 'write-file-hooks 'time-stamp) 1467 | # time-stamp-start: "timestamp='" 1468 | # time-stamp-format: "%:y-%02m-%02d" 1469 | # time-stamp-end: "'" 1470 | # End: 1471 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | 2 | # Process with autoconf to create configure script 3 | 4 | AC_INIT(dh, INTERNAL, nosupport@all) 5 | AC_PREREQ(2.52) 6 | AC_COPYRIGHT([Copyright released into the public domain by Andrew Mortensen, January 2008.]) 7 | AC_CONFIG_SRCDIR([duti.c]) 8 | 9 | build_date=`date "+%B %d, %Y"` 10 | AC_SUBST(build_date) 11 | 12 | # program checks 13 | AC_PROG_AWK 14 | AC_PROG_CC 15 | AC_PROG_INSTALL 16 | 17 | AC_CANONICAL_SYSTEM 18 | DUTI_CHECK_SDK 19 | DUTI_CHECK_DEPLOYMENT_TARGET 20 | 21 | # function checks 22 | AC_CHECK_FUNC(strlcpy,have_strlcpy=yes,) 23 | if test x_$have_strlcpy = x_; then 24 | AC_ERROR([required function strlcpy not found.]) 25 | fi 26 | 27 | if test x_$OPTOPTS = x_; then 28 | if test x_$GCC = x_yes; then 29 | OPTOPTS="$OPTOPTS -Wall -Wmissing-prototypes" 30 | fi 31 | fi 32 | AC_SUBST(OPTOPTS) 33 | 34 | AC_CONFIG_FILES([Makefile version.c]) 35 | AC_OUTPUT 36 | -------------------------------------------------------------------------------- /duti.1: -------------------------------------------------------------------------------- 1 | .TH duti "1" "_DUTI_BUILD_DATE" "Andrew Mortensen" "User Commands" 2 | .SH NAME 3 | .B duti 4 | \- set default document and URL handlers 5 | .SH SYNOPSIS 6 | .B duti 7 | [ 8 | .BI \-hVv 9 | ] [ 10 | .BI \-d\ uti 11 | ] [ 12 | .BI \-l\ uti 13 | ] [ 14 | .I settings_path 15 | ] 16 | .sp 17 | .B duti 18 | .BI \-s 19 | .I bundle_id 20 | { 21 | .I uti 22 | | 23 | .I url_scheme 24 | | 25 | .I extension 26 | | 27 | .I MIME_type 28 | } 29 | [ 30 | .I role 31 | ] 32 | .sp 33 | .B duti 34 | .BI \-x\ extension 35 | .sp 36 | .SH DESCRIPTION 37 | .B duti 38 | sets applications as default handlers for Apple's Uniform Type Identifiers, 39 | for URL schemes, filename extensions, and MIME types. 40 | If 41 | .I settings_path 42 | is not given on the command line, 43 | .B duti 44 | reads settings lines from stdin. If 45 | .I settings_path 46 | is a directory, 47 | .B duti 48 | applies settings from the files in 49 | .IR settings_path . 50 | .sp 51 | The 52 | .BI \-s 53 | flag tells 54 | .B duti 55 | to set a handler based on arguments from the command line. Two arguments 56 | following 57 | .BI \-s 58 | means that 59 | .B duti 60 | will set the handler for a URL scheme. Three arguments means 61 | .B duti 62 | will set the handler for a UTI, an extension or a MIME type, depending on 63 | the formatting of the second argument. 64 | .B duti 65 | treats an argument beginning with a dot as an extension. If the argument 66 | contains no dots, 67 | .B duti 68 | also considers the argument a filename extension, unless it contains a slash, 69 | in which case 70 | .B duti 71 | treats the argument as a MIME type. In all other cases, 72 | .B duti 73 | treats the second argument as a UTI. 74 | .sp 75 | .B duti 76 | .BI \-x 77 | retrieves and prints out information describing the default application 78 | for files with the extension 79 | .IR extension . 80 | .sp 81 | See 82 | .B EXAMPLES 83 | below for usage cases. 84 | .sp 85 | .SH SETTINGS FILE 86 | A settings file is made up of lines with the following format: 87 | .sp 88 | .br 89 | app_id UTI role 90 | .br 91 | .sp 92 | The 93 | .I app_id 94 | is a bundle ID representing the application that will act as the 95 | handler for documents associated with 96 | .IR UTI . 97 | For example: 98 | .sp 99 | .br 100 | com.apple.Safari public.html all 101 | .br 102 | .sp 103 | would cause 104 | .B duti 105 | to set Safari as the default handler in all situations for HTML documents. 106 | A settings file can also contain lines with this format: 107 | .sp 108 | .br 109 | app_id url_scheme 110 | .br 111 | .sp 112 | In this case, 113 | .I app_id 114 | is again a bundle ID, this time for the application that will act as the 115 | default handler for 116 | .IR url_scheme . 117 | For example: 118 | .sp 119 | .br 120 | org.mozilla.Firefox ftp 121 | .br 122 | .sp 123 | would cause 124 | .B duti 125 | to set Firefox as the handler for "ftp://" URLs. 126 | .SH SETTINGS PLIST 127 | If the extension of the file given to 128 | .B duti 129 | is 130 | .IR \.plist , 131 | .B duti 132 | treats the file as an XML property list (plist). 133 | The plist must contain a key-value pair, in which the key is "DUTISettings" 134 | and the value is an array of dictionaries. Each dictionary in the array 135 | contains three key-value pairs representing the application's bundle ID, 136 | the UTI and the role, respectively. Alternatively, a dictionary in the array 137 | may contain two key-value pairs representing the application's bundle ID, 138 | and the URL scheme. A simple plist designed to set Safari as the default 139 | handler of HTML files, and Firefox as the default handler for "ftp://" URLs, 140 | would look like this: 141 | .sp 142 | .br 143 | 144 | .br 145 | 146 | .br 147 | 148 | .br 149 | 150 | .br 151 | DUTISettings 152 | .br 153 | 154 | .br 155 | 156 | .br 157 | DUTIBundleIdentifier 158 | .br 159 | com.apple.Safari 160 | .br 161 | DUTIUniformTypeIdentifier 162 | .br 163 | public.html 164 | .br 165 | DUTIRole 166 | .br 167 | all 168 | .br 169 | 170 | .br 171 | 172 | .br 173 | DUTIBundleIdentifier 174 | .br 175 | org.mozilla.Firefox 176 | .br 177 | DUTIURLScheme 178 | .br 179 | ftp 180 | .br 181 | 182 | .br 183 | 184 | .br 185 | 186 | .br 187 | 188 | .br 189 | .sp 190 | .SH ROLES 191 | Valid roles are defined as follows: 192 | .sp 193 | .TP 19 194 | .B all 195 | application handles all roles for the given UTI. 196 | .TP 19 197 | .B viewer 198 | application handles reading and displaying documents with the given UTI. 199 | .TP 19 200 | .B editor 201 | application can manipulate and save the item. Implies viewer. 202 | .TP 19 203 | .B shell 204 | application can execute the item. 205 | .TP 19 206 | .B none 207 | application cannot open the item, but provides an icon for the given UTI. 208 | .SH EXAMPLES 209 | Running 210 | .B duti 211 | with 212 | .BI \-s 213 | : 214 | .sp 215 | .br 216 | # Set Safari as the default handler for HTML documents 217 | .br 218 | duti -s com.apple.Safari public.html all 219 | .br 220 | .sp 221 | # Set Finder as the default handler for the ftp:// URL scheme 222 | .br 223 | duti -s com.apple.Finder ftp 224 | .sp 225 | 226 | Retrieving default application information for an extension: 227 | .sp 228 | .br 229 | # default application information for .html files 230 | .br 231 | % duti -x html 232 | .br 233 | Safari 234 | .br 235 | /Applications/Safari.app 236 | .br 237 | com.apple.Safari 238 | .br 239 | .sp 240 | 241 | The following examples can be used by passing them to 242 | .B duti 243 | on stdin or as lines in a .duti file. 244 | .sp 245 | Set TextEdit as the default viewer for Microsoft Word documents: 246 | .sp 247 | .br 248 | com.apple.TextEdit com.microsoft.word.doc viewer 249 | .br 250 | .sp 251 | Set VLC as the default viewer for files with .m4v extensions: 252 | .sp 253 | .br 254 | org.videolan.vlc m4v viewer 255 | .br 256 | .sp 257 | Set iHook as the default executor of shell scripts: 258 | .sp 259 | .br 260 | edu.umich.iHook public.shell-script shell 261 | .br 262 | .sp 263 | Set Xcode as the default editor for C source files: 264 | .sp 265 | .br 266 | com.apple.Xcode public.c-source editor 267 | .br 268 | .sp 269 | .SH OPTIONS 270 | .TP 19 271 | .BI \-d\ uti 272 | display the default handler for 273 | .I uti 274 | and exit. 275 | .TP 19 276 | .B \-h 277 | print usage and exit. 278 | .TP 19 279 | .BI \-l\ uti 280 | display all handlers for 281 | .I uti 282 | and exit. 283 | .TP 19 284 | .BI \-s 285 | set the handler from data provided on the command line. 286 | .TP 19 287 | .B \-V 288 | print version number and exit. 289 | .TP 19 290 | .B \-v 291 | verbose output. 292 | .TP 19 293 | .BI \-x\ ext 294 | print information describing the default application for extension 295 | .IR ext . 296 | .sp 297 | .SH EXIT STATUS 298 | .TP 5 299 | 0 300 | All settings applied or displayed successfully. 301 | .TP 5 302 | 1 303 | Settings could not be applied, or the UTI has no handler. 304 | .TP 5 305 | >1 306 | Error. 307 | .sp 308 | .SH MORE INFO 309 | macOS ships with a number of UTIs already defined. Most third-party 310 | software is responsible for defining its own UTIs. Apple documents UTIs 311 | in the Apple Developer Documentation Archive at: 312 | .sp 313 | .br 314 | https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/understanding_utis/understand_utis_intro/understand_utis_intro.html 315 | .br 316 | .sp 317 | To get a list of UTIs on your system, you can use the following command line: 318 | .sp 319 | .br 320 | $(mdfind -name lsregister) -dump | grep -E '^uti:' \\ 321 | .br 322 | | awk '{ print $2 }' | sort | uniq 323 | .sp 324 | .SH SEE ALSO 325 | plutil(1), plist(5) 326 | -------------------------------------------------------------------------------- /duti.c: -------------------------------------------------------------------------------- 1 | /* duti: set default handlers for document types based on a settings file. */ 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "handler.h" 14 | 15 | extern char *duti_version; 16 | extern int nroles; 17 | int verbose = 0; 18 | 19 | struct roles rtm[] = { 20 | { "none", kLSRolesNone }, 21 | { "viewer", kLSRolesViewer }, 22 | { "editor", kLSRolesEditor }, 23 | { "shell", kLSRolesShell }, 24 | { "all", kLSRolesAll }, 25 | }; 26 | 27 | int 28 | main( int ac, char *av[] ) 29 | { 30 | struct stat st; 31 | int c, err = 0; 32 | int set = 0; 33 | int ( *handler_f )( char * ); 34 | char *path = NULL; 35 | char *p; 36 | 37 | extern int optind; 38 | extern char *optarg; 39 | 40 | while (( c = getopt( ac, av, "d:e:l:hsu:Vvx:" )) != -1 ) { 41 | switch ( c ) { 42 | case 'd': /* show default handler for UTI */ 43 | return( uti_handler_show( optarg, 0 )); 44 | 45 | case 'e': /* UTI declarations for extension */ 46 | return( duti_utis_for_extension( optarg )); 47 | 48 | case 'h': /* help */ 49 | default: 50 | err++; 51 | break; 52 | 53 | case 'l': /* list all handlers for UTI */ 54 | return( uti_handler_show( optarg, 1 )); 55 | 56 | case 's': /* set handler */ 57 | set = 1; 58 | break; 59 | 60 | case 'u': /* UTI declarations */ 61 | return( duti_utis( optarg )); 62 | 63 | case 'V': /* version */ 64 | printf( "%s\n", duti_version ); 65 | exit( 0 ); 66 | 67 | case 'v': /* verbose */ 68 | verbose = 1; 69 | break; 70 | 71 | case 'x': /* info for extension */ 72 | return( duti_default_app_for_extension( optarg )); 73 | } 74 | } 75 | 76 | nroles = sizeof( rtm ) / sizeof( rtm[ 0 ] ); 77 | 78 | switch (( ac - optind )) { 79 | case 0 : /* read from stdin */ 80 | if ( set ) { 81 | err++; 82 | } 83 | break; 84 | 85 | case 1 : /* read from file or directory */ 86 | if ( set ) { 87 | err++; 88 | } 89 | path = av[ optind ]; 90 | break; 91 | 92 | case 2 : /* set URI handler */ 93 | if ( set ) { 94 | return( duti_handler_set( av[ optind ], 95 | av[ optind + 1 ], NULL )); 96 | } 97 | /* this fallthrough works because set == 0 */ 98 | 99 | case 3 : /* set UTI handler */ 100 | if ( set ) { 101 | return( duti_handler_set( av[ optind ], 102 | av[ optind + 1 ], av[ optind + 2 ] )); 103 | } 104 | /* fallthrough to error */ 105 | 106 | default : /* error */ 107 | err++; 108 | break; 109 | } 110 | 111 | if ( err ) { 112 | fprintf( stderr, "usage: %s [ -hvV ] [ -d uti ] [ -l uti ] " 113 | "[ settings_path ]\n", av[ 0 ] ); 114 | fprintf( stderr, "usage: %s -s bundle_id { uti | url_scheme } " 115 | "[ role ]\n", av[ 0 ] ); 116 | fprintf( stderr, "usage: %s -x extension\n", av[ 0 ] ); 117 | exit( 1 ); 118 | } 119 | 120 | /* by default, read from a FILE stream */ 121 | handler_f = fsethandler; 122 | 123 | if ( path ) { 124 | if ( stat( path, &st ) != 0 ) { 125 | fprintf( stderr, "stat %s: %s\n", path, strerror( errno )); 126 | exit( 2 ); 127 | } 128 | switch ( st.st_mode & S_IFMT ) { 129 | case S_IFDIR: /* directory of settings files */ 130 | handler_f = dirsethandler; 131 | break; 132 | 133 | case S_IFREG: /* settings file or plist */ 134 | if (( p = strrchr( path, '.' )) != NULL ) { 135 | p++; 136 | if ( strcmp( p, "plist" ) == 0 ) { 137 | handler_f = psethandler; 138 | } 139 | } 140 | break; 141 | 142 | default: 143 | fprintf( stderr, "%s: not a supported settings path\n", path ); 144 | exit( 1 ); 145 | } 146 | } 147 | 148 | return( handler_f( path )); 149 | } 150 | -------------------------------------------------------------------------------- /handler.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "handler.h" 14 | #include "plist.h" 15 | #include "util.h" 16 | 17 | extern int verbose; 18 | extern struct roles rtm[]; 19 | int nroles; 20 | 21 | static void dump_cf_array( const void *value, void *context ); 22 | static void dump_cf_dictionary( const void *key, const void *value, void *context ); 23 | 24 | 25 | int 26 | duti_is_conformant_uti( CFStringRef uti ) 27 | { 28 | /* 29 | * this is gross, but the kUTType CFStringRefs aren't constant, so 30 | * there's no convenient way to make a simple CFStringRef array (not 31 | * a CFArrayRef) with the base types we're checking. creating a 32 | * CFArrayRef with the kUTType CFStringRefs would be worthwhile if 33 | * we weren't running as a one-shot utility. 34 | */ 35 | 36 | if ( UTTypeConformsTo( uti, kUTTypeItem ) || 37 | UTTypeConformsTo( uti, kUTTypeContent ) || 38 | UTTypeConformsTo( uti, kUTTypeMessage ) || 39 | UTTypeConformsTo( uti, kUTTypeContact ) || 40 | UTTypeConformsTo( uti, kUTTypeArchive )) { 41 | return( 1 ); 42 | } 43 | 44 | return( 0 ); 45 | } 46 | 47 | int 48 | set_uti_handler( CFStringRef bid, CFStringRef type, LSRolesMask mask ) 49 | { 50 | OSStatus rc; 51 | char cb[ MAXPATHLEN ]; 52 | char ct[ MAXPATHLEN ]; 53 | 54 | /* get C strings to use in output. CFShow is inadequate. */ 55 | if ( cf2c( bid, cb, sizeof( cb )) != 0 ) { 56 | /* something reasonable on error */ 57 | strlcpy( cb, "bundle_id", sizeof( cb )); 58 | } 59 | if ( cf2c( type, ct, sizeof( ct )) != 0 ) { 60 | strlcpy( ct, "UTI", sizeof( ct )); 61 | } 62 | 63 | 64 | if ( !duti_is_conformant_uti( type )) { 65 | fprintf( stderr, "%s does not conform to any UTI hierarchy\n", ct ); 66 | return( 1 ); 67 | } 68 | 69 | if ( verbose ) { 70 | printf( "setting %s as handler for %s\n", cb, ct ); 71 | } 72 | 73 | rc = LSSetDefaultRoleHandlerForContentType( type, mask, bid ); 74 | if ( rc != noErr ) { 75 | fprintf( stderr, "failed to set %s as handler " 76 | "for %s (error %d)\n", cb, ct, ( int )rc ); 77 | } 78 | 79 | return(( int )rc ); 80 | } 81 | 82 | int 83 | set_url_handler( CFStringRef bid, CFStringRef url_scheme ) 84 | { 85 | OSStatus rc; 86 | char cb[ MAXPATHLEN ]; 87 | char cu[ MAXPATHLEN ]; 88 | 89 | if ( cf2c( bid, cb, sizeof( cb )) != 0 ) { 90 | strlcpy( cb, "bundle_id", sizeof( cb )); 91 | } 92 | if ( cf2c( url_scheme, cu, sizeof( cu )) != 0 ) { 93 | strlcpy( cu, "url_scheme", sizeof( cu )); 94 | } 95 | 96 | if ( verbose ) { 97 | printf( "setting %s as handler for %s:// URLs\n", cb, cu ); 98 | } 99 | 100 | rc = LSSetDefaultHandlerForURLScheme( url_scheme, bid ); 101 | if ( rc != noErr ) { 102 | fprintf( stderr, "failed to set %s as handler " 103 | "for %s:// (error %d)\n", cb, cu, ( int )rc ); 104 | } 105 | 106 | return(( int )rc ); 107 | } 108 | 109 | int 110 | fsethandler( char *spath ) 111 | { 112 | FILE *f = NULL; 113 | char line[ MAXPATHLEN * 2 ]; 114 | char *handler, *type, *role; 115 | char **lineav = NULL; 116 | int linenum = 0, rc = 0; 117 | int len, htype; 118 | 119 | if ( spath != NULL ) { 120 | if (( f = fopen( spath, "r" )) == NULL ) { 121 | fprintf( stderr, "fopen %s: %s\n", spath, strerror( errno )); 122 | return( 1 ); 123 | } 124 | } else { 125 | f = stdin; 126 | } 127 | 128 | while ( fgets( line, sizeof( line ), f ) != NULL ) { 129 | linenum++; 130 | 131 | len = strlen( line ); 132 | if ( line[ len - 1 ] != '\n' ) { 133 | fprintf( stderr, "line %d: line too long\n", linenum ); 134 | exit( 2 ); 135 | } 136 | line[ len - 1 ] = '\0'; 137 | 138 | /* skip blanks and comments */ 139 | if ( *line == '\0' || *line == '#' ) { 140 | continue; 141 | } 142 | 143 | htype = parseline( line, &lineav ); 144 | switch ( htype ) { 145 | case DUTI_TYPE_UTI_HANDLER: 146 | handler = lineav[ 0 ]; 147 | type = lineav[ 1 ]; 148 | role = lineav[ 2 ]; 149 | break; 150 | 151 | case DUTI_TYPE_URL_HANDLER: 152 | handler = lineav[ 0 ]; 153 | type = lineav[ 1 ]; 154 | break; 155 | 156 | default: 157 | fprintf( stderr, "line %d: parsing failed\n", linenum ); 158 | rc = 1; 159 | continue; 160 | } 161 | 162 | if ( htype == DUTI_TYPE_UTI_HANDLER ) { 163 | duti_handler_set( handler, type, role ); 164 | } else if ( htype == DUTI_TYPE_URL_HANDLER ) { 165 | duti_handler_set( handler, type, NULL ); 166 | } 167 | } 168 | if ( ferror( f )) { 169 | perror( "fgets" ); 170 | rc = 1; 171 | } 172 | if ( fclose( f ) != 0 ) { 173 | perror( "fclose" ); 174 | rc = 1; 175 | } 176 | 177 | return( rc ); 178 | } 179 | 180 | int 181 | psethandler( char *spath ) 182 | { 183 | CFDictionaryRef plist; 184 | CFArrayRef dharray; 185 | CFDictionaryRef dhentry; 186 | CFStringRef bid, uti, role, url_scheme; 187 | CFIndex count, index; 188 | 189 | int rc = 0; 190 | int htype = DUTI_TYPE_UTI_HANDLER; 191 | char handler[ MAXPATHLEN ], type[ MAXPATHLEN ]; 192 | char crole[ 255 ]; 193 | 194 | if ( !spath ) { 195 | fprintf( stderr, "%s: invalid argument supplied\n", __FUNCTION__ ); 196 | return( 1 ); 197 | } 198 | 199 | if ( read_plist( spath, &plist ) != 0 ) { 200 | fprintf( stderr, "%s: failed to read plist\n", __FUNCTION__ ); 201 | return( 1 ); 202 | } 203 | 204 | if ( !plist ) { 205 | fprintf( stderr, "%s: Invalid plist\n", __FUNCTION__ ); 206 | return( 1 ); 207 | } 208 | 209 | if (( dharray = CFDictionaryGetValue( plist, 210 | DUTI_KEY_SETTINGS )) == NULL ) { 211 | fprintf( stderr, "%s is missing the settings array\n", spath ); 212 | CFRelease( plist ); 213 | return( 1 ); 214 | } 215 | 216 | count = CFArrayGetCount( dharray ); 217 | for ( index = 0; index < count; index++ ) { 218 | dhentry = CFArrayGetValueAtIndex( dharray, index ); 219 | 220 | if (( bid = CFDictionaryGetValue( dhentry, 221 | DUTI_KEY_BUNDLEID )) == NULL ) { 222 | fprintf( stderr, "Entry %d missing bundle ID\n", ( int )index ); 223 | rc = 1; 224 | continue; 225 | } 226 | if (( url_scheme = CFDictionaryGetValue( dhentry, 227 | DUTI_KEY_URLSCHEME )) != NULL ) { 228 | htype = DUTI_TYPE_URL_HANDLER; 229 | } else if (( uti = CFDictionaryGetValue( dhentry, 230 | DUTI_KEY_UTI )) != NULL ) { 231 | if (( role = CFDictionaryGetValue( dhentry, 232 | DUTI_KEY_ROLE )) == NULL ) { 233 | fprintf( stderr, "Entry %d missing role\n", ( int )index ); 234 | rc = 1; 235 | continue; 236 | } 237 | htype = DUTI_TYPE_UTI_HANDLER; 238 | } else { 239 | fprintf( stderr, "Entry %d invalid\n", ( int )index ); 240 | rc = 1; 241 | continue; 242 | } 243 | 244 | if ( htype == DUTI_TYPE_UTI_HANDLER ) { 245 | if ( cf2c( bid, handler, sizeof( handler )) != 0 ) { 246 | rc = 1; 247 | continue; 248 | } 249 | if ( cf2c( uti, type, sizeof( type )) != 0 ) { 250 | rc = 1; 251 | continue; 252 | } 253 | if ( cf2c( role, crole, sizeof( crole )) != 0 ) { 254 | rc = 1; 255 | continue; 256 | } 257 | if ( duti_handler_set( handler, type, crole ) != 0 ) { 258 | rc = 1; 259 | } 260 | } else if ( htype == DUTI_TYPE_URL_HANDLER ) { 261 | if ( cf2c( bid, handler, sizeof( handler )) != 0 ) { 262 | rc = 1; 263 | continue; 264 | } 265 | if ( cf2c( url_scheme, type, sizeof( type )) != 0 ) { 266 | rc = 1; 267 | continue; 268 | } 269 | if ( duti_handler_set( handler, type, NULL ) != 0 ) { 270 | rc = 1; 271 | } 272 | } 273 | } 274 | 275 | if ( plist != NULL ) { 276 | CFRelease( plist ); 277 | } 278 | 279 | return( rc ); 280 | } 281 | 282 | int 283 | dirsethandler( char *dirpath ) 284 | { 285 | DIR *d = NULL; 286 | struct dirent *de; 287 | struct ll *head = NULL; 288 | struct ll *cur, *tmp; 289 | struct stat st; 290 | char path[ MAXPATHLEN ]; 291 | char *p; 292 | int rc = 0; 293 | int ( *dhandler_f )( char * ); 294 | 295 | if (( d = opendir( dirpath )) == NULL ) { 296 | fprintf( stderr, "opendir %s: %s\n", dirpath, strerror( errno )); 297 | exit( 2 ); 298 | } 299 | 300 | while (( de = readdir( d )) != NULL ) { 301 | if ( de->d_name[ 0 ] == '.' ) { 302 | continue; 303 | } 304 | 305 | if ( snprintf( path, MAXPATHLEN, "%s/%s", 306 | dirpath, de->d_name ) >= MAXPATHLEN ) { 307 | fprintf( stderr, "%s/%s: path too long\n", dirpath, de->d_name ); 308 | continue; 309 | } 310 | 311 | /* skip anything that isn't a file or does not resolve to a file. */ 312 | if ( stat( path, &st ) != 0 ) { 313 | fprintf( stderr, "stat %s: %s\n", path, strerror( errno )); 314 | continue; 315 | } 316 | if ( !S_ISREG( st.st_mode )) { 317 | continue; 318 | } 319 | 320 | /* 321 | * build a sorted list of files in the directory 322 | * so the admin can dictate in what order they'll 323 | * be processed, allowing handler precedence. 324 | * 325 | * HFS+ appears to store files in lexical order 326 | * on disk, but we can't count on an HFS+ volume. 327 | */ 328 | lladd( path, &head ); 329 | } 330 | if ( closedir( d ) != 0 ) { 331 | fprintf( stderr, "closedir: %s\n", strerror( errno )); 332 | rc = 1; 333 | } 334 | 335 | for ( cur = head; cur != NULL; cur = tmp ) { 336 | dhandler_f = fsethandler; 337 | if (( p = strrchr( cur->l_path, '.' )) != NULL ) { 338 | p++; 339 | if ( strcmp( p, "plist" ) == 0 ) { 340 | dhandler_f = psethandler; 341 | } 342 | } 343 | 344 | if ( verbose ) { 345 | printf( "Applying settings from %s\n", cur->l_path ); 346 | } 347 | if ( dhandler_f( cur->l_path ) != 0 ) { 348 | rc = 1; 349 | } 350 | 351 | tmp = cur->l_next; 352 | free( cur->l_path ); 353 | free( cur ); 354 | } 355 | 356 | return( rc ); 357 | } 358 | 359 | int 360 | uti_handler_show( char *uti, int showall ) 361 | { 362 | CFArrayRef cfhandlers = NULL; 363 | CFStringRef cfuti = NULL; 364 | CFStringRef cfhandler = NULL; 365 | char dh[ MAXPATHLEN ]; 366 | int rc = 0; 367 | int count, i; 368 | 369 | if ( uti == NULL ) { 370 | fprintf( stderr, "Invalid UTI.\n" ); 371 | return( 2 ); 372 | } 373 | 374 | if ( c2cf( uti, &cfuti ) != 0 ) { 375 | return( 2 ); 376 | } 377 | 378 | if ( showall ) { 379 | if (( cfhandlers = LSCopyAllRoleHandlersForContentType( 380 | cfuti, kLSRolesAll )) == NULL ) { 381 | if (( cfhandlers = LSCopyAllHandlersForURLScheme( 382 | cfuti )) == NULL ) { 383 | fprintf( stderr, "%s: no handlers\n", uti ); 384 | rc = 1; 385 | goto uti_show_done; 386 | } 387 | } 388 | 389 | if ( verbose ) { 390 | printf( "All handlers for %s:\n", uti ); 391 | } 392 | 393 | count = CFArrayGetCount( cfhandlers ); 394 | for ( i = 0; i < count; i++ ) { 395 | cfhandler = CFArrayGetValueAtIndex( cfhandlers, i ); 396 | if ( cf2c( cfhandler, dh, sizeof( dh )) != 0 ) { 397 | rc = 2; 398 | continue; 399 | } 400 | printf( "%s\n", dh ); 401 | memset( dh, 0, sizeof( dh )); 402 | } 403 | 404 | cfhandler = NULL; 405 | } else { 406 | if (( cfhandler = LSCopyDefaultRoleHandlerForContentType( 407 | cfuti, kLSRolesAll )) == NULL ) { 408 | if (( cfhandler = LSCopyDefaultHandlerForURLScheme( 409 | cfuti )) == NULL ) { 410 | fprintf( stderr, "%s: no default handler\n", uti ); 411 | rc = 1; 412 | goto uti_show_done; 413 | } 414 | } 415 | 416 | if ( cf2c( cfhandler, dh, MAXPATHLEN ) != 0 ) { 417 | rc = 2; 418 | goto uti_show_done; 419 | } 420 | 421 | if ( verbose ) { 422 | printf( "Default handler for %s: ", uti ); 423 | } 424 | printf( "%s\n", dh ); 425 | } 426 | 427 | uti_show_done: 428 | if ( cfhandlers ) { 429 | CFRelease( cfhandlers ); 430 | } 431 | if ( cfuti ) { 432 | CFRelease( cfuti ); 433 | } 434 | if ( cfhandler ) { 435 | CFRelease( cfhandler ); 436 | } 437 | 438 | return( rc ); 439 | } 440 | 441 | int 442 | duti_handler_set( char *bid, char *type, char *role ) 443 | { 444 | CFStringRef cf_bid = NULL; 445 | CFStringRef cf_type = NULL; 446 | CFStringRef tagClass = NULL, preferredUTI = NULL; 447 | int rc = 0; 448 | int i = 0; 449 | 450 | if ( role != NULL ) { 451 | for ( i = 0; i < nroles; i++ ) { 452 | if ( strcasecmp( role, rtm[ i ].r_role ) == 0 ) { 453 | break; 454 | } 455 | } 456 | if ( i >= nroles ) { 457 | fprintf( stderr, "role \"%s\" unrecognized\n", role ); 458 | return( 2 ); 459 | } 460 | } 461 | 462 | if ( role != NULL ) { 463 | if ( *type == '.' ) { 464 | type++; 465 | if ( *type == '\0' ) { 466 | fprintf( stderr, "duti_handler_set: invalid empty type" ); 467 | rc = 2; 468 | goto duti_set_cleanup; 469 | } 470 | tagClass = kUTTagClassFilenameExtension; 471 | } else { 472 | if ( strchr( type, '/' ) != NULL ) { 473 | tagClass = kUTTagClassMIMEType; 474 | } else if ( strchr( type, '.' ) == NULL ) { 475 | tagClass = kUTTagClassFilenameExtension; 476 | } 477 | } 478 | if ( tagClass != NULL ) { 479 | /* 480 | * if no UTI defined for the extension, the system creates a 481 | * dynamic local UTI with a "dyn." prefix & an encoded value. 482 | */ 483 | if ( c2cf( type, &cf_type ) != 0 ) { 484 | rc = 2; 485 | goto duti_set_cleanup; 486 | } 487 | 488 | preferredUTI = UTTypeCreatePreferredIdentifierForTag( 489 | tagClass, cf_type, kUTTypeContent ); 490 | CFRelease( cf_type ); 491 | cf_type = NULL; 492 | 493 | if ( preferredUTI == NULL ) { 494 | fprintf( stderr, "failed to create preferred " 495 | "identifier for type %s", type ); 496 | rc = 2; 497 | goto duti_set_cleanup; 498 | } 499 | } 500 | } 501 | if ( c2cf( bid, &cf_bid ) != 0 ) { 502 | rc = 2; 503 | goto duti_set_cleanup; 504 | } 505 | if ( preferredUTI != NULL ) { 506 | if (( cf_type = CFStringCreateCopy( kCFAllocatorDefault, 507 | preferredUTI )) == NULL ) { 508 | fprintf( stderr, "failed to copy preferred UTI" ); 509 | rc = 2; 510 | goto duti_set_cleanup; 511 | } 512 | } else { 513 | if ( c2cf( type, &cf_type ) != 0 ) { 514 | rc = 1; 515 | goto duti_set_cleanup; 516 | } 517 | } 518 | 519 | if ( role != NULL ) { 520 | /* set UTI handler */ 521 | if (( rc = set_uti_handler( cf_bid, cf_type, 522 | rtm[ i ].r_mask )) != 0 ) { 523 | rc = 2; 524 | } 525 | } else { 526 | /* set URL scheme handler */ 527 | if (( rc = set_url_handler( cf_bid, cf_type )) != 0 ) { 528 | rc = 2; 529 | } 530 | } 531 | 532 | duti_set_cleanup: 533 | if ( cf_bid != NULL ) { 534 | CFRelease( cf_bid ); 535 | } 536 | if ( cf_type != NULL ) { 537 | CFRelease( cf_type ); 538 | } 539 | if ( preferredUTI != NULL ) { 540 | CFRelease( preferredUTI ); 541 | } 542 | 543 | return( rc ); 544 | } 545 | 546 | /* 547 | * print default app info for a given extension. based on 548 | * public domain source posted on the heliumfoot.com blog 549 | * by Keith Alperin. 550 | * 551 | * http://www.heliumfoot.com/blog/77 552 | */ 553 | int 554 | duti_default_app_for_extension( char *ext ) 555 | { 556 | CFDictionaryRef cf_info_dict = NULL; 557 | CFStringRef cf_ext = NULL; 558 | CFStringRef cf_app_bundle_id = NULL; 559 | CFStringRef cf_app_name = NULL; 560 | CFURLRef cf_app_url = NULL; 561 | OSStatus err; 562 | char *rext; 563 | char tmp[ MAXPATHLEN ]; 564 | int rc = 2; 565 | 566 | if (( rext = strrchr( ext, '.' )) == NULL ) { 567 | rext = ext; 568 | } else { 569 | rext++; 570 | if ( *rext == '\0' ) { 571 | fprintf( stderr, "no extension provided\n" ); 572 | return( rc ); 573 | } 574 | } 575 | if ( c2cf( rext, &cf_ext ) != 0 ) { 576 | return( rc ); 577 | } 578 | 579 | err = LSGetApplicationForInfo( kLSUnknownType, kLSUnknownCreator, cf_ext, 580 | kLSRolesAll, NULL, &cf_app_url ); 581 | if ( err != noErr ) { 582 | fprintf( stderr, "Failed to get default application for " 583 | "extension \'%s\'\n", rext ); 584 | goto duti_extension_cleanup; 585 | } 586 | 587 | err = LSCopyDisplayNameForURL( cf_app_url, &cf_app_name ); 588 | if ( err != noErr ) { 589 | fprintf( stderr, "Failed to get display name\n" ); 590 | goto duti_extension_cleanup; 591 | } 592 | if ( cf2c( cf_app_name, tmp, sizeof( tmp )) != 0 ) { 593 | goto duti_extension_cleanup; 594 | } 595 | printf( "%s\n", tmp ); 596 | 597 | if ( cfurl2path( cf_app_url, tmp, sizeof( tmp )) != 0 ) { 598 | goto duti_extension_cleanup; 599 | } 600 | printf( "%s\n", tmp ); 601 | 602 | cf_info_dict = CFBundleCopyInfoDictionaryInDirectory( cf_app_url ); 603 | if ( cf_info_dict == NULL ) { 604 | fprintf( stderr, "Failed to copy info dictionary from %s\n", tmp ); 605 | goto duti_extension_cleanup; 606 | } 607 | 608 | cf_app_bundle_id = CFDictionaryGetValue( cf_info_dict, 609 | kCFBundleIdentifierKey ); 610 | if ( cf_app_bundle_id == NULL ) { 611 | fprintf( stderr, "Failed to get bundle identifier for %s\n", tmp ); 612 | goto duti_extension_cleanup; 613 | } 614 | 615 | if ( cf2c( cf_app_bundle_id, tmp, sizeof( tmp )) != 0 ) { 616 | goto duti_extension_cleanup; 617 | } 618 | printf( "%s\n", tmp ); 619 | 620 | /* success */ 621 | rc = 0; 622 | 623 | duti_extension_cleanup: 624 | if ( cf_ext != NULL ) { 625 | CFRelease( cf_ext ); 626 | } 627 | if ( cf_app_url != NULL ) { 628 | CFRelease( cf_app_url ); 629 | } 630 | if ( cf_info_dict != NULL ) { 631 | CFRelease( cf_info_dict ); 632 | } 633 | if ( cf_app_name != NULL ) { 634 | CFRelease( cf_app_name ); 635 | } 636 | 637 | return( rc ); 638 | } 639 | 640 | int 641 | duti_utis( char * uti ) { 642 | CFStringRef cf_uti_identifier = NULL; 643 | CFStringRef cf_uti_description = NULL; 644 | CFDictionaryRef cf_uti_declaration = NULL; 645 | char tmp[ MAXPATHLEN ]; 646 | int rc = 2; 647 | 648 | if ( uti == NULL ) { 649 | fprintf( stderr, "Invalid UTI.\n" ); 650 | return( rc ); 651 | } 652 | 653 | if ( c2cf( uti, &cf_uti_identifier ) != 0 ) { 654 | return( rc ); 655 | } 656 | 657 | cf_uti_description = UTTypeCopyDescription(cf_uti_identifier); 658 | if ( cf2c( cf_uti_description, tmp, sizeof( tmp )) != 0 ) { 659 | goto duti_utis_cleanup; 660 | } 661 | CFRelease(cf_uti_description); cf_uti_description = NULL; 662 | printf( "description: %s\n", tmp ); 663 | 664 | cf_uti_declaration = UTTypeCopyDeclaration(cf_uti_identifier); 665 | printf( "declaration: {\n" ); 666 | CFDictionaryApplyFunction(cf_uti_declaration, dump_cf_dictionary, "\t"); 667 | CFRelease(cf_uti_declaration); cf_uti_declaration = NULL; 668 | printf( "}\n" ); 669 | 670 | /* success */ 671 | rc = 0; 672 | 673 | duti_utis_cleanup: 674 | if ( cf_uti_identifier ) { 675 | CFRelease( cf_uti_identifier ); 676 | } 677 | if ( cf_uti_description != NULL ) { 678 | CFRelease( cf_uti_description ); 679 | } 680 | if ( cf_uti_declaration != NULL ) { 681 | CFRelease( cf_uti_declaration ); 682 | } 683 | 684 | return rc; 685 | } 686 | 687 | int 688 | duti_utis_for_extension(char* ext) { 689 | CFStringRef cf_ext = NULL; 690 | CFArrayRef cf_array = NULL; 691 | CFStringRef cf_uti_description = NULL; 692 | CFDictionaryRef cf_uti_declaration = NULL; 693 | CFIndex index; 694 | CFIndex count; 695 | char *rext; 696 | char tmp[ MAXPATHLEN ]; 697 | int rc = 2; 698 | 699 | if (( rext = strrchr( ext, '.' )) == NULL ) { 700 | rext = ext; 701 | } else { 702 | rext++; 703 | if ( *rext == '\0' ) { 704 | fprintf( stderr, "no extension provided\n" ); 705 | return( rc ); 706 | } 707 | } 708 | if ( c2cf( rext, &cf_ext ) != 0 ) { 709 | return( rc ); 710 | } 711 | 712 | cf_array = UTTypeCreateAllIdentifiersForTag(kUTTagClassFilenameExtension, cf_ext, nil); 713 | for (index = 0, count = CFArrayGetCount(cf_array); index < count; index++) { 714 | CFStringRef cf_uti_identifier = CFArrayGetValueAtIndex(cf_array, index); 715 | if ( cf2c( cf_uti_identifier, tmp, sizeof( tmp )) != 0 ) { 716 | goto duti_utis_cleanup; 717 | } 718 | printf( "identifier: %s\n", tmp ); 719 | 720 | cf_uti_description = UTTypeCopyDescription(cf_uti_identifier); 721 | if ( cf2c( cf_uti_description, tmp, sizeof( tmp )) != 0 ) { 722 | goto duti_utis_cleanup; 723 | } 724 | CFRelease(cf_uti_description); cf_uti_description = NULL; 725 | printf( "description: %s\n", tmp ); 726 | 727 | cf_uti_declaration = UTTypeCopyDeclaration(cf_uti_identifier); 728 | printf( "declaration: {\n" ); 729 | CFDictionaryApplyFunction(cf_uti_declaration, dump_cf_dictionary, "\t"); 730 | CFRelease(cf_uti_declaration); cf_uti_declaration = NULL; 731 | printf( "}\n" ); 732 | } 733 | 734 | /* success */ 735 | rc = 0; 736 | 737 | duti_utis_cleanup: 738 | if ( cf_ext != NULL ) { 739 | CFRelease( cf_ext ); 740 | } 741 | if ( cf_array != NULL ) { 742 | CFRelease( cf_array ); 743 | } 744 | if ( cf_uti_description != NULL ) { 745 | CFRelease( cf_uti_description ); 746 | } 747 | if ( cf_uti_declaration != NULL ) { 748 | CFRelease( cf_uti_declaration ); 749 | } 750 | 751 | return( rc ); 752 | } 753 | 754 | static void 755 | dump_cf_array( const void *value, void *context ) { 756 | CFTypeID typeID; 757 | char tmp[ MAXPATHLEN ]; 758 | 759 | typeID = CFGetTypeID( value ); 760 | if (typeID == CFStringGetTypeID()) { 761 | if ( cf2c( value, tmp, sizeof( tmp )) != 0 ) { 762 | return; 763 | } 764 | printf( "%s%s\n", (char *) context, tmp ); 765 | } else { 766 | printf( "%sunhandled value\n", (char *) context ); 767 | } 768 | } 769 | 770 | static void 771 | dump_cf_dictionary( const void *key, const void *value, void *context ) { 772 | CFTypeID typeID; 773 | char tmp[ MAXPATHLEN ]; 774 | 775 | if ( cf2c( key, tmp, sizeof( tmp )) != 0 ) { 776 | return; 777 | } 778 | printf( "%s%s = ", (char *) context, tmp ); 779 | 780 | typeID = CFGetTypeID( value ); 781 | if (typeID == CFStringGetTypeID()) { 782 | if ( cf2c( value, tmp, sizeof( tmp )) != 0 ) { 783 | return; 784 | } 785 | printf( "%s\n", tmp ); 786 | } else if (typeID == CFArrayGetTypeID()) { 787 | printf( "[\n" ); 788 | sprintf(tmp, "%s\t", (char *) context ); 789 | CFArrayApplyFunction(value, CFRangeMake( 0, CFArrayGetCount( value )), dump_cf_array, tmp); 790 | printf( "%s]\n", (char *) context ); 791 | } else if (typeID == CFDictionaryGetTypeID()) { 792 | printf( "{\n" ); 793 | sprintf(tmp, "%s\t", (char *) context ); 794 | CFDictionaryApplyFunction(value, dump_cf_dictionary, tmp); 795 | printf( "%s}\n", (char *) context ); 796 | } else { 797 | printf( "unhandled key\n"); 798 | } 799 | } 800 | -------------------------------------------------------------------------------- /handler.h: -------------------------------------------------------------------------------- 1 | struct roles { 2 | const char *r_role; 3 | LSRolesMask r_mask; 4 | }; 5 | 6 | extern int nroles; 7 | 8 | #define DUTI_TYPE_URL_HANDLER 2 9 | #define DUTI_TYPE_UTI_HANDLER 3 10 | 11 | int set_uti_handler( CFStringRef, CFStringRef, LSRolesMask ); 12 | int set_url_handler( CFStringRef, CFStringRef ); 13 | int fsethandler( char * ); 14 | int psethandler( char * ); 15 | int dirsethandler( char * ); 16 | 17 | int uti_handler_show( char *uti, int showall ); 18 | int url_handler_show( char *url_scheme ); 19 | int duti_handler_set( char *, char *, char * ); 20 | int duti_default_app_for_extension( char * ); 21 | int duti_is_conformant_uti( CFStringRef ); 22 | int duti_utis( char * ); 23 | int duti_utis_for_extension( char * ); 24 | -------------------------------------------------------------------------------- /install-sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # install - install a program, script, or datafile 4 | # This comes from X11R5 (mit/util/scripts/install.sh). 5 | # 6 | # Copyright 1991 by the Massachusetts Institute of Technology 7 | # 8 | # Permission to use, copy, modify, distribute, and sell this software and its 9 | # documentation for any purpose is hereby granted without fee, provided that 10 | # the above copyright notice appear in all copies and that both that 11 | # copyright notice and this permission notice appear in supporting 12 | # documentation, and that the name of M.I.T. not be used in advertising or 13 | # publicity pertaining to distribution of the software without specific, 14 | # written prior permission. M.I.T. makes no representations about the 15 | # suitability of this software for any purpose. It is provided "as is" 16 | # without express or implied warranty. 17 | # 18 | # Calling this script install-sh is preferred over install.sh, to prevent 19 | # `make' implicit rules from creating a file called install from it 20 | # when there is no Makefile. 21 | # 22 | # This script is compatible with the BSD install script, but was written 23 | # from scratch. It can only install one file at a time, a restriction 24 | # shared with many OS's install programs. 25 | 26 | 27 | # set DOITPROG to echo to test this script 28 | 29 | # Don't use :- since 4.3BSD and earlier shells don't like it. 30 | doit="${DOITPROG-}" 31 | 32 | 33 | # put in absolute paths if you don't have them in your path; or use env. vars. 34 | 35 | mvprog="${MVPROG-mv}" 36 | cpprog="${CPPROG-cp}" 37 | chmodprog="${CHMODPROG-chmod}" 38 | chownprog="${CHOWNPROG-chown}" 39 | chgrpprog="${CHGRPPROG-chgrp}" 40 | stripprog="${STRIPPROG-strip}" 41 | rmprog="${RMPROG-rm}" 42 | mkdirprog="${MKDIRPROG-mkdir}" 43 | 44 | transformbasename="" 45 | transform_arg="" 46 | instcmd="$mvprog" 47 | chmodcmd="$chmodprog 0755" 48 | chowncmd="" 49 | chgrpcmd="" 50 | stripcmd="" 51 | rmcmd="$rmprog -f" 52 | mvcmd="$mvprog" 53 | src="" 54 | dst="" 55 | dir_arg="" 56 | 57 | while [ x"$1" != x ]; do 58 | case $1 in 59 | -c) instcmd="$cpprog" 60 | shift 61 | continue;; 62 | 63 | -d) dir_arg=true 64 | shift 65 | continue;; 66 | 67 | -m) chmodcmd="$chmodprog $2" 68 | shift 69 | shift 70 | continue;; 71 | 72 | -o) chowncmd="$chownprog $2" 73 | shift 74 | shift 75 | continue;; 76 | 77 | -g) chgrpcmd="$chgrpprog $2" 78 | shift 79 | shift 80 | continue;; 81 | 82 | -s) stripcmd="$stripprog" 83 | shift 84 | continue;; 85 | 86 | -t=*) transformarg=`echo $1 | sed 's/-t=//'` 87 | shift 88 | continue;; 89 | 90 | -b=*) transformbasename=`echo $1 | sed 's/-b=//'` 91 | shift 92 | continue;; 93 | 94 | *) if [ x"$src" = x ] 95 | then 96 | src=$1 97 | else 98 | # this colon is to work around a 386BSD /bin/sh bug 99 | : 100 | dst=$1 101 | fi 102 | shift 103 | continue;; 104 | esac 105 | done 106 | 107 | if [ x"$src" = x ] 108 | then 109 | echo "install: no input file specified" 110 | exit 1 111 | else 112 | : 113 | fi 114 | 115 | if [ x"$dir_arg" != x ]; then 116 | dst=$src 117 | src="" 118 | 119 | if [ -d $dst ]; then 120 | instcmd=: 121 | chmodcmd="" 122 | else 123 | instcmd=$mkdirprog 124 | fi 125 | else 126 | 127 | # Waiting for this to be detected by the "$instcmd $src $dsttmp" command 128 | # might cause directories to be created, which would be especially bad 129 | # if $src (and thus $dsttmp) contains '*'. 130 | 131 | if [ -f $src -o -d $src ] 132 | then 133 | : 134 | else 135 | echo "install: $src does not exist" 136 | exit 1 137 | fi 138 | 139 | if [ x"$dst" = x ] 140 | then 141 | echo "install: no destination specified" 142 | exit 1 143 | else 144 | : 145 | fi 146 | 147 | # If destination is a directory, append the input filename; if your system 148 | # does not like double slashes in filenames, you may need to add some logic 149 | 150 | if [ -d $dst ] 151 | then 152 | dst="$dst"/`basename $src` 153 | else 154 | : 155 | fi 156 | fi 157 | 158 | ## this sed command emulates the dirname command 159 | dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` 160 | 161 | # Make sure that the destination directory exists. 162 | # this part is taken from Noah Friedman's mkinstalldirs script 163 | 164 | # Skip lots of stat calls in the usual case. 165 | if [ ! -d "$dstdir" ]; then 166 | defaultIFS=' 167 | ' 168 | IFS="${IFS-${defaultIFS}}" 169 | 170 | oIFS="${IFS}" 171 | # Some sh's can't handle IFS=/ for some reason. 172 | IFS='%' 173 | set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` 174 | IFS="${oIFS}" 175 | 176 | pathcomp='' 177 | 178 | while [ $# -ne 0 ] ; do 179 | pathcomp="${pathcomp}${1}" 180 | shift 181 | 182 | if [ ! -d "${pathcomp}" ] ; 183 | then 184 | $mkdirprog "${pathcomp}" 185 | else 186 | : 187 | fi 188 | 189 | pathcomp="${pathcomp}/" 190 | done 191 | fi 192 | 193 | if [ x"$dir_arg" != x ] 194 | then 195 | $doit $instcmd $dst && 196 | 197 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else : ; fi && 198 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else : ; fi && 199 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else : ; fi && 200 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else : ; fi 201 | else 202 | 203 | # If we're going to rename the final executable, determine the name now. 204 | 205 | if [ x"$transformarg" = x ] 206 | then 207 | dstfile=`basename $dst` 208 | else 209 | dstfile=`basename $dst $transformbasename | 210 | sed $transformarg`$transformbasename 211 | fi 212 | 213 | # don't allow the sed command to completely eliminate the filename 214 | 215 | if [ x"$dstfile" = x ] 216 | then 217 | dstfile=`basename $dst` 218 | else 219 | : 220 | fi 221 | 222 | # Make a temp file name in the proper directory. 223 | 224 | dsttmp=$dstdir/#inst.$$# 225 | 226 | # Move or copy the file name to the temp name 227 | 228 | $doit $instcmd $src $dsttmp && 229 | 230 | trap "rm -f ${dsttmp}" 0 && 231 | 232 | # and set any options; do chmod last to preserve setuid bits 233 | 234 | # If any of these fail, we abort the whole thing. If we want to 235 | # ignore errors from any of these, just make sure not to ignore 236 | # errors from the above "$doit $instcmd $src $dsttmp" command. 237 | 238 | if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else :;fi && 239 | if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else :;fi && 240 | if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else :;fi && 241 | if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else :;fi && 242 | 243 | # Now rename the file to the real destination. 244 | 245 | $doit $rmcmd -f $dstdir/$dstfile && 246 | $doit $mvcmd $dsttmp $dstdir/$dstfile 247 | 248 | fi && 249 | 250 | 251 | exit 0 252 | -------------------------------------------------------------------------------- /pkg-resources/Description.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IFPkgDescriptionDeleteWarning 6 | 7 | IFPkgDescriptionDescription 8 | A command-line utility designed to set default applications for various document types on Mac OS X. 9 | IFPkgDescriptionTitle 10 | duti _DUTI_VERSION 11 | IFPkgDescriptionVersion 12 | _DUTI_VERSION 13 | 14 | 15 | -------------------------------------------------------------------------------- /pkg-resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleGetInfoString 6 | duti _DUTI_VERSION 7 | CFBundleIdentifier 8 | public-domain.mortensen.duti-installer 9 | CFBundleName 10 | duti 11 | CFBundleShortVersionString 12 | _DUTI_VERSION 13 | IFPkgFlagAllowBackRev 14 | 15 | IFPkgFlagAuthorizationAction 16 | RootAuthorization 17 | IFPkgFlagDefaultLocation 18 | / 19 | IFPkgFlagFollowLinks 20 | 21 | IFPkgFlagInstallFat 22 | 23 | IFPkgFlagIsRequired 24 | 25 | IFPkgFlagRelocatable 26 | 27 | IFPkgFlagRestartAction 28 | NoRestart 29 | IFPkgFlagRootVolumeOnly 30 | 31 | IFPkgFlagUpdateInstalledLanguages 32 | 33 | IFPkgFormatVersion 34 | 0.10000000149011612 35 | 36 | 37 | -------------------------------------------------------------------------------- /pkg-resources/License.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf440 2 | {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;} 3 | {\colortbl;\red255\green255\blue255;} 4 | \margl1440\margr1440\vieww9000\viewh8400\viewkind0 5 | \pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\ql\qnatural\pardirnatural 6 | 7 | \f0\b\fs24 \cf0 This software is released in the public domain by Andrew Mortensen, 2008. It is provided as is without warranties of any kind. 8 | \f1\b0 \ 9 | \ 10 | You may do anything you like with this software. If you incorporate some or all of the source into a project, I'd appreciate a credit for the work I've done, but that's all. Enjoy.} -------------------------------------------------------------------------------- /pkg-resources/ReadMe.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf440 2 | {\fonttbl\f0\fswiss\fcharset77 Helvetica-Bold;\f1\fswiss\fcharset77 Helvetica;} 3 | {\colortbl;\red255\green255\blue255;} 4 | \vieww8640\viewh9000\viewkind0 5 | \pard\ql\qnatural 6 | 7 | \f0\b\fs24 \cf0 About duti 8 | \f1\b0 \ 9 | duti is a command-line utility capable of changing default applications for various document types on Mac OS X. duti is free software, released into the public domain by Andrew Mortensen, 2008.\ 10 | \ 11 | 12 | \f0\b Requirements\ 13 | 14 | \f1\b0 duti requires a PowerPC or Intel Macintosh running Mac OS X 10.4 or later.\ 15 | \ 16 | 17 | \f0\b Installing\ 18 | 19 | \f1\b0 You will need administrator privileges to install duti. Only two files are installed: /usr/local/bin/duti and /usr/local/man/man1/duti.1. If you would prefer to install in a different location, consider building and installing from source.\ 20 | \ 21 | 22 | \f0\b Bug Reports\ 23 | 24 | \f1\b0 duti is unsupported software. However, you may report bugs and add feature requests through the SourceForge tracker here:\ 25 | \ 26 | https://sourceforge.net/tracker/?group_id=213184&atid=1024700\ 27 | \ 28 | 29 | \f0\b More Info\ 30 | 31 | \f1\b0 http://duti.sourceforge.net/} -------------------------------------------------------------------------------- /pkg-resources/Welcome.rtf: -------------------------------------------------------------------------------- 1 | {\rtf1\mac\ansicpg10000\cocoartf824\cocoasubrtf440 2 | {\fonttbl\f0\fswiss\fcharset77 Helvetica;} 3 | {\colortbl;\red255\green255\blue255;} 4 | \vieww9000\viewh9000\viewkind0 5 | \pard\qc 6 | 7 | \f0\fs28 \cf0 Welcome to the duti installer. You will be guided through the steps necessary to install this software. 8 | \fs24 \ 9 | } -------------------------------------------------------------------------------- /plist.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include "plist.h" 9 | 10 | int 11 | read_plist( char *plpath, CFDictionaryRef *dr ) 12 | { 13 | CFURLRef cfurl = NULL; 14 | CFReadStreamRef cfrs = NULL; 15 | CFDictionaryRef cfdict = NULL; 16 | CFPropertyListFormat fmt = kCFPropertyListXMLFormat_v1_0; 17 | CFStreamError err; 18 | 19 | int rc = 0; 20 | char respath[ MAXPATHLEN ]; 21 | 22 | if ( plpath == NULL ) { 23 | fprintf( stderr, "%s: Invalid plist path\n", __FUNCTION__ ); 24 | return( -1 ); 25 | } 26 | 27 | if ( realpath( plpath, respath ) == NULL ) { 28 | fprintf( stderr, "%s: realpath failed: %s\n", 29 | __FUNCTION__, strerror( errno )); 30 | return( -1 ); 31 | } 32 | 33 | /* 34 | * must convert C string path to CFURL to read the plist 35 | * from disk. no convenience methods here like Cocoa's 36 | * -dictionaryWithContentsOfFile: 37 | */ 38 | if (( cfurl = CFURLCreateFromFileSystemRepresentation( 39 | kCFAllocatorDefault, ( const UInt8 * )respath, 40 | ( CFIndex )strlen( respath ), false )) == NULL ) { 41 | fprintf( stderr, "%s: failed to create URL for %s\n", 42 | __FUNCTION__, respath ); 43 | return( -1 ); 44 | } 45 | 46 | if (( cfrs = CFReadStreamCreateWithFile( kCFAllocatorDefault, 47 | cfurl )) == NULL ) { 48 | fprintf( stderr, "%s: failed to create read stream\n", __FUNCTION__ ); 49 | rc = -1; 50 | goto cleanup; 51 | } 52 | if ( CFReadStreamOpen( cfrs ) == false ) { 53 | err = CFReadStreamGetError( cfrs ); 54 | fprintf( stderr, "%s: failed to open read stream\n", __FUNCTION__ ); 55 | if ( err.domain == kCFStreamErrorDomainPOSIX ) { 56 | fprintf( stderr, "%s: %s\n", plpath, strerror( errno )); 57 | } else { 58 | fprintf( stderr, "domain %d, error %d\n", 59 | ( int )err.domain, ( int )err.error ); 60 | } 61 | rc = -1; 62 | goto cleanup; 63 | } 64 | 65 | if (( cfdict = CFPropertyListCreateFromStream( kCFAllocatorDefault, cfrs, 66 | 0, kCFPropertyListImmutable, &fmt, NULL )) == NULL ) { 67 | fprintf( stderr, "%s: failed to read plist\n", __FUNCTION__ ); 68 | rc = -1; 69 | goto cleanup; 70 | } 71 | 72 | if ( !CFPropertyListIsValid( cfdict, fmt )) { 73 | fprintf( stderr, "%s: invalid plist\n", plpath ); 74 | CFRelease( cfdict ); 75 | cfdict = NULL; 76 | rc = -1; 77 | } 78 | 79 | cleanup: 80 | if ( cfurl != NULL ) { 81 | CFRelease( cfurl ); 82 | } 83 | if ( cfrs != NULL ) { 84 | CFReadStreamClose( cfrs ); 85 | CFRelease( cfrs ); 86 | } 87 | 88 | *dr = cfdict; 89 | 90 | return( rc ); 91 | } 92 | -------------------------------------------------------------------------------- /plist.h: -------------------------------------------------------------------------------- 1 | int read_plist( char *, CFDictionaryRef * ); 2 | 3 | /* plist keys */ 4 | #define DUTI_KEY_SETTINGS CFSTR( "DUTISettings" ) 5 | #define DUTI_KEY_BUNDLEID CFSTR( "DUTIBundleIdentifier" ) 6 | #define DUTI_KEY_UTI CFSTR( "DUTIUniformTypeIdentifier" ) 7 | #define DUTI_KEY_ROLE CFSTR( "DUTIRole" ) 8 | #define DUTI_KEY_URLSCHEME CFSTR( "DUTIURLScheme" ) 9 | -------------------------------------------------------------------------------- /util.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "util.h" 8 | 9 | /* 10 | * parseline: a simple argument parser. 11 | * 12 | * parameters: 13 | * line: buffer containing string to parse. Modified. 14 | * lineav: argv resulting from parsing. 15 | * 16 | * return value: 17 | * 0: success, line broken into vector of 3 arguments 18 | * -1: failed 19 | * 20 | */ 21 | int 22 | parseline( char *line, char ***lineav ) 23 | { 24 | static char **pav = NULL; 25 | int i; 26 | 27 | if ( pav == NULL ) { 28 | if (( pav = ( char ** )malloc( 5 * sizeof( char * ))) == NULL ) { 29 | perror( "malloc" ); 30 | exit( 2 ); 31 | } 32 | } 33 | 34 | pav[ 0 ] = line; 35 | 36 | for ( i = 1; i < 3; i++ ) { 37 | while ( isspace( *line )) line++; 38 | while ( *line != '\0' && !isspace( *line )) line++; 39 | *line++ = '\0'; 40 | while ( isspace( *line )) line++; 41 | 42 | pav[ i ] = line; 43 | if ( *pav[ i ] == '\0' ) { 44 | break; 45 | } 46 | } 47 | 48 | *lineav = pav; 49 | 50 | return( i ); 51 | } 52 | 53 | /* 54 | * c2cf: convert a C string to CFStringRef 55 | * 56 | * parameters: 57 | * cstr: the C string to convert 58 | * cfstr: will point to result of conversion. must be CFRelease'd. 59 | * 60 | * return value: 61 | * 0: success 62 | * -1: failure 63 | */ 64 | int 65 | c2cf( char *cstr, CFStringRef *cfstr ) 66 | { 67 | CFStringRef cftmp; 68 | 69 | if ( cstr == NULL ) { 70 | fprintf( stderr, "%s: null C String\n", __FUNCTION__ ); 71 | return( -1 ); 72 | } 73 | 74 | if (( cftmp = CFStringCreateWithBytes( kCFAllocatorDefault, 75 | ( UInt8 * )cstr, ( CFIndex )strlen( cstr ), 76 | kCFStringEncodingUTF8, false )) == NULL ) { 77 | fprintf( stderr, "Failed to convert C string to CFStringRef\n" ); 78 | return( -1 ); 79 | } 80 | 81 | *cfstr = cftmp; 82 | 83 | return( 0 ); 84 | } 85 | 86 | /* 87 | * cf2c: convert a CFStringRef to a C string 88 | * 89 | * parameters: 90 | * cfstr: CFStringRef to convert to C string 91 | * cstr: char buffer that will contain result of conversion 92 | * len: size of cstr buffer 93 | * 94 | * return value: 95 | * -1: conversion failed 96 | * 0: success 97 | */ 98 | int 99 | cf2c( CFStringRef cfstr, char *cstr, int len ) 100 | { 101 | if ( cfstr == NULL ) { 102 | fprintf( stderr, "%s: null CFStringRef\n", __FUNCTION__ ); 103 | return( -1 ); 104 | } 105 | 106 | if ( CFStringGetCString( cfstr, cstr, ( CFIndex )len, 107 | kCFStringEncodingUTF8 ) == false ) { 108 | fprintf( stderr, "Failed to convert CFStringRef to C String\n" ); 109 | return( -1 ); 110 | } 111 | 112 | return( 0 ); 113 | } 114 | 115 | /* 116 | * cfurl2path: convert a CFURLRef to a POSIX C string path 117 | * 118 | * parameters: 119 | * cfurl: CFURLRef to convert to C string path 120 | * cstr: char buffer that will contain result of conversion 121 | * len: size of cstr buffer 122 | * 123 | * return value: 124 | * -1: conversion failed 125 | * 0: success 126 | */ 127 | int 128 | cfurl2path( CFURLRef cfurl, char *cstr, int len ) 129 | { 130 | if ( cfurl == NULL ) { 131 | fprintf( stderr, "Cannot convert a null CFURLRef\n" ); 132 | return( -1 ); 133 | } 134 | 135 | if ( !CFURLGetFileSystemRepresentation( cfurl, false, (UInt8 *)cstr, len)) { 136 | fprintf( stderr, "Failed to convert CFURLRef to C path\n" ); 137 | return( -1 ); 138 | } 139 | 140 | return( 0 ); 141 | } 142 | 143 | /* 144 | * lladd: insert a path into a sorted linked list. 145 | * 146 | * parameters: 147 | * path: char buffer containing path to insert 148 | * head: pointer to pointer at head of linked list. May be modified. 149 | */ 150 | void 151 | lladd( char *path, struct ll **head ) 152 | { 153 | struct ll *new; 154 | struct ll **cur; 155 | 156 | if (( new = ( struct ll * )malloc( sizeof( struct ll ))) == NULL ) { 157 | perror( "malloc" ); 158 | exit( 2 ); 159 | } 160 | if (( new->l_path = strdup( path )) == NULL ) { 161 | perror( "strdup" ); 162 | exit( 2 ); 163 | } 164 | 165 | for ( cur = head; *cur != NULL; cur = &( *cur )->l_next ) { 166 | if ( strcmp(( *cur )->l_path, new->l_path ) > 0 ) { 167 | break; 168 | } 169 | } 170 | 171 | new->l_next = *cur; 172 | *cur = new; 173 | } 174 | -------------------------------------------------------------------------------- /util.h: -------------------------------------------------------------------------------- 1 | struct ll { 2 | char *l_path; 3 | struct ll *l_next; 4 | }; 5 | 6 | int parseline( char *, char *** ); 7 | int c2cf( char *, CFStringRef * ); 8 | int cf2c( CFStringRef, char *, int ); 9 | int cfurl2path( CFURLRef, char *, int ); 10 | void lladd( char *, struct ll ** ); 11 | -------------------------------------------------------------------------------- /version.c.in: -------------------------------------------------------------------------------- 1 | const char *duti_version = "@PACKAGE_VERSION@"; 2 | --------------------------------------------------------------------------------