1 /* buffer.c - Text buffering and word wrapping
2 * Copyright (c) 1995-1997 Stefan Jokisch
4 * This file is part of Frotz.
6 * Frotz is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * Frotz is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23 extern void stream_char (zchar
);
24 extern void stream_word (const zchar
*);
25 extern void stream_new_line (void);
27 static zchar buffer
[TEXT_BUFFER_SIZE
];
28 static int bufpos
= 0;
30 static zchar prev_c
= 0;
35 * Copy the contents of the text buffer to the output streams.
39 void flush_buffer (void)
41 static bool locked
= FALSE
;
43 /* Make sure we stop when flush_buffer is called from flush_buffer.
44 Note that this is difficult to avoid as we might print a newline
45 during flush_buffer, which might cause a newline interrupt, that
46 might execute any arbitrary opcode, which might flush the buffer. */
48 if (locked
|| bufpos
== 0)
51 /* Send the buffer to the output streams */
61 os_speech_output(buffer
);
66 /* Reset the buffer */
76 * High level output function.
80 void print_char (zchar c
)
82 static bool flag
= FALSE
;
84 if (message
|| ostream_memory
|| enable_buffering
) {
88 /* Characters 0 and ZC_RETURN are special cases */
91 { new_line (); return; }
95 /* Flush the buffer before a whitespace or after a hyphen */
97 if (c
== ' ' || c
== ZC_INDENT
|| c
== ZC_GAP
|| (prev_c
== '-' && c
!= '-'))
102 /* Set the flag if this is part one of a style or font change */
104 if (c
== ZC_NEW_FONT
|| c
== ZC_NEW_STYLE
)
107 /* Remember the current character code */
113 /* Insert the character into the buffer */
115 buffer
[bufpos
++] = c
;
117 if (bufpos
== TEXT_BUFFER_SIZE
)
118 runtime_error (ERR_TEXT_BUF_OVF
);
120 } else stream_char (c
);
127 * High level newline function.
134 flush_buffer (); stream_new_line ();
142 * Initialize buffer variables.
146 void init_buffer(void)
148 memset(buffer
, 0, sizeof (zchar
) * TEXT_BUFFER_SIZE
);