summaryrefslogtreecommitdiff
path: root/test/test_dir.c
blob: 6e464eb43210673e70c422c8fcdbc08adb9b2305 (plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "av_format_identify.h"
#define SIZE_BUFF 0xfffffffff//0xffffffffffffffff
#include <dirent.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdint.h>
#define SIZE_FILE 50
typedef struct buff_inf_h
{
        char *buff;
        size_t size;
}buff_inf;

buff_inf *buff_get(char *vfile) {
        buff_inf *buff_inf_h = (buff_inf *)malloc(sizeof(buff_inf));

        FILE *fr = NULL;
        char *buff_ori = (char *)malloc(sizeof(char)*SIZE_BUFF);
        char *buff = buff_ori;
        //memset(buff, 0, sizeof(char)*SIZE_BUFF);
        if ((fr = fopen(vfile, "rb")) == NULL)
        {
                perror("fopen error:");
                buff_inf_h->buff = NULL;
                buff_inf_h->size = 0;
                return buff_inf_h;
        }
        size_t i = 0;
        while (!feof(fr))
        {
                fread(buff, 1, 1, fr);
                buff += 1;
                i++;
        }
        buff_inf_h->buff = (char *)malloc(sizeof(char *) * (i-1));
        memcpy(buff_inf_h->buff, buff - i, i-1);
        buff_inf_h->size = i-1;
        free(buff_ori);
        buff_ori = NULL;
        fclose(fr);
        return buff_inf_h;

}
int main(int argc, char *argv[])
{
        DIR *dirp;
        struct dirent *dp;
        char *vdir = argv[1];
        char *vfile_ori = (char *)malloc(SIZE_FILE);
        memcpy(vfile_ori,vdir,strlen(vdir));
        strcat(vfile_ori, "/");
        char *vfile = (char *)malloc(SIZE_FILE);
        dirp = opendir(vdir);
        struct stat info;

        buff_inf *buff_inf_h;
        int ret;
        int ret_sig = atoi(argv[2]);
        int sig_show_all = atoi(argv[3]);
        int sig_choose_all = atoi(argv[4]);
        size_t size;
        int divide_h;
        int divide_s;
        int divide_e;
        while ((dp = readdir(dirp)) != NULL) 
        {
                memcpy(vfile,vfile_ori,SIZE_FILE);
                strncat(vfile, dp->d_name, strlen(dp->d_name));

                stat(vfile, &info);
                if(S_ISDIR(info.st_mode))
                        continue;
                buff_inf_h = buff_get(vfile);
                if (buff_inf_h->size == 0)
                {
                        printf("read file failed of %s.\n",vfile);
                        return -1;
                }
                if (sig_choose_all == 0)
                {
                        divide_h = 10;//atoi(argv[5]);//10;
                        divide_s = 0;//atoi(argv[6]);//0;
                        divide_e = 1;//atoi(argv[7]);//1;

                        size = (buff_inf_h->size / divide_h)*(divide_e - divide_s);
                        ret = AV_container_identify(buff_inf_h->buff + (buff_inf_h->size / divide_h)*divide_s, size);
                }
                else
                        ret = AV_container_identify(buff_inf_h->buff, buff_inf_h->size);
                if (sig_show_all == 0)
                {
                        if (ret != ret_sig)
                        {
                                printf("-----------------data of [%s] is kind of [%d].\n", dp->d_name, ret);
                                printf("size of whole buff is %zd.\n", buff_inf_h->size);
                                if  (sig_choose_all == 0)
                                        printf("size of chosen buff is %zd.\n", size);

                        }
                }
                else
                {
                        printf("-----------------data of [%s] is kind of [%d].\n", dp->d_name, ret);
                        printf("size of whole buff is %zd.\n", buff_inf_h->size);
                        if  (sig_choose_all == 0)
                                printf("size of chosen buff is %zd.\n", size);
                }
                free(buff_inf_h->buff);
                buff_inf_h->buff = NULL;
                free(buff_inf_h);
                buff_inf_h = NULL;
        }

        free(vfile);
        free(vfile_ori);

        return ret;
}