Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
rokudogobu committed Aug 2, 2019
1 parent 5c40d92 commit beb6e58
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store

tag2uti
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#
# Copyright (c) 2019 rokudogobu
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

tag2uti: main.c
clang -O2 -framework CoreFoundation -framework CoreServices -o $@ $^
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@

# tag2uti
Simple C program to get UTI (= Uniform Type Identifier) from extension or MIME on Mac.

Simple C program to get UTI (= Uniform Type Identifier) from filename extension or MIME type on Mac.

## Usage

usage: tag2uti <ext | mime>...

## Example

$ tag2uti c text/html bash
public.c-source
public.html
public.bash-script com.apple.xcode.bash-script

## License

Copyright (c) 2019 rokudogobu.
Licensed under the Apache License, Version 2.0.
See LICENSE for details.
44 changes: 44 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Copyright (c) 2019 rokudogobu
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>

#define STRENC kCFStringEncodingASCII

int main( int argc, const char * argv[] ) {
for ( int i = 1; i < argc; i++ ) {
CFStringRef tag = CFStringCreateWithCString( kCFAllocatorDefault, argv[i], STRENC );
if ( tag ) {
CFRange range = CFStringFind( tag, CFSTR( "/" ), 0 );
CFStringRef class = range.location == kCFNotFound ? kUTTagClassFilenameExtension: kUTTagClassMIMEType;
CFArrayRef types = UTTypeCreateAllIdentifiersForTag( class, tag, NULL );
if ( types ) {
for ( int j = 0; j < CFArrayGetCount( types ); j++ ) {
printf( j == 0 ? "%s": " %s", CFStringGetCStringPtr( CFArrayGetValueAtIndex( types, j ), STRENC ));
}
CFRelease( types );
}
printf( "\n" );
CFRelease( tag );
}
}
return 0;
}


0 comments on commit beb6e58

Please sign in to comment.