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");
61int 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);
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_BPRINT_SIZE_UNLIMITED
__device__ int printf(const char *,...)
static int getopt(int argc, char *argv[], const char *opts)
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated).
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer.
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define AV_ESCAPE_FLAG_STRICT
Escape only specified special characters.
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_XML_DOUBLE_QUOTES
Within AV_ESCAPE_MODE_XML, additionally escape double quotes for double quoted attributes.
#define AV_ESCAPE_FLAG_WHITESPACE
Consider spaces special and escape them even in the middle of the string.
#define AV_ESCAPE_FLAG_XML_SINGLE_QUOTES
Within AV_ESCAPE_MODE_XML, additionally escape single quotes for single quoted attributes.
@ AV_ESCAPE_MODE_AUTO
Use auto-selected escaping mode.
@ AV_ESCAPE_MODE_XML
Use XML non-markup character data escaping.
@ AV_ESCAPE_MODE_QUOTE
Use single-quote escaping.
@ AV_ESCAPE_MODE_BACKSLASH
Use backslash escaping.
Memory handling functions.