filename.pl 1.44 KB
Newer Older
Thierry Martinez's avatar
Thierry Martinez committed
1 2 3
:- module(
  filename,
  [
Thierry Martinez's avatar
Thierry Martinez committed
4 5
    input_file/1,
    output_file/1,
Thierry Martinez's avatar
Thierry Martinez committed
6
    filename/2,
Thierry Martinez's avatar
NuSMV  
Thierry Martinez committed
7
    automatic_suffix/4
Thierry Martinez's avatar
Thierry Martinez committed
8 9 10
  ]
).

FAGES Francois's avatar
FAGES Francois committed
11 12 13 14 15
:- doc('This reference manual (and its extended version for developpers) is automaticaly generated from the source code of Biocham. 

The syntax of Biocham is described with formal grammar rules which define new syntactic tokens from primitive tokens such as atom (i.e. string), number, term (e.g. atom(..., ...)). 

For instance, the syntax of an input or output file is just the syntax of an atom in both cases, but they are distinguished in this manual for documentation purposes:').
Thierry Martinez's avatar
Thierry Martinez committed
16

Thierry Martinez's avatar
Thierry Martinez committed
17 18 19 20 21 22 23 24 25 26 27 28 29 30
:- grammar(input_file).


input_file(Name) :-
  atom(Name).


:- grammar(output_file).


output_file(Name) :-
  atom(Name).


Thierry Martinez's avatar
Thierry Martinez committed
31
filename(Filename, ExpandedFilename) :-
Thierry Martinez's avatar
Thierry Martinez committed
32 33 34 35 36 37
  (
    atom_concat('library:', SubFilename, Filename)
  ->
    library_path(LibraryPath),
    Options = [relative_to(LibraryPath)]
  ;
Thierry Martinez's avatar
Thierry Martinez committed
38 39
    SubFilename = Filename,
    %Options = [], !bugwar: relative_to(Dir)!
Thierry Martinez's avatar
Thierry Martinez committed
40
    working_directory(Dir, Dir),
Thierry Martinez's avatar
Thierry Martinez committed
41
    Options = [relative_to(Dir)]
Thierry Martinez's avatar
Thierry Martinez committed
42 43
  ),
  absolute_file_name(SubFilename, ExpandedFilename, [expand(true) | Options]).
Thierry Martinez's avatar
Thierry Martinez committed
44 45


Thierry Martinez's avatar
Thierry Martinez committed
46 47
path_delimiter('/').

Thierry Martinez's avatar
Thierry Martinez committed
48

Thierry Martinez's avatar
NuSMV  
Thierry Martinez committed
49
automatic_suffix(Filename, DefaultSuffix, Mode, FullFilename) :-
Thierry Martinez's avatar
Thierry Martinez committed
50
  file_name_extension(_, Suffix, Filename),
Thierry Martinez's avatar
Thierry Martinez committed
51 52 53
  (
    Suffix = '',
    atom_concat(Filename, DefaultSuffix, FullFilename),
Thierry Martinez's avatar
NuSMV  
Thierry Martinez committed
54 55 56 57 58 59 60
    (
      Mode = read
    ->
      exists_file(FullFilename)
    ;
      true
    )
Thierry Martinez's avatar
Thierry Martinez committed
61 62 63 64 65
  ->
    true
  ;
    FullFilename = Filename
  ).