Control characters
Posted in 1995
Kerry says: >BEWARE: It's Friday night, I've had a few beers, and I can be appallingly > obnoxious under such circumstances: > I'd still like to know what brand of beer, and if I'd be able to get some over here. Anyways let me respond properly... After re-reading the original post, and a few of the other responses, I belive the question was more like "Can I trap user entered control characters?" and my answer would be, "No" (maybe I should have left it at that). But the question did intrigue me enough to make me investigate what could be done with control characters. So I posted my results. >In article <3ng850$fh9@cssun.mathcs.emory.edu>, >kmart!jregep@uunet.uu.net wrote: >> >> >I want to use this in ESQL. >> >> Will this do it for you? > >No. He said ESQL. You are right he did say ESQL, but ESQL what? (C, cobol, ada...?) I thought Informix functions would be available in their ESQL products, at least with ESQL-C. Sorry my mistake. If he is using ESQL-C, then for the ascii function he'll have to do something like this: type_char = 0x0a; (Whatever he is using he'll have to work that out for himself). Other than that, he can convert the logic. >> >> main >> define >> cntrl_a, >> cntrl_b, >> # . >> # . >> # . >> cntrl_y, >> cntrl_z char(1), > >Also, when you find yourself repeating the same bit of code 26 times in >a single program it's probably time to consider using a FUNCTION, or >in your example an ARRAY. Yes, a function for everything is always a good idea, but this was meant to get a different point across. I didn't mean to demonstrate how the logic should be implemented, just that you can assign a control character to a char(1) variable, add it to a table, select it, and display it. (you can even print it from a report section). > [snip] >> let cntrl_a = ascii(1) >> let cntrl_b = ascii(2) >> # . >> # . >> # . >> let cntrl_y = ascii(25) >> let cntrl_z = ascii(26) > > [snip] > >> case >> when (input_txt = cntrl_a) >> let type_char = "cntrl-a" >> >> when (input_txt = cntrl_b) >> let type_char = "cntrl-b" >> >> # . >> # . >> # . >> >> when (input_txt = cntrl_y) >> let type_char = "cntrl-y" >> >> when (input_txt = cntrl_z) >> let type_char = "cntrl-z" If I wrote it like this: for i = 1 to 26 if (input_txt = ascii(i)) then let type_char = "cntrl-",ascii(i+64) exit for end if end for display "The variable is: ",type_char I don't feel that I would have gotten my point across. Besides, maybe not all control characters are required. > >Regards, >Kerry S >--------------------------------------,------------------------------------- >Kerry Sainsbury, kerry@kcbbs.gen.nz | THE INFORMIX FAQ >Quanta Systems, Auckland, New Zealand | kcbbs.gen.nz:/informix/* > | mathcs.emory.edu:/pub/informix/faq/* >>+64 9 377-4473 (work) 279-3571 (home) | http://www.garpac.com/informix.html Well anyways.... since I've spent this much time already, I'll end my input into this subject with the following: With 4GL, if the user enters control characters literally (ie ^L) , then the code could look something like this (your implementation will vary): main #or function if you will define i integer, input_txt char(2), ctrl_txt char(1), type_char char(5) prompt "Enter a control character: " for input_txt if (input_txt[1] = "^") then for i = 65 to 90 if (input_txt[2] = ascii(i)) then let ctrl_txt = ascii(i-64) let type_char = "ctrl-",ascii(i) exit for end if end for display "You entered ",type_char display contl_txt else display "not a control character" end if end main -- uunet!kmart!jregep [Warning: Reading this email will destroy your drive... to work in the morning.]