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
36
37
38
39
40
41
#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;
}
//intputargs extension=description extension=descrtiption
int main(int argc, char * argv[] ) {
char result[128];
char filename_buf[512];
while ( fgets(filename_buf,sizeof(filename_buf), stdin) ) {
char * eoln = strchr(filename_buf,'\n');
if(eoln) {
eoln[0]='\0';
}
int desc_ok = get_description(filename_buf, argc,argv,result,sizeof(result));
printf("filename=%s type=%s\n",filename_buf, result);
}
return 0;
}