From 8a8602011b11a4f53a96facd4d5dc0c0aed7b6a4 Mon Sep 17 00:00:00 2001 From: epoch Date: Sun, 16 Jun 2019 10:58:13 -0500 Subject: added ability for uriunescape to read from stdin if there are no arguments --- uriunescape.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/uriunescape.c b/uriunescape.c index aafc6ea..0a7ef5d 100644 --- a/uriunescape.c +++ b/uriunescape.c @@ -2,11 +2,21 @@ #include int main(int argc,char *argv[]) { + int n; int len; - for(argv++,argc--;argc;argc--,argv++) { - len=uriunescape(*argv,*argv); - write(1,*argv,len); - if(argc-1) write(1," ",1); + char buf[4096]; + if(argc > 1) { + for(argv++,argc--;argc;argc--,argv++) { + len=uriunescape(*argv,*argv); + write(1,*argv,len); + if(argc-1) write(1," ",1); + } + } else { + while((n=read(0,buf,sizeof(buf)-1)) > 0) { + buf[n]=0; + len=uriunescape(buf,buf); + write(1,buf,len); + } } return 0; } -- cgit v1.2.3