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) {
 
   85                        "Invalid value '%s' for option -f, " 
   86                        "valid arguments are 'whitespace', and 'strict'\n", 
optarg);
 
   93             long int li = strtol(
optarg, &tail, 10);
 
   94             if (*tail || li > INT_MAX || li < 0) {
 
   96                         "Invalid value '%s' for option -l, argument must be a non negative integer\n",
 
  109                        "Invalid value '%s' for option -m, " 
  110                        "valid arguments are 'backslash', and 'quote'\n", 
optarg);
 
  128     if (!infilename || !strcmp(infilename, 
"-")) {
 
  129         infilename = 
"stdin";
 
  132         infile = fopen(infilename, 
"r");
 
  139     if (!outfilename || !strcmp(outfilename, 
"-")) {
 
  140         outfilename = 
"stdout";
 
  143         outfile = fopen(outfilename, 
"w");
 
  152     while ((c = fgetc(infile)) != EOF)
 
  164         fprintf(outfile, 
"%s", src_buf);
 
  169         if (
av_escape(&dst_buf, src_buf, special_chars, escape_mode, escape_flags) < 0) {
 
  177     fprintf(outfile, 
"%s%s", prompt, dst_buf);
 
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 ...
int av_bprint_finalize(AVBPrint *buf, char **ret_str)
Finalize a print buffer. 
Use single-quote escaping. 
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered. 
#define AV_BPRINT_SIZE_UNLIMITED
void av_bprint_init(AVBPrint *buf, unsigned size_init, unsigned size_max)
#define AV_ESCAPE_FLAG_STRICT
Escape only specified special characters. 
Use auto-selected escaping mode. 
static int av_bprint_is_complete(const AVBPrint *buf)
Test if the print buffer is complete (not truncated). 
static int getopt(int argc, char *argv[], char *opts)
#define AV_ESCAPE_FLAG_WHITESPACE
Consider spaces special and escape them even in the middle of the string. 
int main(int argc, char **argv)
void av_bprint_chars(AVBPrint *buf, char c, unsigned n)
Append char c n times to a print buffer.