.\" -*-nroff-*- .TH selbuf 3 "23 May 1999" mLib .SH NAME selbuf \- line-buffering input selector .\" @selbuf_enable .\" @selbuf_disable .\" @selbuf_init .SH SYNOPSIS .nf .B "#include " .BI "void selbuf_enable(selbuf *" b ); .BI "void selbuf_disable(selbuf *" b ); .BI "void selbuf_init(selbuf *" b , .BI " sel_state *" s , .BI " int " fd , .BI " void (*" func ")(char *" s ", void *" p ), .BI " void *" p ); .fi .SH DESCRIPTION The .B selbuf subsystem is a selector which integrates with the .BR sel (3) system for I/O multiplexing. It reads entire text lines from a file descriptor and passes them to a caller-defined function. It uses the line buffer described in .BR lbuf (3) to do its work: you should read about it in order to understand exactly what gets considered to be a line of text and what doesn't, and the exact rules about what your line handling function should and shouldn't do. .PP All the data for a .B selbuf selector is stored in an object of type .BR selbuf . This object must be allocated by the caller, and initialized using the .B selbuf_init function. This requires a fair few arguments: .TP .I b Pointer to the .B selbuf object to initialize. .TP .I s Pointer to a multiplexor object (type .BR sel_state ) to which this selector should be attached. See .BR sel (3) for more details about multiplexors, and how this whole system works. .TP .I fd The file descriptor of the stream the selector should read from. .TP .I func The .I "line handler" function. It is passed a pointer to each line read from the file (or null to indicate end-of-file) and an arbitrary pointer (the .I p argument to .B selbuf_init described below). .TP .I p A pointer argument passed to .I func for each line read from the file. Apart from this, the pointer is not used at all. .PP The .B selbuf selector is immediately active. Subsequent calls to .B sel_select on the same multiplexor will cause any complete lines read from the file to be passed to your handling function. This function can at any time call .B selbuf_disable to stop itself from being called any more. The selector is then disengaged from the I/O multiplexor and won't do anything until .B selbuf_enable is called. Note that .B selbuf_enable may well immediately start emitting complete lines of text which were queued up from the last I/O operation: it doesn't necessarily wait for the next .B sel_select call. .SH "SEE ALSO" .BR lbuf (3), .BR sel (3), .BR mLib (3). .SH AUTHOR Mark Wooding,