2 single: System Functions; Introduction
8 In this chapter we are going to learn about the system functions
32 * Get Command Line Arguments
34 * Get Active Source File Name
49 pair: System Functions; System() Function
54 We can execute system commands using the system() function
66 System("myapp.exe") # Run myapp.exe
67 System("ls") # print list of files
70 pair: System Functions; SysGet() Function
75 We can get environment variables using the Get() function
87 see sysget("path") # print system path information
91 pair: System Functions; IsMSDOS() Function
96 We can check if the operating system is MSDOS or not using the IsMSDOS() function
102 IsMSDOS() ---> Returns 1 if the operating system is MS-DOS, Returns 0 if it's not
106 pair: System Functions; IsWindows() Function
111 We can check if the operating system is Windows or not using the IsWindows() function
117 IsWindows() ---> Returns 1 if the operating system is Windows, Returns 0 if it's not
121 pair: System Functions; IsWindows64() Function
123 IsWindows64() Function
124 ======================
126 We can check if the operating system is Windows 64bit or not using the IsWindows64() function
132 IsWindows64() ---> Returns 1 if the operating system is Windows64, Returns 0 if it's not
136 pair: System Functions; IsUnix() Function
141 We can check if the operating system is Unix or not using the IsUnix() function
147 IsUnix() ---> Returns 1 if the operating system is Unix, Returns 0 if it's not
151 pair: System Functions; IsMacOSX() Function
156 We can check if the operating system is macOS or not using the IsMacOSX() function
162 IsMacOSX() ---> Returns 1 if the operating system is Mac OS X, Returns 0 if it's not
166 pair: System Functions; IsLinux() Function
171 We can check if the operating system is Linux or not using the IsLinux() function
177 IsLinux() ---> Returns 1 if the operating system is Linux, Returns 0 if it's not
181 pair: System Functions; IsFreeBSD() Function
186 We can check if the operating system is FreeBSD or not using the IsFreeBSD() function
192 IsFreeBSD() ---> Returns 1 if the operating system is FreeBSD, Returns 0 if it's not
196 pair: System Functions; IsAndroid() Function
201 We can check if the operating system is Android or not using the IsAndroid() function
207 IsAndroid() ---> Returns 1 if the operating system is Android, Returns 0 if it's not
210 pair: System Functions; Example
217 see "IsMSDOS() --> " + ismsdos() + nl
218 see "IsWindows() --> " + iswindows() + nl
219 see "IsWindows64() --> " + iswindows64() + nl
220 see "IsUnix() --> " + isunix() + nl
221 see "IsMacOSX() --> " + ismacosx() + nl
222 see "IsLinux() --> " + islinux() + nl
223 see "IsFreeBSD() --> " + isfreebsd() + nl
224 see "IsAndroid() --> " + isandroid() + nl
240 pair: System Functions; Windowsnl() Function
245 We can get the windows new line string using the Windowsnl() function.
251 WindowsNL() ---> Returns a string contains CR+LF = CHAR(13) + CHAR(10)
257 cStr = read("input.txt")
260 cStr = substr(cStr,windowsnl(),nl)
263 aList = str2list(cStr)
264 # to do - list items processing using "for in"
265 cStr = list2str(aList)
268 cStr = substr(cStr,nl,windowsnl())
271 write("ouput.txt",cStr)
274 pair: System Functions; Get Command Line Arguments
276 Get Command Line Arguments
277 ==========================
279 We can get the command line arguments passed to the ring script using the sysargv variable.
281 The sysargv variable is a list contains the command line parameters.
287 see copy("=",30) + nl
288 see "Command Line Parameters" + nl
289 see "Size : " + len(sysargv) + nl
291 see copy("=",30) + nl
292 if len(sysargv) < 4 return ok
295 for x = nStart to nEnd
303 b:\mahmoud\apps\ring>ring tests\syspara.ring 1 10
304 ==============================
305 Command Line Parameters
311 ==============================
324 pair: System Functions; Get Active Source File Name
326 Get Active Source File Name
327 ===========================
329 We can get the active source file name (*.ring) using the filename() function
335 filename() ---> String contains the active source file name.
341 see "Active Source File Name : " + filename() + nl
347 Active Source File Name : tests\filename.ring
354 if sysargv[2] = filename()
355 see "I'm the main program file!" + nl
356 # we can run tests here!
358 see "I'm a sub file in a program" + nl
363 pair: System Functions; PrevFileName() Function
365 PrevFileName() Function
366 =======================
368 Using the PrevFileName() function we can get the previous active source file name.
370 The previous file would be the file of the caller function, Or the file of the function
371 that we called before calling PrevFileName().
377 prevfilename() ---> String contains the previous source file name.
381 The next function in stdlib.ring uses the PrevFileName() to know if the file of the
382 caller function is the main source file of the program or not.
386 Func IsMainSourceFile
387 if PrevFileName() = sysargv[2]
393 pair: System Functions; CurrentDir() Function
395 CurrentDir() Function
396 =====================
398 Return the path of the current directory
404 CurrenDir() ---> String contains the path of the currect directory
407 pair: System Functions; ExeFileName() Function
409 ExeFileName() Function
410 ======================
412 Return the Ring executable file name
418 exefilename() ---> String contains the Ring executable file name
421 pair: System Functions; ChDir() Function
426 Change the current directory
435 pair: System Functions; ExeFolder() Function
440 Return the Ring executable file path
446 exefolder() ---> String contains the Ring executable path
449 pair: System Functions; Version() Function
454 Return the Ring version
460 version() ---> String contains the Ring version
470 pair: System Functions; Shutdown() Function
475 Close the application
481 shutdown(nStatus) ---> Close the application