~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/dialyzer/test/small_tests_SUITE_data/src/appmon_place.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
%%---------------------------------------------------------------------
 
2
%% This is added as a test because it was giving a false positive
 
3
%% (function move/4 will nevr be called) due to the strange use of
 
4
%% self-recursive fun construction in placex/3.
 
5
%%
 
6
%% The analysis was getting confused that the foldl call will never
 
7
%% terminate (due to a wrong hard-coded type for foldl) and inferred
 
8
%% that the remaining calls in the body of placex/3 will not be
 
9
%% reached.  Fixed 11 March 2005.
 
10
%%---------------------------------------------------------------------
 
11
 
 
12
-module(appmon_place).
 
13
-export([place/2]).
 
14
 
 
15
place(DG, Root) ->
 
16
    case appmon_dg:get(data, DG, Root) of
 
17
        false -> [0];
 
18
        _Other -> 
 
19
            placey(DG, Root, 1),
 
20
            placex(DG, Root, [])
 
21
    end.
 
22
 
 
23
placey(DG, V, Y) ->
 
24
    appmon_dg:set(y, DG, V, Y),
 
25
    Y1 = Y+1,
 
26
    lists:foreach(fun(C) -> placey(DG, C, Y1) end, appmon_dg:get(out, DG, V)).
 
27
 
 
28
placex(DG, V, LastX) ->
 
29
    Ch = appmon_dg:get(out, DG, V),
 
30
    ChLX = lists:foldl(fun(C, Accu) -> placex(DG, C, Accu) end,
 
31
                       tll(LastX),
 
32
                       Ch),
 
33
    Width       = appmon_dg:get(w, DG, V),
 
34
    MyX         = calc_mid(DG, Width, Ch),
 
35
    DeltaX      = calc_delta(MyX, hdd(LastX)+20),
 
36
    appmon_dg:set(x, DG, V, MyX),
 
37
    move(DG, V, [MyX+Width | ChLX], DeltaX).
 
38
 
 
39
move(_DG, _L, LastX, 0) -> LastX;
 
40
move(DG, V, LastX, DeltaX) -> move2(DG, V, LastX, DeltaX).
 
41
 
 
42
move2(DG, V, LastX, DeltaX) ->
 
43
    NewX = appmon_dg:get(x, DG, V)+DeltaX,
 
44
    appmon_dg:set(x, DG, V, NewX),
 
45
    ChLX = lists:foldl(fun(C, LX) -> move2(DG, C, LX, DeltaX) end,
 
46
                       tll(LastX), 
 
47
                       appmon_dg:get(out, DG, V)),
 
48
    [max(NewX+appmon_dg:get(w, DG, V), hdd(LastX)) | ChLX].
 
49
 
 
50
max(A, B) when A>B -> A;
 
51
max(_, B) -> B.
 
52
 
 
53
calc_mid(_DG, _Width, []) -> 0;
 
54
calc_mid(DG, Width, ChList) ->
 
55
    LeftMostX = appmon_dg:get(x, DG, hd(ChList)),
 
56
    Z2 = lists:last(ChList),
 
57
    RightMostX = appmon_dg:get(x, DG, Z2)+appmon_dg:get(w, DG, Z2),
 
58
    trunc((LeftMostX+RightMostX)/2)-trunc(Width/2).
 
59
 
 
60
calc_delta(Mid, Right) ->    
 
61
    if  Right>Mid       -> Right-Mid;
 
62
        true            -> 0
 
63
    end.
 
64
 
 
65
%% Special head and tail
 
66
%% Handles empty list in a non-standard way
 
67
tll([]) -> [];
 
68
tll([_|T]) -> T.
 
69
hdd([]) -> 0;
 
70
hdd([H|_]) -> H.
 
71