repo: uritools
action: blob
revision: 
path_from: uriunescape.c
revision_from: refs/heads/master:
path_to: 
revision_to: 
git.thebackupbox.net
uritools
git clone git://git.thebackupbox.net/uritools

blob of:

uritools

/ uriunescape.c

blob_plain of this file

refs/heads/master:/uriunescape.c

 #include "uri.h"
 #include 
 #include 

 #define BUFSIZE 4096

 int main(int argc,char *argv[]) {
   int i=0,j=0;
   int len;
   char buf[BUFSIZE];
   char buf2[BUFSIZE];
   char *ab;
   int blen;
   int hack=0;
   if(argc > 1) {
     for(argv++,argc--;argc;argc--,argv++) {
       ab=malloc(strlen(*argv));
       len=uriunescape(*argv,ab);
       write(1,ab,len);
       if(argc-1) write(1," ",1);
     }
   } else {
     while((blen=read(0,buf+hack,BUFSIZE-hack-1)) > 0) {
       buf[blen+hack]=0;
       blen=strlen(buf);
       hack=0;
       for(i=0;i<2;i++) {//2 being max length of a %XX thing. and we're starting at the last.
         if(buf[blen-i-1] == '%') {//we're looping from the end first...
           buf[blen-i-1] = 0;//zero out the %
           hack=i+1;
           break;
         }
       }
       len=uriunescape(buf,buf2);//uriunescape wants null terminated strings
       write(1,buf2,len);
       if(hack) {
         buf[0]='%';
         for(j=0;j