root/tags/lgt2311/library/systemp.lgt

Revision 2599, 19.5 KB (checked in by pmoura, 3 years ago)

Removed the experimental "systemp.lgt" protocol from the list of files loaded by the "library/all_loader.lgt" loader utility files to avoid compilation errors on some Prolog systems.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1
2:- protocol(systemp).
3
4    :- info([
5        version is 1.10,
6        author is 'Portable Operating-System Interface (POSI) initiative',
7        date is 2006/1/21,
8        comment is 'Portable operating system access protocol.',
9        remarks is [
10            'File names overview:' - 'The main idea is that file names should be operating-system independent. As such, predicates are needed to convert between portable file names and operating-system specific file names. The solution chosen is to use URL syntax for portable file names.',
11            'Local and remote file names:' - 'A (portable) file name may point to either a local file or a remote file.',
12            'URL file names:' - 'These are file names which start with an access protocol (e.g. {http, https, ftp, gopher, file}://).',
13            'Absolute file names:' - 'These are file names that always point to a local file. They always start with a slash character (/).',
14            'Relative file names:' - 'These are file names that always point to a local file. A file name is a relative file name if it does not start with a slash character or a file access protocol (including the :// characters).',
15            'Canonical file names' - 'These are file names where any environment variables was been expanded and where the sequences for current (.) and parent (..) directories have been resolved.',
16            'Time stamps:' - 'Time stamps are used for representing current, system time and in file properties to represent creation, modification, and access times. Time stamps are system-dependent terms but that can be compared (e.g. when testing which of two given files is older).']]).
17
18    :- public(make_directory/1).
19    :- mode(make_directory(+atom), one).
20    :- info(make_directory/1, [
21        comment is 'Makes a new directory. Argument is first expanded to a canonical file name.',
22        argnames is ['Directory'],
23        exceptions is [
24            'Directory is not instantiated' - instantiation_error,
25            'Directory is neither a variable nor a valid file name' - type_error(file_name, 'Directory'),
26            'No permission for making a new directory' - permission_error(write, 'Directory')]]).
27
28    :- public(delete_directory/1).
29    :- mode(delete_directory(+atom), one).
30    :- info(delete_directory/1, [
31        comment is 'Deletes an empty directory.',
32        argnames is ['Directory'],
33        exceptions is [
34            'Directory is not instantiated' - instantiation_error,
35            'Directory is neither a variable nor a valid file name' - type_error(file_name, 'Directory'),
36            'Directory does not exists' - existence_error(directory, 'Directory'),
37            'No permission for deleting the directory' - permission_error(write, 'Directory'),
38            'Directory is not empty' - permission_error(write, 'Directory')]]).
39
40    :- public(change_directory/1).
41    :- mode(change_directory(+atom), one).
42    :- info(change_directory/1, [
43        comment is 'Changes current working directory.',
44        argnames is ['Directory'],
45        exceptions is [
46            'Directory is not instantiated' - instantiation_error,
47            'Directory is neither a variable nor a valid file name' - type_error(file_name, 'Directory'),
48            'No permission for accessing the directory' - permission_error(read, 'Directory'),
49            'Directory does not exists' - existence_error(directory, 'Directory')]]).
50
51    :- public(working_directory/1).
52    :- mode(working_directory(?atom), zero_or_one).
53    :- info(working_directory/1, [
54        comment is 'Current working directory (as an absolute file name).',
55        argnames is ['Directory'],
56        exceptions is [
57            'Directory is neither a variable nor a valid file name' - type_error(file_name, 'Directory')]]).
58
59    :- public(directory_exists/1).
60    :- mode(directory_exists(+atom), zero_or_one).
61    :- info(directory_exists/1, [
62        comment is 'True if the specified directory exists (irrespective of directory permissions).',
63        argnames is ['Directory'],
64        exceptions is [
65            'Directory is not instantiated' - instantiation_error,
66            'Directory is neither a variable nor a valid file name' - type_error(file_name, 'Directory')]]).
67
68    :- public(directory_files/3).
69    :- mode(directory_files(+atom, +atom, -list), one).
70    :- info(directory_files/3, [
71        comment is 'List of all directory files that matches a regular expression (returns an empty list when no file matches; may be used to find hidden files given an appropriate filter).',
72        argnames is ['Directory', 'Filter', 'Files'],
73        exceptions is [
74            'Directory is not instantiated' - instantiation_error,
75            'Directory is neither a variable nor a valid file name' - type_error(file_name, 'Directory'),
76            'No read permission for the directory' - permission_error(read, 'Directory'),
77            'Directory does not exists' - existence_error(directory, 'Directory'),
78            'Filter is not instantiated' - instantiation_error,
79            'Filter is neither a variable nor a valid regular expression' - type_error(regular_expression, 'Filter')]]).
80
81    :- public(directory_files/2).
82    :- mode(directory_files(+atom, -list), one).
83    :- info(directory_files/2, [
84        comment is 'List of all directory files (returns an empty list when the directory is empty; hidden files are not retrieved).',
85        argnames is ['Directory', 'Files'],
86        exceptions is [
87            'Directory is not instantiated' - instantiation_error,
88            'Directory is neither a variable nor a valid file name' - type_error(file_name, 'Directory'),
89            'No read permission for the directory' - permission_error(read, 'Directory'),
90            'Directory does not exists' - existence_error(directory, 'Directory')]]).
91
92    :- public(delete_file/1).
93    :- mode(delete_file(+atom), one).
94    :- info(delete_file/1, [
95        comment is 'Deletes a file.',
96        argnames is ['File'],
97        exceptions is [
98            'File is not instantiated' - instantiation_error,
99            'File is neither a variable nor a valid file name' - type_error(file_name, 'File'),
100            'File does not exists' - existence_error(file, 'File'),
101            'No write permission to the file' - permission_error(write, 'File')]]).
102
103    :- public(delete_files/1).
104    :- mode(delete_files(+atom), one).
105    :- info(delete_files/1, [
106        comment is 'Deletes a set of matching files.',
107        argnames is ['Filter'],
108        exceptions is [
109            'Filter is not instantiated' - instantiation_error,
110            'Filter is neither a variable nor a valid regular expression' - type_error(regular_expression, 'Filter'),
111            'No permission to delete some of the matching files' - permission_error(write, 'File')]]).
112
113    :- public(rename_file/2).
114    :- mode(rename_file(+atom, +atom), zero_or_one).
115    :- info(rename_file/2, [
116        comment is 'Renames a file (or a directory).',
117        argnames is ['Old', 'New'],
118        exceptions is [
119            'Old is not instantiated' - instantiation_error,
120            'New is not instantiated' - instantiation_error,
121            'Old is neither a variable nor a valid file name' - type_error(file_name, 'Old'),
122            'New is neither a variable nor a valid file name' - type_error(file_name, 'New'),
123            'File Old does not exists' - existence_error(file, 'Old'),
124            'No write permission to the file' - permission_error(write, 'Old')]]).
125
126    :- public(copy_file/2).
127    :- mode(copy_file(+atom, +atom), one).
128    :- info(copy_file/2, [
129        comment is 'Makes a copy of a file.',
130        argnames is ['Original', 'Copy'],
131        exceptions is [
132            'Original is not instantiated' - instantiation_error,
133            'Copy is not instantiated' - instantiation_error,
134            'Original is neither a variable nor a valid file name' - type_error(file_name, 'Original'),
135            'Copy is neither a variable nor a valid file name' - type_error(file_name, 'Copy'),
136            'File Original does not exists' - existence_error(file, 'Original'),
137            'No read permission to the original file' - permission_error(read, 'Original'),
138            'No write permission to the file copy' - permission_error(write, 'Copy')]]).
139
140    :- public(make_symlink/2).
141    :- mode(make_symlink(+atom, +atom), one).
142    :- info(make_symlink/2, [
143        comment is 'Makes a symbolic link.',
144        argnames is ['Symlink', 'Target'],
145        exceptions is [
146            'Symlink is not instantiated' - instantiation_error,
147            'Target is not instantiated' - instantiation_error,
148            'Symlink is neither a variable nor a valid file name' - type_error(file_name, 'Symlink'),
149            'Target is neither a variable nor a valid file name' - type_error(file_name, 'Target'),
150            'No permission for creating the symbolic link' - permission_error(write, 'Symlink')]]).
151
152    :- public(file_exists/1).
153    :- mode(file_exists(+atom), zero_or_one).
154    :- info(file_exists/1, [
155        comment is 'True if the specified file exists (irrespective of type and file permissions).',
156        argnames is ['File'],
157        exceptions is [
158            'File is not instantiated' - instantiation_error,
159            'File is neither a variable nor a valid file name' - type_error(file_name, 'File')]]).
160
161    :- public(file_property/2).
162    :- mode(file_property(+atom, +compound), zero_or_one).
163    :- mode(file_property(+atom, -compound), one_or_more).
164    :- info(file_property/2, [
165        comment is 'File properties.',
166        argnames is ['File', 'Property'],
167        exceptions is [
168            'File is not instantiated' - instantiation_error,
169            'File is neither a variable nor a valid file name' - type_error(file_name, 'File'),
170            'File does not exists' - existence_error(file, 'File'),
171            'No read permission to the file' - permission_error(read, 'File'),
172            'Property is neither a variable nor a valid file property' - type_error(file_property, 'Property')],
173        examples is [
174            'Querying file size:' - file_property(foo, size(Bytes)) - {Bytes = 32568},
175            'Querying file type:' - file_property(foo, type(Type)) - {Type = regular},
176            'Querying file creation date:' - file_property(foo, creation_time(Time)) - {Time = 137692},
177            'Querying file last access date:' - file_property(foo, access_time(Time)) - {Time = 811042},
178            'Querying file modification date:' - file_property(foo, modification_time(Time)) - {Time = 811042},
179            'Querying file permissions:' - file_property(foo, permission(Permission)) - {Permission = read}
180      ]]).
181
182    :- public(current_environment_variable/1).
183    :- mode(current_environment_variable(?atom), zero_or_more).
184    :- info(current_environment_variable/1, [
185        comment is 'Argument is a currently defined environment variable . Fails if the variable does not exists.',
186        argnames is ['Variable'],
187        exceptions is [
188            'Variable is neither a variable nor an atom' - type_error(atom, 'Variable')]]).
189
190    :- public(delete_environment_variable/1).
191    :- mode(delete_environment_variable(+atom), one).
192    :- info(delete_environment_variable/1, [
193        comment is 'Deletes an environment variable.',
194        argnames is ['Variable'],
195        exceptions is [
196            'Variable is not instantiated' - instantiation_error,
197            'Variable is neither a variable nor an atom' - type_error(atom, 'Variable'),
198            'Variable is not a currently defined environment variable' - existence_error(environment_variable, 'Variable')]]).
199
200    :- public(get_environment_variable/2).
201    :- mode(get_environment_variable(+atom, ?atom), zero_or_one).
202    :- info(get_environment_variable/2, [
203        comment is 'Gets environment variable value.',
204        argnames is ['Variable', 'Value'],
205        exceptions is [
206            'Variable is not instantiated' - instantiation_error,
207            'Variable is neither a variable nor an atom' - type_error(atom, 'Variable'),
208            'Value is neither a variable nor an atom' - type_error(atom, 'Value'),
209            'Variable is not a currently defined environment variable' - existence_error(environment_variable, 'Variable')]]).
210
211    :- public(set_environment_variable/2).
212    :- mode(set_environment_variable(+atom, +atom), one).
213    :- info(set_environment_variable/2, [
214        comment is 'Sets environment variable value.',
215        argnames is ['Variable', 'Value'],
216        exceptions is [
217            'Variable is not instantiated' - instantiation_error,
218            'Value is not instantiated' - instantiation_error,
219            'Variable is neither a variable nor an atom' - type_error(atom, 'Variable'),
220            'Value is neither a variable nor an atom' - type_error(atom, 'Value')]]).
221
222    :- public(time_stamp/1).
223    :- mode(time_stamp(-number), one).
224    :- info(time_stamp/1, [
225        comment is 'Returns a system-dependent time stamp (which can be used for sorting).',
226        argnames is ['Time']]).
227
228    :- public(local_time/1).
229    :- mode(local_time(?time(?integer, ?integer, ?integer, ?integer, ?integer, ?integer, ?integer)), zero_or_one).
230    :- info(local_time/1, [
231        comment is 'Local time (respecting time zone and daylight savings settings).',
232        argnames is ['time(Year, Month, Day, Hours, Mins, Secs, Microsecs)']]).
233
234    :- public(utc_time/1).
235    :- mode(utc_time(?time(?integer, ?integer, ?integer, ?integer, ?integer, ?integer, ?integer)), zero_or_one).
236    :- info(utc_time/1, [
237        comment is 'Universal Coordinated Time (UTC).',
238        argnames is ['time(Year, Month, Day, Hours, Mins, Secs, Microsecs)']]).
239
240    :- public(convert_time/2).
241    :- mode(convert_time(+number, ?time(?integer, ?integer, ?integer, ?integer, ?integer, ?integer, ?integer)), zero_or_one).
242    :- mode(convert_time(?number, +time(+integer, +integer, +integer, +integer, +integer, +integer, +integer)), zero_or_one).
243    :- info(convert_time/2, [
244        comment is 'Converts between system-dependent time stamps and calendar local date and time.',
245        argnames is ['Time', 'time(Year, Month, Day, Hours, Mins, Secs, Microsecs)'],
246        exceptions is [
247            'Neither argument is instantiated' - instantiation_error,
248            'Time stamp is neither a variable nor a valid time stamp' - type_error(time_stamp, 'Time'),
249            'Time structure is neither a variable nor a valid time structure' - type_error(time_structure, 'time(Year, Month, Day, Hours, Mins, Secs, Microsecs)')]]).
250
251    :- public(cpu_time/1).
252    :- mode(cpu_time(-number), one).
253    :- info(cpu_time/1, [
254        comment is 'System cpu time in seconds.',
255        argnames is ['Time']]).
256
257    :- public(host_name/1).
258    :- mode(host_name(-atom), one).
259    :- info(host_name/1, [
260        comment is 'Host name (default is localhost).',
261        argnames is ['Name']]).
262
263    :- public(portable_os_file_name/2).
264    :- mode(portable_os_file_name(+atom, -atom), one).
265    :- mode(portable_os_file_name(-atom, +atom), one).
266    :- info(portable_os_file_name/2, [
267        comment is 'Converts between portable and operating-system dependent file names.',
268        argnames is ['Canonical', 'OS']]).
269
270    :- public(portable_file_name/3).
271    :- mode(portable_file_name(+atom, -atom, -atom), one).
272    :- mode(portable_file_name(-atom, +atom, -atom), one).
273    :- mode(portable_file_name(-atom, -atom, +atom), one).
274    :- info(portable_file_name/3, [
275        comment is 'Converts between relative, absolute, and URL portable file names.',
276        argnames is ['Relative', 'Absolute', 'URL'],
277        exceptions is [
278            'None of the arguments is instantiated' - instantiation_error,
279            'Relative is neither a variable nor a relative file name' - type_error(relative_file_name, 'Relative'),
280            'Absolute is neither a variable nor a absolute file name' - type_error(absolute_file_name, 'Absolute'),
281            'URL is neither a variable nor a file name URL' - type_error(url_file_name, 'URL')]]).
282
283    :- public(relative_file_name/1).
284    :- mode(relative_file_name(+atom), zero_or_one).
285    :- info(relative_file_name/1, [
286        comment is 'True when the argument is a valid, relative file name. Argument is expanded to a canonical file name before testing.',
287        argnames is ['File'],
288        exceptions is [
289            'File is not instantiated' - instantiation_error,
290            'File is neither a variable nor a valid file name' - type_error(file_name, 'File')]]).
291
292    :- public(absolute_file_name/1).
293    :- mode(absolute_file_name(+atom), zero_or_one).
294    :- info(absolute_file_name/1, [
295        comment is 'True if the argument is a valid, absolute file name. Argument is expanded to a canonical file name before testing.',
296        argnames is ['File'],
297        exceptions is [
298            'File is not instantiated' - instantiation_error,
299            'File is neither a variable nor a valid file name' - type_error(file_name, 'File')]]).
300
301    :- public(url_file_name/1).
302    :- mode(url_file_name(+atom), zero_or_one).
303    :- info(url_file_name/1, [
304        comment is 'True when the argument is a valid, URL file name. Argument is expanded to a canonical file name before testing.',
305        argnames is ['File'],
306        exceptions is [
307            'File is not instantiated' - instantiation_error,
308            'File is neither a variable nor a valid file name' - type_error(file_name, 'File')]]).
309
310    :- public(absolute_file_name/2).
311    :- mode(absolute_file_name(+atom, ?atom), zero_or_one).
312    :- info(absolute_file_name/2, [
313        comment is 'Expands a file name into a canonical absolute file name.',
314        argnames is ['File', 'Absolute'],
315        exceptions is [
316            'File is not instantiated' - instantiation_error,
317            'File is neither a variable nor a valid file name' - type_error(file_name, 'File'),
318            'Absolute is neither a variable nor a valid file name' - type_error(file_name, 'Absolute')]]).
319
320    :- public(url_file_name/2).
321    :- mode(url_file_name(+atom, ?atom), zero_or_one).
322    :- info(url_file_name/2, [
323        comment is 'Expands a file name into a canonical URL file name.',
324        argnames is ['File', 'URL'],
325        exceptions is [
326            'File is not instantiated' - instantiation_error,
327            'File is neither a variable nor a valid file name' - type_error(file_name, 'File'),
328            'URL is neither a variable nor a valid file name URL' - type_error(file_name, 'URL')]]).
329
330    :- public(file_name_part/2).
331    :- mode(file_name_part(+atom, ?compound), zero_or_more).
332    :- info(file_name_part/2, [
333        comment is 'File name parts. The file name is expanded to a canonical file name before decomposing in parts.',
334        argnames is ['File', 'Part'],
335        exceptions is [
336            'File is not instantiated' - instantiation_error,
337            'File is neither a variable nor a valid file name' - type_error(file_name, 'File'),
338            'File does not exists' - existence_error(file, 'File'),
339            'Part is neither a variable nor a file name part' - type_error(file_name_part, 'Port')],
340        examples is [
341            'Querying file access protocol:' - file_name_part(foo, protocol(Protocol)) - {Protocol = file},
342            'Querying file host location:' - file_name_part('http://www.prolog-standard.org:8080/index.html', host(Host)) - {Host = 'www.prolog-standard.org'},
343            'Querying file port:' - file_name_part('http://www.prolog-standard.org:8080/index.html', port(Port)) - {Port = 8080},
344            'Querying file port:' - file_name_part(foo, port(Port)) - {no},
345            'Querying file username:' - file_name_part('http://user@www.prolog-standard.org/', user(Username)) - {Username = user},
346            'Querying file password:' - file_name_part('http://user:password@www.prolog-standard.org/', password(Password)) - {Password = password},
347            'Querying file base name:' - file_name_part('/usr/local/foo.pl', base(Basename)) - {Basename = 'foo.pl'},
348            'Querying file path:' - file_name_part('/usr/local/foo.pl', path(Path)) - {Path = '/usr/local/'},
349            'Querying file extension:' - file_name_part('foo.pl', extension(Extension)) - {Extension = '.pl'},
350            'Querying file extension:' - file_name_part('foo.', extension(Extension)) - {Extension = '.'},
351            'Querying file extension:' - file_name_part(foo, extension(Extension)) - {Extension = ''},
352            'Querying file search pairs:' - file_name_part('http://user@www.prolog-standard.org/updates.cgi?date=today', search(Pairs)) - {Pairs = [date=today]},
353            'Querying file fragment:' - file_name_part('http://user@www.prolog-standard.org/updates.html#latest', fragment(Fragment)) - {Fragment = latest}
354      ]]).
355
356    :- public(file_name_parts/2).
357    :- mode(file_name_parts(+atom, -list(compound)), one).
358    :- mode(file_name_parts(-atom, +list(compound)), zero_or_one).
359    :- info(file_name_parts/2, [
360        comment is 'Converts between a file name and its constituent parts (represented as a list of compound terms). The file name (when instantiated) is expanded to a canonical file name before decomposing in parts.',
361        argnames is ['File', 'Parts'],
362        exceptions is [
363            'None of the arguments are instantiated' - instantiation_error,
364            'File is neither a variable nor a valid file name' - type_error(file_name, 'File'),
365            'Parts is neither a variable nor a list' - type_error(list(compound), 'Parts')],
366        examples is [
367            'Decomposing a file name:' - file_name_parts('http://www.prolog-standard.org:8080/index.html', Parts) - {Parts = [protocol(http), host('www.prolog-standard.org'), port(8080), path('/'), base(index), extension('.html')]}]]).
368
369:- end_protocol.
Note: See TracBrowser for help on using the browser.