COMMENT - CKETEST.INI ; ; Exercises C-Kermit's programming constructs (see Ch.12, "Using C-Kermit"). ; echo echo C-Kermit Programming-Constructs Test echo echo If you don't see the message "Proceeding..." echo on the next line, C-Kermit was not configured for script programming. check if echo Proceeding... sleep 2 echo asg \%p ckedemo.ini if exist \%p goto demo ; ; If ckedemo.ini is not in the current directory, we have to find it... ; asg \%s / ; Directory separator if eq \v(system) VMS asg \%s ] if eq \v(system) AOS/VS asg \%s : if eq \v(system) Macintosh asg \%s : if eq \v(system) Atari_ST asg \%s \\ if eq \v(system) Stratus_VOS > asg \%p \freverse(\v(cmdfile)) asg \%p \freverse(\fsubstr(\%p,\findex(/,\%p)))ckedemo.ini if exist \%p goto demo echo Can't find ckedemo.ini file, proceeding with other tests... goto other :DEMO take \%p ec Spelling some numbers... for \%i 0 9 1 { spellnum \%i } echo Calculator demo... calc echo Adding machine demo - Enter an empty line to quit... addingmachine echo Recursive sum macro... def sum if not def \%1 return,- ; Make sure there is an argument if not numeric \%1 return,- ; Make sure argument is numeric if not > \%1 0 return,- ; Make sure argument is positive if = \%1 1 return 1,- ; If argument is 1, the sum is 1 else return \feval(\%1 + \fexecute(sum \feval(\%1 - 1))) def addemup echo sum of 0..\%1 = \fexec(sum \%1) addemup 1 addemup 2 addemup 3 addemup 4 addemup 5 addemup 10 addemup 20 :LOOP echo ask \%1 { Type 3 numbers separated by spaces or an empty line to quit: } if not def \%1 goto other smallest \%1 goto loop :OTHER ; Other tests echo WHILE-LOOP TEST... echo You should see: echo { 0 1 2 3 4} def \%a 0 while < \%a 5 { write scr { \%a}, incr \%a } echo echo NESTED WHILE-LOOP TEST... echo You should see: echo { 0:0 0:1 0:2 1:0 1:1 1:2 2:0 2:1 2:2} def \%a 0 while < \%a 3 {- def \%b 0,- while < \%b 3 {- write scr { \%a:\%b},- incr \%b,- },- incr \%a - } echo echo FOR-LOOP INSIDE WHILE-LOOP echo You should see: echo { 1:1 1:2 1:3 2:1 2:2 2:3 3:1 3:2 3:3} def \%a 1 while < \%a 4 { - for %i 1 3 1 { write scr { \%a:\%i} },- inc \%a - } echo echo WHILE-LOOP INSIDE FOR-LOOP echo You should see: echo { 1:1 1:2 1:3 2:1 2:2 2:3 3:1 3:2 3:3} for \%i 1 3 1 {- def \%a 1,- while < \%a 4 {- writ scr { \%i:\%a},- incr \%a - }- } echo echo NESTED FOR LOOP TEST echo You should see: echo { 1:1 1:2 1:3 2:2 2:3 3:3} for \%i 1 3 1 {- for \%j \%i 3 1 {- write scr { \%i:\%j} - }- } echo echo NESTED FOR/WHILE/BREAK/CONTINUE TEST echo You should see: echo { 1:1 1:3 3:1 3:3} for \%i 1 4 1 { - if = \%i 2 continue,- else if = \%i 4 break,- asg \%j 0,- while < \%j 4 { - incr \%j,- if = \%j 2 continue,- else if = \%j 4 break,- write screen { \%i:\%j} - },- } echo echo END from inside nested FOR loops (Edit 190 and later) echo You should see: echo { 1:1 1:2 1:3 2:1 2:2 2:3 3:1} define xx - for \%i 1 3 1 {- for \%j 1 3 1 {- write scr { \%i:\%j}, - if = \%i 3 if = \%j 1 end - }- } do xx echo echo RETURN from inside nested FOR loops (Edit 190 and later) echo You should see "IT WORKS": define xx - for \%i 1 3 1 { - for \%j 1 3 1 { - if = \%i 3 if = \%j 1 return IT \%1 - } - } - echo YOU SHOULD NOT SEE THIS echo "\fexec(xx WORKS)" echo END message from inside XIF (Edit 190 and later) echo You should see "IT WORKS" def xx xif = 1 1 { end 0 "IT \%1"} xx WORKS echo Grouping of words in IF EQUAL (Edit 190 and later) echo You should see "IT WORKS": def \%a one two three if equal {\%a} {one two three} echo IT WORKS else echo It doesn't work, foo. ec ec MINPUT test... ec Please type one of the following (without the number): ec 1. ab cd ec 2. abcd ec 3. xyz ec You have 20 seconds... minput 20 {ab cd} abcd xyz ec if success echo You typed Number \v(minput). else echo You did not type any of them within the time limit. echo echo End of \v(cmdfile) echo