'=========================================================================== ' Subject: 4 STRING PARSER Date: 02-08-00 (17:32) ' Author: Hermann Seegert Code: PB ' Origin: Hermann.Seegert@t-online.de Packet: PB.ABC '=========================================================================== ' Parser for 4 Strings in independence of the sequence of input! ' ' *********** ' * ENJOY ! * ' *********** ' ' programed by Hermann Seegert in PowerBASIC, V. 3.2 ' February 2000 ' If you want to make remarks, improvements or anything else, you ' can send an email to: ' hermann.seegert@t-online.de $lib all off defint a-z $if 0 You already know my parser for three strings? Ok now, here is one for 4 (FOUR!) strings. It was a nerving work sometimes, but you know already, that I like command line modus. And because I want to make it comfortable, I was creating this parser. Ok, I know, that most of you don't un- derstand, why I've done this work, but I can tell you, that there are even more senseless works, that must be done, if you are stu- dying computer science. Here you have to care about your mind ;). Nevertheless: Possibly someone can use this parser, which has the big advantage again, that the name of the string doesn't change. Ok, lets do some mathematics again! 1*2*3*4=4!=24 possibilities, if there are 4 signs, to order these signs ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÂÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿ ³ /= is first..... ³ /s+ is third..... ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 1 /=/+/s+/f+ ³ 13 /s+/+/=/f+ ³ ³ 2 /=/s+/+/f+ ³ 14 /s+/=/+/f+ ³ ³ 3 /=/f+/s+/+ ³ 15 /s+/f+/=/+ ³ ³ 4 /=/s+/f+/+ ³ 16 /s+/=/f+/+ ³ ³ 5 /=/f+/+/s+ ³ 17 /s+/f+/+/= ³ ³ 6 /=/+/f+/s+ ³ 18 /s+/+/f+/= ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ /+ is second..... ³ /f+ is fourth (last)..... ³ ÃÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÅÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ´ ³ 7 /+/=/s+/f+ ³ 19 /f+/+/s+/= ³ ³ 8 /+/s+/=/f+ ³ 20 /f+/s+/+/= ³ ³ 9 /+/f+/s+/= ³ 21 /f+/=/s+/+ ³ ³ 10 /+/s+/f+/= ³ 22 /f+/s+/=/+ ³ ³ 11 /+/f+/=/s+ ³ 23 /f+/=/+/s+ ³ ³ 12 /+/=/f+/s+ ³ 24 /f+/+/=/s+ ³ ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÁÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ This is ok, from the point of view of mathematics (I hope!). But if we want to make a source code, we first have to find out, what is the easiest for us. Well, if we look to the last delimiter in the string, we see, that we can cut the last part of the string by writing last$=mid$(wholestring$,instr(wholestring$,delimiter4)+...) That's the reason, why I've done it in this way: I was looking for the first 6 possibilities to make input, where the LAST input is always the same. It's also easier to debug that stuff.. uuuhh! One word about the delimiters: Pay attention, that you are using 4 different delimiters! It's leading up to problems, if you are using /+ and /++, because /+ is IN /++, and so /++ couldn't be found correctly, if /++ is standing before /+ appears! $endif ' %false=0 'we need it for a variable %true=not %false 'we need it for a variable 'try out each of them! '1. Six-pack 'parser$="/s+esplus/f+effplus/+soloplus/=same!" 'parser$="/f+effplus/s+esplus/+soloplus/=same!" 'parser$="/f+effplus/+soloplus/s+esplus/=same!" 'parser$="/+soloplus/f+effplus/s+esplus/=same!" 'parser$="/s+esplus/+soloplus/f+effplus/=same!" 'parser$="/+soloplus/s+esplus/f+effplus/=same!" '2. Six-pack 'parser$="/=same!/f+effplus/+soloplus/s+esplus" 'parser$="/=same!/+soloplus/f+effplus/s+esplus" 'parser$="/+soloplus/f+effplus/=same!/s+esplus" 'parser$="/+soloplus/=same!/f+effplus/s+esplus" 'parser$="/f+effplus/=same!/+soloplus/s+esplus" 'parser$="/f+effplus/+soloplus/=same!/s+esplus" '3. Six-pack 'parser$="/=same!/+soloplus/s+esplus/f+effplus" 'parser$="/=same!/s+esplus/+soloplus/f+effplus" 'parser$="/s+esplus/+soloplus/=same!/f+effplus" 'parser$="/s+esplus/=same!/+soloplus/f+effplus" 'parser$="/+soloplus/=same!/s+esplus/f+effplus" 'parser$="/+soloplus/s+esplus/=same!/f+effplus" '4. Six-pack 'parser$="/=same!/f+effplus/s+esplus/+soloplus" 'parser$="/=same!/s+esplus/f+effplus/+soloplus" 'parser$="/s+esplus/f+effplus/=same!/+soloplus" 'parser$="/s+esplus/=same!/f+effplus/+soloplus" 'parser$="/f+effplus/=same!/s+esplus/+soloplus" 'parser$="/f+effplus/s+esplus/=same!/+soloplus" ' 'now call the parsing- procedure........ ' call string_parser_four("/+",_ 'delimiter 1 - input "/F+",_ 'delimiter 2 - input "/S+",_ 'delimiter 3 - input "/=",_ 'delimiter 4 - input parser$,_ 'the whole string - input shortcut$,_ 'name of string 1 drives$,_ 'name of string 2 checksum$,_ 'name of string 3 pfad$,_ 'name of string 4 %true) 'for /f+ and /F+ the same 'function? If not wanted, 'you have to write %false 'here! print : print ? tab(10) "Here there is the result:" write "Here must stand 'soloplus' : ";shortcut$ ' first return write "Here must stand 'effplus' : ";drives$ ' second return write "Here must stand 'esplus' : ";checksum$ ' third return write "Here must stand 'same!' : ";pfad$ ' fourth return end ' '------------------ Parser for four string- parts ------------------ ' sub string_parser_four(del1$,_ 'Delimiter 1 del2$,_ 'Delimiter 2 del3$,_ 'Delimiter 3 del4$,_ 'Delimiter 4 whole$,_ 'the whole string back1$,_ 'Return 1 (shortcut$) back2$,_ 'Return 2 (Pfad$) back3$,_ 'Return 3 (drives$) back4$,_ 'Return 4 (checksum$) equal_function) 'for /f+ and /F+ the same 'function? local part1,part2,part3,part4 local len_del1,len_del2,len_del3,len_del4 local for_del_check$ 'Here there are some local variables, which aren't realy necessary, 'but in my opinion it was easier for creating the code.... len_del1=len(del1$) : len_del2=len(del2$) len_del3=len(del3$) : len_del4=len(del4$) if equal_function then 'for all delimiters, e.g. /f+ and /F+ : the same function! 'BTW: It's pretty important to overgive /F+ and NOT /f+, if you 'don't want to differ between /f+ and /F+.... for_del_check$=ucase$(whole$) else 'here is differed between /f+ and /F+; it's NOT used in my ex- 'ample, but it should work properly..... for_del_check$=whole$ end if 'We have to know, where the delimiters are.... part1=instr(for_del_check$,del1$)+len_del1 'first /+ from left part2=instr(for_del_check$,del2$)+len_del2 'first /f+ or /F+ from left part3=instr(for_del_check$,del3$)+len_del3 'first /s+ or /S+ from left part4=instr(for_del_check$,del4$)+len_del4 'first /= from left '-- Missing one of the four delimiters? Now we can check out this ' easily! if part1=len_del1 or part2=len_del2 or _ part3=len_del3 or part4=len_del4 then ? tab(5) "One of the delimiters is missing, check your input!"; : end end if ' ' first delimiter is /+ ' second delimiter is /f+ (or /F+) ' third delimiter is /s+ (or /S+) ' last Delimiter is /= ' '-- The first six...... if part4>part3 and part4>part2 and _ ' 4 then /= is last part4>part1 then back4$=mid$(whole$,part4) if part3>part2 and part3>part1 then ' 4 / 3 back3$=mid$(whole$,part3,part4-part3-len_del4) if part2>part1 then ' 4 / 3 / 2 / 1 back2$=mid$(whole$,part2,part3-part2-len_del3) back1$=mid$(whole$,part1,part2-part1-len_del2) elseif part1>part2 then ' 4 / 3 / 1 / 2 back2$=mid$(whole$,part2,part1-part2-len_del1) back1$=mid$(whole$,part1,part3-part1-len_del3) end if elseif part2>part3 and part2>part1 then ' 4 / 2 back2$=mid$(whole$,part2,part4-part2-len_del4) if part3>part1 then ' 4 / 2 / 3 / 1 back3$=mid$(whole$,part3,part2-part3-len_del2) back1$=mid$(whole$,part1,part3-part1-len_del3) elseif part1>part3 then ' 4 / 2 / 1 / 3 back3$=mid$(whole$,part3,part1-part3-len_del1) back1$=mid$(whole$,part1,part2-part1-len_del2) end if elseif part1>part3 and part1>part2 then ' 4 / 1 back1$=mid$(whole$,part1,part4-part1-len_del4) if part3>part2 then ' 4 / 1 / 3 / 2 back3$=mid$(whole$,part3,part1-part3-len_del1) back2$=mid$(whole$,part2,part3-part2-len_del3) elseif part2>part3 then ' 4 / 1 / 2 / 3 back3$=mid$(whole$,part3,part2-part3-len_del2) back2$=mid$(whole$,part2,part1-part2-len_del1) end if end if '-- The second six...... elseif part3>part4 and part3>part2 and _ ' 3 then /s+ (or /S+) is last part3>part1 then back3$=mid$(whole$,part3) if part4>part2 and part4>part1 then ' 3 / 4 back4$=mid$(whole$,part4,part3-part4-len_del3) if part2>part1 then ' 3 / 4 / 2 / 1 back2$=mid$(whole$,part2,part4-part2-len_del4) back1$=mid$(whole$,part1,part2-part1-len_del2) elseif part1>part2 then ' 3 / 4 / 1 / 2 back2$=mid$(whole$,part2,part1-part2-len_del1) back1$=mid$(whole$,part1,part4-part1-len_del4) end if elseif part2>part4 and part2>part1 then ' 3 / 2 back2$=mid$(whole$,part2,part3-part2-len_del3) if part4>part1 then ' 3 / 2 / 4 / 1 back4$=mid$(whole$,part4,part2-part4-len_del2) back1$=mid$(whole$,part1,part4-part1-len_del4) elseif part1>part4 then ' 3 / 2 / 1 / 4 back4$=mid$(whole$,part4,part1-part4-len_del1) back1$=mid$(whole$,part1,part2-part1-len_del2) end if elseif part1>part4 and part1>part2 then ' 3 / 1 back1$=mid$(whole$,part1,part3-part1-len_del3) if part2>part4 then ' 3 / 1 / 2 / 4 back4$=mid$(whole$,part4,part2-part4-len_del2) back2$=mid$(whole$,part2,part1-part2-len_del1) elseif part4>part2 then ' 3 / 1 / 4 / 2 back4$=mid$(whole$,part4,part1-part4-len_del1) back2$=mid$(whole$,part2,part4-part2-len_del4) end if end if '-- The third six...... elseif part2>part4 and part2>part3 and _ ' 2 then /f+ (or /F+) is last part2>part1 then back2$=mid$(whole$,part2) if part4>part3 and part4>part1 then ' 2 / 4 back4$=mid$(whole$,part4,part2-part4-len_del2) if part3>part1 then ' 2 / 4 / 3 / 1 back3$=mid$(whole$,part3,part4-part3-len_del4) back1$=mid$(whole$,part1,part3-part1-len_del3) elseif part1>part3 then ' 2 / 4 / 1 / 3 back3$=mid$(whole$,part3,part1-part3-len_del1) back1$=mid$(whole$,part1,part4-part1-len_del4) end if elseif part3>part4 and part3>part1 then ' 2 / 3 back3$=mid$(whole$,part3,part2-part3-len_del2) if part4>part1 then ' 2 / 3 / 4 / 1 back4$=mid$(whole$,part4,part3-part4-len_del3) back1$=mid$(whole$,part1,part4-part1-len_del1) elseif part1>part4 then ' 2 / 3 / 1 / 4 back4$=mid$(whole$,part4,part1-part4-len_del1) back1$=mid$(whole$,part1,part3-part1-len_del3) end if elseif part1>part4 and part1>part3 then ' 2 / 1 back1$=mid$(whole$,part1,part2-part1-len_del2) if part4>part3 then ' 2 / 1 / 4 / 3 back4$=mid$(whole$,part4,part1-part4-len_del1) back3$=mid$(whole$,part3,part4-part3-len_del4) elseif part3>part4 then ' 2 / 1 / 3 / 4 back4$=mid$(whole$,part4,part3-part4-len_del3) back3$=mid$(whole$,part3,part1-part3-len_del1) end if end if 'The fourth six...... elseif part1>part4 and part1>part3 and _ ' 1 then /+ is last part1>part2 then back1$=mid$(whole$,part1) if part2>part3 and part2>part4 then ' 1 / 2 back2$=mid$(whole$,part2,part1-part2-len_del1) if part4>part3 then ' 1 / 2 / 4 / 3 back4$=mid$(whole$,part4,part2-part4-len_del2) back3$=mid$(whole$,part3,part4-part3-len_del4) elseif part3>part4 then ' 1 / 2 / 3 / 4 back4$=mid$(whole$,part4,part3-part4-len_del3) back3$=mid$(whole$,part3,part2-part3-len_del2) end if elseif part3>part4 and part3>part2 then ' 1 / 3 back3$=mid$(whole$,part3,part1-part3-len_del1) if part4>part2 then ' 1 / 3 / 4 / 2 back4$=mid$(whole$,part4,part3-part4-len_del3) back2$=mid$(whole$,part2,part4-part2-len_del4) elseif part2>part4 then ' 1 / 3 / 2 / 4 back4$=mid$(whole$,part4,part2-part4-len_del2) back2$=mid$(whole$,part2,part3-part2-len_del3) end if elseif part4>part3 and part4>part2 then ' 1 / 4 back4$=mid$(whole$,part4,part1-part4-len_del1) if part2>part3 then ' 1 / 4 / 2 / 3 back3$=mid$(whole$,part3,part2-part3-len_del2) back2$=mid$(whole$,part2,part4-part2-len_del4) elseif part3>part2 then ' 1 / 4 / 3 / 2 back3$=mid$(whole$,part3,part4-part3-len_del4) back2$=mid$(whole$,part2,part3-part2-len_del3) end if end if end if end sub ' '****************************** EOF *******************************