
1 #include<unistd.h> 2 #include<stdio.h> 3 #include<dirent.h> 4 #include<string.h> 5 #include<stdlib.h> 6 #include<sys/stat.h> 7 #include<sys/types.h> 8 #include<sys/wait.h> 9 #include<time.h> 10 FILE *fp,*fbmp,*flog; 11 struct dirent *entry; 12 struct stat statbuf; 13 unsigned short BMP=0x4D42, 14 JPG=0xD8FF, 15 PNG[4]={0x5089,0x474E,0x0A0D,0x0A1A}, 16 GIF[3]={0x4947,0x3846,0x6139}; 17 char path1[256],path2[256],watchdog[256],name[256]; 18 struct tm *tm_ptr; 19 time_t the_time; 20 21 //判断图片头文件的结构体 22 typedef struct tagRGBQUAD 23 { 24 unsigned char Blue;// À¶É«µÄÁÁ¶È£šÖµ·¶Î§Îª0-255) 25 unsigned char Green; // ÂÌÉ«µÄÁÁ¶È£šÖµ·¶Î§Îª0-255) 26 unsigned char Red; // ºìÉ«µÄÁÁ¶È£šÖµ·¶Î§Îª0-255) 27 unsigned char Reserved;// ±£Áô£¬±ØÐëΪ0 28 } RGN; 29 30 void init()/*用于初始化程序*/ 31 { 32 printf("file opened now "); 33 fp=fopen("wrg.text","w+"); 34 flog=fopen("wrlog.text","w+"); 35 fbmp=fopen("bmpname.text","w+"); 36 } 37 void Exit() 38 { 39 printf("everything is gone "); 40 fclose(fp); 41 fclose(fbmp); 42 fclose(flog); 43 } 44 int istupian(char entry[]) 45 /*返加值为 46 1 bmp; 47 2 jpg; 48 3 png; 49 4 gif; 50 */ 51 { 52 FILE *fis; 53 short int i=0; 54 unsigned short pis[5]; 55 int flag=0;//每次调用都进行初始化 56 if((fis=fopen(entry,"r"))==NULL) 57 printf("can not read %s ",entry); 58 fread(pis,8,1,fis); 59 60 if(pis[0]==BMP) 61 { 62 flag=1; 63 printf("it is a bmp "); 64 } 65 else if(pis[0]==JPG) 66 { 67 flag=2; 68 printf("it is a jpg "); 69 } 70 else if(PNG[0]==pis[0]&&PNG[1]==pis[1]&&PNG[2]==pis[2]&&PNG[3]==pis[3]) 71 { 72 flag=3; 73 printf("it is a png "); 74 } 75 else if(GIF[0]==pis[0]&&GIF[1]==pis[1]&&GIF[2]==pis[2]) 76 { 77 flag=4; 78 printf("it is a gif "); 79 } 80 return flag; 81 82 83 } 84 void wrtlog()/*将文件的路径写入路径中*/ 85 { 86 printf("write to wrtlg "); 87 fprintf(fp,"%s/%s ",getcwd(NULL,1024),entry->d_name); 88 fprintf(fbmp,"%s ",entry->d_name); 89 } 90 void wrlog(char name[])// 将日记写入文件中 91 { 92 static int i=0; 93 (void)time(&the_time); 94 //tm_ptr=gmtime(&the_time); 95 if(i==0) fprintf(flog,"文件名 /状态 /时间 / "); 96 ++i; 97 fprintf(flog,"%s 删除 ",name); 98 99 fprintf(flog,"%s ",ctime(&the_time)); 100 //fprintf(flog,"%02d:%02d:%02d:%02d:%02d:%02d ",tm_ptr->tm_year,tm_ptr->tm_mon+1,tm_ptr->tm_mday,tm_ptr->tm_hour,tm_ptr->tm_min,tm_ptr->tm_sec); 101 } 102 void printdir(char dir[])/*打印目录*/ 103 { 104 DIR *dp; 105 printf("printdir ******doing now "); 106 if((dp=opendir(dir))==NULL) 107 { 108 fprintf(stderr,"cannot open directory:%s ",dir); 109 return; 110 } 111 chdir(dir); 112 while((entry=readdir(dp))!=NULL) 113 { 114 lstat(entry->d_name,&statbuf); 115 if(S_ISDIR(statbuf.st_mode)) 116 { 117 if(strcmp(".",entry->d_name)==0||strcmp("..",entry->d_name)==0) 118 continue; 119 printdir(entry->d_name); 120 } 121 else 122 wrtlog(); 123 } 124 chdir(".."); 125 closedir(dp); 126 } 127 int bmp(char filename[]) 128 { 129 FILE *fo,*fin; 130 RGN rgb,black={0,0,0,0},white={255,255,255,0}; 131 char name[256]="