changeset: 2046:2f3cf6cd70eb
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Tue Mar 27 17:39:00 2007 -0400
summary: Fix ARGBEGIN bug. Refactor wmiir.c. Create lib and include directories before installing.
diff -r e9f837c918d6 -r 2f3cf6cd70eb cmd/wmiir.c
--- a/cmd/wmiir.c Mon Mar 26 23:16:36 2007 -0400
+++ b/cmd/wmiir.c Tue Mar 27 17:39:00 2007 -0400
@@ -27,13 +27,12 @@ write_data(IxpCFid *fid, char *name) {
uint len;
buf = ixp_emalloc(fid->iounit);;
- while((len = read(0, buf, fid->iounit)) > 0)
- if(ixp_write(fid, buf, len) != len)
+ do {
+ len = read(0, buf, fid->iounit);
+ if(len >= 0 && ixp_write(fid, buf, len) != len)
fatal("cannot write file '%s': %s\n", name, errstr);
- /* do an explicit empty write when no writing has been done yet */
- if(fid->offset == 0)
- if(ixp_write(fid, buf, 0) != 0)
- fatal("cannot write file '%s': %s\n", name, errstr);
+ } while(len > 0);
+
free(buf);
}
@@ -277,10 +276,25 @@ xls(int argc, char *argv[]) {
return 0;
}
+typedef struct exectab exectab;
+struct exectab {
+ char *cmd;
+ int (*fn)(int, char**);
+} etab[] = {
+ {"write", xwrite},
+ {"xwrite", xawrite},
+ {"read", xread},
+ {"create", xcreate},
+ {"remove", xremove},
+ {"ls", xls},
+ {0, 0}
+};
+
int
main(int argc, char *argv[]) {
+ char *cmd, *address;
+ exectab *tab;
int ret;
- char *cmd, *address;
address = getenv("WMII_ADDRESS");
@@ -304,20 +318,12 @@ main(int argc, char *argv[]) {
if(client == nil)
fatal("%s\n", errstr);
- if(!strcmp(cmd, "create"))
- ret = xcreate(argc, argv);
- else if(!strcmp(cmd, "ls"))
- ret = xls(argc, argv);
- else if(!strcmp(cmd, "read"))
- ret = xread(argc, argv);
- else if(!strcmp(cmd, "remove"))
- ret = xremove(argc, argv);
- else if(!strcmp(cmd, "write"))
- ret = xwrite(argc, argv);
- else if(!strcmp(cmd, "xwrite"))
- ret = xawrite(argc, argv);
- else
- usage();
+ for(tab = etab; tab->cmd; tab++)
+ if(strcmp(cmd, tab->cmd) == 0) break;
+ if(tab->cmd == 0)
+ usage();
+
+ ret = tab->fn(argc, argv);
ixp_unmount(client);
return ret;
diff -r e9f837c918d6 -r 2f3cf6cd70eb include/util.h
--- a/include/util.h Mon Mar 26 23:16:36 2007 -0400
+++ b/include/util.h Tue Mar 27 17:39:00 2007 -0400
@@ -42,7 +42,7 @@ char *argv0;
#define ARGBEGIN int _argi, _argtmp, _inargv=0; char *_argv; \
if(!argv0)argv0=ARGF(); _inargv=1; \
while(argc && argv[0][0] == '-') { \
- _argi=1; _argv=*argv++; argc++; \
+ _argi=1; _argv=*argv++; argc--; \
while(_argv[_argi]) switch(_argv[_argi++])
#define ARGEND }_inargv=0;USED(_argtmp);USED(_argv);USED(_argi)
#define ARGF() ((_inargv && _argv[_argi]) ? \
diff -r e9f837c918d6 -r 2f3cf6cd70eb mk/common.mk
--- a/mk/common.mk Mon Mar 26 23:16:36 2007 -0400
+++ b/mk/common.mk Tue Mar 27 17:39:00 2007 -0400
@@ -5,7 +5,7 @@ depend: cleandep
MANDIRS=${MAN}/man1
mkdirs:
- for i in ${BIN} ${ETC} ${MANDIRS} ${DIRS}; do \
+ for i in ${BIN} ${ETC} ${LIBDIR} ${MANDIRS} ${INCLUDE} ${DIRS}; do \
test -d $$i || echo MKDIR $$i; \
mkdir -pm 0755 $$i; \
done
Received on Tue Mar 27 2007 - 23:44:03 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:28 UTC