xref: /illumos-gate/usr/src/lib/libtecla/common/ioutil.h (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1*7c478bd9Sstevel@tonic-gate #ifndef ioutil_h
2*7c478bd9Sstevel@tonic-gate #define ioutil_h
3*7c478bd9Sstevel@tonic-gate 
4*7c478bd9Sstevel@tonic-gate /*
5*7c478bd9Sstevel@tonic-gate  * Copyright (c) 2000, 2001, 2002, 2003, 2004 by Martin C. Shepherd.
6*7c478bd9Sstevel@tonic-gate  *
7*7c478bd9Sstevel@tonic-gate  * All rights reserved.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * Permission is hereby granted, free of charge, to any person obtaining a
10*7c478bd9Sstevel@tonic-gate  * copy of this software and associated documentation files (the
11*7c478bd9Sstevel@tonic-gate  * "Software"), to deal in the Software without restriction, including
12*7c478bd9Sstevel@tonic-gate  * without limitation the rights to use, copy, modify, merge, publish,
13*7c478bd9Sstevel@tonic-gate  * distribute, and/or sell copies of the Software, and to permit persons
14*7c478bd9Sstevel@tonic-gate  * to whom the Software is furnished to do so, provided that the above
15*7c478bd9Sstevel@tonic-gate  * copyright notice(s) and this permission notice appear in all copies of
16*7c478bd9Sstevel@tonic-gate  * the Software and that both the above copyright notice(s) and this
17*7c478bd9Sstevel@tonic-gate  * permission notice appear in supporting documentation.
18*7c478bd9Sstevel@tonic-gate  *
19*7c478bd9Sstevel@tonic-gate  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20*7c478bd9Sstevel@tonic-gate  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21*7c478bd9Sstevel@tonic-gate  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
22*7c478bd9Sstevel@tonic-gate  * OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23*7c478bd9Sstevel@tonic-gate  * HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
24*7c478bd9Sstevel@tonic-gate  * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
25*7c478bd9Sstevel@tonic-gate  * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
26*7c478bd9Sstevel@tonic-gate  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
27*7c478bd9Sstevel@tonic-gate  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28*7c478bd9Sstevel@tonic-gate  *
29*7c478bd9Sstevel@tonic-gate  * Except as contained in this notice, the name of a copyright holder
30*7c478bd9Sstevel@tonic-gate  * shall not be used in advertising or otherwise to promote the sale, use
31*7c478bd9Sstevel@tonic-gate  * or other dealings in this Software without prior written authorization
32*7c478bd9Sstevel@tonic-gate  * of the copyright holder.
33*7c478bd9Sstevel@tonic-gate  */
34*7c478bd9Sstevel@tonic-gate 
35*7c478bd9Sstevel@tonic-gate /*.......................................................................
36*7c478bd9Sstevel@tonic-gate  * Callback functions of the following type can be registered to write
37*7c478bd9Sstevel@tonic-gate  * to a terminal, when the default blocking writes to a local terminal
38*7c478bd9Sstevel@tonic-gate  * aren't appropriate. In particular, if you don't want gl_get_line()
39*7c478bd9Sstevel@tonic-gate  * to block, then this function should return before writing the
40*7c478bd9Sstevel@tonic-gate  * specified number of characters if doing otherwise would involve
41*7c478bd9Sstevel@tonic-gate  * waiting.
42*7c478bd9Sstevel@tonic-gate  *
43*7c478bd9Sstevel@tonic-gate  * Input:
44*7c478bd9Sstevel@tonic-gate  *  data     void *  The anonymous data pointer that was registered with
45*7c478bd9Sstevel@tonic-gate  *                   this callback function.
46*7c478bd9Sstevel@tonic-gate  *  s  const char *  The string to be written. Beware that this string
47*7c478bd9Sstevel@tonic-gate  *                   may not have a terminating '\0' character.
48*7c478bd9Sstevel@tonic-gate  *  n         int    The length of the prefix of s[] to attempt to
49*7c478bd9Sstevel@tonic-gate  *                   write.
50*7c478bd9Sstevel@tonic-gate  * Output:
51*7c478bd9Sstevel@tonic-gate  *  return    int    The number of characters written from s[]. This
52*7c478bd9Sstevel@tonic-gate  *                   should normally be a number in the range 0 to n.
53*7c478bd9Sstevel@tonic-gate  *                   To signal that an I/O error occurred, return -1.
54*7c478bd9Sstevel@tonic-gate  */
55*7c478bd9Sstevel@tonic-gate #define GL_WRITE_FN(fn) int (fn)(void *data, const char *s, int n)
56*7c478bd9Sstevel@tonic-gate typedef GL_WRITE_FN(GlWriteFn);
57*7c478bd9Sstevel@tonic-gate 
58*7c478bd9Sstevel@tonic-gate /*
59*7c478bd9Sstevel@tonic-gate  * The following output callback function requires a (FILE *) callback
60*7c478bd9Sstevel@tonic-gate  * data argument, and writes to this stream using the fwrite stdio
61*7c478bd9Sstevel@tonic-gate  * function.
62*7c478bd9Sstevel@tonic-gate  */
63*7c478bd9Sstevel@tonic-gate GL_WRITE_FN(_io_write_stdio);
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate /*
66*7c478bd9Sstevel@tonic-gate  * Left justify text within the bounds of the terminal adding optional
67*7c478bd9Sstevel@tonic-gate  * indentation, prefixes and suffixes to each line if requested.
68*7c478bd9Sstevel@tonic-gate  */
69*7c478bd9Sstevel@tonic-gate int _io_display_text(GlWriteFn *write_fn, void *data, int indentation,
70*7c478bd9Sstevel@tonic-gate 		     const char *prefix, const char *suffix, int fill_char,
71*7c478bd9Sstevel@tonic-gate 		     int term_width, int start, const char *string);
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate #endif
74