📄 slangfun.txt
字号:
Get the current working directory USAGE String_Type getcwd () DESCRIPTION The `getcwd' function returns the absolute pathname of the current working directory. If an error occurs or it cannot determine the working directory, it returns `NULL' and sets `errno' accordingly. NOTES Under Unix, OS/2, and MSDOS, the pathname returned by this function includes the trailing slash character. Some versions also include the drive specifier. SEE ALSO mkdir, chdir, errno--------------------------------------------------------------listdir SYNOPSIS Get a list of the files in a directory USAGE String_Type[] listdir (String_Type dir) DESCRIPTION The `listdir' function returns the directory listing of all the files in the specified directory `dir' as an array of strings. It does not return the special files `".."' and `"."' as part of the list. SEE ALSO stat_file, stat_is, length--------------------------------------------------------------lstat_file SYNOPSIS Get information about a symbolic link USAGE Struct_Type lstat_file (String_Type file) DESCRIPTION The `lstat_file' function behaves identically to `stat_file' but if `file' is a symbolic link, `lstat_file' returns information about the link itself, and not the file that it references. See the documentation for `stat_file' for more information. NOTES On systems that do not support symbolic links, there is no difference between this function and the `stat_file' function. SEE ALSO stat_file, readlink--------------------------------------------------------------mkdir SYNOPSIS Create a new directory USAGE Integer_Type mkdir (String_Type dir, Integer_Type mode) DESCRIPTION The `mkdir' function creates a directory whose name is specified by the `dir' parameter with permissions specified by `mode'. Upon success `mkdir' returns zero, or it returns `-1' and sets `errno' accordingly. In particular, if the directory already exists, the function will fail and set errno to `EEXIST'. EXAMPLE define my_mkdir (dir) { if (0 == mkdir (dir, 0777)) return; if (errno == EEXIST) return; verror ("mkdir %s failed: %s", dir, errno_string (errno)); } NOTES The `mode' parameter may not be meaningful on all systems. On systems where it is meaningful, the actual permissions on the newly created directory are modified by the process's umask. SEE ALSO rmdir, getcwd, chdir, fopen, errno--------------------------------------------------------------readlink SYNOPSIS String_Type readlink (String_Type path) USAGE Get the value of a symbolic link DESCRIPTION The `readlink' function returns the value of a symbolic link and returns it as a string. Upon failure, NULL is returned and `errno' set accordingly. NOTES Not all systems support this function. SEE ALSO lstat_file, stat_file, stat_is--------------------------------------------------------------remove SYNOPSIS Delete a file USAGE Integer_Type remove (String_Type file) DESCRIPTION The `remove' function deletes a file. It returns 0 upon success, or -1 upon error and sets `errno' accordingly. SEE ALSO rename, rmdir--------------------------------------------------------------rename SYNOPSIS Rename a file USAGE Integer_Type rename (String_Type old, String_Type new) DESCRIPTION The `rename' function renames a file from `old' to `new' moving it between directories if necessary. This function may fail if the directories do not refer to the same file system. It returns 0 upon success, or -1 upon error and sets `errno' accordingly. SEE ALSO remove, errno--------------------------------------------------------------rmdir SYNOPSIS Remove a directory USAGE Integer_Type rmdir (String_Type dir) DESCRIPTION The `rmdir' function deletes a specified directory. It returns 0 upon success or -1 upon error and sets `errno' accordingly. NOTES The directory must be empty before it can be removed. SEE ALSO rename, remove, mkdir--------------------------------------------------------------stat_file SYNOPSIS Get information about a file USAGE Struct_Type stat_file (String_Type file) DESCRIPTION The `stat_file' function returns information about `file' through the use of the system `stat' call. If the stat call fails, the function returns `NULL' and sets errno accordingly. If it is successful, it returns a stat structure with the following integer fields: st_dev st_ino st_mode st_nlink st_uid st_gid st_rdev st_size st_atime st_mtime st_ctime See the man page for `stat' for a discussion of these fields. EXAMPLE The following example shows how the `stat_file' function may be used to get the size of a file: define file_size (file) { variable st; st = stat_file(file); if (st == NULL) verror ("Unable to stat %s", file); return st.st_size; } SEE ALSO lstat_file, stat_is--------------------------------------------------------------stat_is SYNOPSIS Parse the var{st_mode USAGE Char_Type stat_is (String_Type type, Integer_Type st_mode) DESCRIPTION The `stat_is' function returns a signed character value about the type of file specified by `st_mode'. Specifically, `type' must be one of the strings: "sock" (socket) "fifo" (fifo) "blk" (block device) "chr" (character device) "reg" (regular file) "lnk" (link) "dir" (dir) It returns a non-zero value if `st_mode' corresponds to `type'. EXAMPLE The following example illustrates how to use the `stat_is' function to determine whether or not a file is a directory: define is_directory (file) { variable st; st = stat_file (file); if (st == NULL) return 0; return stat_is ("dir", st.st_mode); } SEE ALSO stat_file, lstat_file--------------------------------------------------------------autoload SYNOPSIS Load a function from a file USAGE autoload (String_Type funct, String_Type file) DESCRIPTION The `autoload' function is used to declare `funct' to the interpreter and indicate that it should be loaded from `file' when it is actually used. EXAMPLE Suppose `bessel_j0' is a function defined in the file `bessel.sl'. Then the statement autoload ("bessel_j0", "bessel.sl"); will cause `bessel.sl' to be loaded prior to the execution of `bessel_j0' SEE ALSO evalfile--------------------------------------------------------------byte_compile_file SYNOPSIS Compile a file to byte-code for faster loading. USAGE byte_compile_file (String_Type file, Integer_Type method) DESCRIPTION The `byte_compile_file' function byte-compiles `file' producing a new file with the same name except a `'c'' is added to the output file name. For example, `file' is `"site.sl"', then the function produces a new file named `site.slc'. NOTES The `method' parameter is not used in the current implementation. Its use is reserved for the future. For now, set it to `0'. SEE ALSO evalfile--------------------------------------------------------------eval SYNOPSIS Interpret a string as slang code USAGE eval (String_Type expression, [,String_Type namespace]) DESCRIPTION The `eval' function parses a string as S-Lang code and executes the result. If called with the optional namespace argument, then the string will be evaluated in the specified namespace. This is a useful function in many contexts such as dynamically generating function definitions where there is no way to generate them otherwise. EXAMPLE if (0 == is_defined ("my_function")) eval ("define my_function () { message (\"my_function\"); }"); SEE ALSO is_defined, autoload, evalfile--------------------------------------------------------------evalfile SYNOPSIS Interpret a file containing slang code. USAGE Integer_Type evalfile (String_Type file, [,String_Type namespace]) DESCRIPTION The `evalfile' function loads `file' into the interpreter and executes it. If called with the optional namespace argument, the file will be loaded into the specified namespace, which will be created if necessary. If no errors were encountered, `1' will be returned; otherwise, a S-Lang error will be generated and the function will return zero. EXAMPLE define load_file (file) { ERROR_BLOCK { _clear_error (); } () = evalfile (file); } NOTES For historical reasons, the return value of this function is not really useful. The file is searched along an application-defined load-path. The `get_slang_load_path' and `set_slang_load_path' functions may be used to set and query the path. SEE ALSO eval, autoload, set_slang_load_path, get_slang_load_path--------------------------------------------------------------get_slang_load_path SYNOPSIS Get the value of the interpreter's load-path USAGE String_Type get_slang_load_path () DESCRIPTION This function retrieves the value of the delimiter-separated search path used for loading files. NOTES Some applications may not support the built-in load-path searching facility provided by the underlying library. SEE ALSO --------------------------------------------------------------set_slang_load_path SYNOPSIS Set the value of the interpreter's load-path USAGE set_slang_load_path (String_Type path) DESCRIPTION This function may be used to set the value of the delimiter-separated search path used by the `evalfile' and `autoload' functions for locating files. EXAMPLE public define prepend_to_slang_load_path (p) { variable s = stat_file (p); if (s == NULL) return; if (0 == stat_is ("dir", s.st_mode)) return; variable d = path_get_delimiter (); set_slang_load_path (strcat (p, d, get_slang_load_path ())); } NOTES Some applications may not support the built-in load-path searching facility provided by the underlying library. SEE ALSO get_slang_load_path, path_get_delimiter, evalfile, autoload--------------------------------------------------------------get_import_module_path SYNOPSIS Get the search path for dynamically loadable objects USAGE String_Type get_import_module_path () DESCRIPTION The `get_import_module_path' may be used to get the search path for dynamically shared objects. Such objects may be made accessable to the application via the `import' function. SEE ALSO import, set_import_module_path--------------------------------------------------------------import SYNOPSIS Dynamically link to a specified module USAGE import (String_Type module [, String_Type namespace]) DESCRIPTION The `import' function causes the run-time linker to dynamically link to the shared object specified by the `module' parameter. It seaches for the shared object as follows: First a search is performed along all module paths specified by the application. Then a search is made along the paths defined via the `set_import_module_path' function. If not found, a search is performed along the paths given by the `SLANG_MODULE_PATH' environment variable. Finally, a system dependent search is performed (e.g., using the `LD_LIBRARY_PATH' environment variable). The optional second parameter may be used to specify a namespace for the intrinsic functions and variables of the module. If this parameter is not present, the intrinsic objects will be placed into the global namespace. This function signals an error if the specified module is not found. NOTES The `import' function is not available on all systems. SEE ALSO set_import_module_path, use_namespace, current_namespace, getenv, evalfile--------------------------------------------------------------set_import_module_path SYNOPSIS Set the search path for dynamically loadable objects USAGE set_import_module_path (String_Type path_list) DESCRIPTION The `set_import_module_path' may be used to set the search path for dynamically shared objects. Such objects may be made accessable to the application via the `import' function. The actual syntax for the specification of the set of paths will vary according to the operating system. Under Unix, a colon character is used to separate paths in `path_list'. For win32 systems a semi-colon is used. SEE ALSO import, get_import_module_path--------------------------------------------------------------_NARGS
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -