plan 9 kernel history: overview | file list | diff list

2001/0418/port/parse.c (diff list | history)

port/parse.c on 1999/0316
1999/0316    
#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) 
{ 
2001/0331    
	Cmdbuf *volatile cb; 
1999/0316    
 
2001/0405    
	if(up != nil) 
		cb = smalloc(sizeof(*cb)); 
	else{ 
		cb = malloc(sizeof(*cb)); 
		if(cb == nil) 
			return nil; 
	} 
1999/0316    
	 
	if(n > sizeof(cb->buf)-1) 
		n = sizeof(cb->buf)-1; 
2001/0331    
 
2001/0405    
	if(up != nil && waserror()){ 
2001/0331    
		free(cb); 
		nexterror(); 
	} 
1999/0316    
	memmove(cb->buf, p, n); 
2001/0405    
	if(up != nil) 
		poperror(); 
2001/0331    
 
1999/0316    
	if(n > 0 && cb->buf[n-1] == '\n') 
		n--; 
	cb->buf[n] = '\0'; 
2001/0418    
	cb->nf = tokenize(cb->buf, cb->f, nelem(cb->f)); 
1999/0316    
	return cb; 
} 
 


source code copyright © 1990-2005 Lucent Technologies; see license
Plan 9 distribution
comments to russ cox (rsc@swtch.com)