speakup: extend synth buffer to 16bit unicode characters
authorSamuel Thibault <samuel.thibault@ens-lyon.org>
Sat, 4 Mar 2017 14:01:55 +0000 (15:01 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Mar 2017 16:28:20 +0000 (17:28 +0100)
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 <samuel.thibault@ens-lyon.org>
Reviewed-by: Chris Brannon <chris@the-brannons.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
12 files changed:
drivers/staging/speakup/buffers.c
drivers/staging/speakup/speakup.h
drivers/staging/speakup/speakup_acntpc.c
drivers/staging/speakup/speakup_apollo.c
drivers/staging/speakup/speakup_decext.c
drivers/staging/speakup/speakup_decpc.c
drivers/staging/speakup/speakup_dectlk.c
drivers/staging/speakup/speakup_dtlk.c
drivers/staging/speakup/speakup_keypc.c
drivers/staging/speakup/speakup_soft.c
drivers/staging/speakup/spk_priv.h
drivers/staging/speakup/synth.c

index 723d5df44221628903c57b5325a4a32dc1c8cac9..f459e4004bfa61775ce0577376c545f68ed87998 100644 (file)
@@ -7,10 +7,10 @@
 
 #define SYNTH_BUF_SIZE 8192    /* currently 8K bytes */
 
-static u_char synth_buffer[SYNTH_BUF_SIZE];    /* guess what this is for! */
-static u_char *buff_in = synth_buffer;
-static u_char *buff_out = synth_buffer;
-static u_char *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1;
+static u16 synth_buffer[SYNTH_BUF_SIZE];       /* guess what this is for! */
+static u16 *buff_in = synth_buffer;
+static u16 *buff_out = synth_buffer;
+static u16 *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1;
 
 /* These try to throttle applications by stopping the TTYs
  * Note: we need to make sure that we will restart them eventually, which is
@@ -44,13 +44,13 @@ static void speakup_stop_ttys(void)
 
 static int synth_buffer_free(void)
 {
-       int bytes_free;
+       int chars_free;
 
        if (buff_in >= buff_out)
-               bytes_free = SYNTH_BUF_SIZE - (buff_in - buff_out);
+               chars_free = SYNTH_BUF_SIZE - (buff_in - buff_out);
        else
-               bytes_free = buff_out - buff_in;
-       return bytes_free;
+               chars_free = buff_out - buff_in;
+       return chars_free;
 }
 
 int synth_buffer_empty(void)
@@ -59,7 +59,7 @@ int synth_buffer_empty(void)
 }
 EXPORT_SYMBOL_GPL(synth_buffer_empty);
 
-void synth_buffer_add(char ch)
+void synth_buffer_add(u16 ch)
 {
        if (!synth->alive) {
                /* This makes sure that we won't stop TTYs if there is no synth
@@ -78,9 +78,9 @@ void synth_buffer_add(char ch)
                buff_in = synth_buffer;
 }
 
-char synth_buffer_getc(void)
+u16 synth_buffer_getc(void)
 {
-       char ch;
+       u16 ch;
 
        if (buff_out == buff_in)
                return 0;
@@ -91,7 +91,7 @@ char synth_buffer_getc(void)
 }
 EXPORT_SYMBOL_GPL(synth_buffer_getc);
 
-char synth_buffer_peek(void)
+u16 synth_buffer_peek(void)
 {
        if (buff_out == buff_in)
                return 0;
@@ -99,6 +99,18 @@ char synth_buffer_peek(void)
 }
 EXPORT_SYMBOL_GPL(synth_buffer_peek);
 
+void synth_buffer_skip_nonlatin1(void)
+{
+       while (buff_out != buff_in) {
+               if (*buff_out < 0x100)
+                       return;
+               buff_out++;
+               if (buff_out > buffer_end)
+                       buff_out = synth_buffer;
+       }
+}
+EXPORT_SYMBOL_GPL(synth_buffer_skip_nonlatin1);
+
 void synth_buffer_clear(void)
 {
        buff_in = synth_buffer;
index b203f0f883a901c14b51fe982a89578f4917ec87..272dd3dd920b117a415812d0615debde2a47bd9f 100644 (file)
@@ -66,7 +66,7 @@ void synth_release(void);
 
 void spk_do_flush(void);
 void speakup_start_ttys(void);
-void synth_buffer_add(char ch);
+void synth_buffer_add(u16 ch);
 void synth_buffer_clear(void);
 void speakup_clear_selection(void);
 int speakup_set_selection(struct tty_struct *tty);
index cf6fcd63498d498435cca28e6f3cf5e6a2caf337..56ece087ff8883a089b6f66e17da94dea105e8dc 100644 (file)
@@ -196,6 +196,7 @@ static void do_catch_up(struct spk_synth *synth)
                        synth->flush(synth);
                        continue;
                }
+               synth_buffer_skip_nonlatin1();
                if (synth_buffer_empty()) {
                        spin_unlock_irqrestore(&speakup_info.spinlock, flags);
                        break;
index 3f43f8105bc07a0f37584a4bb38b1ae26e361338..93969688e7540a7ba6f543be88bbf5ac5524af1d 100644 (file)
@@ -160,6 +160,7 @@ static void do_catch_up(struct spk_synth *synth)
                        synth->flush(synth);
                        continue;
                }
+               synth_buffer_skip_nonlatin1();
                if (synth_buffer_empty()) {
                        spin_unlock_irqrestore(&speakup_info.spinlock, flags);
                        break;
index 6b74a97385daebc550e2573d6898b518e0d8570f..34e03c6b1ae5133f45e45a27c0379a1b278e0673 100644 (file)
@@ -175,6 +175,7 @@ static void do_catch_up(struct spk_synth *synth)
                        synth->flush(synth);
                        continue;
                }
+               synth_buffer_skip_nonlatin1();
                if (synth_buffer_empty()) {
                        spin_unlock_irqrestore(&speakup_info.spinlock, flags);
                        break;
index 3b57347b7c3f353be5c36cc58d48d435643746f5..4cd9730ee03d3a4ac4799206846d0b511f98ae6d 100644 (file)
@@ -390,6 +390,7 @@ static void do_catch_up(struct spk_synth *synth)
                        synth->flush(synth);
                        continue;
                }
+               synth_buffer_skip_nonlatin1();
                if (synth_buffer_empty()) {
                        spin_unlock_irqrestore(&speakup_info.spinlock, flags);
                        break;
index 26036050cdb2c487a0532a124e0b23158b8af0e8..e0f2d6121890e2916730ea2016f7c09f001fe546 100644 (file)
@@ -239,6 +239,7 @@ static void do_catch_up(struct spk_synth *synth)
                        synth->flush(synth);
                        continue;
                }
+               synth_buffer_skip_nonlatin1();
                if (synth_buffer_empty()) {
                        spin_unlock_irqrestore(&speakup_info.spinlock, flags);
                        break;
index e2bf20806d8deea16a6e93233dbf4c4cd14311f8..de67288beb25f88373938f62050f6522f2349b5a 100644 (file)
@@ -209,6 +209,7 @@ static void do_catch_up(struct spk_synth *synth)
                        synth->flush(synth);
                        continue;
                }
+               synth_buffer_skip_nonlatin1();
                if (synth_buffer_empty()) {
                        spin_unlock_irqrestore(&speakup_info.spinlock, flags);
                        break;
index 10f4964782e275bfe69768d7cda86bfb3351cb73..7c24e088549cd6601b91a2d9e496b8066e58819f 100644 (file)
@@ -198,6 +198,7 @@ spin_lock_irqsave(&speakup_info.spinlock, flags);
                        synth->flush(synth);
                        continue;
                }
+               synth_buffer_skip_nonlatin1();
                if (synth_buffer_empty()) {
                        spin_unlock_irqrestore(&speakup_info.spinlock, flags);
                        break;
index d2ff0afd685aea3c60cc7fa75ed38de219c6b23f..2529c4629c53b2a35396778a8e554308f5038ebb 100644 (file)
@@ -213,6 +213,7 @@ static ssize_t softsynth_read(struct file *fp, char __user *buf, size_t count,
        spin_lock_irqsave(&speakup_info.spinlock, flags);
        while (1) {
                prepare_to_wait(&speakup_event, &wait, TASK_INTERRUPTIBLE);
+               synth_buffer_skip_nonlatin1();
                if (!synth_buffer_empty() || speakup_info.flushing)
                        break;
                spin_unlock_irqrestore(&speakup_info.spinlock, flags);
index c78c2b6a2fc9af4ceff3827540648e04f8bcdce1..b8015d817cdd547422a0f631901d0ccff278287a 100644 (file)
@@ -48,8 +48,9 @@ unsigned char spk_serial_in_nowait(void);
 int spk_serial_out(const char ch);
 void spk_serial_release(void);
 
-char synth_buffer_getc(void);
-char synth_buffer_peek(void);
+void synth_buffer_skip_nonlatin1(void);
+u16 synth_buffer_getc(void);
+u16 synth_buffer_peek(void);
 int synth_buffer_empty(void);
 struct var_t *spk_get_var(enum var_id_t var_id);
 ssize_t spk_var_show(struct kobject *kobj, struct kobj_attribute *attr,
@@ -65,6 +66,10 @@ int spk_synth_is_alive_nop(struct spk_synth *synth);
 int spk_synth_is_alive_restart(struct spk_synth *synth);
 __printf(1, 2)
 void synth_printf(const char *buf, ...);
+void synth_putwc(u16 wc);
+void synth_putwc_s(u16 wc);
+void synth_putws(const u16 *buf);
+void synth_putws_s(const u16 *buf);
 int synth_request_region(unsigned long start, unsigned long n);
 int synth_release_region(unsigned long start, unsigned long n);
 int synth_add(struct spk_synth *in_synth);
index 8340748ae9cb72534ee1884921b94c66df02632c..4d59917a2961c2a2c34e796e918064de785872fc 100644 (file)
@@ -109,6 +109,7 @@ void spk_do_catch_up(struct spk_synth *synth)
                        synth->flush(synth);
                        continue;
                }
+               synth_buffer_skip_nonlatin1();
                if (synth_buffer_empty()) {
                        spin_unlock_irqrestore(&speakup_info.spinlock, flags);
                        break;
@@ -255,6 +256,35 @@ void synth_printf(const char *fmt, ...)
 }
 EXPORT_SYMBOL_GPL(synth_printf);
 
+void synth_putwc(u16 wc)
+{
+       synth_buffer_add(wc);
+}
+EXPORT_SYMBOL_GPL(synth_putwc);
+
+void synth_putwc_s(u16 wc)
+{
+       synth_buffer_add(wc);
+       synth_start();
+}
+EXPORT_SYMBOL_GPL(synth_putwc_s);
+
+void synth_putws(const u16 *buf)
+{
+       const u16 *p;
+
+       for (p = buf; *p; p++)
+               synth_buffer_add(*p);
+}
+EXPORT_SYMBOL_GPL(synth_putws);
+
+void synth_putws_s(const u16 *buf)
+{
+       synth_putws(buf);
+       synth_start();
+}
+EXPORT_SYMBOL_GPL(synth_putws_s);
+
 static int index_count;
 static int sentence_count;