跳轉到內容

Aros/開發者/文件/Rexx

來自Wikibooks,開放世界中的開放書籍
Aros 華夏公益教科書的導航欄
Aros 使用者
Aros 使用者文件
Aros 使用者常見問題
Aros 使用者應用程式
Aros 使用者DOS Shell
Aros/使用者/AmigaLegacy
Aros 開發文件
Aros 開發者文件
從AmigaOS/SDL移植軟體
Zune 初學者指南
Zune .MUI 類
SDL 初學者指南
Aros 開發者構建系統
特定平臺
Aros x86 完整系統 HCL
Aros x86 音訊/影片支援
Aros x86 網路支援
Aros 英特爾 AMD x86 安裝
Aros 儲存支援 IDE SATA 等
Aros Poseidon USB 支援
x86-64 支援
摩托羅拉 68k Amiga 支援
Linux 和 FreeBSD 支援
Windows Mingw 和 MacOSX 支援
Android 支援
Arm 覆盆子派支援
PPC Power Architecture
其他
Aros 公共許可證

一種用於處理文字和檔案的指令碼語言。

指令碼只是一個純文字檔案。

rx script.rexx

IBM 的 Rexx 的版權(William S. Hawes)擴充套件

ARexx 是一種指令碼語言,雖然您可以使用它來啟動應用程式,但如果需要,最好使用常規的 DOS 指令碼。

ARexx 比 DOS 強大得多,但實際上並非旨在替代它。ARexx 的主要優勢在於它允許您編寫可以與“主機”通訊的指令碼;也就是說,任何具有 ARexx 埠的應用程式。這允許 ARexx 控制應用程式(在它向 ARexx 公開的功能範圍內)。由於單個指令碼可以與多個主機通訊,因此它可以協調應用程式之間的活動。它不理解的任何命令,它都會轉發到當前選定的主機。預設情況下,主機是 shell 本身。

您呼叫 CALL 搜尋庫中的函式(根據此搜尋順序中的文件):1) 內部函式 2) 內建函式 3) 函式庫和函式主機 4) 外部 AREXX 程式 - 將 Msg 轉發到 AREXX 程序本身並掃描載入的檔案

有三種不同的“模式”:- ARexx 命令主機 - 函式主機 - 函式庫

  /* A simple program */
  say 'Hello World'

DO 控制結構始終以 DO 開始,以 END 結束。

DO UNTIL

   DO UNTIL [condition]
   [instructions]
   END

DO WHILE

   DO WHILE [condition is true]
   [instructions]
   END

遍歷變數

   DO i = x TO y BY z
   [instructions]
   END

無限迴圈,直到使用 LEAVE 退出 - BREAK 有其他可能性,但您可能需要 LEAVE

   DO FOREVER
     IF [condition] THEN LEAVE
   END

迴圈固定次數

   DO i = x TO y BY z FOR a
   [instructions]
   END

條件語句

[編輯 | 編輯原始碼]
   IF [condition] THEN
     [instruction]
   ELSE
     [instruction]

測試多個條件

   SELECT
     WHEN [condition] THEN
     DO
     [instruction]
     END
   OTHERWISE
     DO
     [instruction] or NOP
     END

NOP 表示不執行任何指令。

有一個命令可以檢查變數是否為整數... DATATYPE(WHOLE)

命令和函式

[編輯 | 編輯原始碼]

Rexx 區分命令和函式。使用 ADDRESS,您可以指示將命令傳送到的位置。命令始終為一行。函式必須位於具有 ARexx 支援的庫中,並使用 addlib 新增。您似乎想要函式語法,但正在使用命令埠。

更改命令列上傳遞的引數對呼叫的 Rexx 程式的可用方式。使用此開關,命令列上的每個引數都可用作單獨的引數,而不是僅將組合的命令列引數作為單個內部引數提供的正常行為。

似乎“命令”模式確實不接收超過 1 個引數(arg[0])。

PARSE 指令特別強大;它結合了一些有用的字串處理函式

parse [upper] origin template

其中 origin 指定源

  • arg(命令列變數)
  • linein(鍵盤)
  • pull(REXX 資料佇列)
  • value(文字或函式)**帶**required 指示文字的結束位置
  • var(變數)
  • version(版本/發行版號)

模板可以是

  • 變數列表
  • 列號分隔符
  • 文字分隔符

upper 是可選的;如果指定它,資料將轉換為大寫。如果您不希望輸入大寫,請使用“PARSE PULL var”。“PULL var”與“PARSE UPPER PULL var”相同

示例

使用變數列表作為模板

   myVar = "John Smith"
   parse var MyVar firstName lastName
   say "First name is:" firstName
   say "Last name is:"  lastName

顯示以下內容

   First name is: John
   Last name is: Smith

使用分隔符作為模板

   myVar = "Smith, John"
   parse var MyVar LastName "," FirstName
   say "First name is:" firstName
   say "Last name is:"  lastName

還顯示以下內容

   First name is: John
   Last name is: Smith

使用列號分隔符

   myVar = "(202) 123-1234"
   parse var MyVar 2 AreaCode 5  7 SubNumber
   say "Area code is:" AreaCode
   say "Subscriber number is:" SubNumber

顯示以下內容

   Area code is: 202
   Subscriber number is: 123-1234

模板可以使用變數、文字分隔符和列號分隔符的組合。

高階資料結構

[編輯 | 編輯原始碼]
array(var, var)
record.field1
record.field2
/* check if a library function is available */
SHOW (L, 'rexxsupport.library')

/* if function not available - add library*/
ADDLIB ('rexxsupport.library',0,-30,0)

/* SHOWDIR (directory, {mode), [pad]) */
SHOWDIR ('sys:')

/* if function  - remove library*/
REMLIB ('rexxsupport.library')
parse arg height, width, depth
PROCEDURE EXPOSE WORD

您可以透過“PROCEDURE EXPOSE”語句將整個詞幹傳遞給在同一指令碼中宣告的函式,例如

...
test: procedure expose stem.
say stem.1 stem.a stem.a.ciao
...

(注意要放置“.”,否則只有詞幹變數對函式“test”可見,而不是所有詞幹。對“stem.”的任何修改都是全域性的。無法將詞幹傳遞給外部函式

ARexx 還將在與它同名的檔案中以及<name>.rexx) 中搜索函式,這兩者都在當前目錄和 REXX: 中。不要在我的檔案上放置 .rexx,因為 ~(*:*) 匹配函式,*.rexx 普通指令碼,*.ced ...

檔案操作

[編輯 | 編輯原始碼]
/* Create a file */
if open('file', 'ram:test', 'w') then
  call writeln('file' 'data')
  call close('file')
else
  say 'unable to open'
/* Read a file */
if open('file', 'ram:test', 'r') then
  call readch('file' var) /* read first var characters */
  do while ~eof('file')
    say line
    line=readln('file') /* read next line */
  end
  call close('file')
/* Read a file */
if open('file', 'ram:test', 'a') then
  say 'it is here'
else 
  say 'it is not here'
position = seek ('file', var, string) /* var is +/- bytes from start and string can be b, c or e */

IBM EOL (end of line) = <CR><LF> or (^M^J)
Amiga/UNIX EOL = <LF> or (^J)
Macintosh EOL = <CR> or (^M)
IBM EOF = <EOL><CTRL-Z> or (^M^J^Z)
Amiga EOF = <NULL> or (), optionally <LF> or (^J)

當然,空值表示沒有任何資料。

IBM 文字編輯器在每個<RETURN>處執行<CR><LF>。據我所知,大多數 Amiga 軟體只執行<LF>,並且當沒有更多位元組要讀取時,檔案末尾只是用指示符表示。

ARexx EOF() 指示您何時用完從檔案中讀取的內容。據我所知,它不會四處查詢 IBM 認為表示檔案末尾的內容,而只是在注意到檔案已達到其容量末尾時(例如,您有一個 1024 位元組的檔案,在讀取 1024 位元組後,您將到達檔案末尾或 EOF)。

do UNTILEF("FILE") /* 在此處執行一些讀取操作或其他操作 */ end

將“call readch('rfile',1)”更改為“say c2d(readch('rfile',1))”以顯示“ascii”程式碼。(請注意,只有字元程式碼< 127 是 ASCII)

語法、迴圈錯誤等。

跟蹤

訊號

程式IPC

[編輯 | 編輯原始碼]
rx "address command Dir"

與DOS通訊,

address "program-name"

您可以使用HELP命令獲取任何MUI程式的ARexx命令。以下是以IBrowse為例。

/* CheckIB.rexx*/

address IBrowse

'HELP vd0:IB.txt'

HELP命令後的驅動器規範是輸出的驅動器和檔名。當然,您正在檢查的程式必須正在執行,以便埠可用。輸出將顯示每個MUI程式具有的標準ARexx命令,然後是正在檢查的特定程式的特定命令。

通常,您會為您的應用程式提供一個命令列表,這些命令將由安裝的鉤子“自動”處理。

當您使用未“自動”處理的命令(因為它們不在命令列表中)時,您需要使用您提供的功能(例如MUIA_Application_RexxHook)。

由於這些屬性似乎沒有到位,您需要回退到普通的方式,這意味著您將以某種方式“發明”如何將您的普通命令與arexx命令“同步”。

Regina 3.00

CALL {symbol | string} [expression] [,expression,...]
DO [var=exp] [To exp] [BY exp]] [FOR exp] [FOREVER] [WHILE exp | UNTIL exp]
DROP variable [variable...]
ELSE [;] [conditional statement]
END [variable]
EXIT [expression]
IF expression [THEN] [;] [conditional statement]
INTERPRET expression
ITERATE [variable]
LEAVE [variable]
NOP
NUMERIC {DIGITS | FUZZ} expression  or: NUMERIC FORM {SCIENTIFIC | ENGINEERING}
OPTIONS [FAILAT expression]  or: OPTIONS [PROMPT expression]   or: OPTIONS [RESULTS]
OTHERWISE [;] [conditional statement]
PARSE [UPPER] inputsorce [template] [,template...]
PROCEDURE [EXPOSE variable [variable...]]
PULL [template] [,template...]
PUSH [expression]
QUEUE [expression]
RETURN
SAY [expression]
SELECT
SHELL [symbol | string] [expression]
SIGNAL {ON |OFF} condition   or: SIGNAL [VALUE] expression
THEN[;] [conditional statement]
TRACE [symbol|string|[[VALUE] expression]]
UPPER variable [variable...]
WHEN expression [THEN [;] [conditional statement]]
ABBREV
ABS
ADDLIB
ADDRESS [Symbol|string|VALUE] [expression]]
ALLOCATED
ARG [template] [,template...]
B2C
B2X
BEEP
BITAND
BITCHG
BITCLR
BITCOMP
BITOR
BITSET
BITTST
BITXOR
BUFTYPE
C2B
C2D
C2X
CD
CENTER
CENTRE
CHANGESTR
CHARIN
CHAROUT
CHARS
CHDIR
CLOSE
COMPARE
COMPRESS
CONDITION
COPIES
COUNTSTR
CRYPT
D2C
D2X
DATATYPE
DATE
DELSTR
DELWORD
DESBUF
DIGITS
DIRECTORY
DROPBUF
DUMPFILES
DUMPTREE
DUMPVARS
EOF
ERRORTEXT
EXISTS
EXPORT
FREELISTS
FREESPACE
FUZZ
GETCLIP
GETENV
GETPATH
GETPID
GETSPACE
GETTID
HASH
IMPORT
INDEX
INSERT
JUSTIFY
LASTPOS
LEFT
LENGTH
LINEIN
LINEOUT
LINES
LISTLEAKED
MAKEBUF
MAX
MEMORYSTATS
MIN
OPEN
OVERLAY
POPEN
POS
PRAGMA
QUALIFY
QUEUED
RANDOM
RANDU
READCH
READLN
REMLIB
REVERSE
RIGHT
RXFUNCADD
RXFUNCDROP
RXFUNCERRMSG
RXFUNCQUERY
RXQUEUE
SEEK
SETCLIP
SHOW
SIGN
SLEEP
SOURCELINE
SPACE
STATE
STREAM
STRIP
STORAGE
SUBSTR
SUBWORD
SYMBOL
TIME
TRACE
TRIM
TRACEBACK
TRANSLATE
TRUNC
UNAME
UNIXERROR
UPPER
USERID
VALUE
VERIFY
WORD
WORDINDEX
WORDLENGTH
WORDPOS
WORDS
WRITECH
WRITELN
X2B
X2C
X2D
XRANGE

運算子

[編輯 | 編輯原始碼]
OPERATOR		PRIORITY		OPERATOR DEFINITION

~			8			Logical NOT
+			8			Prefix Conversion
-			8			Prefix Negation
**			7			Exponentiation
*			6			Multiplication
/			6			Division
%			6			Integer Division
//			6			Remainder
+			5			Addition
-			5			Subtraction
||			4			Concatenation
(blank)			4			Blank Concatenation
==			3			Exact Equality
~==			3			Exact Inequality
=			3			Equality
~=			3			Inequality
>			3			Greater Than
>=,~<			3			Greater Than or Equal To
<			3			Less Than
<=,~>			3			Less Than or Equal To
&			2			Logical AND
|			1			Logical Inclusive OR
^,&&			1			Logical Exclusive OR

RexxSupport

[編輯 | 編輯原始碼]
LONG rxsupp_allocmem(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_baddr(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_closeport(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_delay(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_delete(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_forbid(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_freemem(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_getarg(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_getpkt(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_makedir(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_next(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_null(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_offset(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_openport(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_permit(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_rename(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_reply(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_showdir(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_showlist(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_statef(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_typepkt(struct Library *, struct RexxMsg *, UBYTE **);
LONG rxsupp_waitpkt(struct Library *, struct RexxMsg *, UBYTE **);

RexxSyslib

[編輯 | 編輯原始碼]
UBYTE *CreateArgstring(UBYTE *string, ULONG length) (A0, D0)
void DeleteArgstring(UBYTE *argstring) (A0)
ULONG LengthArgstring(UBYTE *argstring) (A0)
struct RexxMsg *CreateRexxMsg(struct MsgPort *port, UBYTE *extension, UBYTE *host) (A0, A1, D0)
void DeleteRexxMsg(struct RexxMsg *packet) (A0)
void ClearRexxMsg(struct RexxMsg *msgptr, ULONG count) (A0, D0)
BOOL FillRexxMsg(struct RexxMsg *msgptr, ULONG count, ULONG mask) (A0, D0, D1)
BOOL IsRexxMsg(struct RexxMsg *msgptr) (A0)
void LockRexxBase(ULONG resource) (D0)
void UnlockRexxBase(ULONG resource) (D0)

將Regina/Rexx新增到程式中

[編輯 | 編輯原始碼]

http://aminet.net/search?query=Minrexx http://www.pcguru.plus.com/tutorial/introduction.html

設定您自己的Rexx埠非常容易。它只是一個標準的MsgPort。如果您只是在任何訊息上退出並且不解析傳送到埠的命令,那麼您甚至不需要開啟rexxsyslib.library...

struct MsgPort *CreatePubPort (UBYTE *name, LONG pri)
/* create a port if port name is not already used */
{
struct MsgPort *pubport;

port = NULL;
Forbid ();
if (FindPort (name) == NULL)
pubport = CreateMsgPort (name, pri);
Permit ();
return (pubport);
}

現在埠已建立,我們只需要等待訊息。

static void PubPortWait (struct MsgPort *pubport)
/* wait for a message or signal on our pubport */
{
ULONG port_mask, signals;
struct RexxMsg *msg;

port_mask = (1L << RexxPort->mp_SigBit);
while (1)
	{
	signals = Wait (port_mask | SIGBREAKF_CTRL_C);
	if (signals & SIGBREAKF_CTRL_C)
	Quit("Aborting");
	if (signals & port_mask)
		{
		while ((msg = (struct RexxMsg *) GetMsg (pubport)) != NULL)
			{
			ProcessRexxMsg (msg); /* routine parses the REXX message */
			ReplyMsg ((struct Message *) msg);
			}
		}
	}
}

ProcessRexxMsg()可以列印您的訊息並退出,但請記住使用ReplyMsg()。如果您想解析Arexx命令,則工作量不會增加太多。以上內容來自較長的列印程式碼示例,並使用來自“arexx.h”和“arexxsyslib.h”的一些REXX包含,但如果您將在埠接收到的任何訊息上退出,則無需開啟rexxsyslib.library。

http://utilitybase.com/forum/index.php?action=vthread&forum=15&topic=1915

/*
#include <proto/exec.h>
#include <proto/alib.h>
#include <proto/rexxsyslib.h>

#include <exec/ports.h>
#include <rexx/errors.h>
#include <rexx/storage.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
    struct MsgPort *port;
    struct RexxMsg *msg;
    struct Library *RexxSysBase;
    char *value;
    
    RexxSysBase = OpenLibrary("rexxsyslib.library", 0);
    if (RexxSysBase == NULL)
    {
	puts("Error opening rexxsyslib.library");
	return 20;
    }
    
    port = CreatePort("VARTEST", 1);
    if (port == NULL)
    {
	puts("Error creating port");
	CloseLibrary(RexxSysBase);
	return 20;
    }

    printf("Port created %x, waiting for message\n", port);
    WaitPort(port);
    msg = (struct RexxMsg *)GetMsg(port);
    puts("Got a message");
    if (!IsRexxMsg(msg))
    {
	puts("Message is not a rexxmsg");
	ReplyMsg((struct Message *)msg);
	DeletePort(port);
	CloseLibrary(RexxSysBase);
	return 20;
    }

    puts("Is a rexx message");
    if (!CheckRexxMsg(msg))
    {
	puts("Message is not from rexx interpreter");
	msg->rm_Result1 = RC_ERROR;
	ReplyMsg((struct Message *)msg);
	DeletePort(port);
	CloseLibrary(RexxSysBase);
	return 20;
    }

    puts("Message is from the rexx interpreter");
    if (!GetRexxVar(msg, "A", &value))
    {
	puts("Error during retrieval of value");
	return 20;
    }
    printf("Length string: %d\n", strlen(value));
    printf("Value of A: %s\n", value);
    
    SetRexxVar(msg, "A", "2", 1);
    msg->rm_Result1 = RC_OK;
    msg->rm_Result2 = NULL;
    ReplyMsg((struct Message *)msg);
    DeletePort(port);
    CloseLibrary(RexxSysBase);
    
    return 0;
}

您現在可以使用以下指令碼向此小程式傳送訊息

/* Testing the variable interface */
a = 1
say 'a before call' a
ADDRESS 'VARTEST' test
say 'a after call' a

將其儲存為(例如)'vartest.rexx',並使用以下命令執行:

rx vartest.rexx

示例指令碼

[編輯 | 編輯原始碼]

更多示例

  /* Calculate some squares and cubes      */
  do i = 1 to 10      /* 10 interations    */
     say i i**2 i**3  /* calculations      */
     end
  say ' all done '
  /* Even or odd? */
  do i = 1 to 10
     if i//2 = 0 then type = 'even'
                 else type = 'odd'
     say i 'is' type
     end
  /* Defining and calling a function     */
  do i = 1 to 5
     say i square(i)     /* call square  */
     end
  exit            /* all done            */
  square:		/* function name       */
  arg x		/* get the "argument"  */
  return x**2     /* square it and return*/
  /* Demonstrate "results" tracing */
  trace results
  sum=0;sumsq=0;
  do i = 1 to 5
     sum = sum + i
     sumsq = sumsq + i**2
     end
  say 'sum=' sum 'sumsq=' sumsq
  /* Calculate age in days */
  say 'Please enter your age'
  pull age
  say 'You are about' age*365 'days old'
DO .... ; you have the code already
  line = READLN(textfile)
  IF line = marker line THEN DO
    target = READLN(textfile)
  END
END
/* File to read */
IF ~OPEN("in", "Path:yourTextFile", "READ") THEN DO
SAY "Can't open 'Path:yourTextFile' for reading."
CALL CLOSE('in')
EXIT
END

/* File to write */
IF ~OPEN("out", "Ram:filename", "WRITE") THEN DO
SAY "Can't open 'Ram:filename' for writing."
CALL CLOSE('out')
EXIT
END

/* Write lines that start with "(" to Ram:filename */
DO UNTIL EOF('in')
line = READLN('in')
temp = STRIP(line, 'L')
IF LEFT(temp, 1) = '(' THEN CALL WRITELN('out', line)
END
/* */
options results

arg sourcefile

if open(input, sourcefile, R) then do
if ~open(output, "ram:output", W) then call error

Do until eof(input)
line=readln(input)
if pos('(',line)=1 then writeln(output,line)    /* line begins with '(' at POS 1 */
end
close(input)
close(output)
end
EXIT

/* function */
ERROR:
SAY "ERROR"
EXIT
/*Bin2AHex*/
/* Convert a binary file to a ASCII representation of Hex.*/

if ~open('bufbin', 'RAM:buffer.bin', 'READ') then do
say "Can't open 'RAM:buffer.bin' for reading."
exit
end

if ~open('buftxt', 'RAM:buffer.txt','WRITE') then do
say "Can't open 'RAM:buffer.txt' for writing."
exit
end

/* 500 seems do be the max for c2x() */
max = 500
in = readch('bufbin', max)
DO until eof('bufbin')
call writech('buftxt',c2x(in))
in = readch('bufbin', max)
END

call close('bufbin')
call close('buftxt')

/* That's All Folks! */
/* Here's a more visible way to enter the control codes */
CSI='9b'x /* control sequence introducer */
boldOn=CSI'1m'
boldOff=CSI'22m'
IF OPEN("Env", "Env:File", "R") THEN DO
filename = READLN("Env")
CALL CLOSE("Env")
END
/* OPEN alone will pop up a filerequester */
OPEN NAME <filename>
/* Displays the data in the source string */
parse source source   /* type results called resolved extension host */
words=words(source)
shell command 'RequestChoice >Nil: Source',
'"Invocation type:' word(source,1)'*n',
||'Result requested:' word(source,2)'*n',
||'Called name:' word(source,3)'*n',
||'Resolved name:' DelWord(trim(DelWord(source,words-1)),1,3)'*n',
||'Search extension:' word(source,words-1)'*n',
||'Initial command host:' word(source,words)'"',
'OK'
/* Grabs the Users Hz thus the tick rate per second of the persons machine
(either 50 or 60 generally) amd pouts it into variable 'f' */
PARSE UPPER VERSION f
f=SUBSTR(WORD(f,6),1,2)

DO UNTIL <expression is valid> | i=<value ya want>
/* Call a delay and do nothing for value times(*) variable 'f' */
Call Delay(1*f)
i=i+1
End

您可以使其使某個值變為真或無限期嘗試。否則,您可以在DO UNTIL部分的任何階段使用“Leave”命令退出迴圈。

因此,以下載入庫工作良好…

libs = "rexxreqtools.library rexxdossupport.library rexxkuang11.library
rexxsupport.library rexxtricks.library"
DO UNTIL libs='';PARSE VAR libs lib libs
IF EXISTS('libs:'lib)|EXISTS('Libs/'lib)|EXISTS(lib) THEN DO
IF ~show('L',lib) THEN call addlib(lib,0,-30,0);END;ELSE DO
/* error output line whether say or echo or defined */
cECHO('Cannot load 'lib);END;END

查詢每個鍵的鍵碼,這可以在ARexx中完成…

rx <RAW: "
do while 1;
z=readch(stdin,1);
c=c2d(z);
if c2d(bitand('7f'x,z)) < 33 then
z='<'c'>';
call writech(stdout,z);
end

(所有內容都在一行上)

CTRL-C將停止此操作。請注意,以上和RAW-KEY Intui訊息(OpenWindow()/intuition,IDCMP標誌)是獲取按鍵資訊的唯一簡單且*系統合法*的方式。

這將提取檔名副檔名(例如.lha或.8svx)及其長度。在重新命名檔案時,它可能很有用。在轉換指令碼中使用它,該指令碼可以轉換不同的檔案型別,因此archive.lha變為archive.lzx,pic.gif變為pic.png。

STRING = ExtPart(filename)
PARSE VAR string extlen ext
/* ExtPart(filename)
** Returns filename extension and length of extension
** freely usable, freely distributable, intellectual property:
** Andreas Mixich <humpty@...>
*/

PARSE ARG filename

posi = LastPos('.',filename)
ext = SubStr(filename,(posi+1))
extlen = Length(SubStr(filename,posi))-1
extpartinfo = extlen||' '||ext
RETURN(extpartinfo)

這個建立了一個有效的路徑,使用它更好。不再有RAM:Envfilename錯誤,而是RAM:Env/filename 此外,它使RAM:脫離Ram Disk

沒什麼特別的,不過,您可以透過使用rexxdossupport.library/AddPart(pathname,“”)獲得相同的結果(除了RAM:<-Ram Disk:) - 不要忘記“” 。

STRING = ValPath("sys:Tools")
/* ValPath()
** make a vaild path out of path (in case it lacks '/')
** Concentrates "Ram Disk:" to "Ram:", so we get rid of this annoying space
** Freely usabel, freely distributable, intellectual property of
** Andreas Mixich <humpty@...>
*/

valpath:
PARSE ARG path

IF (LastPos('/',path) ~= Length(path) & Pos('/',path) ~= 0) THEN
path = path||'/'
ELSE
IF (LastPos(':',path) ~= Length(path) & Pos('/',path) = 0) THEN
path = path||'/'

IF Left(path,9) = "Ram Disk:" THEN
path = Insert("Ram",DelStr(path,1,8))

RETURN(path)

這個小程式用在我的所有ARexx指令碼中,這些指令碼需要外部埠可用。(WaitForPort)由於不喜歡在任何指令碼中寫相同的程式碼行,只需從GoldED列表請求器中選擇此例程,它就會附加到我的原始碼中。該函式很簡單

BOOL = IfPort(portname, prog, mode)

portname是應用程式的ARexx埠名稱,prog是應用程式的完整路徑,如果需要啟動,mode可以為空或WB。如果使用WB,它將使用WBRun啟動。有時這很有用。

該函式的結果為BOOL(TRUE或FALSE),因此易於處理流程控制。

在這個例程中,您會發現我使用的另一個函式

myERR()

您可以將其替換為您想要的任何內容或將其刪除。使用這樣的通用例程,因為它們更強大,因此可以在myERR()或WB請求器或任何其他內容中進行一些日誌記錄。

/*///------------------------------ "IfPort(portname,prog,mode)" ------------------------------ */

/*
** IfPort(portname, prog, mode)
** Shows if portname is available, attempts to launch program if not
** Freely usable, freely distributable, intellectual properties:
** Andreas Mixich <humpty@...>
*/

ifport:

PARSE ARG portname, prog, mode

IF ~Show(P,portname) THEN
DO
IF mode = WB THEN
ADDRESS COMMAND wbrun||' >NIL: '||prog
ELSE
ADDRESS COMMAND 'run >NIL: '||prog

ADDRESS COMMAND 'WaitForPort '||portname
IF RC ~= 0 THEN
DO
Call myERR('Error: Could not start '||prog)
RETURN(FALSE)
END
ELSE
RETURN(TRUE)
END
RETURN(TRUE)
/*\\\*/

給你,這是我在Rexx中見過的最快的SQRT函式,在c.l.rexx中找到的

/* */
parse arg N
if N <= 0 then exit
s = time('e')
call MethodB(N)
say time('e') - s
exit
MethodB:
x1 = 1
x0 = N
if N ~= 0 then
do until x1 = x0
x0 = x1
x1 = ((x0 * x0) + N) / (2 * x0)
end
else x1 = 0
say x1
return

一個非常簡單的函式,很少使用,但作為Translate()函式的一些示例提供給新手,並使函式集更完整。(由於有Upper(),為什麼不應該也有Lower())

/*
** Lower()
** Like Upper(), but this one makes a string lowercase.
** Considers german unmlauts and some accents.
** TODO: Add more national characters. Do you know of any missing
** (and where to find them on the keyboard) ?
*/
Lower: PROCEDURE
PARSE ARG string
res =
Translate(string,'abcdefghijklmnopqrstuvwxyzäöüáéíóú','ABCDEFGHIJKLMNOPQRSTUVWXY\
ZÄÖÜÁÉÍÓÚ')
RETURN(res)
/* convert a file into sentences */
arg fileid .
input=''
do until LINES(fileid)=0
in=LINEIN(fileid)
input=input in
end
t=LINEOUT("sentence.txt","--- "fileid" ---")
out=''
do i=1 to LENGTH(input)
char=SUBSTR(input,i,1)
out=out||char
if char="." then do
out=STRIP(SPACE(out))
t=LINEOUT("sentence.txt",out)
out=''
end
end
out=STRIP(SPACE(out))
t=LINEOUT("sentence.txt",out)
exit

建議您在開啟檔案時執行類似以下操作以檢查檔案是否已成功開啟

if open(tempfile,'t:ms_scenes',w) then do
call writeln(tempfile,'SCENE1')
/* blah, blah... */
call close(file)
end
else do
say 'Unable to open temp file!'
exit
end

獲取檔案大小

/* */

parse arg file

if file="" then do
say "no file given"
exit
end

s=statef(file)
if s="" then do
say "can't find file '"file"'"
exit
end

parse var s type size d d d d d comment
if type~="FILE" then do
say "'"file"' is not a valid file name"
exit
end
say "file '"file"':" size


華夏公益教科書