Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
/* uridec.c URI decoder Ver.0.1 Copyright 1998 todome and HAT This program decode the URIs, but do not convert the character code. Thus, it shuld be used with the character code converter. (e.g., coco, gb2jis, jis2gb, hc, hmconv, jcode.pl, lv, nkf, qkc, etc.) See also RFC2396. usage: uridec [infile [outfile]] from infile to outfile % uridec infile outfile from infile to Shift_JIS textfile % uridec infile | nkf -s > outfile for Shift_JIS terminal % echo '%A4%B3%A4%F3%A4%CB%A4%C1%A4%CF' | uridec | nkf -s for EUC-JP terminal % echo '%82%B1%82%F1%82%CE%82%F1%82%CD' | uridec | nkf -e */ #include #include #include int hex2char(const int *hex); int main(argc, argv) int argc; char **argv; { FILE *fin = stdin, *fout = stdout; int ch, hex[2], xpos = 0; if (argc == 2 || argc == 3) { if ((fin = fopen(*++argv, "rb")) == (FILE *)NULL) { fprintf(stderr, "%s: No such file or directory\n", *argv); exit(1); } } if (argc == 3) { if ((fout = fopen(*++argv, "wb")) == (FILE *)NULL) { fprintf(stderr, "%s: Permission denied\n", *argv); exit(1); } } else if (argc >= 4) { fprintf(stderr, "usage: uridec [infile [outfile]]\n"); exit(1); } while((ch = fgetc(fin)) != EOF) { if(xpos == 1) { if(ch == '%') { fputc('%', fout); continue; } if(isalnum(ch)) { hex[0] = ch; xpos = 2; } else { fputc('%', fout); xpos = 0; } } else if(xpos == 2) { if(ch == '%') { fputc('%', fout); fputc(hex[0], fout); xpos = 1; continue; } if(isalnum(ch)) { hex[1] = ch; ch = hex2char(hex); xpos = 0; } else { fputc('%', fout); fputc(hex[0], fout); xpos = 0; } } else { if(ch == '%') xpos = 1; } if(xpos == 0) (ch == '+') ? fputc(' ', fout) : fputc(ch, fout); } return(0); } int hex2char(const int *hex) { int ch0, ch1; ch0 = (isalpha(*hex)) ? toupper(*hex)-'A'+10 : *hex-'0'; ch1 = (isalpha(*(hex+1))) ? toupper(*(hex+1))-'A'+10 : *(hex+1)-'0'; return ch0*16 + ch1; } /* EOF */