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 /*.......................................................................
36  * Callback functions of the following type can be registered to write
37  * to a terminal, when the default blocking writes to a local terminal
38  * aren't appropriate. In particular, if you don't want gl_get_line()
39  * to block, then this function should return before writing the
40  * specified number of characters if doing otherwise would involve
41  * waiting.
42  *
43  * Input:
44  *  data     void *  The anonymous data pointer that was registered with
45  *                   this callback function.
46  *  s  const char *  The string to be written. Beware that this string
47  *                   may not have a terminating '\0' character.
48  *  n         int    The length of the prefix of s[] to attempt to
49  *                   write.
50  * Output:
51  *  return    int    The number of characters written from s[]. This
52  *                   should normally be a number in the range 0 to n.
53  *                   To signal that an I/O error occurred, return -1.
54  */
55 #define GL_WRITE_FN(fn) int (fn)(void *data, const char *s, int n)
56 typedef GL_WRITE_FN(GlWriteFn);
57 
58 /*
59  * The following output callback function requires a (FILE *) callback
60  * data argument, and writes to this stream using the fwrite stdio
61  * function.
62  */
63 GL_WRITE_FN(_io_write_stdio);
64 
65 /*
66  * Left justify text within the bounds of the terminal adding optional
67  * indentation, prefixes and suffixes to each line if requested.
68  */
69 int _io_display_text(GlWriteFn *write_fn, void *data, int indentation,
70 		     const char *prefix, const char *suffix, int fill_char,
71 		     int term_width, int start, const char *string);
72 
73 #endif
74