File: system.lgt

package info (click to toggle)
yap 5.1.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 16,124 kB
  • ctags: 14,650
  • sloc: ansic: 122,796; perl: 22,545; sh: 3,768; java: 1,277; makefile: 1,191; xml: 739; tcl: 624; lisp: 142; awk: 9
file content (129 lines) | stat: -rw-r--r-- 2,346 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

:-  use_module(library(calendar)).


:- object(system,
	implements(systemp)).


	:- info([
		version is 1.0,
		author is 'Paulo Moura',
		date is 2004/6/5,
		comment is 'Operating system interface for ECLiPSe.']).


	make_directory(Directory) :-
		{mkdir(Directory)}.


	delete_directory(Directory) :-
		{delete(Directory)}.


	change_directory(Directory) :-
		{cd(Directory)}.


	working_directory(Directory) :-
		{getcwd(Directory)}.


	directory_exists(Directory) :-
		{fail}.


	directory_files(Directory, Files) :-
		{read_directory(Directory, "*", _, Files)}.


	absolute_file_name(File) :-
		absolute_file_name(File, File).


	absolute_file_name(File, Full) :-
		{Rel == user ->
			Abs == user  % treat user specially
          ; get_flag(prolog_suffix, Sufs),
          (existing_file(Rel, Sufs, [], ExtRel) -> true ; ExtRel = Rel),
          canonical_path_name(ExtRel, Abs)}.


	file_base_name(File, Base) :-
		{pathname(File, _, Base, _)}.


	file_name_extension(File, Extension) :-
		{pathname(File, _, _, Extension)}.


	file_name_directory(File, Directory) :-
		{pathname(File, Directory, _, _)}.


	file_exists(File) :-
		{exists(File)}.


	file_modification_time(File, Time) :-
		{get_file_info(File, mtime, Time)}.


	file_size(File, Size) :-
		{get_file_info(File, size, Size)}.


	file_type(File, Type) :-
		{get_file_info(File, mode, Mode)},
		Mode /\ 8'170000 =:= Result,
		file_mode_type(Result, Type).

	file_mode_type(8'100000, regular) :- !.
	file_mode_type(8'040000, directory) :- !.
	file_mode_type(8'140000, socket) :- !.
	file_mode_type(8'120000, symlink) :- !.
	file_mode_type(_, unknown).


	delete_file(File) :-
		{delete(File)}.


	rename_file(Old, New) :-
		{rename(Old, New)}.


	symbolic_link(File, Target) :-
		{fail}.


	environment_variable(Variable, Value) :-
		{getenv(Variable, Value)}.


	set_environment_variable(Variable, Value) :-
		{fail}.


	date_time(Year, Month, Day, Hours, Mins, Secs, 0) :-
		{mjd_now(MJD),
		 mjd_to_date(MJD, Day/Month/Year),
		 mjd_to_time(MJD, Hours:Mins:Secs)}.


	convert_time(Time, Year, Month, Day, Hours, Mins, Secs, _) :-
		{unix_to_mjd(Time, MJD),
		 mjd_to_date(MJD, Day/Month/Year),
		 mjd_to_time(MJD, Hours:Mins:Secs)}.


	cpu_time(Time) :-
		{cputime(Time)}.


	host_name(Name) :-
		{get_flag(hostname, String),
		 atom_string(Name, String)}.


:- end_object.