Go to the documentation of this file.
40 printf(
"Escape an input string, adopting the av_get_token() escaping logic\n");
41 printf(
"usage: ffescape [OPTIONS]\n");
44 "-e echo each input line on output\n"
45 "-f flag select an escape flag, can assume the values 'whitespace' and 'strict'\n"
46 "-h print this help\n"
47 "-i INFILE set INFILE as input file, stdin if omitted\n"
48 "-l LEVEL set the number of escaping levels, 1 if omitted\n"
49 "-m ESCAPE_MODE select escape mode between 'auto', 'backslash', 'quote'\n"
50 "-o OUTFILE set OUTFILE as output file, stdout if omitted\n"
51 "-p PROMPT set output prompt, is '=> ' by default\n"
52 "-s SPECIAL_CHARS set the list of special characters\n");
55 int main(
int argc,
char **argv)
58 char *src_buf, *dst_buf;
59 const char *outfilename =
NULL, *infilename =
NULL;
61 const char *prompt =
"=> ";
66 char *special_chars =
NULL;
69 while ((
c =
getopt(argc, argv,
"ef:hi:l:o:m:p:s:")) != -1) {
87 "Invalid value '%s' for option -f, "
88 "valid arguments are 'whitespace', and 'strict'\n",
optarg);
95 long int li = strtol(
optarg, &tail, 10);
96 if (*tail || li > INT_MAX || li < 0) {
98 "Invalid value '%s' for option -l, argument must be a non negative integer\n",
112 "Invalid value '%s' for option -m, "
113 "valid arguments are 'backslash', and 'quote'\n",
optarg);
131 if (!infilename || !strcmp(infilename,
"-")) {
132 infilename =
"stdin";
135 infile = fopen(infilename,
"r");
142 if (!outfilename || !strcmp(outfilename,
"-")) {
143 outfilename =
"stdout";
146 outfile = fopen(outfilename,
"w");
155 while ((
c = fgetc(infile)) != EOF)
167 fprintf(
outfile,
"%s", src_buf);
172 if (
av_escape(&dst_buf, src_buf, special_chars, escape_mode, escape_flags) < 0) {
180 fprintf(
outfile,
"%s%s", prompt, dst_buf);
#define AV_BPRINT_SIZE_UNLIMITED
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
int main(int argc, char **argv)
#define AV_ESCAPE_FLAG_XML_SINGLE_QUOTES
Within AV_ESCAPE_MODE_XML, additionally escape single quotes for single quoted attributes.
int av_escape(char **dst, const char *src, const char *special_chars, enum AVEscapeMode mode, int flags)
Escape string in src, and put the escaped string in an allocated string in *dst, which must be freed ...
#define AV_ESCAPE_FLAG_STRICT
Escape only specified special characters.
#define AV_ESCAPE_FLAG_WHITESPACE
Consider spaces special and escape them even in the middle of the string.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_ESCAPE_FLAG_XML_DOUBLE_QUOTES
Within AV_ESCAPE_MODE_XML, additionally escape double quotes for double quoted attributes.
static int getopt(int argc, char *argv[], char *opts)
@ AV_ESCAPE_MODE_QUOTE
Use single-quote escaping.
@ AV_ESCAPE_MODE_AUTO
Use auto-selected escaping mode.
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
@ AV_ESCAPE_MODE_XML
Use XML non-markup character data escaping.
printf("static const uint8_t my_array[100] = {\n")
@ AV_ESCAPE_MODE_BACKSLASH
Use backslash escaping.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.