📄 ckcbwr.txt
字号:
11. SCRIPT PROGRAMMING [ [78]Top ] [ [79]Contents ] [ [80]Previous ] 11.1. Comments Versus the SCRIPT Command Remember that ";" and "#" introduce comments when (a) they are the first character on the line, or (b) they are preceded by at least one blank or tab within a line. Thus constructions like: INPUT 5 ; SCRIPT ~0 #--#--# must be coded using backslash notation to keep the data from being ignored: INPUT 5 \59 ; 59 is the decimal ASCII code for ";" SCRIPT ~0 \35--#--# ; 43 is the decimal ASCII code for "#" or, more simply: INPUT 5 \; ; Just quote the semicolon SCRIPT ~0 \#--#--# ; Just quote the "#" ________________________________________________________________________ 11.2. Alphabetic Case and the INPUT Command INPUT and MINPUT caseless string comparisons do not work for non-ASCII (international) characters. Workaround: SET INPUT CASE OBSERVE. Even then, the "lexically less than" and "lexically greater than" operations (IF LLT, IF LGT) probably won't work as expected. The same is true for the case-conversion functions \Flower() and \Fupper(). C-Kermit does not know the collating sequence for different character sets and languages. (On the other hand, it might work depending on such items as how Kermit was linked, whether your operating supports "locales", etc) ________________________________________________________________________ 11.3. NUL (0) Characters in C-Kermit Commands You can't include a NUL character (\0) in C-Kermit command text without terminating the character string in which it appears. For example: echo In these brackets [\0] is a NUL will echo "In these brackets [". This applies to ECHO, INPUT, OUTPUT, and all other commands (but you can represent NUL by "\N" in an OUTPUT string). This is because C-language strings are terminated internally by the NUL character, and it allows all of C-Kermit's string comparison and manipulation functions to work in the normal "C" way. To illustrate: INPUT 5 \0 is equivalent to: INPUT 5 and: INPUT 5 ABC\0DEF is equivalent to: INPUT 5 ABC INPUT operations discard and ignore NUL characters that arrive from the communication device, meaning that they do not figure into matching operations (e.g. A<NUL>B matches AB); they are not deposited in the INPUT buffer (\v(input)); and they are not counted in \v(incount), with two exceptions: 1. An arriving NUL character restarts the INPUT SILENCE timer. 2. An arriving NUL character terminates the INPUT command with the SUCCESS condition if the INPUT command was given an empty search string. In this case \v(incount) is set to 1. Also, the \v(inchar) variable is null (completely empty) if the last INPUT character was NUL. That is, there is no way to tell only by looking at \v(inchar) the difference between a NUL that was INPUT and no INPUT at all. If the INPUT command succeeded but \v(inchar) is empty, then a NUL character was input. Also, \v(incount) will be set to 1. Here's a sample script fragment to read characters, possibly including NUL, from the communication connection and write them to a file: while true { input 1 ; read one byte if fail break ; timed out or connection closed fwrite /char \%c \v(inchar) ; record the byte } This works because when \v(inchar) is NUL, that's equivalent to FWRITE /CHAR having no text argument at all, in which case it writes a NUL character. \v(incount) and \v(inchar) are NOT affected by the CLEAR command. ________________________________________________________________________ 11.4. \ffiles() and \fnextfile() Peculiarities The following script program: for \%i 1 \ffiles(oofa.*) 1 { send \fnextfile() } did not work as expected in C-Kermit 6.0 and earlier but does work in C-Kermit 7.0 and later. ________________________________________________________________________ 11.5. Commands That Have Only Local Effect Certain settings are local to each command level, meaning that subordinate command levels (macros or command files) can change them without affecting their values at higher command levels. When a new command level is invoked, the value is inherited from the previous level. These settings are: CASE COUNT and \v(count) INPUT CASE INPUT TIMEOUT MACRO ERROR QUIET TAKE ERROR This arrangement allows CASE, TIMEOUT, and ERROR settings, which are used to control automatic exit from a command file or macro upon error, to be automatically restored when the command file or macro exits. The COUNT variable follows this rule too, which permits nested SET COUNT / IF COUNT loops, as in this example in which the inner loop counts down from the current COUNT value of the outer loop (try it): DEFINE INNER WHILE COUNT { WRITE SCREEN { Inner:}, SHOW COUNT } SET COUNT 5 WHILE COUNT { WRITE SCREEN Outer:, SHOW COUNT, DO INNER } Keep in mind that an inferior command level cannot manipulate the COUNT value held by a higher level. For example: DEFINE OOFA SHOW COUNT, IF COUNT GOTO LOOP SET COUNT 5 :LOOP OOFA ECHO Done results in an infinite loop; the COUNT value remains at 5 because it is never decremented at the same level at which it was set. ________________________________________________________________________ 11.6. Literal Braces in Function Calls Since braces are used in function calls to indicate grouping, there is no way to pass literal braces to the function itself. Solution: Define a variable containing the string that has braces. Example: define \%a ab{cd echo \fsubstring(\%a) ab{cd If the string is to start with a leading brace and end with a closing brace, then double braces must appear around the string (which itself is enclosed in braces): define \%a {{{foo}}} echo \fsubstring(\%a) {foo} This also works for any other kind of string: define \%a {{ab{cd}} echo \fsubstring(\%a) ab{cd ________________________________________________________________________ 11.7. Defining Variables on the C-Kermit Command Line To define variables on the C-Kermit command line, use the -C command-line option with one or more DEFINE or ASSIGN commands. Note that the C-Kermit command line must cope with the quoting rules of your shell. Examples: kermit -C "define \\%a foo, define phonenumber 7654321" In this case we follow UNIX quoting rules by doubling the backslash. Once C-Kermit starts, the \%a and \m(phonenumber) variables are defined as indicated and can be used in the normal way. In DOS or Windows or OS/2 the command would be: kermit -C "define \%%a foo, define phonenumber 7654321" Here we need to double the percent sign rather than the backslash because of DOS shell quoting rules. ________________________________________________________________________ 11.8. Per-Character Echo Check with the OUTPUT Command Sometimes the OUTPUT command must be used to send commands or data to a device in "echoplex" mode, meaning that characters must be sent one at a time, and the next character can not be sent until the echo from the previous one has been received. For example, a certain PBX might have this characteristic. Let's say a Kermit script is used to program the PBX. If characters are sent too fast, they can be lost. It would seem that the command: SET OUTPUT PACING milliseconds could be used to take care of this, but the pacing interval is constant and must be set large enough to allow even the slowest echo to finish. If the script is large (an actual example is 14,000 lines long), this can cause it to take hours longer than it needs to. Here is a macro you can use to OUTPUT a string in an Echoplex environment: define XOUTPUT { local \%c \%i set output pacing 0 for \%i 1 \flen(\%*) 1 { asg \%c \fsubstr(\%*,\%i,1) output \%c input 2 \%c } } C-Kermit 7.0 or later is required. It sends one character at a time and then waits up to 2 seconds for the character to be echoed back, but continues to the next character as soon as the echo appears, so no time is wasted. You can add an IF FAIL clause after the INPUT in case you want to do something special about failure to detect an echo within the timeout period. Obviously you can also change the 2-second limit, and adjust the script in any other desired way. ________________________________________________________________________ 11.9. Scripted File Transfer Sometimes a user complains that when she makes a connection by hand, logs in, and transfers a file, there are no problems, but when she scripts the the exact same sequence, the file transfer always fails after a few packets. Here's a scenario where this can happen: 1. Upon logging in to the remote computer, it sends a "What Are You?" escape sequence. 2. When you log in interactively, your terminal emulator sends the response. This is invisible to you; you don't know it's happening. 3. When you script the login, and begin a file transfer immediately upon logging in, the host still sends the "What Are You?" sequence. Kermit's INPUT ECHO setting is ON by default, so the escape sequence passes through to the terminal, and the terminal sends its response. But by this time Kermit has already started the file transfer. 4. By default, the local Kermit program examines the keyboard for interruption characters between every packet. The "What Are You" response is sitting in the keyboard buffer. Eventually Kermit will read a character such as "c" that is a valid interruption character, and the file transfer stops with "User cancelled". The right way to handle this situation is to have your look for the "What Are You?" sequence and send the response itself, as described in Using C-Kermit, pp.429-431. Or you can work
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -