跳轉到內容

Ring/課程/系統函式

來自華夏公益教科書,開放的書籍,開放的世界

系統函式

[編輯 | 編輯原始碼]

在本章中,我們將學習系統函式

  • System()
  • Get()
  • IsMSDOS()
  • IsWindows()
  • IsWindows64()
  • IsUnix()
  • IsMacOSX()
  • IsLinux()
  • IsFreeBSD()
  • IsAndroid()
  • Windowsnl()
  • 獲取命令列引數
  • 獲取活動原始檔名

System() 函式

[編輯 | 編輯原始碼]

我們可以使用 system() 函式執行系統命令

語法

	System(cCommand)

示例

	System("myapp.exe") 	# Run myapp.exe
	System("ls")		# print list of files

Get() 函式

[編輯 | 編輯原始碼]

我們可以使用 Get() 函式獲取環境變數

語法

	Get(cVariable)

示例

	see get("path")		# print system path information


IsMSDOS()

[編輯 | 編輯原始碼]

我們可以使用 IsMSDOS() 函式檢查作業系統是否為 MSDOS。

語法

	IsMSDOS() ---> Returns 1 if the operating system is MS-DOS, Returns 0 if it's not

IsWindows()

[編輯 | 編輯原始碼]

我們可以使用 IsWindows() 函式檢查作業系統是否為 Windows。

語法

	IsWindows() ---> Returns 1 if the operating system is Windows, Returns 0 if it's not


IsWindows64()

[編輯 | 編輯原始碼]

我們可以使用 IsWindows64() 函式檢查作業系統是否為 Windows 64 位。

語法

	IsWindows64() ---> Returns 1 if the operating system is Windows64, Returns 0 if it's not


我們可以使用 IsUnix() 函式檢查作業系統是否為 Unix。

語法

	IsUnix() ---> Returns 1 if the operating system is Unix, Returns 0 if it's not


IsMacOSX()

[編輯 | 編輯原始碼]

我們可以使用 IsMacOSX() 函式檢查作業系統是否為 Mac OS X。

語法

	IsMacOSX() ---> Returns 1 if the operating system is Mac OS X, Returns 0 if it's not


IsLinux()

[編輯 | 編輯原始碼]

我們可以使用 IsLinux() 函式檢查作業系統是否為 Linux。

語法

	IsLinux() ---> Returns 1 if the operating system is Linux, Returns 0 if it's not


IsFreeBSD()

[編輯 | 編輯原始碼]

我們可以使用 IsFreeBSD() 函式檢查作業系統是否為 FreeBSD。

語法

	IsFreeBSD() ---> Returns 1 if the operating system is FreeBSD, Returns 0 if it's not


IsAndroid()

[編輯 | 編輯原始碼]

我們可以使用 IsAndroid() 函式檢查作業系統是否為 Android。

語法

	IsAndroid() ---> Returns 1 if the operating system is Android, Returns 0 if it's not
	see "IsMSDOS() --> " + ismsdos() + nl
	see "IsWindows() --> " + iswindows() + nl
	see "IsWindows64() --> " + iswindows64() + nl
	see "IsUnix() --> " + isunix() + nl
	see "IsMacOSX() --> " + ismacosx() + nl
	see "IsLinux() --> " + islinux() + nl
	see "IsFreeBSD() --> " + isfreebsd() + nl
	see "IsAndroid() --> " + isandroid() + nl

輸出

	IsMSDOS() --> 0
	IsWindows() --> 1
	IsWindows64() --> 0
	IsUnix() --> 0
	IsMacOSX() --> 0
	IsLinux() --> 0
	IsFreeBSD() --> 0
	IsAndroid() --> 0

Windowsnl()

[編輯 | 編輯原始碼]

我們可以使用 Windowsnl() 函式獲取 Windows 換行符字串。

語法

	WindowsNL() ---> Returns a string contains CR+LF = CHAR(13) + CHAR(10)

示例

	cStr = read("input.txt")

if iswindows() cStr = substr(cStr,windowsnl(),nl) ok

aList = str2list(cStr) # to do - list items processing using "for in" cStr = list2str(aList)

if iswindows() cStr = substr(cStr,nl,windowsnl()) ok

write("ouput.txt",cStr)

獲取命令列引數

[編輯 | 編輯原始碼]

我們可以使用 sysargv 變數獲取傳遞給 Ring 指令碼的命令列引數。

sysargv 變數是一個列表,包含命令列引數。

示例

	see copy("=",30) + nl
	see "Command Line Parameters" + nl
	see "Size : " + len(sysargv) + nl
	see sysargv
	see copy("=",30) + nl
	nStart = sysargv[3]
	nEnd = sysargv[4]
	for x = nStart to nEnd
		see x + nl
	next

輸出

	b:\mahmoud\apps\ring>ring tests\syspara.ring 1 10
	==============================
	Command Line Parameters
	Size : 4
	ring
	tests\syspara.ring
	1
	10
	==============================
	1
	2
	3
	4
	5
	6
	7
	8
	9
	10

獲取活動原始檔名

[編輯 | 編輯原始碼]

我們可以使用 filename() 函式獲取活動原始檔名 (*.ring)

語法

	filename() ---> String contains the active source file name.

示例

	see "Active Source File Name : " + filename() + nl

輸出

	Active Source File Name : tests\filename.ring


示例

	if sysargv[2] = filename()
		see "I'm the main program file!" + nl
		# we can run tests here!
	else
		see "I'm a sub file in a program" + nl
	ok


華夏公益教科書