diff options
| author | Charles.Forsyth <devnull@localhost> | 2006-12-22 20:52:35 +0000 |
|---|---|---|
| committer | Charles.Forsyth <devnull@localhost> | 2006-12-22 20:52:35 +0000 |
| commit | 46439007cf417cbd9ac8049bb4122c890097a0fa (patch) | |
| tree | 6fdb25e5f3a2b6d5657eb23b35774b631d4d97e4 /man/10/parsecmd | |
| parent | 37da2899f40661e3e9631e497da8dc59b971cbd0 (diff) | |
20060303-partial
Diffstat (limited to 'man/10/parsecmd')
| -rw-r--r-- | man/10/parsecmd | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/man/10/parsecmd b/man/10/parsecmd new file mode 100644 index 00000000..a9598773 --- /dev/null +++ b/man/10/parsecmd @@ -0,0 +1,68 @@ +.TH PARSECMD 10.2 +.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 (10.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 sh (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.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 |
