jjohnson@cs.ucf.edu (John Jjohnson) (02/14/91)
HELP! I've written a macro for use with the Brief program editor. The macro keeps a two character memory of your keystrokes. If the second character is recognized as one which indicates the preceding character should be "Spanish-ized", i.e., printed with tildes or accents, it erases the last two characters, prints the Spanish character using extended ASCII (128-255), and advances the cursor to where the next character should go. PROBLEM STATEMENT: Can someone convert (or show me how to convert) this macro into a C program which can be made into an MS-DOS TSR (terminate and stay resident) program? I want to be able to use these Spanish characters on the DOS command line and in other editors\word processors, specifically WordScar and NerdPerfect. E-MAIL IS PREFERRED! Since I'm not able to read this group often, please send ideas to "jjohnson@eola.cs.ucf.edu". Phone #407-381-2218. Collect calls and good suggestions will be accepted, but working code (in Turbo C or Turbo ASM or Microsoft C) will be worshipped! Thanks in advance to all: Mark Johnson -----------------------------------------------------------(cut here) /*------------------------------------*/ /* Written by Mark Johnson on 1/20/91 */ /*------------------------------------* This macro may be used when editing any text file. To call it up, press the F10 key (execute macro), type SPANISH, and press return. Once loaded, the macro is called every time a printable key is pressed. The macro maintains a memory of the last two characters entered. If they match one of the two-character sequences defined to represent a single Spanish character, then the cursor will back up, erase the two English characters, replace them with the appropriate Spanish character, and then advance the cursor. The English-to-Spanish mapping is as follows: (values may show up in octal if using VI) a` = n~ = $ ?? = ( e` = N~ = % !! = - i` = ! u: = << = . o` = " U: = >> = / u` = # n` = $ N` = % The AT-style keyboard has the left quote (my accent) and the tilde character on the same key. The tilde requires the shift key. Since I am lazy, and since it makes no sense for an accent to be placed over the letter "n", I allow the user to enter an accent (no shift required) or tilde after typing an "n" to get the spanish letter "$". --------------------------------------------------------------------*/ /* C-Brief Macro Language */ void spn() { global string new_char; /* will be type char (int?) in C */ global string old_char; /* ' ' ' ' ' ' */ old_char = new_char; prev_char(); /* moves cursor back to last char typed */ new_char = read(1); /* read the last char */ switch(new_char) { /* special char { '~:?!< or > } ? */ case "`": switch(old_char) { case "a": prev_char(); /* move cursor back again */ delete_char(2); /* delete the unaccented a */ insert(" "); /* chr$(160): a w/ accent */ case "e": prev_char(); delete_char(2); insert(""); /* chr$(130) */ case "i": prev_char(); delete_char(2); insert("!"); /* chr$(161) */ case "o": prev_char(); delete_char(2); insert("""); /* chr$(162) */ case "u": prev_char(); delete_char(2); insert("#"); /* chr$(163) */ case "n": prev_char(); delete_char(2); insert("$"); /* chr$(164) */ case "N": prev_char(); delete_char(2); insert("%"); /* chr$(165) */ default: next_char(); } case "~": switch(old_char) { case "n": prev_char(); delete_char(2); insert("$"); /* chr$(164) */ case "N": prev_char(); delete_char(2); insert("%"); /* chr$(165) */ default: next_char(); } case ":": switch(old_char) { case "u": prev_char(); delete_char(2); insert(""); /* chr$(129) */ case "U": prev_char(); delete_char(2); insert(""); /* chr$(154) */ default: next_char(); } case "?": switch(old_char) { case "?": prev_char(); delete_char(2); insert("("); /* chr$(168) */ default: next_char(); } case "!": switch(old_char) { case "!": prev_char(); delete_char(2); insert("-"); /* chr$(173) */ default: next_char(); } case "<": switch(old_char) { case "<": prev_char(); delete_char(2); insert("."); /* chr$(174) */ default: next_char(); } case ">": switch(old_char) { case ">": prev_char(); delete_char(2); insert("/"); /* chr$(175) */ default: next_char(); } default: next_char(); } } /* This is analogous to the keyboard Interrupt Service Routine */ void spanish() /* the actual macro the user invokes */ { register_macro(0,"spn"); /* registers "spn()" as a macro to be */ } /* called every time a key is pressed. */ /* --- the end --- */
freeman@cs.ucf.edu (Holly Freeman) (02/15/91)
Sorry about the kludgey looking code! Those 8-bit extended ASCII characters work fine between my PC and my local UNIX machine, but' they apparently didn't go across the net too well. The ASCII values in comments to the right of the INSERT("string constant") statements are the correct decimal values for the extended ASCII characters. Thanks again for any/all help. MarkJ :w s2