|
18 | 18 | with_output_to_file/2, % (File,Goal) Mode = write
|
19 | 19 | with_output_to_file/3, % (File,Mode,Goal) Encoding = utf8
|
20 | 20 | with_output_to_file/4, % (File,Mode,Goal,Encoding)
|
| 21 | + record_stout_in_file/4, % (+FullFilePath,+OutPreGoal,+Goal,+OutPostGoal) |
| 22 | + record_stout_in_file/2, % (+FullFilePath,+Goal) |
| 23 | + |
21 | 24 | with_output_to_folder/2, % (+Folder,+Call) FileName=Functor+Time
|
22 | 25 | with_output_to_folder/3, % (+Folder,-FileName,+Call) FileName=Functor+Time
|
23 | 26 | report_to_file_ctc/1, % (CallLiteral) As above but in CTC_HOME directory
|
|
221 | 224 | close(Stream) % cleanup
|
222 | 225 | ).
|
223 | 226 |
|
224 |
| -% -- OBSOLETE, use with_output_to_file/3 instead: |
225 | 227 | :- module_transparent with_output_to_file/2, export_goal_output/2.
|
226 | 228 | with_output_to_file(File,Goal) :- with_output_to_file(File,write,Goal).
|
227 | 229 | export_goal_output(File,Goal) :- with_output_to_file(File,write,Goal).
|
228 | 230 |
|
| 231 | + |
| 232 | + |
| 233 | +% record_stout_in_file(+FullFilePath,+Goal) |
| 234 | +% |
| 235 | +% Run a Goal that writes to stout or other Stream and |
| 236 | +% additionally record the output in File. File is an |
| 237 | +% absolute file path. |
| 238 | +:- meta_predicate(record_stout_in_file(+,0)). |
| 239 | +record_stout_in_file(File,OutGoal) :- |
| 240 | + record_stout_in_file(File,true,true,Goal). |
| 241 | + |
| 242 | +% record_stout_in_file(+FullFilePath,+OutPreGoal,+Goal,+OutPostGoal) |
| 243 | +% |
| 244 | +%:- public(record_stout_in_file/4). % (File,OutPreGoal,Goal,OutPostGoal) |
| 245 | +:- meta_predicate(record_stout_in_file(+,0,0,0)). |
| 246 | +record_stout_in_file(File,OutPreGoal,Goal,OutPostGoal) :- |
| 247 | + call(OutPreGoal), % <- must write to stdout without other side-effects |
| 248 | + ctc_util_files:with_output_to_file(File,append,OutPreGoal), % replicates pre output in File |
| 249 | + call(Goal), |
| 250 | + ctc_util_files:with_output_to_file(File,append,OutPostGoal), % replicates post output in File |
| 251 | + call(OutPostGoal). % <- must write to stdout without other side-effects |
| 252 | + |
| 253 | + |
229 | 254 |
|
230 | 255 | % Portable implementation of the above predicate
|
231 | 256 | % (without SWI-specific "with_otput_to"):
|
|
271 | 296 | format(atom(TimeStampAtom), '~a.~a.~a ~a:~a:~d', [D,M,Y,H,Mn,Seconds]).
|
272 | 297 |
|
273 | 298 | /*
|
274 |
| - * Determine the absolute path to the root directory of the current |
275 |
| - * workspace ASSUNIMG that this file is three levels deeper: |
276 |
| - * --> WorkspaceDirPath/ProjectDir/FileDir/thisfile |
| 299 | + * Determine the absolute path to the root directory of the PDT |
| 300 | + * repository, ASSUMIMG that this file is three levels deeper: |
| 301 | + * --> PDTRepoDirPath/prolog.library/pl/files.pl |
277 | 302 | */
|
278 |
| -workspace_root(WorkspaceDirPath) :- |
279 |
| - file_search_path('worspace_root', WorkspaceDirPath), |
| 303 | +pdt_repository_root(WorkspaceDirPath) :- |
| 304 | + file_search_path('pdt_repository_root', WorkspaceDirPath), |
280 | 305 | !.
|
281 |
| -workspace_root(WorkspaceDirPath) :- |
282 |
| - source_file(workspace_root(_), CurrentFile), % get absolute path of current file |
283 |
| - file_directory_name(CurrentFile, FileDirPath), % get path to its containing directory |
284 |
| - file_base_name(FileDirPath, FileDir), % get name of containing directory |
285 |
| - concat(ProjectDirPath, FileDir, FileDirPath), % get path to its containing project |
286 |
| - file_base_name(ProjectDirPath, ProjectDir), % get name of containing project |
287 |
| - concat(WorkspaceDirPath, ProjectDir, ProjectDirPath), % get path of its containing worksapace |
288 |
| - assert(file_search_path('worspace_root', WorkspaceDirPath)). |
289 |
| - |
| 306 | +pdt_repository_root(WorkspaceDirPath) :- |
| 307 | + % get absolute path of current file |
| 308 | + source_file(pdt_repository_root(_), CurrentFile), |
| 309 | + % get the Workspace directory by removing the |
| 310 | + % Filename,FileDirectory and ProjectDirectory |
| 311 | + atomic_list_concat(L,'/',CurrentFile), |
| 312 | + reverse(L,[_FileName,_FileDir,_ProjDir|WorkspaceDirListRev]), |
| 313 | + reverse(WorkspaceDirListRev,WorkspaceDirList), |
| 314 | + atomic_list_concat(WorkspaceDirList,'/',WorkspaceDirPath), |
| 315 | + % remember it as 'workspace_root' alias |
| 316 | + assert(file_search_path('pdt_repository_root', WorkspaceDirPath)). |
290 | 317 |
|
0 commit comments