tenaglia@astroatc.UUCP (Chris Tenaglia) (07/20/89)
I am a heavy Icon user. We have icon in DOS, UNIX, and VMS. Having benefitted so much from it, I feel glad to be able to contribute a little. Below is one of my favorite procedures. I realize it can be done in line with the string scanning features. But I discovered, I do the same string scanning over and over. So I composed this software chip that I include in many programs. It could be ucoded too. I leave that up to the programmer. This first one is more general. As a postscript I include a variation that is a little more specific, but still very useful. It can be used in an assignment -> words := parse(line) Or on the fly -> if parse(line,' :,')[3] == "X800" then... ################################################################## # # # THIS PROCEDURE PULLS ALL THE ELEMENTS (TOKENS) OUT OF A LINE # # BUFFER AND RETURNS THEM IN A LIST. A VARIABLE NAMED 'CHARS' # # CAN BE STATICALLY DEFINED HERE OR GLOBAL. IT IS A CSET THAT # # CONTAINS THE VALID CHARACTERS THAT CAN COMPOSE THE ELEMENTS # # ONE WISHES TO EXTRACT. # # # ################################################################## procedure parse(line,delims) if delims === &null then delims := ' \t' chars := &cset -- delims tokens := [] line ? while tab(upto(chars)) do put(tokens,tab(many(chars))) return tokens end #ps procedure parse(line) static chars initial chars := &cset -- ' \t' tokens := [] line ? while tab(upto(chars)) do put(tokens,tab(many(chars))) return tokens end Chris Tenaglia Astronautics Corporation of America 4115 N. Teutonia Avenue Milwaukee, Wi 53209 USA (414) 447-8200 X-421