/* * simple URL encoder * spd, 2001 - may 2026 */ #include #include #include #include #include static char __ident[] = "@(#)(c)SPDsoft, May 5, 2026"; #define VERS_STR ((char*)&__ident[4]) #define PATH_SEP '/' void usage(void); char *app; void usage(void) { fprintf(stderr,"Use: %s [-ha]\n", app); fprintf(stderr,"%s: -a : only non ascci chars\n", app); exit(0); } int main( int argc, char *argv[]) { int opt; extern char *optarg; extern int optind,opterr; unsigned char c; int all = 1; if ((app = strrchr(argv[0], PATH_SEP)) != NULL) app = app+1; else app = argv[0]; while ( (opt=getopt(argc,argv,"ah")) != EOF ) { switch(opt) { case 'a': all=0; break; case 'h': default: usage(); break; } } if (!all) { for( c=getchar(); (!feof(stdin)); c=getchar()) { if ( c == ' ' ) { printf("%c", '+'); } else if ( (( c >= 'a' ) && ( c <= 'z' )) || (( c >= 'A' ) && ( c <= 'Z' )) || (( c >= '0' ) && ( c <= '9' )) || ( c == '\n' ) || ( c == '=' ) || ( c == '-' ) || ( c == '+' ) || ( c == '&' ) ) { printf("%c",c); } else { printf("%%%0.2X",c); } } } else { for( c=getchar(); (!feof(stdin)); c=getchar()) printf("%%%0.2X",c); } }