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;
60 FILE *
outfile = NULL, *infile = 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");
135 av_log(NULL,
AV_LOG_ERROR,
"Impossible to open input file '%s': %s\n", infilename, strerror(errno));
139 if (!outfilename || !strcmp(outfilename,
"-")) {
140 outfilename =
"stdout";
143 outfile = fopen(outfilename,
"w");
146 av_log(NULL,
AV_LOG_ERROR,
"Impossible to open output file '%s': %s\n", outfilename, strerror(errno));
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);