⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ckedemo.ksc

📁 linux终端仿真程序
💻 KSC
字号:
COMMENT - File CKEDEMO.KSC;; Exercises Kermit's programming constructs.; Converted to block-structured format, March 1996.;; Usage: tell Kermit to "take ckedemo.ksc";; 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; forward arraysswitch \v(program) {  :MS-DOS_KERMIT,    if < \v(version) 315 stop 1 Version 3.15 or later required...    echo MS-DOS Kermit Programming-Constructs Test    break  :C-Kermit,    if < \v(version) 600192 stop 1 Version 6.0 or later required...    echo C-Kermit Programming-Constructs Test}echoecho Defining macros:define ERRMSG if def \%1 echo \%1, end 1COMMENT - COPY macro.  Only works for single files.;echo { COPY}define COPY {  if > \v(argc) 3 -                     ; Too many arguments given?    end 1 \%0: too many arguments       ;  Too many, fail.  if not def \%1 -                      ; Was a source file given?    end 1 copy what?                    ;  No.  if not = \ffiles(\%1) 1 -             ; Yes, but is it "wild?"?    end 1 wildcards not allowed         ;  Sorry, no wildcards.  if not exist \%1 -                    ; Does source file exist?    end 1 file \%1 doesn't exist        ;  No, so it can't be copied.  if not def \%2 -                      ; Destination file specified?    end 1 copy \%1 to what?             ;  No, so it can't be copied to.  if not = \ffiles(\%2) 0 -             ; Does it already exist?    end 1 file \%2 already exists       ;  Yes, so don't write over it.  if equal "\v(system)" "UNIX" -        ; COPY command for UNIX:    run cp \%1 \%2                      ;   cp source destination  else if equal "\v(system)" "AOS/VS" - ; For AOS/VS:    run COPY \%2 \%1                    ;   COPY destination source  else run COPY \%1 \%2                 ; Others: COPY source destination  if exist \%2 end 0                    ; Check our work and return SUCCESS  else end 1 COPY failed.               ;   or FAILURE as appropriate.}COMMENT - SPELLNUM macro.;echo { SPELLNUM}define SPELLNUM {  local \%x  if not def \%1 end 1  if not numeric \%1 end 1 { Sorry, not a number}  xif < \%1 0 {     asg \%x { minus}     asg \%1 \feval(0-\%1)  }  asg \%1 \feval(\%1)  ; This takes care of "09" etc  if > \%1 9 end 1 { Sorry, too hard}  else forward \%1  :0,end 0 \%x zero  :1,end 0 \%x one  :2,end 0 \%x two  :3,end 0 \%x three  :4,end 0 \%x four  :5,end 0 \%x five  :6,end 0 \%x six  :7,end 0 \%x seven  :8,end 0 \%x eight  :9,end 0 \%x nine}COMMENT - CALC macro.  "Pocket calculator".  No arguments.;echo { CALC}define CALC {  echo Press Return to exit       ; Say how to exit.  def \%1 1                       ; Initial condition for loop  while def \%1 {                 ; Loop until they want to exit    ask \%1 { expression: }       ; Ask for an expression    echo \flpad(\feval(\%1),10)   ; Evaluate and print answer  }  echo Back to...                 ; All done}echo { ADDINGMACHINE}define ADDINGMACHINE {  local total \%s  echo Type numbers (one per line) or press Return to quit...  assign total 0                          ; Initialize the sum  while true {                            ; Loop till done    askq \%s                              ; Wait for a number    if not def \%s break                  ; Return quits loop    increment total \%s                   ; Add it to the sum    write screen \flpad(\%s,10)\flpad(\m(total),10) ; Print number and subtotal  }  echo Total\flpad(\m(total),15,.)}COMMENT - SMALLEST macro, recursive.  Arguments:; 1 = a number; 2 = a number; 3 = a number; Prints the smallest of the three.;echo { SMALLEST}def SMALLEST {  if < \v(argc) 4 end 1 { Sorry - three numbers required.}  xif < \%1 \%2 {                   ; Compare first two arguments    echo \%1 is less than \%2       ; The first one is smaller    xif < \%1 \%3 {                 ; Compare it with the third      echo \%1 is less than \%3     ; The first one is smaller      def \%a \%1                   ; Copy it to \%a    } else {                        ; The third is smaller      echo \%1 is not less than \%3      def \%a \%3                   ; Copy it to \%a    }  } else {                          ; Otherwise    echo \%1 is not less than \%2   ; The second is smaller    xif < \%2 \%3 {                 ; Compare it with the third      echo \%2 is less than \%3     ; The second is smaller      def \%a \%2                   ; Copy it to \%a    } else {                        ; The third is smaller      echo \%2 is not less than \%3      def \%a \%3                   ; Copy it to \%a    }  }  echo So the smallest is \%a.      ; Announce the winner}ec Spelling some numbers...for \%i -5 9 1 { spellnum \%i }echo Calculator demo...calcecho Adding machine demo - Enter an empty line to quit...addingmachineif eq {\v(program)} {MS-DOS_KERMIT} forward smallest; No \fexec() in MS-DOS Kermit.COMMENT - SUM macro, recursive.  Argument:; 1 = limit of sum, a positive number.; Returns sum of 1 through the number.;echo { SUM}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)))}COMMENT - ADDEMUP macro, for calling SUM.;echo { ADDEMUP}def ADDEMUP {  local total  assign total \fexec(sum,\%1)  if def total echo SUM = \m(total)  else echo SUM doesn't work for \%1}addemup 1addemup 2addemup 3addemup 4addemup 5addemup 10addemup 20:SMALLESTwhile true {  ask \%x { Type 3 numbers separated by spaces or an empty line to quit:  }  if not def \%x break  smallest \%x}echo WHILE-LOOP TEST...echo You should see:echo { 0 1 2 3 4}def \%a 0while < \%a 5 { write scr { \%a}, incr \%a }echoecho 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 0while < \%a 3 {  def \%b 0  while < \%b 3 {    write scr { \%a:\%b}    incr \%b  }  incr \%a }echoecho FOR-LOOP INSIDE WHILE-LOOPecho You should see:echo { 1:1 1:2 1:3 2:1 2:2 2:3 3:1 3:2 3:3}def \%a 1while < \%a 4 {   for \%i 1 3 1 { write scr { \%a:\%i} }  inc \%a }echoecho WHILE-LOOP INSIDE FOR-LOOPecho 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   }}echoecho NESTED FOR LOOP TESTecho 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}   }}echoecho 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}   }}echoecho END from inside nested FOR loopsecho 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 xxechoif not eq {\v(program)} {C-Kermit} forward xifendtestecho RETURN from inside nested FOR loopsecho You should see "IT WORKS":define xx {  local \%i \%j  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)":XIFENDTESTecho END message from inside XIFecho You should see "IT WORKS"def xx xif = 1 1 { end 0 "IT \%1"}xx WORKSecho Grouping of words in IF EQUALecho You should see "IT WORKS":def \%a one two threeif equal {\%a} {one two three} echo "IT WORKS"else echo It doesn't work, foo.ececho Use of expressions and braces in FOR-loop variablesecho You should see "1 2 3":def \%a 2for \%i 1 { 1 + \%a } 1 { write screen {\%i } }echoecho A macro that echoes its argumentsdef XX {  local \%i  for \%i 1 { \v(argc) - 1 } 1 {    echo \%i. "\&_[\%i]"  }}while true {  ask \%a {Type some words (or just carriage return to quit): }  if not def \%a break  xx \%a}echoif eq {\v(program)} {MS-DOS_KERMIT} forward arraysif not eq {\v(connection)} {\v(remote)} forward arraysec MINPUT test...ec Please type one of the following (without the number):ec 1. ab cdec 2. abcdec 3. xyzec You have 20 seconds...minput 20 {ab cd} abcd xyzecif success echo You typed Number \v(minput).else echo You did not type any of them within the time limit.echo:ARRAYSgetc \%c {ARRAY TEST -- type a char to continue: }declare \&a[26]local \%i \%j \%t                    ; Local variablesassign \%i 1asg \&a[\%i] zebraincr \%iasg \&a[\%i] x-rayincr \%i 1asg \&a[\%i] bakerincr \%i 3-2asg \&a[\%i] abledecr \%i -1asg \&a[\%i] charlieasg \&a[\%i+1] easyasg \&a[\%i+2] georgeasg \&a[\%i+3] dogasg \%n \%i+2+8/4asg \&a[\%n] foxecho ARRAY TEST - Sorting ...getc \%c {Type a char to continue: }for \%i 1 \%n-1 1 {                  ; Outer loop: i from 1 to n-1    for \%j \%i \%n 1 {               ; Inner loop: j from i to n	xif lgt \&a[\%i] \&a[\%j] {  ; Compare array elements	    asg \%t \&a[\%i]         ; If out of order,	    asg \&a[\%i] \&a[\%j]    ; exchange them	    asg \&a[\%j] \%t	}    }}echo You should see 9 words in alphabetical order:getc \%c {Type a char to continue: }for \%i 1 \%n 1 { echo \&a[\%i] }    ; All sorted - print themecho End of \v(cmdfile)echo

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -