'---------------------------------------------------------------------------------------- ' Name: SCAN_OR_SKIP.TIG ' Type: TIGER-BASIC(tm) Source Code ' ' Purpose: Short demo for the SCAN_OR_SKIP function searching or skipping certain ' characters in both directions in strings. ' ' (C) - Copyright Wilke Technology, P.O.Box 1727, D-52018 Aachen, Germany '---------------------------------------------------------------------------------------- ' ' Thank you for using BASIC Tigers in your products. If you have questions, ideas ' or special needs, please contact your next distributor or the Tiger support team ' and visit our web site: ' ' Wilke Technology GmbH ' The Tiger Support Team ' P.O.Box 1727, D-52018 Aachen, Germany ' Krefelder Str. 147, D-52070 Aachen, Germany ' ' email: support@wilke-technology.com (english) ' email: support@wilke.de (german) ' Phone: +49 (241) 918 900 Mo to Fr, 7:00 to 16:00 (GMT) ' Fax: +49 (241) 918 9068 ' ' New information, new drivers and free downloads see: ' ' www.wilke-technology.com (english) ' www.wilke.de (german) ' ' Sincerely, ' ' Your Tiger Support Team ' '---------------------------------------------------------------------------------------- ' ' This program may be executed on a Plug & Play Lab and be compiled with Tiger-BASIC ' Version 5 or later, TAC system 1.13a or later. ' ' Demo on how to use the SCAN_OR_SKIP function to find the next position of a character ' belonging to a group of characters in a source string (SCAN) or the next position of ' any character not belonging to that group of characters (SKIP). ' ' ' NEW_POS = SCAN_OR_SKIP ( SOURCE$, CHARSET$, POS, +=Scan or -=Skip, [Reverse] ) ' ! ! ! ! ! ' ! ! ! ! ! <--- (Optional) ' ! ! ! ! Zero: from POS to end ' ! ! ! ! else: fomr POS to beginning ' ! ! ! ! ' ! ! ! !<--- positive --> SCAN ' ! ! ! negative --> SKIP ' ! ! ! ' ! ! !<--- Start position in SOURCE$ ' ! ! ' ! !<--- Character Set Flag-String: ' ! 00 = not a member of this charset ' ! XX = IS member of this charset ' ! ' !<--- Source string with text, data or whatever ' ' ' Charset$ = Flag-String, always 256 bytes long. Position of flags in string ' determines the code that it represents. ' ' 00 = not a member of this charset ' XX = IS member of this charset ' ' +=Scan or -=Skip = 0 ... nn ==> SCAN function chosen. We l o o k for the first ' character from CHARSET$ ' ' -nn ... -1 ==> SKIP characters of CHARSET$ in SOURCE$ until you ' find the first NON-character of CHARSET$ ' ' So, SKIP is the INVERSE function to SCAN. ' SKIP charset <==> SCAN NON-charset. ' ' Reverse = (Optional parameter) Set the scan/skip direction: ' Zero: scanning/skipping is performed from the specified ' start position in direction of the end of the string ' Non-zero: scanning/skipping is performed from the specified ' start position in direction of the beginning of the string ' ' Result: NEW_POS = 0 ... nnn ==> new POS of the first found char ' -1 ==> not found, end of string reached ' -2 ==> Error, empty string or POS outside SOURCE$ ' '---------------------------------------------------------------------------------------- USER_VAR_STRICT ' variables must be declared TASK MAIN ' begin task MAIN STRING SEPARATOR$(256), SOURCE$ ' declare variables LONG POS INSTALL_DEVICE #1, "LCD1.TDD" ' install LCD driver ' ' build set of separator chars (FF = separator chars, 00 = other chars) ' only "." and " " (blank) are separator characters here ' SEPARATOR$ = "& 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' 00..0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' 10..1F FF 00 00 00 00 00 00 00 00 00 00 00 00 00 FF 00& ' 20..2F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' 30..3F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' 40..4F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' 50..5F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' 60..6F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' 70..7F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' 80..8F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' 90..9F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' A0..AF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' B0..BF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' C0..CF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' D0..DF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00& ' E0..EF 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"% ' F0..FF SOURCE$ = "The quick.brown.fox jumps over.the lazy.dog" ' source string POS = 0 ' start scanning at position 0 PRINT #1, "<1>Separators found at positions:"; ' print start text on LCD WHILE POS >= 0 ' while no error flag POS = SCAN_OR_SKIP (SOURCE$, SEPARATOR$, POS, 1) ' Scan for next separator char IF POS >= 0 THEN ' if valid position PRINT #1, POS; ' print position on LCD POS = POS + 1 ' increase position ENDIF ' ENDWHILE ' PRINT #1, " end" ' print "end-of-string" WAIT_DURATION 5000 ' wait 5 seconds POS = len(SOURCE$)-1 ' start scanning at the end of the string PRINT #1, "<1>Separators found at positions:"; ' print start text on LCD WHILE POS >= 0 ' while no error flag POS = SCAN_OR_SKIP (SOURCE$, SEPARATOR$, POS, 1, 1) ' Scan for next separator char IF POS >= 0 THEN ' if valid position PRINT #1, POS; ' print position on LCD POS = POS - 1 ' decrease position ENDIF ' ENDWHILE ' PRINT #1, " end" ' print "end-of-string" WAIT_DURATION 5000 ' wait 5 seconds SOURCE$ = ".. ..- .... . + ... .-+ . ... -.." ' new source string POS = 0 ' start scanning at position 0 PRINT #1, "<1>Non separator chars found at:"; ' print start text on LCD WHILE POS >= 0 ' while no error flag POS = SCAN_OR_SKIP (SOURCE$, SEPARATOR$, POS, -1) ' Skip all separator chars IF POS >= 0 THEN ' if valid position PRINT #1, POS; ' print position on LCD POS = POS + 1 ' increase position ENDIF ' ENDWHILE ' PRINT #1, " end" ' print "end-of-string" WAIT_DURATION 5000 ' wait 5 seconds POS = len(SOURCE$)-1 ' start scanning at the end of the string PRINT #1, "<1>Non separator chars found at:"; ' print start text on LCD WHILE POS >= 0 ' while no error flag POS = SCAN_OR_SKIP (SOURCE$, SEPARATOR$, POS, -1, 1)' Skip all separator chars IF POS >= 0 THEN ' if valid position PRINT #1, POS; ' print position on LCD POS = POS - 1 ' decrease position ENDIF ' ENDWHILE ' PRINT #1, " end" ' print "end-of-string" END ' end of task MAIN