home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc190.zip / ckedemo.ini < prev    next >
Text File  |  1994-06-05  |  5KB  |  135 lines

  1. COMMENT - C-Kermit 5A Macro Demonstration File
  2. ;
  3. ; Filename:
  4. ;   CKEDEMO.INI: Demonstration macros from "Using C-Kermit"
  5. ;
  6. ; Authors:
  7. ;   Frank da Cruz, Christine M. Gianone
  8. ;   Columbia University, New York, NY USA 10027
  9. ;
  10. ; Date: 23 November 1992
  11. ;
  12. set take error on        ; Script programming language required!
  13. check if
  14. set take error off
  15.  
  16. echo Executing \v(cmdfile)...
  17. echo Defining macros:
  18.  
  19. define errmsg if def \%1 echo \%1, end 1
  20.  
  21. COMMENT - COPY macro.  Only works for single files.
  22. ;
  23. echo { COPY}
  24. define COPY -
  25.   if > \v(argc) 3 -                     ; Too many arguments given?
  26.     end 1 \%0: too many arguments,-     ;  Too many, fail.
  27.   if not def \%1 -                      ; Was a source file given?
  28.     end 1 copy what?,-                  ;  No.
  29.   if not = \ffiles(\%1) 1 -             ; Yes, but is it "wild?"?
  30.     end 1 wildcards not allowed,-       ;  Sorry, no wildcards.
  31.   if not exist \%1 -                    ; Does source file exist?
  32.     end 1 file \%1 doesn't exist,-      ;  No, so it can't be copied.
  33.   if not def \%2 -                      ; Destination file specified?
  34.     end 1 copy \%1 to what?,-           ;  No, so it can't be copied to.
  35.   if not = \ffiles(\%2) 0 -             ; Does it already exist?
  36.     end 1 file \%2 already exists,-     ;  Yes, so don't write over it.
  37.   if equal "\v(system)" "UNIX" -        ; COPY command for UNIX:
  38.     run cp \%1 \%2,-                    ;   cp source destination
  39.   else if equal "\v(system)" "AOS/VS" - ; For AOS/VS:
  40.     run COPY \%2 \%1,-                  ;   COPY destination source
  41.   else run COPY \%1 \%2,-               ; Others: COPY source destination
  42.   if exist \%2 end 0,-                  ; Check our work and return SUCCESS
  43.     else end 1 COPY failed.             ;   or FAILURE as appropriate.
  44.  
  45. COMMENT - SPELLNUM macro.
  46. ;
  47. echo { SPELLNUM}
  48. define spellnum if not def \%1 end 1,-
  49.   else if not numeric \%1 end 1 { Sorry, not a number},-
  50.   else if > \%1 9 end 1 { Sorry, too hard},-
  51.   else if < \%1 0 end 1 { Sorry, I can't spell negative numbers},-
  52.   else goto \%1,-
  53. :0,end 0 zero,-
  54. :1,end 0 one,-
  55. :2,end 0 two,-
  56. :3,end 0 three,-
  57. :4,end 0 four,-
  58. :5,end 0 five,-
  59. :6,end 0 six,-
  60. :7,end 0 seven,-
  61. :8,end 0 eight,-
  62. :9,end 0 nine
  63.  
  64. COMMENT - CALC macro.  "Pocket calculator".  No arguments.
  65. ;
  66. echo { CALC}
  67. define CALC -
  68. echo Press Return to exit,-       ; Say how to exit.
  69. def \%1 1,-                       ; Initial condition for loop
  70. while def \%1 { -                 ; Loop until they want to exit
  71.     ask \%1 { expression: },-     ; Ask for an expression
  72.     echo \flpad(\feval(\%1),10)-  ; Evaluate and print answer
  73. },-
  74. echo Back to...                   ; All done
  75.  
  76. echo { ADDINGMACHINE}
  77. define ADDINGMACHINE -
  78. echo Type numbers (one per line) or press Return to quit...,-
  79. assign \%3 0,-                            ; Initialize the sum
  80. while = 1 1 {-                            ; Loop till done
  81.     askq \%1,-                            ; Wait for a number
  82.     if not def \%1 break,-                ; Return quits loop
  83.     increment \%3 \%1,-                   ; Add it to the sum
  84.     write screen \flpad(\%1,10)\flpad(\%3,10),- ; Print number and subtotal
  85. },-
  86. echo Total\flpad(\%3,15,.)
  87.  
  88. COMMENT - ADDEMUP macro, for calling SUM.
  89. ;
  90. echo { ADDEMUP}
  91. def addemup assign \%9 \fexec(sum \%1), -
  92.   if def \%9 echo SUM = \%9, -
  93.   else echo SUM doesn't work for \%1
  94.  
  95. COMMENT - SUM macro, recursive.  Argument:
  96. ; 1 = limit of sum, a positive number.
  97. ; Returns sum of 1 through the number.
  98. ;
  99. echo { SUM}
  100. def sum if not def \%1 return,-  ; Make sure there is an argument
  101.   if not numeric \%1 return,-    ; Make sure argument is numeric
  102.   if not > \%1 0 return,-        ; Make sure argument is positive
  103.   if = \%1 1 return 1,-          ; If argument is 1, the sum is 1
  104.   else return \feval(\%1 + \fexecute(sum \feval(\%1 - 1)))
  105.  
  106. COMMENT - SMALLEST macro, recursive.  Arguments:
  107. ; 1 = a number
  108. ; 2 = a number
  109. ; 3 = a number
  110. ; Prints the smallest of the three.
  111. ;
  112. echo { SMALLEST}
  113. def smallest xif < \%1 \%2 {-       ; Compare first two arguments
  114.   echo \%1 is less than \%2,-       ; The first one is smaller
  115.   xif < \%1 \%3 {-                  ; Compare it with the third
  116.     echo \%1 is less than \%3,-     ; The first one is smaller
  117.     def \%a \%1-                    ; Copy it to \%a
  118.   } else {-                         ; The third is smaller
  119.     echo \%1 is not less than \%3,-
  120.     def \%a \%3-                    ; Copy it to \%a
  121.   }-
  122. } else {-                           ; Otherwise
  123.   echo \%1 is not less than \%2,-   ; The second is smaller
  124.   xif < \%2 \%3 {-                  ; Compare it with the third
  125.     echo \%2 is less than \%3,-     ; The second is smaller
  126.     def \%a \%2-                    ; Copy it to \%a
  127.   } else {-                         ; The third is smaller
  128.     echo \%2 is not less than \%3,-
  129.     def \%a \%3-                    ; Copy it to \%a
  130.   }-
  131. }, echo So the smallest is \%a.     ; Announce the winner
  132.  
  133.  
  134. ; (End of CKEDEMO.INI)
  135.