diff options
author | cinap_lenrek <cinap_lenrek@felloff.net> | 2013-11-23 01:05:33 +0100 |
---|---|---|
committer | cinap_lenrek <cinap_lenrek@felloff.net> | 2013-11-23 01:05:33 +0100 |
commit | 2f9ae0f8ac8610e13ced184847b57b87fe5db580 (patch) | |
tree | f9ad2223d518585a2cfe9ea1c73e1e37d07bf637 /sys/src/cmd/unix/drawterm/kern/parse.c | |
parent | ea5797c0731203c09ec5fb7172e77eab2750f1a9 (diff) |
removing (outdated) drawterm
drawterm is much better maintained by russ cox,
so removing this outdated copy.
for a more recent version, go to:
http://swtch.com/drawterm/
Diffstat (limited to 'sys/src/cmd/unix/drawterm/kern/parse.c')
-rw-r--r-- | sys/src/cmd/unix/drawterm/kern/parse.c | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/sys/src/cmd/unix/drawterm/kern/parse.c b/sys/src/cmd/unix/drawterm/kern/parse.c deleted file mode 100644 index 8c991f8dc..000000000 --- a/sys/src/cmd/unix/drawterm/kern/parse.c +++ /dev/null @@ -1,113 +0,0 @@ -#include "u.h" -#include "lib.h" -#include "dat.h" -#include "fns.h" -#include "error.h" - -/* - * Generous estimate of number of fields, including terminal nil pointer - */ -static int -ncmdfield(char *p, int n) -{ - int white, nwhite; - char *ep; - int nf; - - if(p == nil) - return 1; - - nf = 0; - ep = p+n; - white = 1; /* first text will start field */ - while(p < ep){ - nwhite = (strchr(" \t\r\n", *p++ & 0xFF) != 0); /* UTF is irrelevant */ - if(white && !nwhite) /* beginning of field */ - nf++; - white = nwhite; - } - return nf+1; /* +1 for nil */ -} - -/* - * parse a command written to a device - */ -Cmdbuf* -parsecmd(char *p, int n) -{ - Cmdbuf *volatile cb; - int nf; - char *sp; - - nf = ncmdfield(p, n); - - /* allocate Cmdbuf plus string pointers plus copy of string including \0 */ - sp = smalloc(sizeof(*cb) + nf * sizeof(char*) + n + 1); - cb = (Cmdbuf*)sp; - cb->f = (char**)(&cb[1]); - cb->buf = (char*)(&cb->f[nf]); - - if(up!=nil && waserror()){ - free(cb); - nexterror(); - } - memmove(cb->buf, p, n); - if(up != nil) - poperror(); - - /* dump new line and null terminate */ - if(n > 0 && cb->buf[n-1] == '\n') - n--; - cb->buf[n] = '\0'; - - cb->nf = tokenize(cb->buf, cb->f, nf-1); - cb->f[cb->nf] = nil; - - return cb; -} - -/* - * Reconstruct original message, for error diagnostic - */ -void -cmderror(Cmdbuf *cb, char *s) -{ - int i; - char *p, *e; - - p = up->genbuf; - e = p+ERRMAX-10; - p = seprint(p, e, "%s \"", s); - for(i=0; i<cb->nf; i++){ - if(i > 0) - p = seprint(p, e, " "); - p = seprint(p, e, "%q", cb->f[i]); - } - strcpy(p, "\""); - error(up->genbuf); -} - -/* - * Look up entry in table - */ -Cmdtab* -lookupcmd(Cmdbuf *cb, Cmdtab *ctab, int nctab) -{ - int i; - Cmdtab *ct; - - if(cb->nf == 0) - error("empty control message"); - - for(ct = ctab, i=0; i<nctab; i++, ct++){ - if(strcmp(ct->cmd, "*") !=0) /* wildcard always matches */ - if(strcmp(ct->cmd, cb->f[0]) != 0) - continue; - if(ct->narg != 0 && ct->narg != cb->nf) - cmderror(cb, Ecmdargs); - return ct; - } - - cmderror(cb, "unknown control message"); - return nil; -} |