tizen 2.3.1 release
[framework/system/libfeedback.git] / test / getdata.c
1 #include <stdio.h>
2 #include <dirent.h>
3 #include <unistd.h>
4 #include <string.h>
5 #include <sys/stat.h>
6 #include <stdlib.h>
7 #include <glib.h>
8
9 #define DBG(fmt, argc...)       printf("<%s:%d> "fmt"\n", __func__, __LINE__, ##argc)
10 #define ERR(fmt, argc...)       printf("<%s:%d> [ERROR] "fmt"\n", __func__, __LINE__, ##argc)
11
12 #define BUF_SIZE                1024
13
14 static int print_content(const char *filename)
15 {
16         FILE *fp;
17         unsigned char buf[BUF_SIZE];
18         char *b64_de, *b64_en;
19         unsigned int n;
20
21         fp = fopen(filename, "r");
22         if (fp == NULL) {
23                 ERR("fopen fail");
24                 return -1;
25         }
26
27         while ((n = fread(buf, 1, sizeof(buf), fp)) > 0) {
28                 printf("[[[");
29                 b64_en = g_base64_encode(buf, n);
30                 fwrite(b64_en, 1, n, stdout);
31                 printf("]]]\n(((");
32                 b64_de = (char*)g_base64_decode(b64_en, &n);
33                 fwrite(b64_de, 1, n, stdout);
34                 printf(")))\n");
35
36                 free(b64_en);
37                 free(b64_de);
38         }
39
40         fclose(fp);
41         printf("\n");
42         return 0;
43
44 }
45
46 static void printdir(char *dir, int depth)
47 {
48         DIR *dp;
49         struct dirent *entry;
50         struct stat statbuf;
51
52         if ((dp = opendir(dir)) == NULL) {
53                 ERR("opendir fail");
54                 return;
55         }
56
57         chdir(dir);
58         while ((entry = readdir(dp)) != NULL) {
59                 lstat(entry->d_name, &statbuf);
60                 if (S_ISDIR(statbuf.st_mode)) {
61                         if (strcmp(".", entry->d_name) == 0 ||
62                                 strcmp("..", entry->d_name) == 0)
63                                 continue;
64
65                         DBG("%*s%s", depth, "", entry->d_name);
66                         printdir(entry->d_name, depth+strlen(entry->d_name));
67                 } else {
68
69                         DBG("%*s%s", depth, "", entry->d_name);
70                         print_content(entry->d_name);
71                 }
72         }
73         chdir("..");
74         closedir(dp);
75 }
76
77 int main(int argc, char *argv[])
78 {
79         printdir(argv[1], 0);
80         DBG("done");
81         return 0;
82 }