diff options
Diffstat (limited to 'plugins/mpcinfo')
-rw-r--r-- | plugins/mpcinfo/functions.c | 105 | ||||
-rw-r--r-- | plugins/mpcinfo/mp3Info.c | 102 | ||||
-rw-r--r-- | plugins/mpcinfo/mpcInfo.c | 27 | ||||
-rw-r--r-- | plugins/mpcinfo/mpcinfo.vcxproj | 68 | ||||
-rw-r--r-- | plugins/mpcinfo/oggInfo.c | 20 | ||||
-rw-r--r-- | plugins/mpcinfo/theme.c | 44 |
6 files changed, 151 insertions, 215 deletions
diff --git a/plugins/mpcinfo/functions.c b/plugins/mpcinfo/functions.c index ff2d563e..e5993948 100644 --- a/plugins/mpcinfo/functions.c +++ b/plugins/mpcinfo/functions.c @@ -14,54 +14,27 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ -/* -typedef int (*MYPROC)(HWND,HWND,char*,char*,BOOL,BOOL); - -int dllProc(char *name, char *data){ - HINSTANCE hinstLib; - hinstLib = LoadLibrary("mpcinfo"); - //MYPROC proc; - int res; - if (hinstLib != NULL){ - //proc = ; - if ((MYPROC) GetProcAddress(hinstLib, name)!=NULL){ - res=(MYPROC)(NULL,NULL,data,NULL,TRUE,TRUE); - } - else{fprintf(stderr,"can't get proc: %s\n",name);res=-2;} - } - else{fprintf(stderr,"can't access dll\n");return -1;} - FreeLibrary(hinstLib); - return res; -} -*/ +#include <glib.h> -/* -int dllProc(char *name, char *data) +char *split(char *text, char separator) { - static HMODULE lib = NULL; - if (!lib) + int pos = -1; + size_t i; + for (i = 0; i < strlen(text); i++) { - lib = LoadLibraryA ("mpcinfo"); - if (!lib) - { - return FALSE; + if (text[i] == separator) { + pos = i; + i = strlen(text) + 1; } - FreeLibrary (lib); } - return TRUE; -} -*/ + if (pos == -1) + { + return text; + } -char *split(char *text, char seperator){ - //if (DEBUG==1) putlog("splitting"); - int i;int pos=-1; - for (i=0;i<strlen(text);i++){ - if (text[i]==seperator){pos=i;i=strlen(text)+1;} - } - if (pos==-1) return text; - text[pos]=0; - return &(text[pos+1]); + text[pos] = 0; + return &(text[pos + 1]); } int endsWith(char *text, char *suffix){ @@ -71,21 +44,32 @@ int endsWith(char *text, char *suffix){ return 0; } -int inStr(char *s1, int sl1, char *s2){ - //if (DEBUG==1) putlog("checking instr"); - int i;int j; - for(i=0;i<sl1-strlen(s2);i++){ - for (j=0;j<strlen(s2);j++){ - if (s1[i+j]!=s2[j]) j=strlen(s2)+2; +int inStr(char *s1, size_t sl1, char *s2) +{ + size_t i; + for (i = 0; i < sl1 - strlen(s2); i++) + { + size_t j; + for (j = 0; j < strlen(s2); j++) + { + if (s1[i + j] != s2[j]) + { + j = strlen(s2) + 2; + } + } + + if (j == strlen(s2)) + { + return i; } - if (j==strlen(s2)) return i; } + return -1; } static char *subString(char *text, int first, int length, int spcKill){ //if (DEBUG==1) putlog("creating substring"); - char *ret=(char*) calloc (length+1,sizeof(char)); //malloc(sizeof(char)*(length+1)); + char *ret = g_new (char, length + 1); int i; ret[length]=0; for (i=0;i<length;i++){ @@ -107,7 +91,7 @@ static char *substring(char *text, int first, int length){return subString(text, char *readLine(FILE *f){ //if (DEBUG==1) putlog("reading line from file"); - char *buffer=(char*)calloc(1024,sizeof(char)); //malloc(sizeof(char)*1024); + char *buffer = g_new (char, 1024); int pos=0; int cc=0; while((cc!=EOF)&&(pos<1024)&&(cc!=10)){ @@ -121,14 +105,19 @@ char *readLine(FILE *f){ return buffer; } -char *toUpper(char *text){ - //if (DEBUG==1) putlog("converting text to upper case"); - char *ret=(char*) calloc(strlen(text)+1,sizeof(char)); - int i; - for (i=0;i<strlen(text);i++) ret[i]=toupper(text[i]); - ret[strlen(text)]=0; - //if (DEBUG==1) putlog("uc done"); - return ret; +char *toUpper(char *text) +{ + char *ret = (char*) calloc(strlen(text) + 1, sizeof(char)); + + size_t i; + for (i = 0; i < strlen(text); i++) + { + ret[i] = toupper(text[i]); + } + + ret[strlen(text)] = 0; + + return ret; } static char *str3cat(char *s1, char *s2, char *s3){ diff --git a/plugins/mpcinfo/mp3Info.c b/plugins/mpcinfo/mp3Info.c index 99718624..1af29e45 100644 --- a/plugins/mpcinfo/mp3Info.c +++ b/plugins/mpcinfo/mp3Info.c @@ -75,62 +75,25 @@ static char MODES [][13]={"Stereo","Joint-Stereo","Dual-Channel","Mono"}; int iPow(int x, int y){return (int)(pow((double)x,(double) y));} -int str2int(char *text){ - //if (DEBUG==1) putlog("converting string to int"); - int i; - int ret=0; - for (i=1;i<=strlen(text);i++){ - if ((text[strlen(text)-i]>57)||(text[strlen(text)-i]<48)){ - hexchat_printf(ph,"invalid char in string: %i",text[strlen(text)-i]); - return 255; - } - ret+=((int)text[strlen(text)-i]-48)*iPow(10,i-1); - } - //hexchat_printf(ph, "str2int(%s)=%i",text,ret); - //if (DEBUG==1) putlog("int converted"); - return ret; -} -/* -static int getSize(char *file){ - //if (DEBUG==1) putlog("reading filesize"); - struct stat info; - if (stat(file,&info)!=0) return -1; - return info.st_size; -}*/ -/* -int inStr(char *s1, int sl1, char *s2){ - //if (DEBUG==1) putlog("checking instr"); - int i;int j; - for(i=0;i<sl1-strlen(s2);i++){ - for (j=0;j<strlen(s2);j++){ - if (s1[i+j]!=s2[j]) j=strlen(s2)+2; +int str2int(char *text) +{ + int ret = 0; + + size_t i; + for (i = 1; i <= strlen(text); i++) + { + if ((text[strlen(text) - i] > 57) || (text[strlen(text) - i] < 48)) + { + hexchat_printf(ph, "invalid char in string: %i", (int) text[strlen(text) - i]); + return 255; } - if (j==strlen(s2)) return i; - } - return -1; -} -static char *subString(char *text, int first, int length, int spcKill){ -//if (DEBUG==1) putlog("creating substring"); - char *ret=(char*) calloc (length+1,sizeof(char)); //malloc(sizeof(char)*(length+1)); - ret[length]=0;int i; - for (i=0;i<length;i++){ - ret[i]=text[i+first]; - //if (ret[i]==0) ret[i]='0'; + ret += ((int) text[strlen(text) - i] - 48)*iPow(10, i - 1); } - if (spcKill==1){ - for (i=length-1;i>=0;i--){ - if (ret[i]==32) ret[i]=0; - else i=-1; - } - } - //if (DEBUG==1) putlog("substring created"); + return ret; } -static char *substring(char *text, int first, int length){return subString(text,first,length,0);} //1 -*/ - static char *tagExtract(char *tag, int tagLen, char* info){ //if (DEBUG==1) putlog("extracting tag"); int pos, len, i; @@ -204,23 +167,28 @@ struct tagInfo readID3V1(char *file){ return ret; } -char *extractID3Genre(char *tag){ - //if (DEBUG==1) putlog("extracting id3 genre"); - if (tag[strlen(tag)-1]==')'){ - tag[strlen(tag)-1]=0; - tag=&tag[1]; - return GENRES[str2int(tag)]; - //return tag; - } - else{ - int i; - //hexchat_print(ph, "Using 2 criteria"); - for (i=0;i<strlen(tag);i++){ - if (tag[i]==')'){ tag=&tag[i]+1;return tag;} - //return tag; - } - } - return "[152] failed"; +char *extractID3Genre(char *tag) +{ + if (tag[strlen(tag) - 1] == ')') + { + tag[strlen(tag) - 1] = 0; + tag = &tag[1]; + return GENRES[str2int(tag)]; + } + else + { + size_t i; + for (i = 0; i < strlen(tag); i++) + { + if (tag[i] == ')') + { + tag = &tag[i] + 1; + return tag; + } + } + } + + return "[152] failed"; } struct tagInfo readID3V2(char *file){ diff --git a/plugins/mpcinfo/mpcInfo.c b/plugins/mpcinfo/mpcInfo.c index 4ab16642..4ad17689 100644 --- a/plugins/mpcinfo/mpcInfo.c +++ b/plugins/mpcinfo/mpcInfo.c @@ -48,12 +48,20 @@ static int mpc_tell(char *word[], char *word_eol[], void *userdata){ HWND hwnd = FindWindow("MediaPlayerClassicW",NULL); if (hwnd==0) {hexchat_print(ph, randomLine(notRunTheme));return HEXCHAT_EAT_ALL;} - tTitle=(char*)malloc(sizeof(char)*1024); + tTitle = g_new(char, 1024); GetWindowText(hwnd, tTitle, 1024); - zero=strstr(tTitle," - Media Player Classic"); - if (zero!=NULL) zero[0]=0; - else hexchat_print(ph,"pattern not found"); - + zero = strstr (tTitle, " - Media Player Classic"); + if (zero != NULL) + { + zero[0] = 0; + } + else + { + g_free(tTitle); + hexchat_print(ph, "pattern not found"); + return HEXCHAT_EAT_ALL; + } + if ((tTitle[1]==':')&&(tTitle[2]=='\\')){ //hexchat_print(ph,"seams to be full path"); if (endsWith(tTitle,".mp3")==1){ @@ -82,7 +90,8 @@ static int mpc_tell(char *word[], char *word_eol[], void *userdata){ //mp3Line=intReplace(mp3Line,"%perc",perc); //mp3Line=replace(mp3Line,"%plTitle",title); mp3Line=replace(mp3Line,"%file",tTitle); - hexchat_command(ph, mp3Line); + g_free(tTitle); + hexchat_command(ph, mp3Line); return HEXCHAT_EAT_ALL; } } @@ -111,14 +120,16 @@ static int mpc_tell(char *word[], char *word_eol[], void *userdata){ //oggLine=intReplace(oggLine,"%perc",perc); //oggLine=replace(oggLine,"%plTitle",title); oggLine=replace(oggLine,"%file",tTitle); - hexchat_command(ph, oggLine); + g_free(tTitle); + hexchat_command(ph, oggLine); return HEXCHAT_EAT_ALL; } } } line=randomLine(titleTheme); line=replace(line,"%title", tTitle); - hexchat_command(ph,line); + g_free(tTitle); + hexchat_command(ph, line); return HEXCHAT_EAT_ALL; } diff --git a/plugins/mpcinfo/mpcinfo.vcxproj b/plugins/mpcinfo/mpcinfo.vcxproj index f69e8968..3c4b3e7d 100644 --- a/plugins/mpcinfo/mpcinfo.vcxproj +++ b/plugins/mpcinfo/mpcinfo.vcxproj @@ -2,6 +2,7 @@ <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup Label="Configuration"> <PlatformToolset>v120</PlatformToolset> + <ConfigurationType>DynamicLibrary</ConfigurationType> </PropertyGroup> <ItemGroup Label="ProjectConfigurations"> <ProjectConfiguration Include="Release|Win32"> @@ -19,75 +20,32 @@ <RootNamespace>mpcinfo</RootNamespace> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> - <ConfigurationType>DynamicLibrary</ConfigurationType> - <UseDebugLibraries>false</UseDebugLibraries> - <WholeProgramOptimization>true</WholeProgramOptimization> - <CharacterSet>MultiByte</CharacterSet> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> - <ConfigurationType>DynamicLibrary</ConfigurationType> - <UseDebugLibraries>false</UseDebugLibraries> - <WholeProgramOptimization>true</WholeProgramOptimization> - <CharacterSet>MultiByte</CharacterSet> - </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> - <ImportGroup Label="ExtensionSettings"> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - <Import Project="..\..\win32\hexchat.props" /> - </ImportGroup> - <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - <Import Project="..\..\win32\hexchat.props" /> - </ImportGroup> - <PropertyGroup Label="UserMacros" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> - <LinkIncremental>false</LinkIncremental> - <TargetName>hcmpcinfo</TargetName> - <OutDir>$(HexChatBin)</OutDir> - <IntDir>$(HexChatObj)$(ProjectName)\</IntDir> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <LinkIncremental>false</LinkIncremental> + <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> + <Import Project="..\..\win32\hexchat.props" /> + <PropertyGroup> <TargetName>hcmpcinfo</TargetName> - <OutDir>$(HexChatBin)</OutDir> - <IntDir>$(HexChatObj)$(ProjectName)\</IntDir> + <OutDir>$(HexChatRel)plugins\</OutDir> </PropertyGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> - <PrecompiledHeader> - </PrecompiledHeader> - <FunctionLevelLinking>true</FunctionLevelLinking> - <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;MPCINFO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - <AdditionalIncludeDirectories>..\..\src\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..\..\src\common;$(Glib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> - <SubSystem>Windows</SubSystem> - <GenerateDebugInformation>true</GenerateDebugInformation> - <EnableCOMDATFolding>true</EnableCOMDATFolding> - <OptimizeReferences>true</OptimizeReferences> + <AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies> <ModuleDefinitionFile>mpcinfo.def</ModuleDefinitionFile> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> - <PrecompiledHeader> - </PrecompiledHeader> - <FunctionLevelLinking>true</FunctionLevelLinking> - <IntrinsicFunctions>true</IntrinsicFunctions> <PreprocessorDefinitions>WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;MPCINFO_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - <AdditionalIncludeDirectories>..\..\src\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..\..\src\common;$(Glib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> </ClCompile> <Link> - <SubSystem>Windows</SubSystem> - <GenerateDebugInformation>true</GenerateDebugInformation> - <EnableCOMDATFolding>true</EnableCOMDATFolding> - <OptimizeReferences>true</OptimizeReferences> + <AdditionalLibraryDirectories>$(DepsRoot)\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories> + <AdditionalDependencies>$(DepLibs);%(AdditionalDependencies)</AdditionalDependencies> <ModuleDefinitionFile>mpcinfo.def</ModuleDefinitionFile> </Link> </ItemDefinitionGroup> @@ -98,6 +56,4 @@ <ClCompile Include="mpcInfo.c" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> - <ImportGroup Label="ExtensionTargets"> - </ImportGroup> -</Project> \ No newline at end of file +</Project> diff --git a/plugins/mpcinfo/oggInfo.c b/plugins/mpcinfo/oggInfo.c index 59d84791..e1191649 100644 --- a/plugins/mpcinfo/oggInfo.c +++ b/plugins/mpcinfo/oggInfo.c @@ -25,14 +25,18 @@ static int getOggInt(char *buff, int beg, int bytes){ return ret; } -static char *upperStr(char *text){ -//if (DEBUG==1) putlog("converting text to uc"); - //printf("upperStr(%s)\n",text); - int i; - char *ret=(char*) malloc(sizeof(char)*(strlen(text)+1)); - ret[strlen(text)]=0; - for (i=0;i<strlen(text);i++) ret[i]=toupper(text[i]); - //printf("Result: %s\n",ret); +static char *upperStr(char *text) +{ + char *ret = (char*) malloc(sizeof(char)*(strlen(text) + 1)); + + size_t i; + for (i = 0; i < strlen(text); i++) + { + ret[i] = toupper(text[i]); + } + + ret[strlen(text)] = 0; + return ret; } diff --git a/plugins/mpcinfo/theme.c b/plugins/mpcinfo/theme.c index 3f98a59c..3d8a7a0e 100644 --- a/plugins/mpcinfo/theme.c +++ b/plugins/mpcinfo/theme.c @@ -49,24 +49,32 @@ void printThemes(){ hexchat_printf(ph,"\nTitle-Theme:\n");printTheme(titleTheme); } -void cbFix(char *line){ - //if (DEBUG==1) putlog("cbfix"); - int i, j; - for (i=0;i<strlen(line);i++){ - if (line[i]=='%'){ - if ((line[i+1]=='C')||(line[i+1]=='B')||(line[i+1]=='U')||(line[i+1]=='O')||(line[i+1]=='R')){ - if(line[i+1]=='C') line[i]=3; - if(line[i+1]=='B') line[i]=2; - if(line[i+1]=='U') line[i]=37; - if(line[i+1]=='O') line[i]=17; - if(line[i+1]=='R') line[i]=26; - - for (j=i+1;j<strlen(line)-1;j++) line[j]=line[j+1]; - line[strlen(line)-1]=0; - } - } - } - //if (DEBUG==1) putlog("cbfix done"); +void cbFix(char *line) +{ + size_t i; + for (i = 0; i < strlen(line); i++) + { + size_t j; + + if (line[i] == '%') + { + if ((line[i + 1] == 'C') || (line[i + 1] == 'B') || (line[i + 1] == 'U') || (line[i + 1] == 'O') || (line[i + 1] == 'R')) + { + if (line[i + 1] == 'C') line[i] = 3; + if (line[i + 1] == 'B') line[i] = 2; + if (line[i + 1] == 'U') line[i] = 37; + if (line[i + 1] == 'O') line[i] = 17; + if (line[i + 1] == 'R') line[i] = 26; + + for (j = i + 1; j < strlen(line) - 1; j++) + { + line[j] = line[j + 1]; + } + + line[strlen(line) - 1] = 0; + } + } + } } struct theme themeAdd(struct theme data, char *info){ |