⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myviewwin3.c

📁 在Linux下实现文件的拷贝
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <gtk/gtk.h>#include <string.h>#include <unistd.h>#include <fcntl.h>#include <sys/types.h>#include <sys/stat.h>#include <dirent.h>#include <stdio.h>#include <stdlib.h>#include <errno.h>#include <time.h>struct fileinfo{  char *tiaomu;  char *dir;  char tiaomu1[80];  char tiaomu2[20];  char tiaomu3[20];  char tiaomu4[20];  char tiaomu5[20];  char tiaomu6[20];  int size1;  int nlink;  int uid;  int gid;  int size2;  char *time;  int tongji[10];  int frequent;  struct fileinfo *next;};void trim(char s[]){int i;for(i=strlen(s)-1;i>=0;i--)  if(s[i]!=' '&&s[i]!='\t'&&s[i]!='\n')             break;s[i+1]='\0';}struct fileinfo *tongji(){    struct fileinfo * ziyuan,*ziyuan1;    int i=0,j,times=0,items,marks,k;    FILE *fp;    char buf[80];   // long buffer[18];    char cache[10];    int frequent;    ziyuan=(struct fileinfo *)malloc(sizeof(struct fileinfo));    ziyuan1=(struct fileinfo *)malloc(sizeof(struct fileinfo));    if((fp=fopen("/proc/meminfo","r"))==NULL)      printf("Cannot open the file!\n");    for(items=0,j=0;items<5;items++,j=0,i=0)          {         fgets(buf,80,fp); 			while(buf[i]!=' ')    		   i++;  			while(buf[i]==' ')          		  i++;  			while(buf[i]!=' ')           cache[j++]=buf[i++];         cache[j]='\0';         puts(cache);//printf("%d\n",atoi(cache));         ziyuan->tongji[times++]=atoi(cache);       //  printf("%d\n",ziyuan->tongji[times-1]);                 // printf("%d\n",ziyuan->tongji[times-1]);           }  frequent=(ziyuan->tongji[1]+ ziyuan->tongji[2]+ziyuan->tongji[3]+ziyuan->tongji[4])*100/ziyuan->tongji[0];  // printf("%.1f%\n",frequent);   ziyuan->frequent=frequent;return ziyuan;}struct fileinfo * readthread(char * name){    DIR *dp,*dp2;    int lineno=0;    struct dirent *dir,*dir2;    struct fileinfo *dir_node;    struct fileinfo *head=NULL;    char buf[80],index[30],index1[30];    int  i,stop,tongji=0,j;    char *position;    char pnamebuf[30];    FILE *fp;    if((dp=opendir(name))==NULL)                sprintf(stderr,"%s:cannt open.\n",name);    while((dir=readdir(dp))!=NULL)          {       strcpy(pnamebuf,"");       strcat(pnamebuf,"/proc/");       strcpy(buf,dir->d_name);       if((buf[0]>='1')&&(buf[0]<='9'))                  {                           tongji++;         strcat(pnamebuf,dir->d_name);         strcat(pnamebuf,"/");         dir_node = (struct fileinfo *)malloc(sizeof(struct fileinfo));         if((dp2=opendir(pnamebuf))==NULL)                     sprintf(stderr,"%s:cannt open.\n",name);                 while((dir2=readdir(dp2))!=NULL)                        {           if((strcmp(dir2->d_name,"status"))==0)                            {              strcat(pnamebuf,"status");              if((fp=fopen(pnamebuf,"r"))==NULL)                                     {                 printf("Cannot open the file!\n");                 break;                                     }              lineno=0;              while (fgets(buf,80,fp))                                     {                  lineno++;                 if(lineno==1||lineno==2||lineno==3||lineno==5||lineno==22||lineno==23)                                             {                    position=strchr(buf,':');                    strcpy(index,++position);                    i=0;                    j=0;                                                   while(index[i]==' ')                      i++;                   while(index[i]!=' '&&index[i]!='\n')                      index1[j++]=index[i++];                   index1[j]='\0';                   if(lineno==1)                      strcpy(dir_node -> tiaomu1 ,index1);                   if(lineno==2)                      strcpy(dir_node -> tiaomu2 ,index1);                   if(lineno==3)                      strcpy(dir_node -> tiaomu3 ,index1);                   if(lineno==5)                      strcpy(dir_node -> tiaomu4 ,index1);                   if(lineno==22)                      strcpy(dir_node -> tiaomu5 ,index1);                   if(lineno==23)                      strcpy(dir_node -> tiaomu6 ,index1);                                                                       }                                                                 }                             }                           }                                    dir_node -> next = head;          head = dir_node;                          close(dp2);                 }          close(dp2);          }    close(dp);    return head;}struct fileinfo *listcheck(char * name){    DIR *dp;    struct dirent *dir;    struct fileinfo *dir_node;    struct stat sbuf;    char newname[1024];    struct fileinfo *head=NULL;    if((dp=opendir(name))==NULL)                sprintf(stderr,"%s:cannt open.\n",name);     while((dir=readdir(dp))!=NULL)          {              sprintf(newname,"%s/%s",name,dir->d_name);       stat(newname,&sbuf);       dir_node = (struct fileinfo *)malloc(sizeof(struct fileinfo));       dir_node -> tiaomu=dir -> d_name;       dir_node -> dir=name;       dir_node -> size1 = (sbuf.st_size+1024-1)/1024;       dir_node -> nlink = sbuf.st_nlink;       dir_node ->uid = sbuf.st_uid;       dir_node ->gid = sbuf.st_gid;       dir_node ->size2 = sbuf.st_size;       dir_node ->time = ctime(&sbuf.st_mtime);       dir_node -> next = head;       head = dir_node;            }    close(dp);    return head;}struct fileinfo* readhost(){     FILE *fp;      char * zuhe[] = { "/proc/cpuinfo","/proc/sys/kernel/hostname","/proc/version", "/proc/sys/kernel/osrelease","/proc/meminfo","/proc/stat"};     char *mulu[]={"CPU信息:\n","主机名:\n","系统版本:\n","分配信息:\n","内存信息:\n","系统状态:\n"};     struct fileinfo *dir_node=NULL,*head,*index;      char buf[80];      int i,j=0,k;     char *read;     head = (struct fileinfo *)malloc(sizeof(struct fileinfo));     index= (struct fileinfo *)malloc(sizeof(struct fileinfo));     head=NULL;    // index=NULL;     for(i=0; i<6; i++)            {         if ((fp=fopen(zuhe[i],"r"))==NULL)                               printf("Cannot open the file!");                              while(fgets(buf,80,fp))                      {          dir_node = (struct fileinfo *)malloc(sizeof(struct fileinfo));          strcpy(dir_node->tiaomu1,buf);          dir_node-> next = head;          head=dir_node;                      }          dir_node = (struct fileinfo *)malloc(sizeof(struct fileinfo));          strcpy(dir_node->tiaomu1,mulu[i]);          dir_node-> next = head;          head=dir_node;                                                                                       }return head;}/* 必须的基本回调 */static void print_hello( GtkWidget *w,                         gpointer   data ){  g_message ("Hello, World!\n");}gint delete( GtkWidget *widget,             GtkWidget *event,             gpointer   data ){    gtk_main_quit ();    return FALSE;}/* 这是用来生成新菜单的 GtkItemFactoryEntry 结构。   第一项:菜单路径。下划线后的字母指出菜单打开时           的快捷键。   第二项:这个条目的快捷键   第三项:回调函数。   第四项:回调动作。这个改变被调用的函数的参数。默认是0.   第五项:项类型,用来定义它是哪种项,           这里是可能的值:           NULL               -> "<Item>"           ""                 -> "<Item>"           "<Title>"          -> 创建一个标题(title)项           "<Item>"           -> 创建一个简单(simple)项           "<CheckItem>"      -> 创建一个检查(check)项           "<ToggleItem>"     -> 创建一个开关(toggle)项           "<RadioItem>"      -> 创建一个选择(radio)项           <path>             -> 选择项连接到的路径           "<Separator>"      -> 创建一个分隔线(separator)           "<Branch>"         -> 创建一个包含子项的项(可选)           "<LastBranch>"     -> 创建一个右对齐的分枝(branch)*/static GtkItemFactoryEntry menu_items[] = {  {"/监视器(_M)", NULL,NULL,0,"<Branch>" }, {"/监视器(_M)/退出(_Q)", "<control>Q",gtk_main_quit,0,NULL},  {"/编辑(_E)", NULL,NULL,0,"<Branch>" },  {"/编辑(_E)/停止进程(_S)", "<control>S",print_hello,0,NULL},  { "/编辑(_E)/继续进程(_C)",   "<control>C", print_hello,0,NULL },  { "/编辑(_E)/sep1",NULL,NULL, 0, "<Separator>" },  { "/编辑(_E)/结束进程(_P)",    "<control>P",print_hello,0,NULL },  { "/编辑(_E)/杀死进程(_K)",    "<control>K",print_hello,0,NULL },  { "/编辑(_E)/sep1",NULL, NULL, 0, "<Separator>" },  { "/编辑(_E)/更改优先级(_C)",    "<control>R",print_hello, 0, NULL },  { "/编辑(_E)/sep1",     NULL,         NULL, 0, "<Separator>" },  { "/编辑(_E)/首选项(_N)",             NULL,         NULL, 0, NULL },  { "/查看(_V)",  NULL,         NULL, 0, "<Branch>" },  { "/查看(_V)/活动的进程(_A)",     NULL,         NULL, 0, NULL },  { "/查看(_V)/全部进程(_L)",         NULL,         NULL, 0, NULL },  { "/查看(_V)/我的进程(_Y)",         NULL,         NULL, 0, NULL },  { "/查看(_V)/sep1",        NULL,         NULL, 0, "<Separator>" },  { "/查看(_V)/依赖关系(_D)",    "<control>D",    print_hello, 0, NULL },  { "/查看(_V)/sep1",        NULL,         NULL, 0, "<Separator>" },  { "/查看(_V)/隐藏进程(_H)",    "<control>H",    print_hello, 0, NULL }, { "/查看(_V)/隐藏的进程(_H)",    "<control>P",   print_hello, 0, NULL }, { "/查看(_V)/sep1",        NULL,         NULL, 0, "<Separator>" }, { "/查看(_V)/内存镜像(_M)",    "<control>M",    print_hello, 0, NULL }, { "/查看(_V)/打开的文件(_F)",    "<control>F",    print_hello, 0, NULL }, { "/帮助(_H)",        NULL,         NULL, 0, "<LastBranch>"  }, { "/帮助(_H)/关于",      "F" ,         print_hello, 0, NULL  }, { "/帮助(_H)/内容",        NULL,        print_hello, 0, NULL  },};void get_main_menu( GtkWidget  *window,                    GtkWidget **menubar ){  GtkItemFactory *item_factory;  GtkAccelGroup *accel_group;  gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);  accel_group = gtk_accel_group_new ();  /* 这个函数初始化套件。     参数1:菜单类型 - 可以是GTK_TYPE_MENU_BAR, GTK_TYPE_MENU,            或GTK_TYPE_OPTION_MENU。     参数2:菜单路径。

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -