Go to the documentation of this file.
46 printf(
"Escape an input string, adopting the av_get_token() escaping logic\n");
47 printf(
"usage: ffescape [OPTIONS]\n");
50 "-e echo each input line on output\n"
51 "-f flag select an escape flag, can assume the values 'whitespace' and 'strict'\n"
52 "-h print this help\n"
53 "-i INFILE set INFILE as input file, stdin if omitted\n"
54 "-l LEVEL set the number of escaping levels, 1 if omitted\n"
55 "-m ESCAPE_MODE select escape mode between 'auto', 'backslash', 'quote'\n"
56 "-o OUTFILE set OUTFILE as output file, stdout if omitted\n"
57 "-p PROMPT set output prompt, is '=> ' by default\n"
58 "-s SPECIAL_CHARS set the list of special characters\n");
61 int main(
int argc,
char **argv)
64 char *src_buf, *dst_buf;
65 const char *outfilename =
NULL, *infilename =
NULL;
67 const char *prompt =
"=> ";
72 char *special_chars =
NULL;
75 while ((
c =
getopt(argc, argv,
"ef:hi:l:o:m:p:s:")) != -1) {
93 "Invalid value '%s' for option -f, "
94 "valid arguments are 'whitespace', and 'strict'\n",
optarg);
101 long int li = strtol(
optarg, &tail, 10);
102 if (*tail || li > INT_MAX || li < 0) {
104 "Invalid value '%s' for option -l, argument must be a non negative integer\n",
118 "Invalid value '%s' for option -m, "
119 "valid arguments are 'backslash', and 'quote'\n",
optarg);
137 if (!infilename || !strcmp(infilename,
"-")) {
138 infilename =
"stdin";
141 infile = fopen(infilename,
"r");
148 if (!outfilename || !strcmp(outfilename,
"-")) {
149 outfilename =
"stdout";
152 outfile = fopen(outfilename,
"w");
161 while ((
c = fgetc(infile)) != EOF)
173 fprintf(
outfile,
"%s", src_buf);
178 if (
av_escape(&dst_buf, src_buf, special_chars, escape_mode, escape_flags) < 0) {
186 fprintf(
outfile,
"%s%s", prompt, dst_buf);
#define AV_BPRINT_SIZE_UNLIMITED
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
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
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
@ 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.