FFmpeg
bprint.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Nicolas George
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 #include "libavutil/bprint.c"
22 
23 #undef printf
24 
25 static void bprint_pascal(AVBPrint *b, unsigned size)
26 {
27  unsigned i, j;
28  unsigned p[42];
29 
31 
32  p[0] = 1;
33  av_bprintf(b, "%8d\n", 1);
34  for (i = 1; i <= size; i++) {
35  p[i] = 1;
36  for (j = i - 1; j > 0; j--)
37  p[j] = p[j] + p[j - 1];
38  for (j = 0; j <= i; j++)
39  av_bprintf(b, "%8d", p[j]);
40  av_bprintf(b, "\n");
41  }
42 }
43 
44 int main(void)
45 {
46  AVBPrint b;
47  char buf[256];
48  struct tm testtime = { .tm_year = 100, .tm_mon = 11, .tm_mday = 20 };
49 
51  bprint_pascal(&b, 5);
52  printf("Short text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
53  printf("%s\n", b.str);
55 
57  bprint_pascal(&b, 25);
58  printf("Long text in unlimited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
60 
61  av_bprint_init(&b, 0, 2048);
62  bprint_pascal(&b, 25);
63  printf("Long text in limited buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
65 
67  bprint_pascal(&b, 5);
68  printf("Short text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
69 
71  bprint_pascal(&b, 25);
72  printf("Long text in automatic buffer: %u/%u\n", (unsigned)strlen(b.str)/8*8, b.len);
73  /* Note that the size of the automatic buffer is arch-dependent. */
74 
76  bprint_pascal(&b, 25);
77  printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(b.str), b.len);
78 
79  av_bprint_init_for_buffer(&b, buf, sizeof(buf));
80  bprint_pascal(&b, 25);
81  printf("Long text count only buffer: %u/%u\n", (unsigned)strlen(buf), b.len);
82 
84  av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
85  printf("strftime full: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
87 
88  av_bprint_init(&b, 0, 8);
89  av_bprint_strftime(&b, "%Y-%m-%d", &testtime);
90  printf("strftime truncated: %u/%u \"%s\"\n", (unsigned)strlen(buf), b.len, b.str);
91 
92  return 0;
93 }
AV_BPRINT_SIZE_UNLIMITED
#define AV_BPRINT_SIZE_UNLIMITED
av_bprint_finalize
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
Definition: bprint.c:235
av_bprint_init
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
Definition: bprint.c:69
main
int main(void)
Definition: bprint.c:44
av_bprint_strftime
void av_bprint_strftime(AVBPrint *buf, const char *fmt, const struct tm *tm)
Append a formatted date and time to a print buffer.
Definition: bprint.c:176
b
#define b
Definition: input.c:41
AV_BPRINT_SIZE_COUNT_ONLY
#define AV_BPRINT_SIZE_COUNT_ONLY
AV_BPRINT_SIZE_AUTOMATIC
#define AV_BPRINT_SIZE_AUTOMATIC
bprint.c
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
NULL
#define NULL
Definition: coverity.c:32
bprint_pascal
static void bprint_pascal(AVBPrint *b, unsigned size)
Definition: bprint.c:25
size
int size
Definition: twinvq_data.h:11134
printf
printf("static const uint8_t my_array[100] = {\n")
av_bprint_init_for_buffer
void av_bprint_init_for_buffer(AVBPrint *buf, char *buffer, unsigned size)
Init a print buffer using a pre-existing buffer.
Definition: bprint.c:85
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
av_bprintf
void av_bprintf(AVBPrint *buf, const char *fmt,...)
Definition: bprint.c:94
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen_template.c:38