[dev] [sbase] [patch v3] Add sum.[ch] and update md5sum and sha1sum

2013-07-12 Thread sin
Hi,

Renamed from crypt to sum.

Thanks,
stateless
From be2fbf8c8cb6ec434ad2d65ac3eeaf8882c60d77 Mon Sep 17 00:00:00 2001
From: sin s...@2f30.org
Date: Sun, 7 Jul 2013 15:29:45 +0100
Subject: [PATCH] Add sum.[ch] and update md5sum and sha1sum

Factor out the code from md5sum and sha1sum into a util function.

Use FILE * instead of a file descriptor.  This will make it a bit
easier/more consistent when we implement support for the -c option.
---
 Makefile|  3 ++-
 md5.h   |  6 +++---
 md5sum.c| 49 +
 sha1.h  |  6 +++---
 sha1sum.c   | 49 +
 sum.h   | 10 ++
 util/md5.c  |  9 ++---
 util/sha1.c | 10 +++---
 util/sum.c  | 25 +
 9 files changed, 98 insertions(+), 69 deletions(-)
 create mode 100644 sum.h
 create mode 100644 util/sum.c

diff --git a/Makefile b/Makefile
index f825ec4..a5cd1e4 100644
--- a/Makefile
+++ b/Makefile
@@ -19,7 +19,8 @@ LIB = \
util/putword.o   \
util/recurse.o   \
util/rm.o\
-   util/sha1.o
+   util/sha1.o  \
+   util/sum.o
 
 SRC = \
basename.c \
diff --git a/md5.h b/md5.h
index 0895d3e..0b5005e 100644
--- a/md5.h
+++ b/md5.h
@@ -9,10 +9,10 @@ struct md5 {
 enum { MD5_DIGEST_LENGTH = 16 };
 
 /* reset state */
-void md5_init(struct md5 *s);
+void md5_init(void *ctx);
 /* process message */
-void md5_update(struct md5 *s, const void *m, unsigned long len);
+void md5_update(void *ctx, const void *m, unsigned long len);
 /* get message digest */
 /* state is ruined after sum, keep a copy if multiple sum is needed */
 /* part of the message might be left in s, zero it if secrecy is needed */
-void md5_sum(struct md5 *s, uint8_t md[MD5_DIGEST_LENGTH]);
+void md5_sum(void *ctx, uint8_t md[MD5_DIGEST_LENGTH]);
diff --git a/md5sum.c b/md5sum.c
index 722416f..4077bc8 100644
--- a/md5sum.c
+++ b/md5sum.c
@@ -1,15 +1,21 @@
 /* See LICENSE file for copyright and license details. */
-#include sys/types.h
-#include sys/stat.h
-#include fcntl.h
-#include unistd.h
 #include stdio.h
 #include stdlib.h
 #include stdint.h
 #include util.h
+#include sum.h
 #include md5.h
 
-static void md5sum(int fd, const char *f);
+static void md5_print(void *, const char *, uint8_t *);
+
+struct md5 s;
+struct sum_ops md5_ops = {
+   md5_init,
+   md5_update,
+   md5_sum,
+   md5_print,
+   s,
+};
 
 static void
 usage(void)
@@ -20,7 +26,8 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
-   int fd;
+   FILE *fp;
+   uint8_t md[MD5_DIGEST_LENGTH];
 
ARGBEGIN {
default:
@@ -28,13 +35,13 @@ main(int argc, char *argv[])
} ARGEND;
 
if (argc == 0) {
-   md5sum(STDIN_FILENO, stdin);
+   sum(md5_ops, stdin, stdin, md);
} else {
for (; argc  0; argc--) {
-   if ((fd = open(*argv, O_RDONLY))  0)
-   eprintf(open %s:, *argv);
-   md5sum(fd, *argv);
-   close(fd);
+   if ((fp = fopen(*argv, r))  == NULL)
+   eprintf(fopen %s:, *argv);
+   sum(md5_ops, fp, *argv, md);
+   fclose(fp);
argv++;
}
}
@@ -43,25 +50,11 @@ main(int argc, char *argv[])
 }
 
 static void
-md5sum(int fd, const char *f)
+md5_print(void *s, const char *f, uint8_t *md)
 {
-   unsigned char buf[BUFSIZ];
-   unsigned char digest[MD5_DIGEST_LENGTH];
-   struct md5 s;
-   ssize_t n;
int i;
 
-   md5_init(s);
-   while ((n = read(fd, buf, sizeof buf))  0)
-   md5_update(s, buf, n);
-   if (n  0) {
-   eprintf(%s: read error:, f);
-   return;
-   }
-
-   md5_sum(s, digest);
-
-   for (i = 0; i  sizeof(digest); i++)
-   printf(%02x, digest[i]);
+   for (i = 0; i  MD5_DIGEST_LENGTH; i++)
+   printf(%02x, md[i]);
printf(  %s\n, f);
 }
diff --git a/sha1.h b/sha1.h
index e11f49e..8631777 100644
--- a/sha1.h
+++ b/sha1.h
@@ -9,10 +9,10 @@ struct sha1 {
 enum { SHA1_DIGEST_LENGTH = 20 };
 
 /* reset state */
-void sha1_init(struct sha1 *s);
+void sha1_init(void *ctx);
 /* process message */
-void sha1_update(struct sha1 *s, const void *m, unsigned long len);
+void sha1_update(void *ctx, const void *m, unsigned long len);
 /* get message digest */
 /* state is ruined after sum, keep a copy if multiple sum is needed */
 /* part of the message might be left in s, zero it if secrecy is needed */
-void sha1_sum(struct sha1 *s, uint8_t md[SHA1_DIGEST_LENGTH]);
+void sha1_sum(void *ctx, uint8_t md[SHA1_DIGEST_LENGTH]);
diff --git a/sha1sum.c b/sha1sum.c
index e38346a..d948966 100644
--- a/sha1sum.c
+++ b/sha1sum.c
@@ -1,15 +1,21 @@
 /* See LICENSE file for copyright and license details. */
-#include sys/types.h

[dev] [dwm] [patch] Fix warning about XKeycodeToKeysym

2013-07-12 Thread Alexander Rødseth
Attaching a patch for fixing a warning about XKeycodeToKeysym, by
replacing it with a call to XGetKeyboardMapping.

-- 
Sincerely,
  Alexander Rødseth
  Arch Linux TU


dwm-6.1-xgetkeyboardmapping.diff
Description: Binary data


Re: [dev] [sbase] [patch v3] Add sum.[ch] and update md5sum and sha1sum

2013-07-12 Thread Galos, David
 Renamed from crypt to sum.
I think crypt was a good name. cryptsum made sense as a function,
I think that printing should be removed from cryptsum, though.
Another function, cryptprint (or mdprint) could take a digest, and
a length. I  believe this is a better separation of concerns.

v2 was good, and with those changes, I think it is definitely
getting close to the point where I will apply it.



Re: [dev] [sbase] [patch v3] Add sum.[ch] and update md5sum and sha1sum

2013-07-12 Thread sin
On Fri, Jul 12, 2013 at 09:56:21AM -0500, Galos, David wrote:
  Renamed from crypt to sum.
 I think crypt was a good name. cryptsum made sense as a function,
 I think that printing should be removed from cryptsum, though.
 Another function, cryptprint (or mdprint) could take a digest, and
 a length. I  believe this is a better separation of concerns.
 
 v2 was good, and with those changes, I think it is definitely
 getting close to the point where I will apply it.

Ok, will keep it crypt.  Will implement the suggested changes
over the weekend and send another patch.



[dev] [sbase] [patch] Adding tar v2

2013-07-12 Thread Galos, David
Thanks in large part to your information about how you invoke tar, I
believe I have come up with a decent solution. I also was able to
find the structified version of tar I had worked on in the past.

The argument parsing is a bit ugly, so simplifications are welcome,
provided they keep the current functionality



[dev] Re: [sbase] [patch] Adding tar v2

2013-07-12 Thread Galos, David
And, here is that patch that I stupidly forgot to attach.


sbase-adding-tar-2.diff
Description: Binary data


Re: [dev] [sbase] [patch] Adding tar v2

2013-07-12 Thread Truls Becken
On 2013-07-12, at 17:30, David Galos wrote:

 The argument parsing is a bit ugly, so simplifications are welcome,
 provided they keep the current functionality

The goto seems uncalled for. An ordinary if does the job equally well.
Also, I wonder if a mode variable isn't just as simple as the flg array.

Proposed patch attached. Is (argc != (mode == 'c')) too clever?

By the way, what is the purpose of strlcpy in xt and unarchive?
Is it in case header fields are not properly zero terminated?



sbase-adding-tar-2.diff.diff
Description: Binary data


[dev] [sbase] [patch] Get it building on OpenBSD

2013-07-12 Thread Steve Dee
OpenBSD doesn't have utmpx.h or clearenv. Also, the dependency
$(BIN): util.a seems to shadow the implicit build rule in BSD make,
resulting in nothing past util.a getting built. The patch includes a
rather stupid workaround for this. (Less stupid solutions welcome ---
it'd be simple to specify with a .for, but then it'd be
BSD-make--specific, and I don't feel like figuring out cross-platform
makefiles.)


sbase-openbsd.diff
Description: Binary data


Re: [dev] [sbase] [patch] Get it building on OpenBSD

2013-07-12 Thread Galos, David
 OpenBSD doesn't have utmpx.h or clearenv.
Does it also not have getutent? Replacing clearenv with
environ=NULL is fine, though.

 it'd be simple to specify with a .for, but then it'd be
 BSD-make--specific, and I don't feel like figuring out cross-platform
 makefiles.)
Good, we want nothing to do with cross platform makefiles!



[dev] [sbase] [patch] Adding tar v2

2013-07-12 Thread Galos, David
 The goto seems uncalled for. An ordinary if does the job equally well.
 Also, I wonder if a mode variable isn't just as simple as the flg array.
Good catches. I probably went through 10 permutations of argument
parsing until I found the current one, so I'm not surprised that I missed
some simplification

 Proposed patch attached. Is (argc != (mode == 'c')) too clever?
Thanks, the patch is an improvement over my initial code. That
expression is entirely acceptable.

 By the way, what is the purpose of strlcpy in xt and unarchive?
 Is it in case header fields are not properly zero terminated?
Precisely. Although the tar format requires null-termination, I
wanted to be sure that malformed archives couldn't be evil.



[dev] tmux export buffer to pastebin

2013-07-12 Thread Kai Hendry
Hi guys,

Since hopefully most of you are running http://st.suckless.org/ and
tmux, perhaps you'll find this bind interesting:

bind-key p capture-pane -S -32768 \; save-buffer /tmp/tmux-buffer \;
run cat /tmp/tmux-buffer | curl -F 'sprunge=-' http://sprunge.us
| tmux load-buffer -; tmux show-buffer

Which I used here for example: http://sprunge.us/XRFS

So it's a way of people showing their output, which can be used for
teaching/debugging etc.

Would be cool to easily make videos ala http://youterm.com or
highlight selections.

Also it would be nice if tmux could bind the
http://en.wikipedia.org/wiki/Print_screen button with `bind -u`.
Though `cat -v` doesn't seem to notice when I hit PrtSc on my
keyboard.

Cheers,