[hackers] [9base] added missing urlencode, thanks sl for checking this || anselm
changeset: 102:b334e60eb121
tag: tip
user: anselm_AT_garbe.us
date: Thu Nov 01 18:42:41 2012 +0100
files: urlencode/Makefile urlencode/urlencode.1 urlencode/urlencode.c
description:
added missing urlencode, thanks sl for checking this
diff -r 9ece76608eb1 -r b334e60eb121 urlencode/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/urlencode/Makefile Thu Nov 01 18:42:41 2012 +0100
_AT_@ -0,0 +1,10 @@
+# urlencode - url encode and decode files
+# Depends on ../lib9
+
+TARG = urlencode
+
+include ../std.mk
+
+pre-uninstall:
+
+post-install:
diff -r 9ece76608eb1 -r b334e60eb121 urlencode/urlencode.1
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/urlencode/urlencode.1 Thu Nov 01 18:42:41 2012 +0100
_AT_@ -0,0 +1,20 @@
+.TH URLENCODE 1
+.SH NAME
+urlencode \- URL encode and decode files
+.SH SYNOPSIS
+.B urlencode
+[
+.B -d
+] [
+.I file
+]
+.SH DESCRIPTION
+.I Urlencode
+is a helper program to URL encode and decode files. The
+.B -d
+flag insead of encoding, decodes URL encoded file. If no
+.I file
+is given, standard input is read. The resulting data
+is written to standard output.
+.SH SOURCE
+.B \*9/src/urlencode/urlencode.c
diff -r 9ece76608eb1 -r b334e60eb121 urlencode/urlencode.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/urlencode/urlencode.c Thu Nov 01 18:42:41 2012 +0100
_AT_@ -0,0 +1,103 @@
+#include <u.h>
+#include <libc.h>
+#include <bio.h>
+
+Biobuf bin;
+Biobuf bout;
+int dflag;
+
+char hex[] = "0123456789abcdef";
+char Hex[] = "0123456789ABCDEF";
+
+int
+hexdigit(int c)
+{
+ char *p;
+
+ if(c > 0){
+ if((p = strchr(Hex, c)) != 0)
+ return p - Hex;
+ if((p = strchr(hex, c)) != 0)
+ return p - hex;
+ }
+ return -1;
+}
+
+void
+usage(void)
+{
+ fprint(2, "Usage: %s [ -d ] [ file ]\n", argv0);
+ exits("usage");
+}
+
+void
+main(int argc, char *argv[])
+{
+ int c;
+
+ ARGBEGIN {
+ case 'd':
+ dflag = 1;
+ break;
+ default:
+ usage();
+ } ARGEND;
+
+ if(argc == 1){
+ int fd;
+
+ fd = open(*argv, OREAD);
+ if(fd < 0)
+ sysfatal("%r");
+ if(fd != 0) dup(fd, 0);
+ } else if(argc > 1)
+ usage();
+
+ Binit(&bin, 0, OREAD);
+ Binit(&bout, 1, OWRITE);
+
+ if(dflag){
+ while((c = Bgetc(&bin)) >= 0){
+ if(c == '%'){
+ int c1, c2, x1, x2;
+
+ if((c1 = Bgetc(&bin)) < 0)
+ break;
+ if((x1 = hexdigit(c1)) < 0){
+ Bungetc(&bin);
+ Bputc(&bout, c);
+ continue;
+ }
+ if((c2 = Bgetc(&bin)) < 0)
+ break;
+ if((x2 = hexdigit(c2)) < 0){
+ Bungetc(&bin);
+ Bputc(&bout, c);
+ Bputc(&bout, c1);
+ continue;
+ }
+ c = x1<<4 | x2;
+ } else if(c == '+')
+ c = ' ';
+ Bputc(&bout, c);
+ }
+ } else {
+ while((c = Bgetc(&bin)) >= 0){
+ if(c>0 && strchr("/$-__AT_.!*'(),", c)
+ || 'a'<=c && c<='z'
+ || 'A'<=c && c<='Z'
+ || '0'<=c && c<='9')
+ Bputc(&bout, c);
+ else if(c == ' ')
+ Bputc(&bout, '+');
+ else {
+ Bputc(&bout, '%');
+ Bputc(&bout, Hex[c>>4]);
+ Bputc(&bout, Hex[c&15]);
+ }
+ }
+ }
+
+ Bflush(&bout);
+ exits(0);
+}
Received on Thu Nov 01 2012 - 18:42:41 CET
This archive was generated by hypermail 2.3.0
: Thu Nov 01 2012 - 18:48:10 CET