Skip to content

Commit 89fc2ae

Browse files
sthibaulgregkh
authored andcommitted
speakup: extend synth buffer to 16bit unicode characters
This extends the synth buffer slots to 16bit, so as to hold 16bit unicode characters. synth_buffer_getc and synth_buffer_peek now return 16bit characters. Speech synthesizers which do not support characters beyond latin1 can use the synth_buffer_skip_nonlatin1() helper to skip the non-latin1 characters before getting or peeking. All synthesizers are made to use it for now. This makes synth_buffer_add take a 16bit character. For simplicity for now, synth_printf is left to using latin1 formats and strings. synth_putwc, synth_putwc_s, synth_putws and synth_putws_s helpers are however added to put 16bit characters and strings. Signed-off-by: Samuel Thibault <[email protected]> Reviewed-by: Chris Brannon <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 981b7ae commit 89fc2ae

File tree

12 files changed

+70
-15
lines changed

12 files changed

+70
-15
lines changed

drivers/staging/speakup/buffers.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
#define SYNTH_BUF_SIZE 8192 /* currently 8K bytes */
99

10-
static u_char synth_buffer[SYNTH_BUF_SIZE]; /* guess what this is for! */
11-
static u_char *buff_in = synth_buffer;
12-
static u_char *buff_out = synth_buffer;
13-
static u_char *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1;
10+
static u16 synth_buffer[SYNTH_BUF_SIZE]; /* guess what this is for! */
11+
static u16 *buff_in = synth_buffer;
12+
static u16 *buff_out = synth_buffer;
13+
static u16 *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1;
1414

1515
/* These try to throttle applications by stopping the TTYs
1616
* Note: we need to make sure that we will restart them eventually, which is
@@ -44,13 +44,13 @@ static void speakup_stop_ttys(void)
4444

4545
static int synth_buffer_free(void)
4646
{
47-
int bytes_free;
47+
int chars_free;
4848

4949
if (buff_in >= buff_out)
50-
bytes_free = SYNTH_BUF_SIZE - (buff_in - buff_out);
50+
chars_free = SYNTH_BUF_SIZE - (buff_in - buff_out);
5151
else
52-
bytes_free = buff_out - buff_in;
53-
return bytes_free;
52+
chars_free = buff_out - buff_in;
53+
return chars_free;
5454
}
5555

5656
int synth_buffer_empty(void)
@@ -59,7 +59,7 @@ int synth_buffer_empty(void)
5959
}
6060
EXPORT_SYMBOL_GPL(synth_buffer_empty);
6161

62-
void synth_buffer_add(char ch)
62+
void synth_buffer_add(u16 ch)
6363
{
6464
if (!synth->alive) {
6565
/* This makes sure that we won't stop TTYs if there is no synth
@@ -78,9 +78,9 @@ void synth_buffer_add(char ch)
7878
buff_in = synth_buffer;
7979
}
8080

81-
char synth_buffer_getc(void)
81+
u16 synth_buffer_getc(void)
8282
{
83-
char ch;
83+
u16 ch;
8484

8585
if (buff_out == buff_in)
8686
return 0;
@@ -91,14 +91,26 @@ char synth_buffer_getc(void)
9191
}
9292
EXPORT_SYMBOL_GPL(synth_buffer_getc);
9393

94-
char synth_buffer_peek(void)
94+
u16 synth_buffer_peek(void)
9595
{
9696
if (buff_out == buff_in)
9797
return 0;
9898
return *buff_out;
9999
}
100100
EXPORT_SYMBOL_GPL(synth_buffer_peek);
101101

102+
void synth_buffer_skip_nonlatin1(void)
103+
{
104+
while (buff_out != buff_in) {
105+
if (*buff_out < 0x100)
106+
return;
107+
buff_out++;
108+
if (buff_out > buffer_end)
109+
buff_out = synth_buffer;
110+
}
111+
}
112+
EXPORT_SYMBOL_GPL(synth_buffer_skip_nonlatin1);
113+
102114
void synth_buffer_clear(void)
103115
{
104116
buff_in = synth_buffer;

drivers/staging/speakup/speakup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ void synth_release(void);
6666

6767
void spk_do_flush(void);
6868
void speakup_start_ttys(void);
69-
void synth_buffer_add(char ch);
69+
void synth_buffer_add(u16 ch);
7070
void synth_buffer_clear(void);
7171
void speakup_clear_selection(void);
7272
int speakup_set_selection(struct tty_struct *tty);

drivers/staging/speakup/speakup_acntpc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ static void do_catch_up(struct spk_synth *synth)
196196
synth->flush(synth);
197197
continue;
198198
}
199+
synth_buffer_skip_nonlatin1();
199200
if (synth_buffer_empty()) {
200201
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
201202
break;

drivers/staging/speakup/speakup_apollo.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ static void do_catch_up(struct spk_synth *synth)
160160
synth->flush(synth);
161161
continue;
162162
}
163+
synth_buffer_skip_nonlatin1();
163164
if (synth_buffer_empty()) {
164165
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
165166
break;

drivers/staging/speakup/speakup_decext.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ static void do_catch_up(struct spk_synth *synth)
175175
synth->flush(synth);
176176
continue;
177177
}
178+
synth_buffer_skip_nonlatin1();
178179
if (synth_buffer_empty()) {
179180
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
180181
break;

drivers/staging/speakup/speakup_decpc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ static void do_catch_up(struct spk_synth *synth)
390390
synth->flush(synth);
391391
continue;
392392
}
393+
synth_buffer_skip_nonlatin1();
393394
if (synth_buffer_empty()) {
394395
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
395396
break;

drivers/staging/speakup/speakup_dectlk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ static void do_catch_up(struct spk_synth *synth)
239239
synth->flush(synth);
240240
continue;
241241
}
242+
synth_buffer_skip_nonlatin1();
242243
if (synth_buffer_empty()) {
243244
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
244245
break;

drivers/staging/speakup/speakup_dtlk.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ static void do_catch_up(struct spk_synth *synth)
209209
synth->flush(synth);
210210
continue;
211211
}
212+
synth_buffer_skip_nonlatin1();
212213
if (synth_buffer_empty()) {
213214
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
214215
break;

drivers/staging/speakup/speakup_keypc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ spin_lock_irqsave(&speakup_info.spinlock, flags);
198198
synth->flush(synth);
199199
continue;
200200
}
201+
synth_buffer_skip_nonlatin1();
201202
if (synth_buffer_empty()) {
202203
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
203204
break;

drivers/staging/speakup/speakup_soft.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ static ssize_t softsynth_read(struct file *fp, char __user *buf, size_t count,
213213
spin_lock_irqsave(&speakup_info.spinlock, flags);
214214
while (1) {
215215
prepare_to_wait(&speakup_event, &wait, TASK_INTERRUPTIBLE);
216+
synth_buffer_skip_nonlatin1();
216217
if (!synth_buffer_empty() || speakup_info.flushing)
217218
break;
218219
spin_unlock_irqrestore(&speakup_info.spinlock, flags);

0 commit comments

Comments
 (0)