nScriptm - Two data type - integer and string are supported Assignment by a variable a = 1234; // assignment of number in the decimal system a = -123; // a = 0123; // in the octal system a = 0x12; // in the hexadecimal system Assignment of strings str = "abc" + "def"; // "abcdef" i = 1 + 2; str = "1+2=%i% "; // " 1 + 2 = 3 " str = "abc" + 1; // "abc1" str = 1 + 2 + "abc"; // "3abc" str = " " + 1 + 2 + "abc"; // "12abc" Parsing of strings Using regular expressions 1) a = "aaa\r\nbbb\r\nccc"; RegMatchAll (".*$", a, b[]); // b [0] - aaa // b [1] - bbb // b [2] - ccc 2) "^http://([^:/]+)%server%(:(\d+)%port%)?%path%$"=" http://www.url.com/index.html"; // server - www.url.com // path - index.html Using the function parse() str="http://www.url.com/index.html"; parse(str,strnull,"http://",server,"/",path); //server - www.url.com //path - index.html Special characters \n line feed \r CR \t TAB \b beep \\ \ \ " " %% of % \ooo the octal character \xhh the hexadecimal character The arrays a [0] = "abc"; a [1] = "def"; b ["foo"] = 13; a [100]; a ["100"]; a [1] [0] = f; a ["foo"] [2] = f; a [] = b []; a [] = b [] + c []; a [] = {1,2,3}; // a [0] = 1; a [1] = 2; a [2] = 3; a [] = {a = 10, b = 20}; // a ["a"] = 10; a ["b"] = 20; a [] = {1,2, {10,20 {, "a", "b", "c"}}, 3}; a [] = 0; // a [] = 0 [] b = {"A", "B", "C"} [1]; str = "%hoge[\"ab\" + i]%"; The description of variables var i, j = 100, f []; for (i=1; i < 10; i ++) { m [i] =i; f [i] =1; } a=f [3] // 3 b=m [3] // 0 as m [] is created and is deleted in the block Operations binary a + b addition a - b subtraction a * b multiplying a / b division a of % b the rest modulo a and b and a | b or a ^ b a degree a < < b shift a > > b shift Operations unary +a -a a ++ a- ++ a - a ! a ~a The operation of assignment a = 1; b = a ++; a = (b = 4) + 5; // a=9 b=4 " ([ABC]+)%i%" = "123ABCCBA456"; // i = "ABCCBA" Operations of matching a == b a = ~ b a! = b a < b a > b a < = b a > = b a && b logical and a || b logical or Operators Conditions if () { } else { } Example if (a == 0) { b = 0; } else if (b == 0) { a = 0; } else if (a > b) { b = a; } else { a = b; } Cycle while () {} i = 1; while (i < = 10) { j = j + i; i = i + 1; } do {} while (); for (;;) {} for (i = 1; i < = 10; i ++) { j = j + i; } for (;;) { // eternal cycle } break [n]; Loop termination while () { while () { break 1; // 1 output(exit) from both cycles } } continue continuation of cycle with new iterations Case statement switch switch (m) { case 1: ; break; case 2: case 3: ; break; default: ; break; } Definition of functions Function a name (parameter [, parameter 2...]) { Body of the function; } ArgMatch a name ("arguments") { Body of the function; } Function sum (arg_1, arg_2) { return arg_1 + arg_2; } Function func(&a) // transmission of the parameter to the address { a = 100; } func (i); // i=100 Function func (a, b) { i = a; j = b; } Function func () // one more method of obtaining of parameters { i = arg [0]; j = arg [1]; } Function func (a, b = 100) // assignment to the second parameter a default value { } Function func ("%a%,%b%") { i = a; // "123" j = b; // "456" } func ("123,456"); ArgMatch func ("%a%,%b%") { i = a; j = b; } ? ("123,456"); ArgMatch func1 ("%a%,%b%") { i = a; j = b; exit; } ArgMatch func2 ("%a%,%b%") { i = a; j = b; } cnt =? ("123,456"); Access to functions and variable from other script file script.func (); script.? (); &script.func(); script.i = 0; Regular expressions Supported commands \ ^ . $ | () [] % " of % * + ? {n} {n}, {n, m} *? +? ?? {n},? {n, m}? \t \n \r \xhh \w \W \s \S \d \D " ([ABC] +) %i of % " = "123ABCCBA456"; // i = "ABCCBA" a = "aaa\r\nbbb\r\nccc"; RegMatchAll (".*$",a,b[]); // b [0] - aaa // b [1] - bbb // b [2] - ccc Commands #option(explicit) #import(script file) load script file script.func (); script.i; #library(script file) Functions Common Error (buf) To output error message Return - 0 Sleep (time in seconds), _sleep (time in milliseconds) Return 0 GetDate (format) format - for example such "yyyy/MM/dd" Return string containing date GetTime (format) format - for example such "HH:mm:ss" Return string containing time SetTime(hh,mm,ss) SetDate(year[,month[,day]]) Sets time and date All parameters - integer Return 0 in error case playsound(filename,strparameters) play wav-file named filename strparameters="str1 str2 ... strn" strX=SYNC ASYNC NODEFAULT LOOP NOSTOP msgbox (message, title, type) Outputs the message in the window type = 0 - 7 (see MessageBox in Win32 API) Return the answer of the user fileopendialog (title) fileopendialog (title) folderdialog (title) Standard open/save/select folder dialogues Return or path to the selected file or empty string poweroff () suspend PPC getsdialog (title,string) The dialogue of input of string return string getcbdialog (title, items[],titleokbutton="Ok",titlecanselbutton="Cancel",titlebutton3="",titlebutton4= " ") listbox with 4 button items - hash(array) with variants of choice titleokbutton,titlecanselbutton,titlebutton3,titlebutton4 - title for buttons Reset value: a position of a unit (if are pushed 3 or 4 buttons are incremented on 1000 or 10000), If is pushed cancel -1 getscriptfullname () Return path and name of running script getnsfullname () Return path to the file ns.exe Functions of processing of strings IsType (val) Return - type of argument 0 - integer 1 - string Int (str) UIntStr (i) Chr (i) Asc (buf) String (cnt, char) Return string from the repeating character cnt - number of repetitions char - character Trim (buf) Len (buf) StrCmp (str1, str2, len = -1) Return 0 - str1 == str2 > 0 - str1 > str2 < 0 - str1 < str2 Left (buf, len) Right (buf, len) Mid (buf, index, len = -1) InStr (buf, str, start = 0, op = 0) ToLower (buf) ToUpper (buf) translate (str, s1, s2) Return string where the characters from s1 are replaced from s2 pos (substring, string) Return a position of a substring in string strtok (delimiters, string) clone strtok from C, only arguments have changed places parse (string, substring1,delimiter1,...,substringN,delimiterN) divides(parsing) string into substrings, delimiters can be both string or character _e(string) Calculates expression preset in string. Return string with result. The calculations with a floating point (unique variant are supported to make in nScriptm such calculations). It is possible to use the following mathematical functions: sin,cos,tan,asin,acos,atan,sinh,cosh,tanh,exp,log,log10,sqrt,floor,ceil,fabs,deg,rad It is possible to use variables, for example _e (" a=cos (0.5) "); The reserved constants - pi, e Example: str=_e("cos(0.23)/(4-2.5)"); // str = " 0.64911093000358322" Hash GetHashCount (hash []) SetHashCount(&hash [], len) GetHashKey (hash [], n) SetHashKey(&hash [], n, name) IsHashKey (hash [], key) HashInsert(&hash [], n, val) HashDelete(&hash [], n) HashFind (hash [], val) HashKeySort(&hash [], order = 0, icase = 0) HashSort(&hash [], order = 0 [1], icase = 0 [1]) HashCopy (hash [], start = 0, len = -1) HashMerge (hash1 [], hash2 [], hash3 []...) HashToString (hash []) StringToHash (buf) Regular expressions RegMatch ("reg", buf, &hash [] = 0, op = " ") RegMatchAll ("reg", buf, &hash [] = 0, op = " ") RegReplace ("reg", to, buf, op = " ") Data conversion IsLeadChar (buf) GetCodeType (buf) Return 0 - ASCII 1 - SJIS 2 - JIS 3 - EUC SjisToJis (buf) JisToSjis (buf) SjisToEuc (buf) EucToSjis (buf) Base64Decode (buf) Base64DecodeHash (buf, &hash[]) Base64Encode (buf) Base64EncodeHash (hash []) cpconvert (string, fromto) recode string fromto - "win2alt","win2koi","win2iso","koi2alt","koi2win","koi2iso","alt2koi","alt2win","alt2iso","iso2win","iso2koi","iso2alt" Return the recoded string cpaconvert (string, to) recode string automatically determining the initial format to - "win", "koi", "iso", "alt", "lat" Return the recoded string File system CreateDirectory (dir) RemoveDirectory (dir) GetCurrentDirectory () SetCurrentDirectory (dir) CopyFile (from, to) Return 0 - ok -1 - error MoveFile (from, to) Return 0 - ok -1 - error DeleteFile (file) Return 0 - ok -1 - error FileOpen (type, file) Opens the file type - "read", "write", "new" file - filename Return Descriptor of the file or -1 in case of error FileClose (f) Filesetptr (f, pos, type) Sets the pointer in the file type - 0,1,2 pos - position f - the descriptor of the file Return 0 in case of successful completion GetFileSize (f) Return File size or -1 in case of error FileRead (f, &buf, len) reads out from the file in the buffer f - descriptor of the file buf - buffer len - number read - out byte (default - file size) Return the number is successful reading bytes Readstr(,&buf,len=1024) Reads string from the file in the buffer Return number successfully read out byte or -1 in case of error FileReadHash (f, &hash [], len) FileWrite (f, buf, len = 0) f - descriptor of the file buf - buffer len - size of the buffer Return 0 - ok -1 - error FileWriteHash (f, hash [], len = 0) FileFindInit (file) Initialization of search of files file - the filename (is possible usage of characters * and ?) Return a descriptor or 0 in case of error or absence of suitable files FileFindNext (hFind) Searches for the following file hFind - descriptor obtained by the function FileFindInit () Return 1 - the file is retrieved 0 - the file is not retrieved FileFindClose (hFind) hFind - descriptor obtained by the function FileFindInit () FileFindAttributes (hFind) Return the file attributes on a descriptor of value see in the description Win32 API FileFindName (hFind) Return a filename on a descriptor FileFindSize (hFind) Return a file size on a descriptor System databases dblist (a []) Places in a the list of databases as strings of sort " name, type, size, nrecord, date, time " Return number of bases dbdelete (name) Deletes the database Program management Shell (file, param = " ", dir = " ", style = 1) execute the file file - filename param - parameters dir - folder style - 0,1,2,3 (look the description Win32 API) Return 0 in case of successful execution -1 in a case of error Shellwait (file, param = " ", dir = " ", style = 1) execute the file and wait it terminate file - filename param - parameters dir - folder style - 0,1,2,3 (look the description Win32 API) Return 0 in case of successful execution -1 in a case of error runappattime(file,year,month,day[,hour,minutes,second]) Registers the file in the system on start at the appointed time Return : 1 in case of successful execution 0 in a case of error ExecScript (path, file, param []) Execute script setwindowtext (hwnd,title) Changes title of the window listwindow (list[]) Creates the list (list[]) windows and return number of items of the list iswindowvisible (hwnd) Return value > 0 if the window with a descriptor "hwnd" can be made visible FindWindow(string, full=0) full - if 1, the search is carried on on complete coincidence "string" and title of the window, Differently on a contents in title of a substring equal "string" Return the identifier of the window having in title "string", or 0 in a case of error SendKeys (hWnd, string, keys) Send to the indicated window string of input hWnd - handle of the window, string - the string of characters, can include \r - ENTER and \t - TAB keys - key of handle shift - 16 ctrl - 17 alt - 18) destroywindow (hWnd) Destroy the window setfwindow ([hWnd]) Does the window active, if the descriptor is not becomes indicated an active console nScript getfwindow () Receives a descriptor of active window tap (x, y [, hWnd]) Imitates pressing of stylus in a point (x, y) if the descriptor of the window is indicated, the given window is made active Functions of operation with gethostname () gethostbyname (server) getsockport (soc) socket (af = 2, type = 1, protocol = 0) af - Address family 0 - AF_UNSPEC 1 - AF_UNIX 2 - AF_INET type 1 - SOCK_STREAM (TCP) 2 - SOCK_DGRAM (UDP) protocol - protocol closesocket (soc) connect (soc, ip, port) bind (soc, ip, port) listen (soc, backlog) accept (soc) select (soc, time) recv (soc, &buf, len = 256, flags = 0) flags MSG_OOB - 0x1 MSG_PEEK - 0x2 RecvHash (soc, &hash [], len = 256, flags = 0) send (soc, buf, len = 0, flags = 0) flags MSG_OOB - 0x1 MSG_DONTROUTE - 0x4 SendHash (soc, hash [], len = 0, flags = 0) The functions Return -1 in a random error Operation with the registry rgset (key, subkey [, valuename, valuedata, valuetype]) creates key / value in the registry key - "HKEY_CLASSES_ROOT","HKEY_CURRENT_USER","HKEY_LOCAL_MACHINE" subkey - name and path of a key, valuename - name of a variable valuedata - data valuetype - " REG_SZ, " REG_DWORD "," REG_BINARY " Return 0 in case of successful completion rggetvalue (key, subkey, valuename, buf) key - "HKEY_CLASSES_ROOT","HKEY_CURRENT_USER","HKEY_LOCAL_MACHINE" Receives value valuename from the registry, the value is located in buf Return a negative error code or positive code such as value rgexport (key, subkey, filename) export keys of the registry to the file, Return 1 in case of successful completion rgimport (filename) The import keys of the registry from the file Return 1 in case of successful completion rgdeletevalue (key, subkey, valuename) deletes a variable key - "HKEY_CLASSES_ROOT","HKEY_CURRENT_USER","HKEY_LOCAL_MACHINE" subkey - name and path of a key valuename - the name of a variable Return 0 in case of successful completion rgdeletekey (key, subkey) deletes a key, key - "HKEY_CLASSES_ROOT","HKEY_CURRENT_USER","HKEY_LOCAL_MACHINE" subkey - name and path of a key Return 0 in case of successful completion; Clipboard clipset (string) Places string in a clipboard clipget () Receives string from a clipboard Input / output puts (buf) Outputs string(line) on a console gets (len) Receives string(line) from a console getchar () Receives the character SetEchoMode (n) n - 0 = echo off, 1 = echo on -