include stdio include string define icon_no const char ICON_NO int get

 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
#include <stdio.h>
#include <string.h>
#define icon_no -
const char ICON_NO[] = "-";
int get_description(char * filename, int argc, char * argv[], char* result,int result_maxlen) {
char * ext_pnt = strrchr(filename,'.');
if(ext_pnt) {
char * ext = &ext_pnt[1];
int i;
for ( i = 1; i< argc ; i++ ) {
char * arg = argv[i];
int extlen = strlen(ext);
if( strncmp(ext,arg,extlen) == 0 ) {
strncpy(result,&arg[extlen+1],result_maxlen);
return 1;
}
}
}
strcpy(result,ICON_NO);
strcat(result,ext_pnt);
return 0;
}
char TEST_FILENAME[] = "test.rar.xpng";
//intputargs extension=description extension=descrtiption
int main(int argc, char * argv[] ) {
char result[128];
int desc_ok = get_description(TEST_FILENAME, argc,argv,result,sizeof(result));
printf("result=%s\n",result);
return 0;
}