summary refs log blame commit diff stats
path: root/plugins/mpcinfo/functions.c
blob: ed0632d41395da38a39a985817d55815a3675d6c (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { 
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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;
}
*/

/*
int dllProc(char *name, char *data)
{
	static HMODULE lib = NULL;
	if (!lib)
	{
		lib = LoadLibraryA ("mpcinfo");
		if (!lib)
		{
			return FALSE;
		}
		FreeLibrary (lib);
	}

	return TRUE;
}
*/

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]);
}

int endsWith(char *text, char *suffix){
    char *tmp=strstr(text,suffix);
    if (tmp==NULL) return 0;
    if (strlen(tmp)==strlen(suffix)) return 1;
    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;
		}
		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));
	int i;
	ret[length]=0;
	for (i=0;i<length;i++){
		ret[i]=text[i+first];
		//if (ret[i]==0) ret[i]='0';
	}
	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);}


char *readLine(FILE *f){
     //if (DEBUG==1) putlog("reading line from file");
     char *buffer=(char*)calloc(1024,sizeof(char)); //malloc(sizeof(char)*1024);
     int pos=0;
     int cc=0;
     while((cc!=EOF)&&(pos<1024)&&(cc!=10)){
          cc=fgetc(f);
          if ((cc!=10)&&(cc!=13)){
             if (cc==EOF) buffer[pos]=0;
             else buffer[pos]=(char)cc;pos++;
          }
     }
     if (buffer[pos]==EOF) xchat_printf(ph,"EOF: %i\n",pos);
     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;
}

static char *str3cat(char *s1, char *s2, char *s3){
       //if (DEBUG==1) putlog("cating 3 strings");
       char *ret=(char*)calloc(strlen(s1)+strlen(s2)+strlen(s3)+1,sizeof(char));
       strcpy(ret,s1);strcat(ret,s2);strcat(ret,s3);
       ret[strlen(s1)+strlen(s2)+strlen(s3)]=0;
       //if (DEBUG==1) putlog("strings cated");
       return ret;
}

char *replace(char *text, char *from, char *to){
     //if (DEBUG==1) putlog("replacing");
     char *ret=(char*)calloc( strlen(text)+(strlen(to)-strlen(from)),sizeof(char));
     char *left;
     char *right;
     int pos=inStr(text,strlen(text),from);
     if (pos!=-1){
           left=substring(text,0,pos);
           right=substring(text,pos+strlen(from),strlen(text)-(pos+strlen(from)));          
           ret=str3cat(left,to,right);
           return replace(ret,from,to);
     }
     //if (DEBUG==1) putlog("replaced");
     return text;
}

char *intReplaceF(char *text, char *from, int to, char *form){
     //if (DEBUG==1) putlog("replaceF");
     char *buffer=(char*) calloc(16,sizeof(char));
     sprintf(buffer,form,to);
     //if (DEBUG==1) putlog("replaceF done");
     return replace(text,from,buffer);
}

char *intReplace(char *text, char *from, int to){return intReplaceF(text,from,to,"%i");}