apps/editconf/unescape.c

Go to the documentation of this file.
00001 /*
00002 ** -----------------------------------------------------------------------------**
00003 ** editconf.c
00004 **
00005 ** Copyright (C) 2006 Elphel, Inc.
00006 **
00007 ** -----------------------------------------------------------------------------**
00008 **  This program is free software: you can redistribute it and/or modify
00009 **  it under the terms of the GNU General Public License as published by
00010 **  the Free Software Foundation, either version 3 of the License, or
00011 **  (at your option) any later version.
00012 **
00013 **  This program is distributed in the hope that it will be useful,
00014 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 **  GNU General Public License for more details.
00017 **
00018 **  You should have received a copy of the GNU General Public License
00019 **  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 ** -----------------------------------------------------------------------------**
00021 */
00022 
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025  int hexdigit (char c) {
00026   int i;
00027   i=c-'0';
00028   if ((i>=0) && (i<10)) return i;
00029   i=c-'a'+10;
00030   if ((i>=10) && (i<16)) return i;
00031   i=c-'A'+10;
00032   if ((i>=10) && (i<16)) return i;
00033   return 0;     // could be -1??
00034 }
00035 
00036 int main(argc, argv)
00037     int argc;
00038     char *argv[];
00039 {
00040     if (argc<2) {printf("unescape returnes unescaped string (argument) to stdout\n");  return 0; }
00041   int i=0;
00042   while (argv[1][i]) {
00043     if ((argv[1][i]=='%') &&  argv[1][i+1]) { // behavior from Mozilla
00044       printf("%c", (char) (hexdigit(argv[1][i+1])<<4) | hexdigit(argv[1][i+2]));
00045       i+=3;
00046     } else printf("%c",argv[1][i++]);
00047   }
00048   return 0;
00049 }

Generated on Fri Nov 28 00:06:21 2008 for elphel by  doxygen 1.5.1