Plan 9 from Bell Labs’s /usr/web/sources/contrib/dho/kimp/p9/parsecmd

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


.TH PARSECMD 10
.SH NAME
parsecmd \- parse device commands
.SH SYNOPSIS
.ta \w'\fLCmdbuf* 'u
.B
Cmdbuf*	parsecmd(char *a, int n)
.SH DESCRIPTION
.I Parsecmd
is an interface to
.I tokenize
(see
.IR getfields (2)),
that safely parses a command, with blank-separated fields, as might be
written to a device's
.B ctl
file.
The buffer
.I a
and count
.I n
can be those passed to the driver's
.I write
function.
.I Parsecmd
converts the byte array (which might not be null-terminated) to a null-terminated string,
trimming any trailing new line,
before invoking
.I tokenize
to break the string into arguments, interpreting blank and tab as field separators
when they are not quoted
(in the style of
.IR rc (1)).
It returns a pointer to a dynamically-allocated
.B Cmdbuf
structure,
which holds a copy of the string as
modified by
.IR parsefields ,
and the resulting fields; it is defined as follows:
.IP
.EX
.ta 6n +\w'char* 'u
typedef
struct Cmdbuf
{
	char	buf[128];
	char	*f[16];
	int	nf;
} Cmdbuf;
.EE
.PP
The array
.B f
holds the field pointers;
.B nf
gives the number of fields.
.B Cmdbuf
is allocated by
.I smalloc
(see
.IR malloc (10)),
and the caller is responsible for freeing it using
.IR free .
.SH SOURCE
.B /sys/src/9/port/parse.c
.br
.B /emu/port/dev.c

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].