aboutsummaryrefslogtreecommitdiff
path: root/man/man3/9p-cmdbuf.html
blob: 122a5857092cef6fa0cb9d6431d348bfdd1e6944 (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<head>
<title>9p-cmdbuf(3) - Plan 9 from User Space</title>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
</head>
<body bgcolor=#ffffff>
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=10><td>
<tr><td width=20><td>
<tr><td width=20><td><b>9P-CMDBUF(3)</b><td align=right><b>9P-CMDBUF(3)</b>
<tr><td width=20><td colspan=2>
    <br>
<p><font size=+1><b>NAME     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    Cmdbuf, parsecmd, respondcmderror, lookupcmd &ndash; control message
    parsing<br>
    
</table>
<p><font size=+1><b>SYNOPSIS     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>#include &lt;u.h&gt;<br>
    #include &lt;libc.h&gt;<br>
    #include &lt;fcall.h&gt;<br>
    #include &lt;thread.h&gt;<br>
    #include &lt;9p.h&gt;<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    typedef struct Cmdbuf<br>
    {<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        char &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*buf;<br>
        char &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;**f;<br>
        int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nf;<br>
        
    </table>
    } Cmdbuf;<br>
    typedef struct Cmdtab<br>
    {<br>
    
    <table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

        int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index;<br>
        char &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*cmd;<br>
        int &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;narg;<br>
        
    </table>
    };<br>
    Cmdbuf &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*parsecmd(char *p, int n)<br>
    Cmdtab &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;*lookupcmd(Cmdbuf *cb, Cmdtab *tab, int ntab)<br>
    void &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;respondcmderror(Req *r, Cmdbuf *cb, char *fmt, ...)<br>
    </font></tt>
</table>
<p><font size=+1><b>DESCRIPTION     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    These data structures and functions provide parsing of textual
    control messages. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Parsecmd</i> treats the <i>n</i> bytes at <i>p</i> (which need not be NUL-terminated)
    as a UTF string and splits it using <i>tokenize</i> (see <a href="../man3/getfields.html"><i>getfields</i>(3)</a>).
    It returns a <tt><font size=+1>Cmdbuf</font></tt> structure holding pointers to each field in
    the message. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Lookupcmd</i> walks through the array <i>ctab</i>, which has <i>ntab</i> entries,
    looking for the first <tt><font size=+1>Cmdtab</font></tt> that matches the parsed command.
    (If the parsed command is empty, <i>lookupcmd</i> returns nil immediately.)
    A <tt><font size=+1>Cmdtab</font></tt> matches the command if <i>cmd</i> is equal to <i>cb</i><tt><font size=+1>&#8722;&gt;</font></tt><i>f</i><tt><font size=+1>[0]</font></tt> or if
    <i>cmd</i> is <tt><font size=+1>*</font></tt>. Once a matching <tt><font size=+1>Cmdtab</font></tt> has been
    found, if <i>narg</i> is not zero, then the parsed command must have
    exactly <i>narg</i> fields (including the command string itself). If
    the command has the wrong number of arguments, <i>lookupcmd</i> returns
    nil. Otherwise, it returns a pointer to the <tt><font size=+1>Cmdtab</font></tt> entry. If <i>lookupcmd</i>
    does not find a matching command at all, it returns
    nil. Whenever <i>lookupcmd</i> returns nil, it sets the system error
    string. 
    <table border=0 cellpadding=0 cellspacing=0><tr height=5><td></table>
    
    <i>Respondcmderror</i> resoponds to request <i>r</i> with an error of the form
    &#8216;<i>fmt</i>: <i>cmd</i>,&#8217; where <i>fmt</i> is the formatted string and <i>cmd</i> is a reconstruction
    of the parsed command. Fmt is often simply <tt><font size=+1>%r .<br>
    </font></tt>
</table>
<p><font size=+1><b>EXAMPLES     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    This interface is not used in any distributed 9P servers. It was
    lifted from the Plan 9 kernel. Almost any Plan 9 kernel driver
    (<tt><font size=+1>/sys/src/9/*/dev*.c</font></tt> on Plan 9) is a good example.<br>
    
</table>
<p><font size=+1><b>SOURCE     </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <tt><font size=+1>/usr/local/plan9/src/lib9p/parse.c<br>
    </font></tt>
</table>
<p><font size=+1><b>SEE ALSO    </b></font><br>

<table border=0 cellpadding=0 cellspacing=0><tr height=2><td><tr><td width=20><td>

    <a href="../man3/9p.html"><i>9p</i>(3)</a><br>
    
</table>

<td width=20>
<tr height=20><td>
</table>
<!-- TRAILER -->
<table border=0 cellpadding=0 cellspacing=0 width=100%>
<tr height=15><td width=10><td><td width=10>
<tr><td><td>
<center>
<a href="../../"><img src="../../dist/spaceglenda100.png" alt="Space Glenda" border=1></a>
</center>
</table>
<!-- TRAILER -->
</body></html>