main.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /* speakup.c
  3. * review functions for the speakup screen review package.
  4. * originally written by: Kirk Reiser and Andy Berdan.
  5. *
  6. * extensively modified by David Borowski.
  7. *
  8. ** Copyright (C) 1998 Kirk Reiser.
  9. * Copyright (C) 2003 David Borowski.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/vt.h>
  13. #include <linux/tty.h>
  14. #include <linux/mm.h> /* __get_free_page() and friends */
  15. #include <linux/vt_kern.h>
  16. #include <linux/ctype.h>
  17. #include <linux/selection.h>
  18. #include <linux/unistd.h>
  19. #include <linux/jiffies.h>
  20. #include <linux/kthread.h>
  21. #include <linux/keyboard.h> /* for KT_SHIFT */
  22. #include <linux/kbd_kern.h> /* for vc_kbd_* and friends */
  23. #include <linux/input.h>
  24. #include <linux/kmod.h>
  25. /* speakup_*_selection */
  26. #include <linux/module.h>
  27. #include <linux/sched.h>
  28. #include <linux/slab.h>
  29. #include <linux/types.h>
  30. #include <linux/consolemap.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/notifier.h>
  33. #include <linux/uaccess.h> /* copy_from|to|user() and others */
  34. #include "spk_priv.h"
  35. #include "speakup.h"
  36. #define MAX_DELAY msecs_to_jiffies(500)
  37. #define MINECHOCHAR SPACE
  38. MODULE_AUTHOR("Kirk Reiser <[email protected]>");
  39. MODULE_AUTHOR("Daniel Drake <[email protected]>");
  40. MODULE_DESCRIPTION("Speakup console speech");
  41. MODULE_LICENSE("GPL");
  42. MODULE_VERSION(SPEAKUP_VERSION);
  43. char *synth_name;
  44. module_param_named(synth, synth_name, charp, 0444);
  45. module_param_named(quiet, spk_quiet_boot, bool, 0444);
  46. MODULE_PARM_DESC(synth, "Synth to start if speakup is built in.");
  47. MODULE_PARM_DESC(quiet, "Do not announce when the synthesizer is found.");
  48. special_func spk_special_handler;
  49. short spk_pitch_shift, synth_flags;
  50. static u16 buf[256];
  51. int spk_attrib_bleep, spk_bleeps, spk_bleep_time = 10;
  52. int spk_no_intr, spk_spell_delay;
  53. int spk_key_echo, spk_say_word_ctl;
  54. int spk_say_ctrl, spk_bell_pos;
  55. short spk_punc_mask;
  56. int spk_punc_level, spk_reading_punc;
  57. char spk_str_caps_start[MAXVARLEN + 1] = "\0";
  58. char spk_str_caps_stop[MAXVARLEN + 1] = "\0";
  59. char spk_str_pause[MAXVARLEN + 1] = "\0";
  60. bool spk_paused;
  61. const struct st_bits_data spk_punc_info[] = {
  62. {"none", "", 0},
  63. {"some", "/$%&@", SOME},
  64. {"most", "$%&#()=+*/@^<>|\\", MOST},
  65. {"all", "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", PUNC},
  66. {"delimiters", "", B_WDLM},
  67. {"repeats", "()", CH_RPT},
  68. {"extended numeric", "", B_EXNUM},
  69. {"symbols", "", B_SYM},
  70. {NULL, NULL}
  71. };
  72. static char mark_cut_flag;
  73. #define MAX_KEY 160
  74. static u_char *spk_shift_table;
  75. u_char *spk_our_keys[MAX_KEY];
  76. u_char spk_key_buf[600];
  77. const u_char spk_key_defaults[] = {
  78. #include "speakupmap.h"
  79. };
  80. /* cursor track modes, must be ordered same as cursor_msgs in enum msg_index_t */
  81. enum cursor_track {
  82. CT_Off = 0,
  83. CT_On,
  84. CT_Highlight,
  85. CT_Window,
  86. CT_Max,
  87. read_all_mode = CT_Max,
  88. };
  89. /* Speakup Cursor Track Variables */
  90. static enum cursor_track cursor_track = 1, prev_cursor_track = 1;
  91. static struct tty_struct *tty;
  92. static void spkup_write(const u16 *in_buf, int count);
  93. static char *phonetic[] = {
  94. "alfa", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel",
  95. "india", "juliett", "keelo", "leema", "mike", "november", "oscar",
  96. "papa",
  97. "keh beck", "romeo", "sierra", "tango", "uniform", "victer", "whiskey",
  98. "x ray", "yankee", "zulu"
  99. };
  100. /* array of 256 char pointers (one for each character description)
  101. * initialized to default_chars and user selectable via
  102. * /proc/speakup/characters
  103. */
  104. char *spk_characters[256];
  105. char *spk_default_chars[256] = {
  106. /*000*/ "null", "^a", "^b", "^c", "^d", "^e", "^f", "^g",
  107. /*008*/ "^h", "^i", "^j", "^k", "^l", "^m", "^n", "^o",
  108. /*016*/ "^p", "^q", "^r", "^s", "^t", "^u", "^v", "^w",
  109. /*024*/ "^x", "^y", "^z", "control", "control", "control", "control",
  110. "control",
  111. /*032*/ "space", "bang!", "quote", "number", "dollar", "percent", "and",
  112. "tick",
  113. /*040*/ "left paren", "right paren", "star", "plus", "comma", "dash",
  114. "dot",
  115. "slash",
  116. /*048*/ "zero", "one", "two", "three", "four", "five", "six", "seven",
  117. "eight", "nine",
  118. /*058*/ "colon", "semmy", "less", "equals", "greater", "question", "at",
  119. /*065*/ "EIGH", "B", "C", "D", "E", "F", "G",
  120. /*072*/ "H", "I", "J", "K", "L", "M", "N", "O",
  121. /*080*/ "P", "Q", "R", "S", "T", "U", "V", "W", "X",
  122. /*089*/ "Y", "ZED", "left bracket", "backslash", "right bracket",
  123. "caret",
  124. "line",
  125. /*096*/ "accent", "a", "b", "c", "d", "e", "f", "g",
  126. /*104*/ "h", "i", "j", "k", "l", "m", "n", "o",
  127. /*112*/ "p", "q", "r", "s", "t", "u", "v", "w",
  128. /*120*/ "x", "y", "zed", "left brace", "bar", "right brace", "tihlduh",
  129. /*127*/ "del", "control", "control", "control", "control", "control",
  130. "control", "control", "control", "control", "control",
  131. /*138*/ "control", "control", "control", "control", "control",
  132. "control", "control", "control", "control", "control",
  133. "control", "control",
  134. /*150*/ "control", "control", "control", "control", "control",
  135. "control", "control", "control", "control", "control",
  136. /*160*/ "nbsp", "inverted bang",
  137. /*162*/ "cents", "pounds", "currency", "yen", "broken bar", "section",
  138. /*168*/ "diaeresis", "copyright", "female ordinal", "double left angle",
  139. /*172*/ "not", "soft hyphen", "registered", "macron",
  140. /*176*/ "degrees", "plus or minus", "super two", "super three",
  141. /*180*/ "acute accent", "micro", "pilcrow", "middle dot",
  142. /*184*/ "cedilla", "super one", "male ordinal", "double right angle",
  143. /*188*/ "one quarter", "one half", "three quarters",
  144. "inverted question",
  145. /*192*/ "A GRAVE", "A ACUTE", "A CIRCUMFLEX", "A TILDE", "A OOMLAUT",
  146. "A RING",
  147. /*198*/ "AE", "C CIDELLA", "E GRAVE", "E ACUTE", "E CIRCUMFLEX",
  148. "E OOMLAUT",
  149. /*204*/ "I GRAVE", "I ACUTE", "I CIRCUMFLEX", "I OOMLAUT", "ETH",
  150. "N TILDE",
  151. /*210*/ "O GRAVE", "O ACUTE", "O CIRCUMFLEX", "O TILDE", "O OOMLAUT",
  152. /*215*/ "multiplied by", "O STROKE", "U GRAVE", "U ACUTE",
  153. "U CIRCUMFLEX",
  154. /*220*/ "U OOMLAUT", "Y ACUTE", "THORN", "sharp s", "a grave",
  155. /*225*/ "a acute", "a circumflex", "a tilde", "a oomlaut", "a ring",
  156. /*230*/ "ae", "c cidella", "e grave", "e acute",
  157. /*234*/ "e circumflex", "e oomlaut", "i grave", "i acute",
  158. "i circumflex",
  159. /*239*/ "i oomlaut", "eth", "n tilde", "o grave", "o acute",
  160. "o circumflex",
  161. /*245*/ "o tilde", "o oomlaut", "divided by", "o stroke", "u grave",
  162. "u acute",
  163. /* 251 */ "u circumflex", "u oomlaut", "y acute", "thorn", "y oomlaut"
  164. };
  165. /* array of 256 u_short (one for each character)
  166. * initialized to default_chartab and user selectable via
  167. * /sys/module/speakup/parameters/chartab
  168. */
  169. u_short spk_chartab[256];
  170. static u_short default_chartab[256] = {
  171. B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, /* 0-7 */
  172. B_CTL, B_CTL, A_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, /* 8-15 */
  173. B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, /*16-23 */
  174. B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, B_CTL, /* 24-31 */
  175. WDLM, A_PUNC, PUNC, PUNC, PUNC, PUNC, PUNC, A_PUNC, /* !"#$%&' */
  176. PUNC, PUNC, PUNC, PUNC, A_PUNC, A_PUNC, A_PUNC, PUNC, /* ()*+, -./ */
  177. NUM, NUM, NUM, NUM, NUM, NUM, NUM, NUM, /* 01234567 */
  178. NUM, NUM, A_PUNC, PUNC, PUNC, PUNC, PUNC, A_PUNC, /* 89:;<=>? */
  179. PUNC, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, /* @ABCDEFG */
  180. A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, /* HIJKLMNO */
  181. A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, /* PQRSTUVW */
  182. A_CAP, A_CAP, A_CAP, PUNC, PUNC, PUNC, PUNC, PUNC, /* XYZ[\]^_ */
  183. PUNC, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /* `abcdefg */
  184. ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /* hijklmno */
  185. ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /* pqrstuvw */
  186. ALPHA, ALPHA, ALPHA, PUNC, PUNC, PUNC, PUNC, 0, /* xyz{|}~ */
  187. B_CAPSYM, B_CAPSYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, /* 128-134 */
  188. B_SYM, /* 135 */
  189. B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, /* 136-142 */
  190. B_CAPSYM, /* 143 */
  191. B_CAPSYM, B_CAPSYM, B_SYM, B_CAPSYM, B_SYM, B_SYM, B_SYM, /* 144-150 */
  192. B_SYM, /* 151 */
  193. B_SYM, B_SYM, B_CAPSYM, B_CAPSYM, B_SYM, B_SYM, B_SYM, /*152-158 */
  194. B_SYM, /* 159 */
  195. WDLM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_CAPSYM, /* 160-166 */
  196. B_SYM, /* 167 */
  197. B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, /* 168-175 */
  198. B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, /* 176-183 */
  199. B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, B_SYM, /* 184-191 */
  200. A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, /* 192-199 */
  201. A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, /* 200-207 */
  202. A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, B_SYM, /* 208-215 */
  203. A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, A_CAP, ALPHA, /* 216-223 */
  204. ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /* 224-231 */
  205. ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, /* 232-239 */
  206. ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, B_SYM, /* 240-247 */
  207. ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA, ALPHA /* 248-255 */
  208. };
  209. struct task_struct *speakup_task;
  210. struct bleep spk_unprocessed_sound;
  211. static int spk_keydown;
  212. static u16 spk_lastkey;
  213. static u_char spk_close_press, keymap_flags;
  214. static u_char last_keycode, this_speakup_key;
  215. static u_long last_spk_jiffy;
  216. struct st_spk_t *speakup_console[MAX_NR_CONSOLES];
  217. DEFINE_MUTEX(spk_mutex);
  218. static int keyboard_notifier_call(struct notifier_block *,
  219. unsigned long code, void *param);
  220. static struct notifier_block keyboard_notifier_block = {
  221. .notifier_call = keyboard_notifier_call,
  222. };
  223. static int vt_notifier_call(struct notifier_block *,
  224. unsigned long code, void *param);
  225. static struct notifier_block vt_notifier_block = {
  226. .notifier_call = vt_notifier_call,
  227. };
  228. static unsigned char get_attributes(struct vc_data *vc, u16 *pos)
  229. {
  230. pos = screen_pos(vc, pos - (u16 *)vc->vc_origin, true);
  231. return (scr_readw(pos) & ~vc->vc_hi_font_mask) >> 8;
  232. }
  233. static void speakup_date(struct vc_data *vc)
  234. {
  235. spk_x = spk_cx = vc->state.x;
  236. spk_y = spk_cy = vc->state.y;
  237. spk_pos = spk_cp = vc->vc_pos;
  238. spk_old_attr = spk_attr;
  239. spk_attr = get_attributes(vc, (u_short *)spk_pos);
  240. }
  241. static void bleep(u_short val)
  242. {
  243. static const short vals[] = {
  244. 350, 370, 392, 414, 440, 466, 491, 523, 554, 587, 619, 659
  245. };
  246. short freq;
  247. int time = spk_bleep_time;
  248. freq = vals[val % 12];
  249. if (val > 11)
  250. freq *= (1 << (val / 12));
  251. spk_unprocessed_sound.freq = freq;
  252. spk_unprocessed_sound.jiffies = msecs_to_jiffies(time);
  253. spk_unprocessed_sound.active = 1;
  254. /* We can only have 1 active sound at a time. */
  255. }
  256. static void speakup_shut_up(struct vc_data *vc)
  257. {
  258. if (spk_killed)
  259. return;
  260. spk_shut_up |= 0x01;
  261. spk_parked &= 0xfe;
  262. speakup_date(vc);
  263. if (synth)
  264. spk_do_flush();
  265. }
  266. static void speech_kill(struct vc_data *vc)
  267. {
  268. char val = synth->is_alive(synth);
  269. if (val == 0)
  270. return;
  271. /* re-enables synth, if disabled */
  272. if (val == 2 || spk_killed) {
  273. /* dead */
  274. spk_shut_up &= ~0x40;
  275. synth_printf("%s\n", spk_msg_get(MSG_IAM_ALIVE));
  276. } else {
  277. synth_printf("%s\n", spk_msg_get(MSG_YOU_KILLED_SPEAKUP));
  278. spk_shut_up |= 0x40;
  279. }
  280. }
  281. static void speakup_off(struct vc_data *vc)
  282. {
  283. if (spk_shut_up & 0x80) {
  284. spk_shut_up &= 0x7f;
  285. synth_printf("%s\n", spk_msg_get(MSG_HEY_THATS_BETTER));
  286. } else {
  287. spk_shut_up |= 0x80;
  288. synth_printf("%s\n", spk_msg_get(MSG_YOU_TURNED_ME_OFF));
  289. }
  290. speakup_date(vc);
  291. }
  292. static void speakup_parked(struct vc_data *vc)
  293. {
  294. if (spk_parked & 0x80) {
  295. spk_parked = 0;
  296. synth_printf("%s\n", spk_msg_get(MSG_UNPARKED));
  297. } else {
  298. spk_parked |= 0x80;
  299. synth_printf("%s\n", spk_msg_get(MSG_PARKED));
  300. }
  301. }
  302. static void speakup_cut(struct vc_data *vc)
  303. {
  304. static const char err_buf[] = "set selection failed";
  305. int ret;
  306. if (!mark_cut_flag) {
  307. mark_cut_flag = 1;
  308. spk_xs = (u_short)spk_x;
  309. spk_ys = (u_short)spk_y;
  310. spk_sel_cons = vc;
  311. synth_printf("%s\n", spk_msg_get(MSG_MARK));
  312. return;
  313. }
  314. spk_xe = (u_short)spk_x;
  315. spk_ye = (u_short)spk_y;
  316. mark_cut_flag = 0;
  317. synth_printf("%s\n", spk_msg_get(MSG_CUT));
  318. ret = speakup_set_selection(tty);
  319. switch (ret) {
  320. case 0:
  321. break; /* no error */
  322. case -EFAULT:
  323. pr_warn("%sEFAULT\n", err_buf);
  324. break;
  325. case -EINVAL:
  326. pr_warn("%sEINVAL\n", err_buf);
  327. break;
  328. case -ENOMEM:
  329. pr_warn("%sENOMEM\n", err_buf);
  330. break;
  331. }
  332. }
  333. static void speakup_paste(struct vc_data *vc)
  334. {
  335. if (mark_cut_flag) {
  336. mark_cut_flag = 0;
  337. synth_printf("%s\n", spk_msg_get(MSG_MARK_CLEARED));
  338. } else {
  339. synth_printf("%s\n", spk_msg_get(MSG_PASTE));
  340. speakup_paste_selection(tty);
  341. }
  342. }
  343. static void say_attributes(struct vc_data *vc)
  344. {
  345. int fg = spk_attr & 0x0f;
  346. int bg = spk_attr >> 4;
  347. synth_printf("%s", spk_msg_get(MSG_COLORS_START + fg));
  348. if (bg > 7) {
  349. synth_printf(" %s ", spk_msg_get(MSG_ON_BLINKING));
  350. bg -= 8;
  351. } else {
  352. synth_printf(" %s ", spk_msg_get(MSG_ON));
  353. }
  354. synth_printf("%s\n", spk_msg_get(MSG_COLORS_START + bg));
  355. }
  356. /* must be ordered same as edge_msgs in enum msg_index_t */
  357. enum edge {
  358. edge_none = 0,
  359. edge_top,
  360. edge_bottom,
  361. edge_left,
  362. edge_right,
  363. edge_quiet
  364. };
  365. static void announce_edge(struct vc_data *vc, enum edge msg_id)
  366. {
  367. if (spk_bleeps & 1)
  368. bleep(spk_y);
  369. if ((spk_bleeps & 2) && (msg_id < edge_quiet))
  370. synth_printf("%s\n",
  371. spk_msg_get(MSG_EDGE_MSGS_START + msg_id - 1));
  372. }
  373. static void speak_char(u16 ch)
  374. {
  375. char *cp;
  376. struct var_t *direct = spk_get_var(DIRECT);
  377. if (ch >= 0x100 || (direct && direct->u.n.value)) {
  378. if (ch < 0x100 && IS_CHAR(ch, B_CAP)) {
  379. spk_pitch_shift++;
  380. synth_printf("%s", spk_str_caps_start);
  381. }
  382. synth_putwc_s(ch);
  383. if (ch < 0x100 && IS_CHAR(ch, B_CAP))
  384. synth_printf("%s", spk_str_caps_stop);
  385. return;
  386. }
  387. cp = spk_characters[ch];
  388. if (!cp) {
  389. pr_info("%s: cp == NULL!\n", __func__);
  390. return;
  391. }
  392. if (IS_CHAR(ch, B_CAP)) {
  393. spk_pitch_shift++;
  394. synth_printf("%s %s %s",
  395. spk_str_caps_start, cp, spk_str_caps_stop);
  396. } else {
  397. if (*cp == '^') {
  398. cp++;
  399. synth_printf(" %s%s ", spk_msg_get(MSG_CTRL), cp);
  400. } else {
  401. synth_printf(" %s ", cp);
  402. }
  403. }
  404. }
  405. static u16 get_char(struct vc_data *vc, u16 *pos, u_char *attribs)
  406. {
  407. u16 ch = ' ';
  408. if (vc && pos) {
  409. u16 w;
  410. u16 c;
  411. pos = screen_pos(vc, pos - (u16 *)vc->vc_origin, true);
  412. w = scr_readw(pos);
  413. c = w & 0xff;
  414. if (w & vc->vc_hi_font_mask) {
  415. w &= ~vc->vc_hi_font_mask;
  416. c |= 0x100;
  417. }
  418. ch = inverse_translate(vc, c, true);
  419. *attribs = (w & 0xff00) >> 8;
  420. }
  421. return ch;
  422. }
  423. static void say_char(struct vc_data *vc)
  424. {
  425. u16 ch;
  426. spk_old_attr = spk_attr;
  427. ch = get_char(vc, (u_short *)spk_pos, &spk_attr);
  428. if (spk_attr != spk_old_attr) {
  429. if (spk_attrib_bleep & 1)
  430. bleep(spk_y);
  431. if (spk_attrib_bleep & 2)
  432. say_attributes(vc);
  433. }
  434. speak_char(ch);
  435. }
  436. static void say_phonetic_char(struct vc_data *vc)
  437. {
  438. u16 ch;
  439. spk_old_attr = spk_attr;
  440. ch = get_char(vc, (u_short *)spk_pos, &spk_attr);
  441. if (ch <= 0x7f && isalpha(ch)) {
  442. ch &= 0x1f;
  443. synth_printf("%s\n", phonetic[--ch]);
  444. } else {
  445. if (ch < 0x100 && IS_CHAR(ch, B_NUM))
  446. synth_printf("%s ", spk_msg_get(MSG_NUMBER));
  447. speak_char(ch);
  448. }
  449. }
  450. static void say_prev_char(struct vc_data *vc)
  451. {
  452. spk_parked |= 0x01;
  453. if (spk_x == 0) {
  454. announce_edge(vc, edge_left);
  455. return;
  456. }
  457. spk_x--;
  458. spk_pos -= 2;
  459. say_char(vc);
  460. }
  461. static void say_next_char(struct vc_data *vc)
  462. {
  463. spk_parked |= 0x01;
  464. if (spk_x == vc->vc_cols - 1) {
  465. announce_edge(vc, edge_right);
  466. return;
  467. }
  468. spk_x++;
  469. spk_pos += 2;
  470. say_char(vc);
  471. }
  472. /* get_word - will first check to see if the character under the
  473. * reading cursor is a space and if spk_say_word_ctl is true it will
  474. * return the word space. If spk_say_word_ctl is not set it will check to
  475. * see if there is a word starting on the next position to the right
  476. * and return that word if it exists. If it does not exist it will
  477. * move left to the beginning of any previous word on the line or the
  478. * beginning off the line whichever comes first..
  479. */
  480. static u_long get_word(struct vc_data *vc)
  481. {
  482. u_long cnt = 0, tmpx = spk_x, tmp_pos = spk_pos;
  483. u16 ch;
  484. u16 attr_ch;
  485. u_char temp;
  486. spk_old_attr = spk_attr;
  487. ch = get_char(vc, (u_short *)tmp_pos, &temp);
  488. /* decided to take out the sayword if on a space (mis-information */
  489. if (spk_say_word_ctl && ch == SPACE) {
  490. *buf = '\0';
  491. synth_printf("%s\n", spk_msg_get(MSG_SPACE));
  492. return 0;
  493. } else if (tmpx < vc->vc_cols - 2 &&
  494. (ch == SPACE || ch == 0 || (ch < 0x100 && IS_WDLM(ch))) &&
  495. get_char(vc, (u_short *)tmp_pos + 1, &temp) > SPACE) {
  496. tmp_pos += 2;
  497. tmpx++;
  498. } else {
  499. while (tmpx > 0) {
  500. ch = get_char(vc, (u_short *)tmp_pos - 1, &temp);
  501. if ((ch == SPACE || ch == 0 ||
  502. (ch < 0x100 && IS_WDLM(ch))) &&
  503. get_char(vc, (u_short *)tmp_pos, &temp) > SPACE)
  504. break;
  505. tmp_pos -= 2;
  506. tmpx--;
  507. }
  508. }
  509. attr_ch = get_char(vc, (u_short *)tmp_pos, &spk_attr);
  510. buf[cnt++] = attr_ch;
  511. while (tmpx < vc->vc_cols - 1) {
  512. tmp_pos += 2;
  513. tmpx++;
  514. ch = get_char(vc, (u_short *)tmp_pos, &temp);
  515. if (ch == SPACE || ch == 0 ||
  516. (buf[cnt - 1] < 0x100 && IS_WDLM(buf[cnt - 1]) &&
  517. ch > SPACE))
  518. break;
  519. buf[cnt++] = ch;
  520. }
  521. buf[cnt] = '\0';
  522. return cnt;
  523. }
  524. static void say_word(struct vc_data *vc)
  525. {
  526. u_long cnt = get_word(vc);
  527. u_short saved_punc_mask = spk_punc_mask;
  528. if (cnt == 0)
  529. return;
  530. spk_punc_mask = PUNC;
  531. buf[cnt++] = SPACE;
  532. spkup_write(buf, cnt);
  533. spk_punc_mask = saved_punc_mask;
  534. }
  535. static void say_prev_word(struct vc_data *vc)
  536. {
  537. u_char temp;
  538. u16 ch;
  539. enum edge edge_said = edge_none;
  540. u_short last_state = 0, state = 0;
  541. spk_parked |= 0x01;
  542. if (spk_x == 0) {
  543. if (spk_y == 0) {
  544. announce_edge(vc, edge_top);
  545. return;
  546. }
  547. spk_y--;
  548. spk_x = vc->vc_cols;
  549. edge_said = edge_quiet;
  550. }
  551. while (1) {
  552. if (spk_x == 0) {
  553. if (spk_y == 0) {
  554. edge_said = edge_top;
  555. break;
  556. }
  557. if (edge_said != edge_quiet)
  558. edge_said = edge_left;
  559. if (state > 0)
  560. break;
  561. spk_y--;
  562. spk_x = vc->vc_cols - 1;
  563. } else {
  564. spk_x--;
  565. }
  566. spk_pos -= 2;
  567. ch = get_char(vc, (u_short *)spk_pos, &temp);
  568. if (ch == SPACE || ch == 0)
  569. state = 0;
  570. else if (ch < 0x100 && IS_WDLM(ch))
  571. state = 1;
  572. else
  573. state = 2;
  574. if (state < last_state) {
  575. spk_pos += 2;
  576. spk_x++;
  577. break;
  578. }
  579. last_state = state;
  580. }
  581. if (spk_x == 0 && edge_said == edge_quiet)
  582. edge_said = edge_left;
  583. if (edge_said > edge_none && edge_said < edge_quiet)
  584. announce_edge(vc, edge_said);
  585. say_word(vc);
  586. }
  587. static void say_next_word(struct vc_data *vc)
  588. {
  589. u_char temp;
  590. u16 ch;
  591. enum edge edge_said = edge_none;
  592. u_short last_state = 2, state = 0;
  593. spk_parked |= 0x01;
  594. if (spk_x == vc->vc_cols - 1 && spk_y == vc->vc_rows - 1) {
  595. announce_edge(vc, edge_bottom);
  596. return;
  597. }
  598. while (1) {
  599. ch = get_char(vc, (u_short *)spk_pos, &temp);
  600. if (ch == SPACE || ch == 0)
  601. state = 0;
  602. else if (ch < 0x100 && IS_WDLM(ch))
  603. state = 1;
  604. else
  605. state = 2;
  606. if (state > last_state)
  607. break;
  608. if (spk_x >= vc->vc_cols - 1) {
  609. if (spk_y == vc->vc_rows - 1) {
  610. edge_said = edge_bottom;
  611. break;
  612. }
  613. state = 0;
  614. spk_y++;
  615. spk_x = 0;
  616. edge_said = edge_right;
  617. } else {
  618. spk_x++;
  619. }
  620. spk_pos += 2;
  621. last_state = state;
  622. }
  623. if (edge_said > edge_none)
  624. announce_edge(vc, edge_said);
  625. say_word(vc);
  626. }
  627. static void spell_word(struct vc_data *vc)
  628. {
  629. static char const *delay_str[] = { "", ",", ".", ". .", ". . ." };
  630. u16 *cp = buf;
  631. char *cp1;
  632. char *str_cap = spk_str_caps_stop;
  633. char *last_cap = spk_str_caps_stop;
  634. struct var_t *direct = spk_get_var(DIRECT);
  635. u16 ch;
  636. if (!get_word(vc))
  637. return;
  638. while ((ch = *cp)) {
  639. if (cp != buf)
  640. synth_printf(" %s ", delay_str[spk_spell_delay]);
  641. /* FIXME: Non-latin1 considered as lower case */
  642. if (ch < 0x100 && IS_CHAR(ch, B_CAP)) {
  643. str_cap = spk_str_caps_start;
  644. if (*spk_str_caps_stop)
  645. spk_pitch_shift++;
  646. else /* synth has no pitch */
  647. last_cap = spk_str_caps_stop;
  648. } else {
  649. str_cap = spk_str_caps_stop;
  650. }
  651. if (str_cap != last_cap) {
  652. synth_printf("%s", str_cap);
  653. last_cap = str_cap;
  654. }
  655. if (ch >= 0x100 || (direct && direct->u.n.value)) {
  656. synth_putwc_s(ch);
  657. } else if (this_speakup_key == SPELL_PHONETIC &&
  658. ch <= 0x7f && isalpha(ch)) {
  659. ch &= 0x1f;
  660. cp1 = phonetic[--ch];
  661. synth_printf("%s", cp1);
  662. } else {
  663. cp1 = spk_characters[ch];
  664. if (*cp1 == '^') {
  665. synth_printf("%s", spk_msg_get(MSG_CTRL));
  666. cp1++;
  667. }
  668. synth_printf("%s", cp1);
  669. }
  670. cp++;
  671. }
  672. if (str_cap != spk_str_caps_stop)
  673. synth_printf("%s", spk_str_caps_stop);
  674. }
  675. static int get_line(struct vc_data *vc)
  676. {
  677. u_long tmp = spk_pos - (spk_x * 2);
  678. int i = 0;
  679. u_char tmp2;
  680. spk_old_attr = spk_attr;
  681. spk_attr = get_attributes(vc, (u_short *)spk_pos);
  682. for (i = 0; i < vc->vc_cols; i++) {
  683. buf[i] = get_char(vc, (u_short *)tmp, &tmp2);
  684. tmp += 2;
  685. }
  686. for (--i; i >= 0; i--)
  687. if (buf[i] != SPACE)
  688. break;
  689. return ++i;
  690. }
  691. static void say_line(struct vc_data *vc)
  692. {
  693. int i = get_line(vc);
  694. u16 *cp;
  695. u_short saved_punc_mask = spk_punc_mask;
  696. if (i == 0) {
  697. synth_printf("%s\n", spk_msg_get(MSG_BLANK));
  698. return;
  699. }
  700. buf[i++] = '\n';
  701. if (this_speakup_key == SAY_LINE_INDENT) {
  702. cp = buf;
  703. while (*cp == SPACE)
  704. cp++;
  705. synth_printf("%zd, ", (cp - buf) + 1);
  706. }
  707. spk_punc_mask = spk_punc_masks[spk_reading_punc];
  708. spkup_write(buf, i);
  709. spk_punc_mask = saved_punc_mask;
  710. }
  711. static void say_prev_line(struct vc_data *vc)
  712. {
  713. spk_parked |= 0x01;
  714. if (spk_y == 0) {
  715. announce_edge(vc, edge_top);
  716. return;
  717. }
  718. spk_y--;
  719. spk_pos -= vc->vc_size_row;
  720. say_line(vc);
  721. }
  722. static void say_next_line(struct vc_data *vc)
  723. {
  724. spk_parked |= 0x01;
  725. if (spk_y == vc->vc_rows - 1) {
  726. announce_edge(vc, edge_bottom);
  727. return;
  728. }
  729. spk_y++;
  730. spk_pos += vc->vc_size_row;
  731. say_line(vc);
  732. }
  733. static int say_from_to(struct vc_data *vc, u_long from, u_long to,
  734. int read_punc)
  735. {
  736. int i = 0;
  737. u_char tmp;
  738. u_short saved_punc_mask = spk_punc_mask;
  739. spk_old_attr = spk_attr;
  740. spk_attr = get_attributes(vc, (u_short *)from);
  741. while (from < to) {
  742. buf[i++] = get_char(vc, (u_short *)from, &tmp);
  743. from += 2;
  744. if (i >= vc->vc_size_row)
  745. break;
  746. }
  747. for (--i; i >= 0; i--)
  748. if (buf[i] != SPACE)
  749. break;
  750. buf[++i] = SPACE;
  751. buf[++i] = '\0';
  752. if (i < 1)
  753. return i;
  754. if (read_punc)
  755. spk_punc_mask = spk_punc_info[spk_reading_punc].mask;
  756. spkup_write(buf, i);
  757. if (read_punc)
  758. spk_punc_mask = saved_punc_mask;
  759. return i - 1;
  760. }
  761. static void say_line_from_to(struct vc_data *vc, u_long from, u_long to,
  762. int read_punc)
  763. {
  764. u_long start = vc->vc_origin + (spk_y * vc->vc_size_row);
  765. u_long end = start + (to * 2);
  766. start += from * 2;
  767. if (say_from_to(vc, start, end, read_punc) <= 0)
  768. if (cursor_track != read_all_mode)
  769. synth_printf("%s\n", spk_msg_get(MSG_BLANK));
  770. }
  771. /* Sentence Reading Commands */
  772. static int currsentence;
  773. static int numsentences[2];
  774. static u16 *sentbufend[2];
  775. static u16 *sentmarks[2][10];
  776. static int currbuf;
  777. static int bn;
  778. static u16 sentbuf[2][256];
  779. static int say_sentence_num(int num, int prev)
  780. {
  781. bn = currbuf;
  782. currsentence = num + 1;
  783. if (prev && --bn == -1)
  784. bn = 1;
  785. if (num > numsentences[bn])
  786. return 0;
  787. spkup_write(sentmarks[bn][num], sentbufend[bn] - sentmarks[bn][num]);
  788. return 1;
  789. }
  790. static int get_sentence_buf(struct vc_data *vc, int read_punc)
  791. {
  792. u_long start, end;
  793. int i, bn;
  794. u_char tmp;
  795. currbuf++;
  796. if (currbuf == 2)
  797. currbuf = 0;
  798. bn = currbuf;
  799. start = vc->vc_origin + ((spk_y) * vc->vc_size_row);
  800. end = vc->vc_origin + ((spk_y) * vc->vc_size_row) + vc->vc_cols * 2;
  801. numsentences[bn] = 0;
  802. sentmarks[bn][0] = &sentbuf[bn][0];
  803. i = 0;
  804. spk_old_attr = spk_attr;
  805. spk_attr = get_attributes(vc, (u_short *)start);
  806. while (start < end) {
  807. sentbuf[bn][i] = get_char(vc, (u_short *)start, &tmp);
  808. if (i > 0) {
  809. if (sentbuf[bn][i] == SPACE &&
  810. sentbuf[bn][i - 1] == '.' &&
  811. numsentences[bn] < 9) {
  812. /* Sentence Marker */
  813. numsentences[bn]++;
  814. sentmarks[bn][numsentences[bn]] =
  815. &sentbuf[bn][i];
  816. }
  817. }
  818. i++;
  819. start += 2;
  820. if (i >= vc->vc_size_row)
  821. break;
  822. }
  823. for (--i; i >= 0; i--)
  824. if (sentbuf[bn][i] != SPACE)
  825. break;
  826. if (i < 1)
  827. return -1;
  828. sentbuf[bn][++i] = SPACE;
  829. sentbuf[bn][++i] = '\0';
  830. sentbufend[bn] = &sentbuf[bn][i];
  831. return numsentences[bn];
  832. }
  833. static void say_screen_from_to(struct vc_data *vc, u_long from, u_long to)
  834. {
  835. u_long start = vc->vc_origin, end;
  836. if (from > 0)
  837. start += from * vc->vc_size_row;
  838. if (to > vc->vc_rows)
  839. to = vc->vc_rows;
  840. end = vc->vc_origin + (to * vc->vc_size_row);
  841. for (from = start; from < end; from = to) {
  842. to = from + vc->vc_size_row;
  843. say_from_to(vc, from, to, 1);
  844. }
  845. }
  846. static void say_screen(struct vc_data *vc)
  847. {
  848. say_screen_from_to(vc, 0, vc->vc_rows);
  849. }
  850. static void speakup_win_say(struct vc_data *vc)
  851. {
  852. u_long start, end, from, to;
  853. if (win_start < 2) {
  854. synth_printf("%s\n", spk_msg_get(MSG_NO_WINDOW));
  855. return;
  856. }
  857. start = vc->vc_origin + (win_top * vc->vc_size_row);
  858. end = vc->vc_origin + (win_bottom * vc->vc_size_row);
  859. while (start <= end) {
  860. from = start + (win_left * 2);
  861. to = start + (win_right * 2);
  862. say_from_to(vc, from, to, 1);
  863. start += vc->vc_size_row;
  864. }
  865. }
  866. static void top_edge(struct vc_data *vc)
  867. {
  868. spk_parked |= 0x01;
  869. spk_pos = vc->vc_origin + 2 * spk_x;
  870. spk_y = 0;
  871. say_line(vc);
  872. }
  873. static void bottom_edge(struct vc_data *vc)
  874. {
  875. spk_parked |= 0x01;
  876. spk_pos += (vc->vc_rows - spk_y - 1) * vc->vc_size_row;
  877. spk_y = vc->vc_rows - 1;
  878. say_line(vc);
  879. }
  880. static void left_edge(struct vc_data *vc)
  881. {
  882. spk_parked |= 0x01;
  883. spk_pos -= spk_x * 2;
  884. spk_x = 0;
  885. say_char(vc);
  886. }
  887. static void right_edge(struct vc_data *vc)
  888. {
  889. spk_parked |= 0x01;
  890. spk_pos += (vc->vc_cols - spk_x - 1) * 2;
  891. spk_x = vc->vc_cols - 1;
  892. say_char(vc);
  893. }
  894. static void say_first_char(struct vc_data *vc)
  895. {
  896. int i, len = get_line(vc);
  897. u16 ch;
  898. spk_parked |= 0x01;
  899. if (len == 0) {
  900. synth_printf("%s\n", spk_msg_get(MSG_BLANK));
  901. return;
  902. }
  903. for (i = 0; i < len; i++)
  904. if (buf[i] != SPACE)
  905. break;
  906. ch = buf[i];
  907. spk_pos -= (spk_x - i) * 2;
  908. spk_x = i;
  909. synth_printf("%d, ", ++i);
  910. speak_char(ch);
  911. }
  912. static void say_last_char(struct vc_data *vc)
  913. {
  914. int len = get_line(vc);
  915. u16 ch;
  916. spk_parked |= 0x01;
  917. if (len == 0) {
  918. synth_printf("%s\n", spk_msg_get(MSG_BLANK));
  919. return;
  920. }
  921. ch = buf[--len];
  922. spk_pos -= (spk_x - len) * 2;
  923. spk_x = len;
  924. synth_printf("%d, ", ++len);
  925. speak_char(ch);
  926. }
  927. static void say_position(struct vc_data *vc)
  928. {
  929. synth_printf(spk_msg_get(MSG_POS_INFO), spk_y + 1, spk_x + 1,
  930. vc->vc_num + 1);
  931. synth_printf("\n");
  932. }
  933. /* Added by brianb */
  934. static void say_char_num(struct vc_data *vc)
  935. {
  936. u_char tmp;
  937. u16 ch = get_char(vc, (u_short *)spk_pos, &tmp);
  938. synth_printf(spk_msg_get(MSG_CHAR_INFO), ch, ch);
  939. }
  940. /* these are stub functions to keep keyboard.c happy. */
  941. static void say_from_top(struct vc_data *vc)
  942. {
  943. say_screen_from_to(vc, 0, spk_y);
  944. }
  945. static void say_to_bottom(struct vc_data *vc)
  946. {
  947. say_screen_from_to(vc, spk_y, vc->vc_rows);
  948. }
  949. static void say_from_left(struct vc_data *vc)
  950. {
  951. say_line_from_to(vc, 0, spk_x, 1);
  952. }
  953. static void say_to_right(struct vc_data *vc)
  954. {
  955. say_line_from_to(vc, spk_x, vc->vc_cols, 1);
  956. }
  957. /* end of stub functions. */
  958. static void spkup_write(const u16 *in_buf, int count)
  959. {
  960. static int rep_count;
  961. static u16 ch = '\0', old_ch = '\0';
  962. static u_short char_type, last_type;
  963. int in_count = count;
  964. spk_keydown = 0;
  965. while (count--) {
  966. if (cursor_track == read_all_mode) {
  967. /* Insert Sentence Index */
  968. if ((in_buf == sentmarks[bn][currsentence]) &&
  969. (currsentence <= numsentences[bn]))
  970. synth_insert_next_index(currsentence++);
  971. }
  972. ch = *in_buf++;
  973. if (ch < 0x100)
  974. char_type = spk_chartab[ch];
  975. else
  976. char_type = ALPHA;
  977. if (ch == old_ch && !(char_type & B_NUM)) {
  978. if (++rep_count > 2)
  979. continue;
  980. } else {
  981. if ((last_type & CH_RPT) && rep_count > 2) {
  982. synth_printf(" ");
  983. synth_printf(spk_msg_get(MSG_REPEAT_DESC),
  984. ++rep_count);
  985. synth_printf(" ");
  986. }
  987. rep_count = 0;
  988. }
  989. if (ch == spk_lastkey) {
  990. rep_count = 0;
  991. if (spk_key_echo == 1 && ch >= MINECHOCHAR)
  992. speak_char(ch);
  993. } else if (char_type & B_ALPHA) {
  994. if ((synth_flags & SF_DEC) && (last_type & PUNC))
  995. synth_buffer_add(SPACE);
  996. synth_putwc_s(ch);
  997. } else if (char_type & B_NUM) {
  998. rep_count = 0;
  999. synth_putwc_s(ch);
  1000. } else if (char_type & spk_punc_mask) {
  1001. speak_char(ch);
  1002. char_type &= ~PUNC; /* for dec nospell processing */
  1003. } else if (char_type & SYNTH_OK) {
  1004. /* these are usually puncts like . and , which synth
  1005. * needs for expression.
  1006. * suppress multiple to get rid of long pauses and
  1007. * clear repeat count
  1008. * so if someone has
  1009. * repeats on you don't get nothing repeated count
  1010. */
  1011. if (ch != old_ch)
  1012. synth_putwc_s(ch);
  1013. else
  1014. rep_count = 0;
  1015. } else {
  1016. /* send space and record position, if next is num overwrite space */
  1017. if (old_ch != ch)
  1018. synth_buffer_add(SPACE);
  1019. else
  1020. rep_count = 0;
  1021. }
  1022. old_ch = ch;
  1023. last_type = char_type;
  1024. }
  1025. spk_lastkey = 0;
  1026. if (in_count > 2 && rep_count > 2) {
  1027. if (last_type & CH_RPT) {
  1028. synth_printf(" ");
  1029. synth_printf(spk_msg_get(MSG_REPEAT_DESC2),
  1030. ++rep_count);
  1031. synth_printf(" ");
  1032. }
  1033. rep_count = 0;
  1034. }
  1035. }
  1036. static const int NUM_CTL_LABELS = (MSG_CTL_END - MSG_CTL_START + 1);
  1037. static void read_all_doc(struct vc_data *vc);
  1038. static void cursor_done(struct timer_list *unused);
  1039. static DEFINE_TIMER(cursor_timer, cursor_done);
  1040. static void do_handle_shift(struct vc_data *vc, u_char value, char up_flag)
  1041. {
  1042. unsigned long flags;
  1043. if (!synth || up_flag || spk_killed)
  1044. return;
  1045. spin_lock_irqsave(&speakup_info.spinlock, flags);
  1046. if (cursor_track == read_all_mode) {
  1047. switch (value) {
  1048. case KVAL(K_SHIFT):
  1049. del_timer(&cursor_timer);
  1050. spk_shut_up &= 0xfe;
  1051. spk_do_flush();
  1052. read_all_doc(vc);
  1053. break;
  1054. case KVAL(K_CTRL):
  1055. del_timer(&cursor_timer);
  1056. cursor_track = prev_cursor_track;
  1057. spk_shut_up &= 0xfe;
  1058. spk_do_flush();
  1059. break;
  1060. }
  1061. } else {
  1062. spk_shut_up &= 0xfe;
  1063. spk_do_flush();
  1064. }
  1065. if (spk_say_ctrl && value < NUM_CTL_LABELS)
  1066. synth_printf("%s", spk_msg_get(MSG_CTL_START + value));
  1067. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1068. }
  1069. static void do_handle_latin(struct vc_data *vc, u_char value, char up_flag)
  1070. {
  1071. unsigned long flags;
  1072. spin_lock_irqsave(&speakup_info.spinlock, flags);
  1073. if (up_flag) {
  1074. spk_lastkey = 0;
  1075. spk_keydown = 0;
  1076. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1077. return;
  1078. }
  1079. if (!synth || spk_killed) {
  1080. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1081. return;
  1082. }
  1083. spk_shut_up &= 0xfe;
  1084. spk_lastkey = value;
  1085. spk_keydown++;
  1086. spk_parked &= 0xfe;
  1087. if (spk_key_echo == 2 && value >= MINECHOCHAR)
  1088. speak_char(value);
  1089. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1090. }
  1091. int spk_set_key_info(const u_char *key_info, u_char *k_buffer)
  1092. {
  1093. int i = 0, states, key_data_len;
  1094. const u_char *cp = key_info;
  1095. u_char *cp1 = k_buffer;
  1096. u_char ch, version, num_keys;
  1097. version = *cp++;
  1098. if (version != KEY_MAP_VER) {
  1099. pr_debug("version found %d should be %d\n",
  1100. version, KEY_MAP_VER);
  1101. return -EINVAL;
  1102. }
  1103. num_keys = *cp;
  1104. states = (int)cp[1];
  1105. key_data_len = (states + 1) * (num_keys + 1);
  1106. if (key_data_len + SHIFT_TBL_SIZE + 4 >= sizeof(spk_key_buf)) {
  1107. pr_debug("too many key_infos (%d over %u)\n",
  1108. key_data_len + SHIFT_TBL_SIZE + 4,
  1109. (unsigned int)(sizeof(spk_key_buf)));
  1110. return -EINVAL;
  1111. }
  1112. memset(k_buffer, 0, SHIFT_TBL_SIZE);
  1113. memset(spk_our_keys, 0, sizeof(spk_our_keys));
  1114. spk_shift_table = k_buffer;
  1115. spk_our_keys[0] = spk_shift_table;
  1116. cp1 += SHIFT_TBL_SIZE;
  1117. memcpy(cp1, cp, key_data_len + 3);
  1118. /* get num_keys, states and data */
  1119. cp1 += 2; /* now pointing at shift states */
  1120. for (i = 1; i <= states; i++) {
  1121. ch = *cp1++;
  1122. if (ch >= SHIFT_TBL_SIZE) {
  1123. pr_debug("(%d) not valid shift state (max_allowed = %d)\n",
  1124. ch, SHIFT_TBL_SIZE);
  1125. return -EINVAL;
  1126. }
  1127. spk_shift_table[ch] = i;
  1128. }
  1129. keymap_flags = *cp1++;
  1130. while ((ch = *cp1)) {
  1131. if (ch >= MAX_KEY) {
  1132. pr_debug("(%d), not valid key, (max_allowed = %d)\n",
  1133. ch, MAX_KEY);
  1134. return -EINVAL;
  1135. }
  1136. spk_our_keys[ch] = cp1;
  1137. cp1 += states + 1;
  1138. }
  1139. return 0;
  1140. }
  1141. static struct var_t spk_vars[] = {
  1142. /* bell must be first to set high limit */
  1143. {BELL_POS, .u.n = {NULL, 0, 0, 0, 0, 0, NULL} },
  1144. {SPELL_DELAY, .u.n = {NULL, 0, 0, 4, 0, 0, NULL} },
  1145. {ATTRIB_BLEEP, .u.n = {NULL, 1, 0, 3, 0, 0, NULL} },
  1146. {BLEEPS, .u.n = {NULL, 3, 0, 3, 0, 0, NULL} },
  1147. {BLEEP_TIME, .u.n = {NULL, 30, 1, 200, 0, 0, NULL} },
  1148. {PUNC_LEVEL, .u.n = {NULL, 1, 0, 4, 0, 0, NULL} },
  1149. {READING_PUNC, .u.n = {NULL, 1, 0, 4, 0, 0, NULL} },
  1150. {CURSOR_TIME, .u.n = {NULL, 120, 50, 600, 0, 0, NULL} },
  1151. {SAY_CONTROL, TOGGLE_0},
  1152. {SAY_WORD_CTL, TOGGLE_0},
  1153. {NO_INTERRUPT, TOGGLE_0},
  1154. {KEY_ECHO, .u.n = {NULL, 1, 0, 2, 0, 0, NULL} },
  1155. V_LAST_VAR
  1156. };
  1157. static void toggle_cursoring(struct vc_data *vc)
  1158. {
  1159. if (cursor_track == read_all_mode)
  1160. cursor_track = prev_cursor_track;
  1161. if (++cursor_track >= CT_Max)
  1162. cursor_track = 0;
  1163. synth_printf("%s\n", spk_msg_get(MSG_CURSOR_MSGS_START + cursor_track));
  1164. }
  1165. void spk_reset_default_chars(void)
  1166. {
  1167. int i;
  1168. /* First, free any non-default */
  1169. for (i = 0; i < 256; i++) {
  1170. if (spk_characters[i] &&
  1171. (spk_characters[i] != spk_default_chars[i]))
  1172. kfree(spk_characters[i]);
  1173. }
  1174. memcpy(spk_characters, spk_default_chars, sizeof(spk_default_chars));
  1175. }
  1176. void spk_reset_default_chartab(void)
  1177. {
  1178. memcpy(spk_chartab, default_chartab, sizeof(default_chartab));
  1179. }
  1180. static const struct st_bits_data *pb_edit;
  1181. static int edit_bits(struct vc_data *vc, u_char type, u_char ch, u_short key)
  1182. {
  1183. short mask = pb_edit->mask, ch_type = spk_chartab[ch];
  1184. if (type != KT_LATIN || (ch_type & B_NUM) || ch < SPACE)
  1185. return -1;
  1186. if (ch == SPACE) {
  1187. synth_printf("%s\n", spk_msg_get(MSG_EDIT_DONE));
  1188. spk_special_handler = NULL;
  1189. return 1;
  1190. }
  1191. if (mask < PUNC && !(ch_type & PUNC))
  1192. return -1;
  1193. spk_chartab[ch] ^= mask;
  1194. speak_char(ch);
  1195. synth_printf(" %s\n",
  1196. (spk_chartab[ch] & mask) ? spk_msg_get(MSG_ON) :
  1197. spk_msg_get(MSG_OFF));
  1198. return 1;
  1199. }
  1200. /* Allocation concurrency is protected by the console semaphore */
  1201. static int speakup_allocate(struct vc_data *vc, gfp_t gfp_flags)
  1202. {
  1203. int vc_num;
  1204. vc_num = vc->vc_num;
  1205. if (!speakup_console[vc_num]) {
  1206. speakup_console[vc_num] = kzalloc(sizeof(*speakup_console[0]),
  1207. gfp_flags);
  1208. if (!speakup_console[vc_num])
  1209. return -ENOMEM;
  1210. speakup_date(vc);
  1211. } else if (!spk_parked) {
  1212. speakup_date(vc);
  1213. }
  1214. return 0;
  1215. }
  1216. static void speakup_deallocate(struct vc_data *vc)
  1217. {
  1218. int vc_num;
  1219. vc_num = vc->vc_num;
  1220. kfree(speakup_console[vc_num]);
  1221. speakup_console[vc_num] = NULL;
  1222. }
  1223. enum read_all_command {
  1224. RA_NEXT_SENT = KVAL(K_DOWN)+1,
  1225. RA_PREV_LINE = KVAL(K_LEFT)+1,
  1226. RA_NEXT_LINE = KVAL(K_RIGHT)+1,
  1227. RA_PREV_SENT = KVAL(K_UP)+1,
  1228. RA_DOWN_ARROW,
  1229. RA_TIMER,
  1230. RA_FIND_NEXT_SENT,
  1231. RA_FIND_PREV_SENT,
  1232. };
  1233. static u_char is_cursor;
  1234. static u_long old_cursor_pos, old_cursor_x, old_cursor_y;
  1235. static int cursor_con;
  1236. static void reset_highlight_buffers(struct vc_data *);
  1237. static enum read_all_command read_all_key;
  1238. static int in_keyboard_notifier;
  1239. static void start_read_all_timer(struct vc_data *vc, enum read_all_command command);
  1240. static void kbd_fakekey2(struct vc_data *vc, enum read_all_command command)
  1241. {
  1242. del_timer(&cursor_timer);
  1243. speakup_fake_down_arrow();
  1244. start_read_all_timer(vc, command);
  1245. }
  1246. static void read_all_doc(struct vc_data *vc)
  1247. {
  1248. if ((vc->vc_num != fg_console) || !synth || spk_shut_up)
  1249. return;
  1250. if (!synth_supports_indexing())
  1251. return;
  1252. if (cursor_track != read_all_mode)
  1253. prev_cursor_track = cursor_track;
  1254. cursor_track = read_all_mode;
  1255. spk_reset_index_count(0);
  1256. if (get_sentence_buf(vc, 0) == -1) {
  1257. del_timer(&cursor_timer);
  1258. if (!in_keyboard_notifier)
  1259. speakup_fake_down_arrow();
  1260. start_read_all_timer(vc, RA_DOWN_ARROW);
  1261. } else {
  1262. say_sentence_num(0, 0);
  1263. synth_insert_next_index(0);
  1264. start_read_all_timer(vc, RA_TIMER);
  1265. }
  1266. }
  1267. static void stop_read_all(struct vc_data *vc)
  1268. {
  1269. del_timer(&cursor_timer);
  1270. cursor_track = prev_cursor_track;
  1271. spk_shut_up &= 0xfe;
  1272. spk_do_flush();
  1273. }
  1274. static void start_read_all_timer(struct vc_data *vc, enum read_all_command command)
  1275. {
  1276. struct var_t *cursor_timeout;
  1277. cursor_con = vc->vc_num;
  1278. read_all_key = command;
  1279. cursor_timeout = spk_get_var(CURSOR_TIME);
  1280. mod_timer(&cursor_timer,
  1281. jiffies + msecs_to_jiffies(cursor_timeout->u.n.value));
  1282. }
  1283. static void handle_cursor_read_all(struct vc_data *vc, enum read_all_command command)
  1284. {
  1285. int indcount, sentcount, rv, sn;
  1286. switch (command) {
  1287. case RA_NEXT_SENT:
  1288. /* Get Current Sentence */
  1289. spk_get_index_count(&indcount, &sentcount);
  1290. /*printk("%d %d ", indcount, sentcount); */
  1291. spk_reset_index_count(sentcount + 1);
  1292. if (indcount == 1) {
  1293. if (!say_sentence_num(sentcount + 1, 0)) {
  1294. kbd_fakekey2(vc, RA_FIND_NEXT_SENT);
  1295. return;
  1296. }
  1297. synth_insert_next_index(0);
  1298. } else {
  1299. sn = 0;
  1300. if (!say_sentence_num(sentcount + 1, 1)) {
  1301. sn = 1;
  1302. spk_reset_index_count(sn);
  1303. } else {
  1304. synth_insert_next_index(0);
  1305. }
  1306. if (!say_sentence_num(sn, 0)) {
  1307. kbd_fakekey2(vc, RA_FIND_NEXT_SENT);
  1308. return;
  1309. }
  1310. synth_insert_next_index(0);
  1311. }
  1312. start_read_all_timer(vc, RA_TIMER);
  1313. break;
  1314. case RA_PREV_SENT:
  1315. break;
  1316. case RA_NEXT_LINE:
  1317. read_all_doc(vc);
  1318. break;
  1319. case RA_PREV_LINE:
  1320. break;
  1321. case RA_DOWN_ARROW:
  1322. if (get_sentence_buf(vc, 0) == -1) {
  1323. kbd_fakekey2(vc, RA_DOWN_ARROW);
  1324. } else {
  1325. say_sentence_num(0, 0);
  1326. synth_insert_next_index(0);
  1327. start_read_all_timer(vc, RA_TIMER);
  1328. }
  1329. break;
  1330. case RA_FIND_NEXT_SENT:
  1331. rv = get_sentence_buf(vc, 0);
  1332. if (rv == -1)
  1333. read_all_doc(vc);
  1334. if (rv == 0) {
  1335. kbd_fakekey2(vc, RA_FIND_NEXT_SENT);
  1336. } else {
  1337. say_sentence_num(1, 0);
  1338. synth_insert_next_index(0);
  1339. start_read_all_timer(vc, RA_TIMER);
  1340. }
  1341. break;
  1342. case RA_FIND_PREV_SENT:
  1343. break;
  1344. case RA_TIMER:
  1345. spk_get_index_count(&indcount, &sentcount);
  1346. if (indcount < 2)
  1347. kbd_fakekey2(vc, RA_DOWN_ARROW);
  1348. else
  1349. start_read_all_timer(vc, RA_TIMER);
  1350. break;
  1351. }
  1352. }
  1353. static int pre_handle_cursor(struct vc_data *vc, u_char value, char up_flag)
  1354. {
  1355. unsigned long flags;
  1356. spin_lock_irqsave(&speakup_info.spinlock, flags);
  1357. if (cursor_track == read_all_mode) {
  1358. spk_parked &= 0xfe;
  1359. if (!synth || up_flag || spk_shut_up) {
  1360. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1361. return NOTIFY_STOP;
  1362. }
  1363. del_timer(&cursor_timer);
  1364. spk_shut_up &= 0xfe;
  1365. spk_do_flush();
  1366. start_read_all_timer(vc, value + 1);
  1367. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1368. return NOTIFY_STOP;
  1369. }
  1370. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1371. return NOTIFY_OK;
  1372. }
  1373. static void do_handle_cursor(struct vc_data *vc, u_char value, char up_flag)
  1374. {
  1375. unsigned long flags;
  1376. struct var_t *cursor_timeout;
  1377. spin_lock_irqsave(&speakup_info.spinlock, flags);
  1378. spk_parked &= 0xfe;
  1379. if (!synth || up_flag || spk_shut_up || cursor_track == CT_Off) {
  1380. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1381. return;
  1382. }
  1383. spk_shut_up &= 0xfe;
  1384. if (spk_no_intr)
  1385. spk_do_flush();
  1386. /* the key press flushes if !no_inter but we want to flush on cursor
  1387. * moves regardless of no_inter state
  1388. */
  1389. is_cursor = value + 1;
  1390. old_cursor_pos = vc->vc_pos;
  1391. old_cursor_x = vc->state.x;
  1392. old_cursor_y = vc->state.y;
  1393. speakup_console[vc->vc_num]->ht.cy = vc->state.y;
  1394. cursor_con = vc->vc_num;
  1395. if (cursor_track == CT_Highlight)
  1396. reset_highlight_buffers(vc);
  1397. cursor_timeout = spk_get_var(CURSOR_TIME);
  1398. mod_timer(&cursor_timer,
  1399. jiffies + msecs_to_jiffies(cursor_timeout->u.n.value));
  1400. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1401. }
  1402. static void update_color_buffer(struct vc_data *vc, const u16 *ic, int len)
  1403. {
  1404. int i, bi, hi;
  1405. int vc_num = vc->vc_num;
  1406. bi = (vc->vc_attr & 0x70) >> 4;
  1407. hi = speakup_console[vc_num]->ht.highsize[bi];
  1408. i = 0;
  1409. if (speakup_console[vc_num]->ht.highsize[bi] == 0) {
  1410. speakup_console[vc_num]->ht.rpos[bi] = vc->vc_pos;
  1411. speakup_console[vc_num]->ht.rx[bi] = vc->state.x;
  1412. speakup_console[vc_num]->ht.ry[bi] = vc->state.y;
  1413. }
  1414. while ((hi < COLOR_BUFFER_SIZE) && (i < len)) {
  1415. if (ic[i] > 32) {
  1416. speakup_console[vc_num]->ht.highbuf[bi][hi] = ic[i];
  1417. hi++;
  1418. } else if ((ic[i] == 32) && (hi != 0)) {
  1419. if (speakup_console[vc_num]->ht.highbuf[bi][hi - 1] !=
  1420. 32) {
  1421. speakup_console[vc_num]->ht.highbuf[bi][hi] =
  1422. ic[i];
  1423. hi++;
  1424. }
  1425. }
  1426. i++;
  1427. }
  1428. speakup_console[vc_num]->ht.highsize[bi] = hi;
  1429. }
  1430. static void reset_highlight_buffers(struct vc_data *vc)
  1431. {
  1432. int i;
  1433. int vc_num = vc->vc_num;
  1434. for (i = 0; i < 8; i++)
  1435. speakup_console[vc_num]->ht.highsize[i] = 0;
  1436. }
  1437. static int count_highlight_color(struct vc_data *vc)
  1438. {
  1439. int i, bg;
  1440. int cc;
  1441. int vc_num = vc->vc_num;
  1442. u16 ch;
  1443. u16 *start = (u16 *)vc->vc_origin;
  1444. for (i = 0; i < 8; i++)
  1445. speakup_console[vc_num]->ht.bgcount[i] = 0;
  1446. for (i = 0; i < vc->vc_rows; i++) {
  1447. u16 *end = start + vc->vc_cols * 2;
  1448. u16 *ptr;
  1449. for (ptr = start; ptr < end; ptr++) {
  1450. ch = get_attributes(vc, ptr);
  1451. bg = (ch & 0x70) >> 4;
  1452. speakup_console[vc_num]->ht.bgcount[bg]++;
  1453. }
  1454. start += vc->vc_size_row;
  1455. }
  1456. cc = 0;
  1457. for (i = 0; i < 8; i++)
  1458. if (speakup_console[vc_num]->ht.bgcount[i] > 0)
  1459. cc++;
  1460. return cc;
  1461. }
  1462. static int get_highlight_color(struct vc_data *vc)
  1463. {
  1464. int i, j;
  1465. unsigned int cptr[8];
  1466. int vc_num = vc->vc_num;
  1467. for (i = 0; i < 8; i++)
  1468. cptr[i] = i;
  1469. for (i = 0; i < 7; i++)
  1470. for (j = i + 1; j < 8; j++)
  1471. if (speakup_console[vc_num]->ht.bgcount[cptr[i]] >
  1472. speakup_console[vc_num]->ht.bgcount[cptr[j]])
  1473. swap(cptr[i], cptr[j]);
  1474. for (i = 0; i < 8; i++)
  1475. if (speakup_console[vc_num]->ht.bgcount[cptr[i]] != 0)
  1476. if (speakup_console[vc_num]->ht.highsize[cptr[i]] > 0)
  1477. return cptr[i];
  1478. return -1;
  1479. }
  1480. static int speak_highlight(struct vc_data *vc)
  1481. {
  1482. int hc, d;
  1483. int vc_num = vc->vc_num;
  1484. if (count_highlight_color(vc) == 1)
  1485. return 0;
  1486. hc = get_highlight_color(vc);
  1487. if (hc != -1) {
  1488. d = vc->state.y - speakup_console[vc_num]->ht.cy;
  1489. if ((d == 1) || (d == -1))
  1490. if (speakup_console[vc_num]->ht.ry[hc] != vc->state.y)
  1491. return 0;
  1492. spk_parked |= 0x01;
  1493. spk_do_flush();
  1494. spkup_write(speakup_console[vc_num]->ht.highbuf[hc],
  1495. speakup_console[vc_num]->ht.highsize[hc]);
  1496. spk_pos = spk_cp = speakup_console[vc_num]->ht.rpos[hc];
  1497. spk_x = spk_cx = speakup_console[vc_num]->ht.rx[hc];
  1498. spk_y = spk_cy = speakup_console[vc_num]->ht.ry[hc];
  1499. return 1;
  1500. }
  1501. return 0;
  1502. }
  1503. static void cursor_done(struct timer_list *unused)
  1504. {
  1505. struct vc_data *vc = vc_cons[cursor_con].d;
  1506. unsigned long flags;
  1507. del_timer(&cursor_timer);
  1508. spin_lock_irqsave(&speakup_info.spinlock, flags);
  1509. if (cursor_con != fg_console) {
  1510. is_cursor = 0;
  1511. goto out;
  1512. }
  1513. speakup_date(vc);
  1514. if (win_enabled) {
  1515. if (vc->state.x >= win_left && vc->state.x <= win_right &&
  1516. vc->state.y >= win_top && vc->state.y <= win_bottom) {
  1517. spk_keydown = 0;
  1518. is_cursor = 0;
  1519. goto out;
  1520. }
  1521. }
  1522. if (cursor_track == read_all_mode) {
  1523. handle_cursor_read_all(vc, read_all_key);
  1524. goto out;
  1525. }
  1526. if (cursor_track == CT_Highlight) {
  1527. if (speak_highlight(vc)) {
  1528. spk_keydown = 0;
  1529. is_cursor = 0;
  1530. goto out;
  1531. }
  1532. }
  1533. if (cursor_track == CT_Window)
  1534. speakup_win_say(vc);
  1535. else if (is_cursor == 1 || is_cursor == 4)
  1536. say_line_from_to(vc, 0, vc->vc_cols, 0);
  1537. else
  1538. say_char(vc);
  1539. spk_keydown = 0;
  1540. is_cursor = 0;
  1541. out:
  1542. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1543. }
  1544. /* called by: vt_notifier_call() */
  1545. static void speakup_bs(struct vc_data *vc)
  1546. {
  1547. unsigned long flags;
  1548. if (!speakup_console[vc->vc_num])
  1549. return;
  1550. if (!spin_trylock_irqsave(&speakup_info.spinlock, flags))
  1551. /* Speakup output, discard */
  1552. return;
  1553. if (!spk_parked)
  1554. speakup_date(vc);
  1555. if (spk_shut_up || !synth) {
  1556. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1557. return;
  1558. }
  1559. if (vc->vc_num == fg_console && spk_keydown) {
  1560. spk_keydown = 0;
  1561. if (!is_cursor)
  1562. say_char(vc);
  1563. }
  1564. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1565. }
  1566. /* called by: vt_notifier_call() */
  1567. static void speakup_con_write(struct vc_data *vc, u16 *str, int len)
  1568. {
  1569. unsigned long flags;
  1570. if ((vc->vc_num != fg_console) || spk_shut_up || !synth)
  1571. return;
  1572. if (!spin_trylock_irqsave(&speakup_info.spinlock, flags))
  1573. /* Speakup output, discard */
  1574. return;
  1575. if (spk_bell_pos && spk_keydown && (vc->state.x == spk_bell_pos - 1))
  1576. bleep(3);
  1577. if ((is_cursor) || (cursor_track == read_all_mode)) {
  1578. if (cursor_track == CT_Highlight)
  1579. update_color_buffer(vc, str, len);
  1580. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1581. return;
  1582. }
  1583. if (win_enabled) {
  1584. if (vc->state.x >= win_left && vc->state.x <= win_right &&
  1585. vc->state.y >= win_top && vc->state.y <= win_bottom) {
  1586. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1587. return;
  1588. }
  1589. }
  1590. spkup_write(str, len);
  1591. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1592. }
  1593. static void speakup_con_update(struct vc_data *vc)
  1594. {
  1595. unsigned long flags;
  1596. if (!speakup_console[vc->vc_num] || spk_parked || !synth)
  1597. return;
  1598. if (!spin_trylock_irqsave(&speakup_info.spinlock, flags))
  1599. /* Speakup output, discard */
  1600. return;
  1601. speakup_date(vc);
  1602. if (vc->vc_mode == KD_GRAPHICS && !spk_paused && spk_str_pause[0]) {
  1603. synth_printf("%s", spk_str_pause);
  1604. spk_paused = true;
  1605. }
  1606. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1607. }
  1608. static void do_handle_spec(struct vc_data *vc, u_char value, char up_flag)
  1609. {
  1610. unsigned long flags;
  1611. int on_off = 2;
  1612. char *label;
  1613. if (!synth || up_flag || spk_killed)
  1614. return;
  1615. spin_lock_irqsave(&speakup_info.spinlock, flags);
  1616. spk_shut_up &= 0xfe;
  1617. if (spk_no_intr)
  1618. spk_do_flush();
  1619. switch (value) {
  1620. case KVAL(K_CAPS):
  1621. label = spk_msg_get(MSG_KEYNAME_CAPSLOCK);
  1622. on_off = vt_get_leds(fg_console, VC_CAPSLOCK);
  1623. break;
  1624. case KVAL(K_NUM):
  1625. label = spk_msg_get(MSG_KEYNAME_NUMLOCK);
  1626. on_off = vt_get_leds(fg_console, VC_NUMLOCK);
  1627. break;
  1628. case KVAL(K_HOLD):
  1629. label = spk_msg_get(MSG_KEYNAME_SCROLLLOCK);
  1630. on_off = vt_get_leds(fg_console, VC_SCROLLOCK);
  1631. if (speakup_console[vc->vc_num])
  1632. speakup_console[vc->vc_num]->tty_stopped = on_off;
  1633. break;
  1634. default:
  1635. spk_parked &= 0xfe;
  1636. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1637. return;
  1638. }
  1639. if (on_off < 2)
  1640. synth_printf("%s %s\n",
  1641. label, spk_msg_get(MSG_STATUS_START + on_off));
  1642. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1643. }
  1644. static int inc_dec_var(u_char value)
  1645. {
  1646. struct st_var_header *p_header;
  1647. struct var_t *var_data;
  1648. char num_buf[32];
  1649. char *cp = num_buf;
  1650. char *pn;
  1651. int var_id = (int)value - VAR_START;
  1652. int how = (var_id & 1) ? E_INC : E_DEC;
  1653. var_id = var_id / 2 + FIRST_SET_VAR;
  1654. p_header = spk_get_var_header(var_id);
  1655. if (!p_header)
  1656. return -1;
  1657. if (p_header->var_type != VAR_NUM)
  1658. return -1;
  1659. var_data = p_header->data;
  1660. if (spk_set_num_var(1, p_header, how) != 0)
  1661. return -1;
  1662. if (!spk_close_press) {
  1663. for (pn = p_header->name; *pn; pn++) {
  1664. if (*pn == '_')
  1665. *cp = SPACE;
  1666. else
  1667. *cp++ = *pn;
  1668. }
  1669. }
  1670. snprintf(cp, sizeof(num_buf) - (cp - num_buf), " %d ",
  1671. var_data->u.n.value);
  1672. synth_printf("%s", num_buf);
  1673. return 0;
  1674. }
  1675. static void speakup_win_set(struct vc_data *vc)
  1676. {
  1677. char info[40];
  1678. if (win_start > 1) {
  1679. synth_printf("%s\n", spk_msg_get(MSG_WINDOW_ALREADY_SET));
  1680. return;
  1681. }
  1682. if (spk_x < win_left || spk_y < win_top) {
  1683. synth_printf("%s\n", spk_msg_get(MSG_END_BEFORE_START));
  1684. return;
  1685. }
  1686. if (win_start && spk_x == win_left && spk_y == win_top) {
  1687. win_left = 0;
  1688. win_right = vc->vc_cols - 1;
  1689. win_bottom = spk_y;
  1690. snprintf(info, sizeof(info), spk_msg_get(MSG_WINDOW_LINE),
  1691. (int)win_top + 1);
  1692. } else {
  1693. if (!win_start) {
  1694. win_top = spk_y;
  1695. win_left = spk_x;
  1696. } else {
  1697. win_bottom = spk_y;
  1698. win_right = spk_x;
  1699. }
  1700. snprintf(info, sizeof(info), spk_msg_get(MSG_WINDOW_BOUNDARY),
  1701. (win_start) ?
  1702. spk_msg_get(MSG_END) : spk_msg_get(MSG_START),
  1703. (int)spk_y + 1, (int)spk_x + 1);
  1704. }
  1705. synth_printf("%s\n", info);
  1706. win_start++;
  1707. }
  1708. static void speakup_win_clear(struct vc_data *vc)
  1709. {
  1710. win_top = 0;
  1711. win_bottom = 0;
  1712. win_left = 0;
  1713. win_right = 0;
  1714. win_start = 0;
  1715. synth_printf("%s\n", spk_msg_get(MSG_WINDOW_CLEARED));
  1716. }
  1717. static void speakup_win_enable(struct vc_data *vc)
  1718. {
  1719. if (win_start < 2) {
  1720. synth_printf("%s\n", spk_msg_get(MSG_NO_WINDOW));
  1721. return;
  1722. }
  1723. win_enabled ^= 1;
  1724. if (win_enabled)
  1725. synth_printf("%s\n", spk_msg_get(MSG_WINDOW_SILENCED));
  1726. else
  1727. synth_printf("%s\n", spk_msg_get(MSG_WINDOW_SILENCE_DISABLED));
  1728. }
  1729. static void speakup_bits(struct vc_data *vc)
  1730. {
  1731. int val = this_speakup_key - (FIRST_EDIT_BITS - 1);
  1732. if (spk_special_handler || val < 1 || val > 6) {
  1733. synth_printf("%s\n", spk_msg_get(MSG_ERROR));
  1734. return;
  1735. }
  1736. pb_edit = &spk_punc_info[val];
  1737. synth_printf(spk_msg_get(MSG_EDIT_PROMPT), pb_edit->name);
  1738. spk_special_handler = edit_bits;
  1739. }
  1740. static int handle_goto(struct vc_data *vc, u_char type, u_char ch, u_short key)
  1741. {
  1742. static u_char goto_buf[8];
  1743. static int num;
  1744. int maxlen;
  1745. char *cp;
  1746. u16 wch;
  1747. if (type == KT_SPKUP && ch == SPEAKUP_GOTO)
  1748. goto do_goto;
  1749. if (type == KT_LATIN && ch == '\n')
  1750. goto do_goto;
  1751. if (type != 0)
  1752. goto oops;
  1753. if (ch == 8) {
  1754. u16 wch;
  1755. if (num == 0)
  1756. return -1;
  1757. wch = goto_buf[--num];
  1758. goto_buf[num] = '\0';
  1759. spkup_write(&wch, 1);
  1760. return 1;
  1761. }
  1762. if (ch < '+' || ch > 'y')
  1763. goto oops;
  1764. wch = ch;
  1765. goto_buf[num++] = ch;
  1766. goto_buf[num] = '\0';
  1767. spkup_write(&wch, 1);
  1768. maxlen = (*goto_buf >= '0') ? 3 : 4;
  1769. if ((ch == '+' || ch == '-') && num == 1)
  1770. return 1;
  1771. if (ch >= '0' && ch <= '9' && num < maxlen)
  1772. return 1;
  1773. if (num < maxlen - 1 || num > maxlen)
  1774. goto oops;
  1775. if (ch < 'x' || ch > 'y') {
  1776. oops:
  1777. if (!spk_killed)
  1778. synth_printf(" %s\n", spk_msg_get(MSG_GOTO_CANCELED));
  1779. goto_buf[num = 0] = '\0';
  1780. spk_special_handler = NULL;
  1781. return 1;
  1782. }
  1783. /* Do not replace with kstrtoul: here we need cp to be updated */
  1784. goto_pos = simple_strtoul(goto_buf, &cp, 10);
  1785. if (*cp == 'x') {
  1786. if (*goto_buf < '0')
  1787. goto_pos += spk_x;
  1788. else if (goto_pos > 0)
  1789. goto_pos--;
  1790. if (goto_pos >= vc->vc_cols)
  1791. goto_pos = vc->vc_cols - 1;
  1792. goto_x = 1;
  1793. } else {
  1794. if (*goto_buf < '0')
  1795. goto_pos += spk_y;
  1796. else if (goto_pos > 0)
  1797. goto_pos--;
  1798. if (goto_pos >= vc->vc_rows)
  1799. goto_pos = vc->vc_rows - 1;
  1800. goto_x = 0;
  1801. }
  1802. goto_buf[num = 0] = '\0';
  1803. do_goto:
  1804. spk_special_handler = NULL;
  1805. spk_parked |= 0x01;
  1806. if (goto_x) {
  1807. spk_pos -= spk_x * 2;
  1808. spk_x = goto_pos;
  1809. spk_pos += goto_pos * 2;
  1810. say_word(vc);
  1811. } else {
  1812. spk_y = goto_pos;
  1813. spk_pos = vc->vc_origin + (goto_pos * vc->vc_size_row);
  1814. say_line(vc);
  1815. }
  1816. return 1;
  1817. }
  1818. static void speakup_goto(struct vc_data *vc)
  1819. {
  1820. if (spk_special_handler) {
  1821. synth_printf("%s\n", spk_msg_get(MSG_ERROR));
  1822. return;
  1823. }
  1824. synth_printf("%s\n", spk_msg_get(MSG_GOTO));
  1825. spk_special_handler = handle_goto;
  1826. }
  1827. static void speakup_help(struct vc_data *vc)
  1828. {
  1829. spk_handle_help(vc, KT_SPKUP, SPEAKUP_HELP, 0);
  1830. }
  1831. static void do_nothing(struct vc_data *vc)
  1832. {
  1833. return; /* flush done in do_spkup */
  1834. }
  1835. static u_char key_speakup, spk_key_locked;
  1836. static void speakup_lock(struct vc_data *vc)
  1837. {
  1838. if (!spk_key_locked) {
  1839. spk_key_locked = 16;
  1840. key_speakup = 16;
  1841. } else {
  1842. spk_key_locked = 0;
  1843. key_speakup = 0;
  1844. }
  1845. }
  1846. typedef void (*spkup_hand) (struct vc_data *);
  1847. static spkup_hand spkup_handler[] = {
  1848. /* must be ordered same as defines in speakup.h */
  1849. do_nothing, speakup_goto, speech_kill, speakup_shut_up,
  1850. speakup_cut, speakup_paste, say_first_char, say_last_char,
  1851. say_char, say_prev_char, say_next_char,
  1852. say_word, say_prev_word, say_next_word,
  1853. say_line, say_prev_line, say_next_line,
  1854. top_edge, bottom_edge, left_edge, right_edge,
  1855. spell_word, spell_word, say_screen,
  1856. say_position, say_attributes,
  1857. speakup_off, speakup_parked, say_line, /* this is for indent */
  1858. say_from_top, say_to_bottom,
  1859. say_from_left, say_to_right,
  1860. say_char_num, speakup_bits, speakup_bits, say_phonetic_char,
  1861. speakup_bits, speakup_bits, speakup_bits,
  1862. speakup_win_set, speakup_win_clear, speakup_win_enable, speakup_win_say,
  1863. speakup_lock, speakup_help, toggle_cursoring, read_all_doc, NULL
  1864. };
  1865. static void do_spkup(struct vc_data *vc, u_char value)
  1866. {
  1867. if (spk_killed && value != SPEECH_KILL)
  1868. return;
  1869. spk_keydown = 0;
  1870. spk_lastkey = 0;
  1871. spk_shut_up &= 0xfe;
  1872. this_speakup_key = value;
  1873. if (value < SPKUP_MAX_FUNC && spkup_handler[value]) {
  1874. spk_do_flush();
  1875. (*spkup_handler[value]) (vc);
  1876. } else {
  1877. if (inc_dec_var(value) < 0)
  1878. bleep(9);
  1879. }
  1880. }
  1881. static const char *pad_chars = "0123456789+-*/\015,.?()";
  1882. static int
  1883. speakup_key(struct vc_data *vc, int shift_state, int keycode, u_short keysym,
  1884. int up_flag)
  1885. {
  1886. unsigned long flags;
  1887. int kh;
  1888. u_char *key_info;
  1889. u_char type = KTYP(keysym), value = KVAL(keysym), new_key = 0;
  1890. u_char shift_info, offset;
  1891. int ret = 0;
  1892. if (!synth)
  1893. return 0;
  1894. spin_lock_irqsave(&speakup_info.spinlock, flags);
  1895. tty = vc->port.tty;
  1896. if (type >= 0xf0)
  1897. type -= 0xf0;
  1898. if (type == KT_PAD &&
  1899. (vt_get_leds(fg_console, VC_NUMLOCK))) {
  1900. if (up_flag) {
  1901. spk_keydown = 0;
  1902. goto out;
  1903. }
  1904. value = pad_chars[value];
  1905. spk_lastkey = value;
  1906. spk_keydown++;
  1907. spk_parked &= 0xfe;
  1908. goto no_map;
  1909. }
  1910. if (keycode >= MAX_KEY)
  1911. goto no_map;
  1912. key_info = spk_our_keys[keycode];
  1913. if (!key_info)
  1914. goto no_map;
  1915. /* Check valid read all mode keys */
  1916. if ((cursor_track == read_all_mode) && (!up_flag)) {
  1917. switch (value) {
  1918. case KVAL(K_DOWN):
  1919. case KVAL(K_UP):
  1920. case KVAL(K_LEFT):
  1921. case KVAL(K_RIGHT):
  1922. case KVAL(K_PGUP):
  1923. case KVAL(K_PGDN):
  1924. break;
  1925. default:
  1926. stop_read_all(vc);
  1927. break;
  1928. }
  1929. }
  1930. shift_info = (shift_state & 0x0f) + key_speakup;
  1931. offset = spk_shift_table[shift_info];
  1932. if (offset) {
  1933. new_key = key_info[offset];
  1934. if (new_key) {
  1935. ret = 1;
  1936. if (new_key == SPK_KEY) {
  1937. if (!spk_key_locked)
  1938. key_speakup = (up_flag) ? 0 : 16;
  1939. if (up_flag || spk_killed)
  1940. goto out;
  1941. spk_shut_up &= 0xfe;
  1942. spk_do_flush();
  1943. goto out;
  1944. }
  1945. if (up_flag)
  1946. goto out;
  1947. if (last_keycode == keycode &&
  1948. time_after(last_spk_jiffy + MAX_DELAY, jiffies)) {
  1949. spk_close_press = 1;
  1950. offset = spk_shift_table[shift_info + 32];
  1951. /* double press? */
  1952. if (offset && key_info[offset])
  1953. new_key = key_info[offset];
  1954. }
  1955. last_keycode = keycode;
  1956. last_spk_jiffy = jiffies;
  1957. type = KT_SPKUP;
  1958. value = new_key;
  1959. }
  1960. }
  1961. no_map:
  1962. if (type == KT_SPKUP && !spk_special_handler) {
  1963. do_spkup(vc, new_key);
  1964. spk_close_press = 0;
  1965. ret = 1;
  1966. goto out;
  1967. }
  1968. if (up_flag || spk_killed || type == KT_SHIFT)
  1969. goto out;
  1970. spk_shut_up &= 0xfe;
  1971. kh = (value == KVAL(K_DOWN)) ||
  1972. (value == KVAL(K_UP)) ||
  1973. (value == KVAL(K_LEFT)) ||
  1974. (value == KVAL(K_RIGHT));
  1975. if ((cursor_track != read_all_mode) || !kh)
  1976. if (!spk_no_intr)
  1977. spk_do_flush();
  1978. if (spk_special_handler) {
  1979. if (type == KT_SPEC && value == 1) {
  1980. value = '\n';
  1981. type = KT_LATIN;
  1982. } else if (type == KT_LETTER) {
  1983. type = KT_LATIN;
  1984. } else if (value == 0x7f) {
  1985. value = 8; /* make del = backspace */
  1986. }
  1987. ret = (*spk_special_handler) (vc, type, value, keycode);
  1988. spk_close_press = 0;
  1989. if (ret < 0)
  1990. bleep(9);
  1991. goto out;
  1992. }
  1993. last_keycode = 0;
  1994. out:
  1995. spin_unlock_irqrestore(&speakup_info.spinlock, flags);
  1996. return ret;
  1997. }
  1998. static int keyboard_notifier_call(struct notifier_block *nb,
  1999. unsigned long code, void *_param)
  2000. {
  2001. struct keyboard_notifier_param *param = _param;
  2002. struct vc_data *vc = param->vc;
  2003. int up = !param->down;
  2004. int ret = NOTIFY_OK;
  2005. static int keycode; /* to hold the current keycode */
  2006. in_keyboard_notifier = 1;
  2007. if (vc->vc_mode == KD_GRAPHICS)
  2008. goto out;
  2009. /*
  2010. * First, determine whether we are handling a fake keypress on
  2011. * the current processor. If we are, then return NOTIFY_OK,
  2012. * to pass the keystroke up the chain. This prevents us from
  2013. * trying to take the Speakup lock while it is held by the
  2014. * processor on which the simulated keystroke was generated.
  2015. * Also, the simulated keystrokes should be ignored by Speakup.
  2016. */
  2017. if (speakup_fake_key_pressed())
  2018. goto out;
  2019. switch (code) {
  2020. case KBD_KEYCODE:
  2021. /* speakup requires keycode and keysym currently */
  2022. keycode = param->value;
  2023. break;
  2024. case KBD_UNBOUND_KEYCODE:
  2025. /* not used yet */
  2026. break;
  2027. case KBD_UNICODE:
  2028. /* not used yet */
  2029. break;
  2030. case KBD_KEYSYM:
  2031. if (speakup_key(vc, param->shift, keycode, param->value, up))
  2032. ret = NOTIFY_STOP;
  2033. else if (KTYP(param->value) == KT_CUR)
  2034. ret = pre_handle_cursor(vc, KVAL(param->value), up);
  2035. break;
  2036. case KBD_POST_KEYSYM:{
  2037. unsigned char type = KTYP(param->value) - 0xf0;
  2038. unsigned char val = KVAL(param->value);
  2039. switch (type) {
  2040. case KT_SHIFT:
  2041. do_handle_shift(vc, val, up);
  2042. break;
  2043. case KT_LATIN:
  2044. case KT_LETTER:
  2045. do_handle_latin(vc, val, up);
  2046. break;
  2047. case KT_CUR:
  2048. do_handle_cursor(vc, val, up);
  2049. break;
  2050. case KT_SPEC:
  2051. do_handle_spec(vc, val, up);
  2052. break;
  2053. }
  2054. break;
  2055. }
  2056. }
  2057. out:
  2058. in_keyboard_notifier = 0;
  2059. return ret;
  2060. }
  2061. static int vt_notifier_call(struct notifier_block *nb,
  2062. unsigned long code, void *_param)
  2063. {
  2064. struct vt_notifier_param *param = _param;
  2065. struct vc_data *vc = param->vc;
  2066. switch (code) {
  2067. case VT_ALLOCATE:
  2068. if (vc->vc_mode == KD_TEXT)
  2069. speakup_allocate(vc, GFP_ATOMIC);
  2070. break;
  2071. case VT_DEALLOCATE:
  2072. speakup_deallocate(vc);
  2073. break;
  2074. case VT_WRITE:
  2075. if (param->c == '\b') {
  2076. speakup_bs(vc);
  2077. } else {
  2078. u16 d = param->c;
  2079. speakup_con_write(vc, &d, 1);
  2080. }
  2081. break;
  2082. case VT_UPDATE:
  2083. speakup_con_update(vc);
  2084. break;
  2085. }
  2086. return NOTIFY_OK;
  2087. }
  2088. /* called by: module_exit() */
  2089. static void __exit speakup_exit(void)
  2090. {
  2091. int i;
  2092. unregister_keyboard_notifier(&keyboard_notifier_block);
  2093. unregister_vt_notifier(&vt_notifier_block);
  2094. speakup_unregister_devsynth();
  2095. speakup_cancel_selection();
  2096. speakup_cancel_paste();
  2097. del_timer_sync(&cursor_timer);
  2098. kthread_stop(speakup_task);
  2099. speakup_task = NULL;
  2100. mutex_lock(&spk_mutex);
  2101. synth_release();
  2102. mutex_unlock(&spk_mutex);
  2103. spk_ttyio_unregister_ldisc();
  2104. speakup_kobj_exit();
  2105. for (i = 0; i < MAX_NR_CONSOLES; i++)
  2106. kfree(speakup_console[i]);
  2107. speakup_remove_virtual_keyboard();
  2108. for (i = 0; i < MAXVARS; i++)
  2109. speakup_unregister_var(i);
  2110. for (i = 0; i < 256; i++) {
  2111. if (spk_characters[i] != spk_default_chars[i])
  2112. kfree(spk_characters[i]);
  2113. }
  2114. spk_free_user_msgs();
  2115. }
  2116. /* call by: module_init() */
  2117. static int __init speakup_init(void)
  2118. {
  2119. int i;
  2120. long err = 0;
  2121. struct vc_data *vc = vc_cons[fg_console].d;
  2122. struct var_t *var;
  2123. /* These first few initializations cannot fail. */
  2124. spk_initialize_msgs(); /* Initialize arrays for i18n. */
  2125. spk_reset_default_chars();
  2126. spk_reset_default_chartab();
  2127. spk_strlwr(synth_name);
  2128. spk_vars[0].u.n.high = vc->vc_cols;
  2129. for (var = spk_vars; var->var_id != MAXVARS; var++)
  2130. speakup_register_var(var);
  2131. for (var = synth_time_vars;
  2132. (var->var_id >= 0) && (var->var_id < MAXVARS); var++)
  2133. speakup_register_var(var);
  2134. for (i = 1; spk_punc_info[i].mask != 0; i++)
  2135. spk_set_mask_bits(NULL, i, 2);
  2136. spk_set_key_info(spk_key_defaults, spk_key_buf);
  2137. /* From here on out, initializations can fail. */
  2138. err = speakup_add_virtual_keyboard();
  2139. if (err)
  2140. goto error_virtkeyboard;
  2141. for (i = 0; i < MAX_NR_CONSOLES; i++)
  2142. if (vc_cons[i].d) {
  2143. err = speakup_allocate(vc_cons[i].d, GFP_KERNEL);
  2144. if (err)
  2145. goto error_kobjects;
  2146. }
  2147. if (spk_quiet_boot)
  2148. spk_shut_up |= 0x01;
  2149. err = speakup_kobj_init();
  2150. if (err)
  2151. goto error_kobjects;
  2152. spk_ttyio_register_ldisc();
  2153. synth_init(synth_name);
  2154. speakup_register_devsynth();
  2155. /*
  2156. * register_devsynth might fail, but this error is not fatal.
  2157. * /dev/synth is an extra feature; the rest of Speakup
  2158. * will work fine without it.
  2159. */
  2160. err = register_keyboard_notifier(&keyboard_notifier_block);
  2161. if (err)
  2162. goto error_kbdnotifier;
  2163. err = register_vt_notifier(&vt_notifier_block);
  2164. if (err)
  2165. goto error_vtnotifier;
  2166. speakup_task = kthread_create(speakup_thread, NULL, "speakup");
  2167. if (IS_ERR(speakup_task)) {
  2168. err = PTR_ERR(speakup_task);
  2169. goto error_task;
  2170. }
  2171. set_user_nice(speakup_task, 10);
  2172. wake_up_process(speakup_task);
  2173. pr_info("speakup %s: initialized\n", SPEAKUP_VERSION);
  2174. pr_info("synth name on entry is: %s\n", synth_name);
  2175. goto out;
  2176. error_task:
  2177. unregister_vt_notifier(&vt_notifier_block);
  2178. error_vtnotifier:
  2179. unregister_keyboard_notifier(&keyboard_notifier_block);
  2180. del_timer(&cursor_timer);
  2181. error_kbdnotifier:
  2182. speakup_unregister_devsynth();
  2183. mutex_lock(&spk_mutex);
  2184. synth_release();
  2185. mutex_unlock(&spk_mutex);
  2186. speakup_kobj_exit();
  2187. error_kobjects:
  2188. for (i = 0; i < MAX_NR_CONSOLES; i++)
  2189. kfree(speakup_console[i]);
  2190. speakup_remove_virtual_keyboard();
  2191. error_virtkeyboard:
  2192. for (i = 0; i < MAXVARS; i++)
  2193. speakup_unregister_var(i);
  2194. for (i = 0; i < 256; i++) {
  2195. if (spk_characters[i] != spk_default_chars[i])
  2196. kfree(spk_characters[i]);
  2197. }
  2198. spk_free_user_msgs();
  2199. out:
  2200. return err;
  2201. }
  2202. module_init(speakup_init);
  2203. module_exit(speakup_exit);