Charles.Forsyth20060303-partialeea662d19 years agoHistory
68 lines · 1.2 KB · Text
RawDownload
.TH PARSECMD 10.2.SH NAMEparsecmd \- parse device commands.SH SYNOPSIS.ta \w'\fLCmdbuf* 'u.BCmdbuf*	parsecmd(char *a, int n).SH DESCRIPTION.I Parsecmdis an interface to.I tokenize(see.IR getfields (10.2)),that safely parses a command, with blank-separated fields, as might bewritten to a device's.B ctlfile.The buffer.I aand count.I ncan be those passed to the driver's.I writefunction..I Parsecmdconverts the byte array (which might not be null-terminated) to a null-terminated string,trimming any trailing new line,before invoking.I tokenizeto break the string into arguments, interpreting blank and tab as field separatorswhen they are not quoted(in the style of.IR sh (1)).It returns a pointer to a dynamically-allocated.B Cmdbufstructure,which holds a copy of the string asmodified by.IR parsefields ,and the resulting fields; it is defined as follows:.IP.EX.ta 6n +\w'char* 'utypedefstruct Cmdbuf{	char	buf[128];	char	*f[16];	int	nf;} Cmdbuf;.EE.PPThe array.B fholds the field pointers;.B nfgives the number of fields..B Cmdbufis allocated by.I smalloc(see.IR malloc (10.2)),and the caller is responsible for freeing it using.IR free ..SH SOURCE.B /os/port/parse.c.br.B /emu/port/dev.c