|
|
tree - plstree - ps and ls displayed as a tree |
|
|
 |
git clone git://bitreich.org/plstree git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/plstree (git://bitreich.org) |
|
|
 |
Log |
|
|
 |
Files |
|
|
 |
Refs |
|
|
 |
Tags |
|
|
 |
README |
|
|
|
--- |
|
|
|
tree (1764B) |
|
|
|
--- |
|
|
|
1 #!/usr/bin/awk -f |
|
|
|
2 |
|
|
|
3 # convert a list of paths into a tree |
|
|
|
4 |
|
|
|
5 BEGIN { |
|
|
|
6 LINE = "| "; |
|
|
|
7 NODE = "|- "; |
|
|
|
8 TAIL = "`- "; |
|
|
|
9 VOID = " "; |
|
|
|
10 |
|
|
|
11 num = list(entries); |
|
|
|
12 tree(entries, num); |
|
|
|
13 display(entries, num); |
|
|
|
14 } |
|
|
|
15 |
|
|
|
16 # Get a recursive list of all entries into entries[] with entries[i:j] |
|
|
|
17 # holding the component j of the path i, and 0 has all the -l details, |
|
|
|
18 # then return the number of entries in entries[]. |
|
|
|
19 # |
|
|
|
20 # [ 1:[ 1:"etc" ], |
|
|
|
21 # 2:[ 1:"etc", 2:"sv" ], |
|
|
|
22 # 3:[ 1:"etc", 2:"tor" ] ] |
|
|
|
23 # |
|
|
|
24 # Only the leaves are present, the intermediates components are LINE or |
|
|
|
25 # NODE if just before a leave |
|
|
|
26 # |
|
|
|
27 # [ 1:[ 1:LINE, 2:LINE, 3:LINE, 4:LINE, 5:NODE, 6:"filename" ], |
|
|
|
28 # 2:[ 1:LINE, 2:LINE, 3:LINE, 4:NODE, 5:"filename" ] ] |
|
|
|
29 |
|
|
|
30 function list(entries) |
|
|
|
31 { |
|
|
|
32 for (num = 0; getline; num++) { |
|
|
|
33 sub("^/", "", $0); |
|
|
|
34 sub("/$", "", $0); |
|
|
|
35 count = split($0, nodelist, "/"); |
|
|
|
36 for (i = 1; i < count; i++) |
|
|
|
37 entries[num":"i] = LINE; |
|
|
|
38 entries[num":"count] = NODE; |
|
|
|
39 entries[num"name"] = nodelist[count]; |
|
|
|
40 } |
|
|
|
41 |
|
|
|
42 return num - 1; |
|
|
|
43 } |
|
|
|
44 |
|
|
|
45 # Transform entries into a tree by replacing some LINE by VOID when needed. |
|
|
|
46 # The tree is walked from the bottom to the top, and column by column |
|
|
|
47 # toward the right until an empty column is met which stops the algorithm. |
|
|
|
48 |
|
|
|
49 function tree(entries, num) |
|
|
|
50 { |
|
|
|
51 for (i = 1; !stop; i++) { |
|
|
|
52 stop = tail = 1; |
|
|
|
53 for (l = num; l > 0; l--) { |
|
|
|
54 if (entries[l":"i] == LINE && tail) { |
|
|
|
55 entries[l":"i] = VOID; |
|
|
|
56 stop = 0; |
|
|
|
57 } else if (entries[l":"i] == NODE && tail) { |
|
|
|
58 entries[l":"i] = TAIL; |
|
|
|
59 tail = stop = 0; |
|
|
|
60 } else if (!entries[l":"i]) { |
|
|
|
61 tail = 1; |
|
|
|
62 } |
|
|
|
63 } |
|
|
|
64 } |
|
|
|
65 } |
|
|
|
66 |
|
|
|
67 # Print all entries line by line. |
|
|
|
68 |
|
|
|
69 function display(entries, num) |
|
|
|
70 { |
|
|
|
71 for (l = 1; l <= num; l++) { |
|
|
|
72 for (i = 1; entries[l":"i] != ""; i++) |
|
|
|
73 printf("%s", entries[l":"i]); |
|
|
|
74 printf("%s\n", entries[l"name"]); |
|
|
|
75 } |
|
|
|
76 } |
|