CompuServe Thread

#Text Filtering

5 messages in this thread
#46509From: Thomas DeVeauApr 13, 1995 9:00 PM
Greetings, I need help! I am writing a small ascii terminal program and I am having problems filtering out control codes and other nonsensical characters before displaying the read buffer from the serial port. I have been able to strip bit 8 from the chars in the buffer but am stuck with control codes intermixed with the text. How do I get rid of unneccessary control codes? Thanx, Tom.
#46517From: Greg Comeau@Comeau CmptgApr 14, 1995 6:54 AM
>How do I get rid of unneccessary control codes? Not fully clear on your questions. Do you mean Perhaps with a switch statement? A table? An array?
#46524From: Thomas DeVeauApr 14, 1995 4:10 PM
Hi Greg, I mean I need to remove the control codes from the read stream that I don't need. I am trying to get plain ascii text out of the stream. Any suggestions? Tom.
#46534From: Peter WadeApr 16, 1995 8:57 AM
Most C compilers have a function called isprint that returns TRUE for printable ascii characters and FALSE for everything else. Peter Wade Autopiloting from London, England
#46529From: Jim ButterfieldApr 15, 1995 8:02 AM
> How do I get rid of unnecessary control codes? Depends on what form your data is in, what the purpose of the control codes is, what you mean by 'get rid of' …. Generally: you identify a control code by the fact that it's in the range 0-31 or 128-159, specifically excepting whatever end-of-line signals you want to catch (10=NewLine, 13=Return, possibly TAB and also the delete character). So: the general approach is: 1. Detect and bypass any special control codes you want to detect, such as those named above; 2. temporarily knock off the high bit of the character with something like AND 07Fh; 3. if the result of the previous operation is less than 32 (020h), it's a control code and you can throw it out. 4. Don't forget to restore the character to its original state (before step 2 mangling) if you want to use it. –Jim