glue.pl
that loads the extensions
and supporting Prolog goals.
glue.pl
, which
loads the C extensions and defines needed Prolog goals, then load your
application program and execute a query. This can be done on the
command line as documented in the SWI-Prolog manual.
"string"
are not understood, while the atom
'string'
is treated as if it were a string.
The prototype is notably incomplete, and syntax is subject to change
without notice, as we are not satisfied with the names and syntax of
the principal goals. This documentation is provided simply to give
the reader a flavor of what we are doing.
We do not expect to release this version of the software;
rather we are working on a front-end preprocessor that generates calls
to this code as a result of compiling a simpler configuration
language. This compiler will:
hostid(-Hostid)
Hostid
is unified with the current system id.
hostname(-Hostname)
Hostname
is unified with the current host name.
sysinfo(-Name,-Release,-Version,-Machine,-Arch,-IsaList,-Platform,-Provider,-Serial,-SrpcDomain)
sysinfo
function and returns its responses.
Name
is the host name.
Release
is the OS release.
Version
is the OS version.
Machine
is the HW machine type.
Arch
is the HW architecture.
IsaList
is the ISA list.
Platform
is the HW platform.
Provider
is the HW provider.
Serial
is the HW serial number.
SrpcDomain
is the OS's secure-RPC domain name.
sysname(-Name)
release(-Release)
version(-Version)
machine(-Machine)
architecture(-Arch)
isalist(-IsaList)
platform(-Platform)
hw_provider(-Provider)
hw_serial(-Serial)
srpc_domain(-SrpcDomain)
passwd(-Login,-Passwd,-Uid,-Gid,-Gcos,-Home,-Shell)
/etc/nsswitch.conf
.
All matching entries are returned when backtracking.
Login
: the user's login name.
Passwd
: the user's encrypted password.
Uid
: the user's user ID (an integer).
Gid
: the user's primary group ID (an integer).
Gcos
: string description of the user.
Home
: the user's home directory.
Shell
: the user's shell.
login(-Login)
uid(-Uid)
login_passwd(+Login,-Passwd)
login_uid(+Login,-Uid)
login_gid(+Login,-Gid)
login_gcos(+Login,-Gcos)
login_home(+Login,-Home)
login_shell(+Login,-Shell)
uid_login(+Uid,-Login)
uid_passwd(+Uid,-Passwd)
uid_gid(+Uid,-Gid)
uid_gcos(+Uid,-Gcos)
uid_home(+Uid,-Home)
uid_shell(+Uid,-Shell)
group(-Group,-Passwd,-Gid,-Members)
/etc/nsswitch.conf
.
Group
: a group name.
Passwd
: a group password (unused).
Gid
: the numeric group ID.
Members
: a Prolog list of group members.
group(-Group)
group_passwd(+Group,-Passwd)
group_gid(+Group,-Gid)
group_members(+Group,-Members)
group_member(-Group,-Member)
iterates over all members of each group in the group database.
Group
: the group name.
Member
: a member login name.
login_in_group(+Login,-Group)
Login
: login name of user.
Group
: unified with each group of which Login
is a member, either in the passwd
or group
databases.
/etc/nsswitch.conf
. All calls assume that the host has
an IP number and are blind to other forms of addressing. Note also
that stat
functions had to be broken into two parts,
because SWI-Prolog limits foreign functions to 10 or fewer arguments.
gethostbyname(+Name,-Address,-Aliases,-Addresses)
gethostbyname
and returns all information given.
Name
: the host's name.
Address
: the host's "canonical" address.
Aliases
: a Prolog list of aliases.
Addresses
: a Prolog list of other addresses.
gethostbyaddr(+Address,-Name,-Aliases,-Addresses)
gethostbyaddr
and returns all information given.
Address
: one of the host's addresses.
Name
: the host's "canonical" name.
Aliases
: a Prolog list of aliases.
Addresses
: a Prolog list of other addresses.
gethostent(-Name,-Aliases,-Addresses)
gethostent
repeatedly to iterate over all host names.
This should only be used if you do not know host name or
address, because it is considerably slower than using gethostbyname
or gethostbyaddr
.
Name
: the host's canonical name.
Aliases
: aliases for the name.
Addresses
: all addresses known for the host.
gethost(-Name,-Address)
Name
: the host's name.
Address
: the host's IP address
getservbyname(+Name,-Proto,-Cname,-Aliases, -Port)
Proto
is set,
the query uses it.
Name
: name of the service.
Proto
: protocol code for the service.
Cname
: canonical name of the service.
Aliases
: Prolog list of aliases for the name.
Port
: integer port assigned to the service.
getservbyport(+Port,-Proto,-Cname,-Aliases)
Proto
is set,
the query uses it.
Port
: integer port assigned to the service.
Proto
: protocol code for the service.
Cname
: canonical name of the service.
Aliases
: Prolog list of aliases for the name.
getservent(-Name,-Aliases,-Port,-Proto)
Name
: name of the service.
Aliases
: Prolog list of aliases for the name.
Port
: integer port assigned to the service.
Proto
: protocol code for the service.
getserv(-Name,-Alias,-Port,-Proto)
Name
: name of the service.
Alias
: one alias for the name.
Port
: integer port assigned to the service.
Proto
: protocol code for the service.
getprotobyname(+Name,-Aliases,-Proto)
Name
: name of the protocol.
Aliases
: naming aliases.
Proto
: protocol number.
getprotobynumber(-Name,-Aliases,+Proto)
gets a protocol description from its number.
Name
: name of the protocol.
Aliases
: naming aliases.
Proto
: protocol number.
getprotoent(-Name,-Aliases,-Proto)
Name
: name of the protocol.
Aliases
: naming aliases.
Proto
: protocol number.
getproto(-Name,-Alias,-Proto)
Name
: name of the protocol.
Alias
: one alias for the protocol.
Proto
: protocol number.
copy(+SourcePath,+DestPath)
SourcePath
to DestPath
if necessary.
Does nothing if the content of the two paths is identical.
SourcePath
: full pathname of the file to be copied.
DestPath
: full pathname of the file to modify.
link(+SourcePath,+LinkName)
SourcePath
to LinkName
if necessary.
Does nothing if the SourcePath
doesn't exist or the
LinkName
is already correct.
SourcePath
: full pathname of the file to be copied.
DestPath
: full pathname of the file to modify.
path_mode(+Path,-Mode)
Mode
is uninstantiated, unify it with the path's
current mode. Succeed if this can be read, fail if not.
Mode
is instantiated, change the mode of the path
on disk to match. Succeed if this is possible, fail if not.
Path
: full pathname of the filesystem node to operate upon
Mode
: the numeric mode of the path.
mode(+Path,-Mode)
mode_ascii(-Mode,-Ascii)
Mode
: the numeric mode of a file.
Ascii
: the ASCII equivalent of a numeric mode.
?- mode_ascii(0o2755,X). X='rwxr-sr-x'The
s
, S
, t
, and T
conventions are observed in both directions.
path_amode(+Path,-Code)
Code
is unset, unify it with the current ASCII
mode of the file. Succeed if possible, fail if not.
Code
is set, try to make this the actual mode
of the physical path. Succeed if possible, fail if not.
Path
: the full pathname of a UNIX filesystem node.
Code
: the ASCII representation of the file's protections.
?- path_amode('/tmp',X). X='rwxrwxrwt'The
s
, S
, t
, and T
conventions are observed in both directions.
path_owner(+Path,-Uid,-Gid)
Uid
or Gid
is uninstantiated,
it's unified with the Path
's
current UID or GID, respectively.
Uid
or Gid
is instantiated,
try to change the true UID or GID of Path
to
this value. Succeed if possible, fail if not.
Path
: the full pathname of the path in question.
Uid
: the numeric UID of the owner.
Gid
: the numeric GID of the group.
owner(Path,Uid,Gid)
path_uid(Path,Uid)
path_gid(Path,Gid)
path_lowner(+Path,-Uid,-Gid)
path_owner
, except that when given a
Path
that's a link, operates on the link rather than its target.
Path
: the full pathname of the link in question.
Uid
: the numeric UID of the owner.
Gid
: the numeric GID of the group.
lowner(Path,Uid,Gid)
path_luid(Path,Uid)
path_lgid(Path,Gid)
stat(+Path,-Mode,-Inode,-Nlinks,-Uid,-Gid,-Size,-Atime,-Mtime,-Ctime)
stat
function for a path and returns the results.
Path
: the full pathname of the node to be probed.
Mode
: its numeric access mode.
Inode
: its inode number.
Nlinks
: the number of hard links to it.
Uid
: its numeric UID
Gid
: its numeric GID
Size
: its size in bytes
Atime
: its access time as seconds since the Epoch.
Mtime
: its modification time.
Ctime
: its creation time.
stat_mode(+Path,-Mode)
stat_inode(+Path,-Inode)
stat_nlink(+Path,-Nlinks)
stat_uid(+Path,-Uid)
stat_gid(+Path,-Gid)
stat_size(+Path,-Size)
stat_atime(+Path,-Atime)
stat_mtime(+Path,-Mtime)
stat_ctime(+Path,-Ctime)
lstat(+Path,-Mode,-Inode,-Nlinks,-Uid,-Gid,-Size,-Atime,-Mtime,-Ctime)
lstat
function for a path and returns the results.
Path
: the full pathname of the node to be probed.
Mode
: its numeric access mode.
Inode
: its inode number.
Nlinks
: the number of hard links to it.
Uid
: its numeric UID
Gid
: its numeric GID
Size
: its size in bytes
Atime
: its access time as seconds since the Epoch.
Mtime
: its modification time.
Ctime
: its creation time.
lstat_mode(+Path,-Mode)
lstat_inode(+Path,-Inode)
lstat_nlink(+Path,-Nlinks)
lstat_uid(+Path,-Uid)
lstat_gid(+Path,-Gid)
lstat_size(+Path,-Size)
lstat_atime(+Path,-Atime)
lstat_mtime(+Path,-Mtime)
lstat_ctime(+Path,-Ctime)
stat(+Path,-Dev,-Rdev,-Blocksize,-Blocks)
stat
call that wouldn't fit into
the SWI-Prolog foreign function call.
Path
Dev
Rdev
Blocksize
Blocks
stat_dev(+Path,-Dev)
stat_rdev(+Path,-Rdev)
stat_blksize(+Path,-Blocksize)
stat_blocks(+Path,-Blocks)
lstat(+Path,-Dev,-Rdev,-Blocksize,-Blocks)
lstat
call that wouldn't fit into
the SWI-Prolog foreign function call.
Path
Dev
Rdev
Blocksize
Blocks
lstat_dev(+Path,-Dev)
lstat_rdev(+Path,-Rdev)
lstat_blksize(+Path,-Blocksize)
lstat_blocks(+Path,-Blocks)
deleteLinesContaining(+Path,+Pattern)
Path
in place
to delete matching lines. The file is not touched at all if no
lines match.
appendIfNoSuchLine(+Path,+ListOrAtom)
concat_atom
before the call.
prependIfNoSuchLine(+Path,+ListOrAtom)
concat_atom
before the call.
file_line(+Path,-Line)
Path
as a regular text file and unifies Line
with the first line of the file.
Repeatedly assigns text lines from the file to Line
when backtracking.
Example:
?- file_line('/etc/inetd.conf', Line).
output_line(+Command,-Line)
Command
as a UNIX command and
repeatedly places lines from command output into Line
,
providing the next line of output after each backtracking operation.
Command
: command to execute.
Line
: a line of output.
output_head(+Command,+Head,-Line)
Command
as a UNIX command, provides
Head
lines of output, and then stops. Each line of output
is bound to Line
in turn through backtracking.
output_head(+Command,-Line)
: read one header line.
?- output_head('who',5,UserInfo).makes
UserInfo
range over the first five lines of who
output.
output_tail(+Command,+Skip,-Line)
Command
as a UNIX command, skips
Skip
lines of output, and then binds Line
repeatedly to the rest of the lines of output.
output_tail(+Command,-Line)
: skip one header line.
?- output_tail('who',1,UserInfo).puts out every line after the first.
output_range(+Command,+First,+Last,-Line)
Command
as a UNIX command,
and then binds Line
repeatedly to outputs between line First
and line
Last
, inclusive. Example:
?- output_range('who',5,8,UserInfo).makes
UserInfo
range between lines 5 and 8 of the
who
output.
field(+Line,+Start,+End,-Field)
Field
to characters in Line
starting at character Start
and ending
at character End
. Leading and trailing spaces
are stripped. If End
is -1
, then include all text
to end of line.
Line
: a line of text as a Prolog atom.
Start
: the first character of a field to extract (from 0).
End
: the first character not in the field (from 0).
Field
: the resulting stripped field.
?- field('hello there',5,8,Field). Field='the'
match(+Line,+Pattern,-Match)
Line
matches the regular expression pattern
Pattern
, and sets Match
to the text matched
by the pattern. Patterns accepted are regular expressions conformant
with the Solaris regexp
library.
Line
: an atom containing text to match.
Pattern
: a regular expression pattern as an atom.
Match
: an atom containing matched text.
match(+Line,+Pattern)
: matches without returning characters matched.
?- match('ho ttthere', 't*', X). X='ttt'
replace(+Line,+Pattern,+Replacement,-Result)
Line
contained Pattern
, and
replaces every instance of Pattern
with Replacement
, yielding the result Result
.
Line
: an atom containing text to match.
Pattern
: a regular expression pattern as an atom.
Replacement
: atom whose text will be used as a replacement.
Result
: an atom containing the result.
Replacement
;
this is not as powerful as vi
replacement!
Example:
?- replace('ho there', 'h.', 'hi', X). X='hi thire'
split(+Line,+Pattern,-List)
Pattern
as a description of delimiters to use to
split Line
into a list List
of sub-atoms.
These can be recombined into a single atom with the Prolog builtin
concat_atom
.
Line
: an atom containing text to match.
Pattern
: a regular expression pattern as an atom.
List
: a Prolog list of atoms obtained by splitting
the line Line
at the delimiters given in Pattern
.
split('this is a test', '[ \t][ \t]*', X). X=['this','is','a','test']
ps_f(-User,-Pid,-Ppid,-C,-Stime,-Tty,-Time,-Cmd)
ps -f
command and returns the result
in the variables listed, as atoms.
If User
, Pid
, Tty
are uninstantiated,
this does a raw ps -fl
and returns the first process.
Other processes can be discovered through backtracking.
If User
, Pid
, or Tty
are
instantiated, adds the appropriate flags to the ps
to limit output to a particular user, process ID, or tty, respectively.
User
: a user name.
Pid
: a process ID.
Ppid
: a parent process ID.
C
: status
Stime
: start time (as a string).
Tty
: controlling tty.
Time
: CPU time so far (as a string).
Cmd
: Command known to ps
ps_fl(-User,-Pid,-Ppid,-C,-Pri,-Nice,-Addr,-Size,-Wch,-Stime,-Tty,-Time,-Cmd)
ps -fl
with appropriate arguments and
returns the result in the variables listed, as atoms.
If User
, Pid
, Tty
are uninstantiated,
this does a raw ps -fl
and returns the first process.
Other processes can be discovered through backtracking.
If User
, Pid
, or Tty
are
instantiated, adds the appropriate flags to the ps
to limit output to a particular user, process ID, or tty, respectively.
User
: a user name.
Pid
: a process ID.
Ppid
: a parent process ID.
C
: status
Pri
: scheduling priority.
Nice
: niceness level.
Addr
: base address.
Size
: size of runtime image.
Wch
: I/O status
Stime
: start time (as a string).
Tty
: controlling tty.
Time
: CPU time so far (as a string).
Cmd
: Command known to ps
df(+Path,-FS,-Kbytes,-Used,-Avail,-PercentCap,-MountPoint)
df
command on
a specific given Path
Path
: a Path to study.
FS
: the corresponding filesystem.
Kbytes
: total size in kilobytes.
Used
: used space in kilobytes.
Avail
: available space in kilobytes.
PercentCap
: percent used (including overhead).
MountPoint
: current mount point.
df
!
mount_point(+Path,-Root)
: returns df
's idea
of the mount point for the filesystem containing a specific file.
du(+Path,-Size)
du
command.
Path
: full pathname of the path to be measured.
Size
: size of that path.
quota(+User,+FS,-DDsage,-DQuota,-DLimit,-DTimeleft,-FUsage,-FQuota,-FLimit,-FTimeleft)
calls the quota -v
command (as root) and returns its data.
User
: user name.
FS
: full path of filesystem
DUsage
: disk usage
DQuota
: disk quota
DLimit
: disk limit
DTimeleft
: time left for disk.
FUsage
: file usage.
FQuota
: file quota.
FLimit
: file limit.
FTimeleft
: time left for files.
inetd(-Service,-Type,-Protocol,-Wait,-User,-Path,-Command)
inetd.conf
and provides matching lines
one at a time through backtracking.
Service
: service name.
Type
: type of service.
Protocol
: protocol (tcp
or udp
)
Wait
: wait status (wait
or nowait
).
User
: user to execute as.
Path
: command path.
Command
: short command name.
services(-Service,-Description,-Aliases)
services
file
and provides matching lines one at a time through backtracking.
Comments in the file are silently ignored.
This differs from getservbyname
in looking at the
local file instead of the network services database, if applicable.
Service
: the service name, e.g., ftp
.
Description
: the service description, e.g.,
21/tcp
.
Aliases
: aliases for the service.
field1=value1 field2=value2
is translated to the Prolog list
[field1('value1'),field2('value2')]
.
parse_db(+Path, -Parsed)
Path
as a text file, returns parsed lines
one at a time in the Prolog list Parsed
, through
backtracking.
Path
: full pathname of the file to read.
Parsed
: a list of terms describing the terms in a single line
of the file.
syskill(+Pid,+Signal)
kill
takes two integers
and performs the appropriate action.
Pid
: the process identifier to signal.
Signal
: the numeric signal to send.
signal_code(-SigName,-SigCode)
SigName
: the name of a signal (as a Prolog atom).
SigCode
: the numeric code for the name.
?- signal_code(hup,X). X=1
kill(Process,Signal)
Process
and Signal
are numeric,
calls syskill
with these values.
Process
is an atom, treats that as a name and
kills a process with that name.
Signal
is an atom, translates it from signal name
to numeric code.
Process
: process ID or name.
Signal
: signal ID or name.
kill('inetd','hup')sends a hangup to all processes named
inetd
.
email(+Person,+Message,+Subject)
Message
to Person
labelled with Subject
.
email(+Person,+Message)
sends a message with no subject.
page(+Person,+Message)
Message
to Person
,
utilizing the qpage
utility.