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