~rdoering/ubuntu/karmic/erlang/fix-535090

« back to all changes in this revision

Viewing changes to lib/kernel/src/packages.erl

  • Committer: Bazaar Package Importer
  • Author(s): Sergei Golovan
  • Date: 2009-02-15 16:42:52 UTC
  • mfrom: (3.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090215164252-q5x4rcf8a5pbesb1
Tags: 1:12.b.5-dfsg-2
Upload to unstable after lenny is released.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
%% list containing atoms. A name may be empty, but may not contain two
27
27
%% consecutive period (`.') characters or end with a period character.
28
28
 
29
 
-spec(to_string/1 :: (atom() | string()) -> string()).
 
29
-type package_name() :: atom() | string().
30
30
 
 
31
-spec to_string(package_name()) -> string().
31
32
to_string(Name) when is_atom(Name) ->
32
33
    atom_to_list(Name);
33
34
to_string(Name) ->
38
39
%% dangling period characters, if any of the segments after the first
39
40
%% are empty. Use 'is_valid' to check the result if necessary.
40
41
 
 
42
-spec concat(package_name(), package_name()) -> string().
41
43
concat(A, B) ->
42
44
    concat([A, B]).
43
45
 
 
46
-spec concat([package_name()]) -> string().
44
47
concat([H | T]) when is_atom(H) ->
45
48
    concat([atom_to_list(H) | T]);
46
49
concat(["" | T]) ->
59
62
concat_1(Name) ->
60
63
    erlang:error({badarg, Name}).
61
64
 
 
65
-spec is_valid(package_name()) -> bool().
62
66
is_valid(Name) when is_atom(Name) ->
63
67
    is_valid_1(atom_to_list(Name));
64
68
is_valid([$. | _]) ->
73
77
is_valid_1([]) -> true;
74
78
is_valid_1(_) -> false.
75
79
 
 
80
-spec split(package_name()) -> [string()].
76
81
split(Name) when is_atom(Name) ->
77
82
    split_1(atom_to_list(Name), []);
78
83
split(Name) ->
91
96
%% length larger than one (i.e., if the name can be split into two or
92
97
%% more segments), but is cheaper.
93
98
 
 
99
-spec is_segmented(package_name()) -> bool().
94
100
is_segmented(Name) when is_atom(Name) ->
95
101
    is_segmented_1(atom_to_list(Name));
96
102
is_segmented(Name) ->
103
109
is_segmented_1(_) ->
104
110
    erlang:error(badarg).
105
111
 
 
112
-spec last(package_name()) -> string().
106
113
last(Name) ->
107
114
    last_1(split(Name)).
108
115
 
109
116
last_1([H]) -> H;
110
117
last_1([_ | T]) -> last_1(T).
111
118
 
 
119
-spec first(package_name()) -> [string()].
112
120
first(Name) ->
113
121
    first_1(split(Name)).
114
122
 
115
123
first_1([H | T]) when T =/= [] -> [H | first_1(T)];
116
124
first_1(_) -> [].
117
125
 
 
126
-spec strip_last(package_name()) -> string().
118
127
strip_last(Name) ->
119
128
    concat(first(Name)).
120
129
 
122
131
%% current code server search path. (There is no guarantee that the
123
132
%% modules are loadable; only that the object files exist.)
124
133
 
 
134
-spec find_modules(package_name()) -> [string()].
125
135
find_modules(P) ->
126
136
    find_modules(P, code:get_path()).
127
137
 
 
138
-spec find_modules(package_name(), [string()]) -> [string()].
128
139
find_modules(P, Paths) ->
129
140
    P1 = filename:join(packages:split(P)),
130
141
    find_modules(P1, Paths, code:objfile_extension(), sets:new()).