#include <sys/types.h>
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <dirent.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
static void strtoupper(char *p)
{
?int i;
?int j=strlen(p);
?for(i=0;i<j;i++)
??{
?*p=toupper(*p);
?p++;
?}
};
int main( void )
{
?
?
?int fd;
?DIR * dir;
?struct dirent * ent;
?
?char *p1;
?char *p2;
?char temp[255];
?char lower[50];
?memset(temp,0,sizeof(temp));
?memset(lower,0,sizeof(lower));
?
?
?if(!(dir=opendir("/opt/sip_ui/res/."))){ //目錄
?perror("opendir");
?return;
?}
?errno=0;
?
?if((fd=open("hw",O_TRUNC|O_CREAT|O_WRONLY,0644))<0){
?perror("open");
?exit(1);?
?}
?
?while((ent=readdir(dir))){
??
?if(strstr(ent->d_name,".bmp")){ //后綴名
?p1=strtok(ent->d_name,".");
?p2=strtok(NULL,".");
?memcpy(lower,p1,strlen(p1));
?lower[strlen(p1)]='\0';
?strtoupper(p1);
?strtoupper(p2);
?
? strcat(p1,"_PIC");
?//strcat(p1,p2);
?
?sprintf(temp,"#define %s \"res\" PATH_SEP \"%s.\" RESFILE_EXT\n",p1,lower);
?
??????
?????
?if(write(fd,temp,strlen(temp)) < 0){
?perror("write");
?exit(1);
?}
?}
?errno=0;
?}
?if(errno)
?{
?perror("readdir");
?return ;
?}
?
?close(fd);
?closedir(dir);
?return 1;
}