Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*******************************************************************************
- * urlde.c
- * Commandline URL deocde - fast and dirty
- * by tovis 2011
- * Build: make urlde and strip urlde
- * Usage: cat or echo "url coded text" | urlde
- *******************************************************************************/
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <ctype.h>
- //******************************************************************************
- int main(int c,char *argv[])
- {
- int ichr = 0;
- char shex[3];
- //... code ...
- do
- {
- ichr = getchar();
- switch ( ichr )
- {
- case '+':
- ichr = ' ';
- break;
- case '%':
- ichr = getchar();
- if ( ichr != '%' )
- {
- memset(shex,0,sizeof(shex));
- shex[0] = (char)ichr;
- shex[1] = (char)getchar();
- if ( !isxdigit(shex[0]) || !isxdigit(shex[1]) )
- ichr = '?';
- else
- {
- ichr = 0;
- ichr = ( shex[0] > 0x39 ) ? (shex[0] - 0x37 ) : (shex[0] - 0x30 );
- ichr = ichr << 4;
- ichr += ( shex[1] > 0x39 ) ? (shex[1] - 0x37 ) : (shex[1] - 0x30 );
- if ( ichr == '\n' )
- {
- putchar(ichr);
- ichr = 0;
- continue;
- }
- }
- }
- break;
- default:
- break;
- }
- putchar(ichr);
- } while ( ichr != '\n' );
- exit ( 0 );
- } //end main
- /*******************************************************************************
- * end urlde.c
- *******************************************************************************/
Advertisement
Add Comment
Please, Sign In to add comment