~kris/9p

9hist

ref: 8d56d8a01106a05f1530797fef6a907dc41e3fc4 9hist/port/parse.c -rw-r--r-- 458 bytes
8d56d8a0 — David du Colombier Plan 9 from Bell Labs 2000-04-25 26 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include	"u.h"
#include	"../port/lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"../port/error.h"

/*
 *  parse a command written to a device
 */
Cmdbuf*
parsecmd(char *p, int n)
{
	Cmdbuf *cb;

	cb = smalloc(sizeof(*cb));
	
	if(n > sizeof(cb->buf)-1)
		n = sizeof(cb->buf)-1;
	memmove(cb->buf, p, n);
	if(n > 0 && cb->buf[n-1] == '\n')
		n--;
	cb->buf[n] = '\0';
	cb->nf = getfields(cb->buf, cb->f, nelem(cb->f), 1, " ");
	return cb;
}