/* $Id: escape.c,v 1.1 2005/07/18 16:43:05 dm Exp $ */ /* * * Copyright (C) 2005 David Mazieres (dm@uun.org) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA * */ #include "avutil.h" #include "getopt_long.h" char *progname; const char shellspec[128] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, }; void escape (const char *_s) { const unsigned char *s = (const unsigned char *) _s; while (*s) { if (*s < sizeof (shellspec) && shellspec[*s]) printf ("\\"); printf ("%c", *s++); } printf ("\n"); } static void usage (void) __attribute__ ((noreturn)); static void usage (void) { fprintf (stderr, "usage: %s string\n", progname); exit (1); } int main (int argc, char **argv) { struct option o[] = { { "version", no_argument, NULL, 'v' }, { NULL, 0, NULL, 0 } }; int c; progname = strrchr (argv[0], '/'); if (progname) progname++; else progname = argv[0]; while ((c = getopt_long (argc, argv, "+ilrsc:f:n:p:qx:", o, NULL)) != -1) switch (c) { case 'v': version (progname, 1); exit (0); /* XXX */ break; default: usage (); break; } if (optind + 1 != argc) usage (); escape (argv[optind]); exit (0); }