1 /*
2  * Copyright (c) 2013 Stefano Sabatini
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifdef TEST
22 #include <stdio.h>
23 
24 #include "libavutil/avstring.h"
25 #include "libavutil/file.h"
26 
print_sequence(const char * p,int l,int indent)27 static void print_sequence(const char *p, int l, int indent)
28 {
29     int i;
30     for (i = 0; i < l; i++)
31         printf("%02X", (uint8_t)p[i]);
32     printf("%*s", indent-l*2, "");
33 }
34 
main(int argc,char ** argv)35 int main(int argc, char **argv)
36 {
37     int ret;
38     char *filename = argv[1];
39     uint8_t *file_buf;
40     size_t file_buf_size;
41     uint32_t code;
42     const uint8_t *p, *endp;
43 
44     ret = av_file_map(filename, &file_buf, &file_buf_size, 0, NULL);
45     if (ret < 0)
46         return 1;
47 
48     p = file_buf;
49     endp = file_buf + file_buf_size;
50     while (p < endp) {
51         int l, r;
52         const uint8_t *p0 = p;
53         code = UINT32_MAX;
54         r = av_utf8_decode(&code, &p, endp, 0);
55         l = (int)(p-p0);
56         print_sequence(p0, l, 20);
57         if (code != UINT32_MAX) {
58             printf("%-10d 0x%-10X %-5d ", code, code, l);
59             if (r >= 0) {
60                 if (*p0 == '\n') printf("\\n\n");
61                 else             printf ("%.*s\n", l, p0);
62             } else {
63                 printf("invalid code range\n");
64             }
65         } else {
66             printf("invalid sequence\n");
67         }
68     }
69 
70     av_file_unmap(file_buf, file_buf_size);
71     return 0;
72 }
73 #endif
74