Support SEGA CRI adx codec with demuxer lavf.
[mplayer/greg.git] / osdep / macosx_finder_args.c
blobcbd88ad4acbaeb758513d54b0f82f73ff3837669
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <Carbon/Carbon.h>
20 #include <ApplicationServices/ApplicationServices.h>
21 #include "stream/url.h"
22 #include "mp_msg.h"
23 #include "m_option.h"
24 #include "m_config.h"
25 #include "playtree.h"
26 #include "macosx_finder_args.h"
28 static play_tree_t *files=NULL;
30 static inline void add_entry(play_tree_t **last_parentp, play_tree_t **last_entryp, play_tree_t *entry) {
32 if(*last_entryp==NULL)
33 play_tree_set_child(*last_parentp, entry);
34 else
35 play_tree_append_entry(*last_entryp, entry);
37 *last_entryp=entry;
40 static pascal OSErr AppleEventHandlerProc(const AppleEvent *theAppleEvent, AppleEvent* reply, SInt32 handlerRefcon) {
41 OSErr err=errAEEventNotHandled, res=noErr;
42 AEDescList docList;
43 long itemsInList;
45 AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, NULL, FALSE);
46 if((res=AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList))==noErr) {
47 if((res=AECountItems(&docList, &itemsInList))==noErr) {
48 Size currentSize=0;
49 int valid=0,i;
50 char *parm=NULL;
51 play_tree_t *last_entry=NULL;
53 files=play_tree_new();
54 for(i=1;i<=itemsInList;++i) {
56 for(;;) {
57 OSErr e;
58 Size actualSize=0;
59 AEKeyword keywd;
60 DescType returnedType;
62 if((e=AEGetNthPtr(&docList, i, typeFileURL, &keywd, &returnedType, (Ptr)parm, currentSize, &actualSize))==noErr) {
63 if(actualSize>=currentSize) {
64 currentSize=actualSize+1;
65 parm=realloc(parm, currentSize);
67 else {
68 parm[actualSize]=0;
69 valid=1;
70 break;
73 else {
74 valid=0;
75 break;
79 if(valid) {
80 URL_t *url=url_new(parm);
82 if(url && !strcmp(url->protocol,"file") && !strcmp(url->hostname,"localhost")) {
83 play_tree_t *entry=play_tree_new();
85 url_unescape_string(url->file, url->file);
86 play_tree_add_file(entry, url->file);
87 add_entry(&files, &last_entry, entry);
90 url_free(url);
94 if(parm)
95 free(parm);
97 err=noErr;
99 else
100 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "AECountItems() error %d\n", res);
102 AEDisposeDesc(&docList);
104 else
105 mp_msg(MSGT_CFGPARSER, MSGL_ERR, "AEGetParamDesc() error %d\n", res);
107 QuitApplicationEventLoop();
108 return err;
111 play_tree_t *macosx_finder_args(m_config_t *config, int argc, char **argv) {
112 ProcessSerialNumber myPsn;
113 char myPsnStr[5+10+1+10+1];
115 GetCurrentProcess(&myPsn);
116 snprintf(myPsnStr, 5+10+1+10+1, "-psn_%u_%u", myPsn.highLongOfPSN, myPsn.lowLongOfPSN);
117 myPsnStr[5+10+1+10]=0;
119 if((argc==2) && !strcmp(myPsnStr, argv[1])) {
120 m_config_set_option(config, "quiet", NULL);
121 InitCursor();
122 AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(AppleEventHandlerProc), 0, FALSE);
123 RunApplicationEventLoop();
126 return files;