From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- mpeglib/lib/input/inputDetector.cpp | 192 ++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 mpeglib/lib/input/inputDetector.cpp (limited to 'mpeglib/lib/input/inputDetector.cpp') diff --git a/mpeglib/lib/input/inputDetector.cpp b/mpeglib/lib/input/inputDetector.cpp new file mode 100644 index 00000000..28bcad5c --- /dev/null +++ b/mpeglib/lib/input/inputDetector.cpp @@ -0,0 +1,192 @@ +/* + returns inputtype for a given string + Copyright (C) 1999 Martin Vogt + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Library General Public License as published by + the Free Software Foundation. + + For more information look at the file COPYRIGHT in this package + + */ + + + +#include "inputDetector.h" + +#include + +using namespace std; + +static const char *filestrglobal1="/"; +static const char *filestrglobal2="./"; + +typedef struct prot2type_s { + const char* name; + int type; +} prot2type; + +static prot2type protocols[]= { {"http:" , __INPUT_HTTP }, + {"cdi:" , __INPUT_CDI }, + {"vcd:" , __INPUT_CDI }, + {"file:" , __INPUT_FILE }, + {"cdda:" , __INPUT_CDDA }, + {"audiocd:", __INPUT_CDDA }, + {NULL , __INPUT_UNKNOWN} }; + + +InputDetector::InputDetector() { +} + + +InputDetector::~InputDetector() { +} + +int InputDetector::getProtocolPos(int type,const char* url) { + prot2type* current=protocols; + int i=0; + while(current->name != NULL) { + if (current->type == type) { + int len=strlen(current->name); + if (strncmp(url,current->name,len)==0) { + return i; + } + } + i++; + current++; + } + return -1; +} + +int InputDetector::getProtocolType(const char* url) { + prot2type* current=protocols; + int n=strlen(url); + if (n > 0) { + while(current->name != NULL) { + int k=strlen(current->name); + if (n >= k) { + if (strncmp(url,current->name,k)==0) { + return current->type; + } + } + current++; + } + } + return __INPUT_UNKNOWN; +} + +int InputDetector::getInputType(const char* url) { + int back=__INPUT_FILE; + + if (url == NULL) { + return back; + } + + back=InputDetector::getProtocolType(url); + if (back == __INPUT_UNKNOWN) { + back = __INPUT_FILE; + } + + return back; + +} + +char* InputDetector::removeProtocol(const char* url) { + int type=InputDetector::getProtocolType(url); + int n=strlen(url); + if (n == 0) { + return NULL; + } + if (type == __INPUT_UNKNOWN) { + return strdup(url); + } + int pos=InputDetector::getProtocolPos(type,url); + if (pos == -1) { + return NULL; + } + const char* name=protocols[pos].name; + int k=strlen(name); + if (n >= k) { + return strdup(url+k); + } + return NULL; + +} + +char* InputDetector::getExtension(const char* url) { + if (url == NULL) { + cout << "get url NULL"<= nExt) { + if(strncmp(url+nUrl-nExt,extension,nExt)==0) { + back=new char[nUrl-nExt+1]; + back[nUrl-nExt]=0; + strncpy(back,url,nUrl-nExt); + } + } + cout << "removeExt:"<