1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//! Partial port of `linux/HugePageMeter.c` — htop's Linux huge-page usage
//! meter.
//!
//! C names are preserved verbatim (htop uses `CamelCase_snake`), so
//! `non_snake_case` is allowed for the whole module — matching the spec
//! name-for-name is the point of the port. The C `static void
//! HugePageMeter_display(const Object* cast, RichString* out)` casts `cast`
//! back to `const Meter*` and reads `this->total` / `this->values[...]`, so
//! it ports to a free fn `pub fn HugePageMeter_display(this: &Meter, out:
//! &mut RichString)` — the `cast` → `this` down-cast collapses into the typed
//! `&Meter` parameter (the same mapping `filedescriptormeter.rs` uses). The
//! shared `Meter` model is [`crate::ported::meter::Meter`].
//!
//! `CRT_colors[X]` (C's active-scheme row `const int* CRT_colors`, set by
//! `CRT_setColors` to point at `CRT_colorSchemes[colorScheme]`) is reproduced
//! as `ColorElements::X.packed(ColorScheme::active())`; the per-item color
//! `CRT_colors[HUGEPAGE_1 + i]` is the raw scheme-row index
//! `CRT_colorSchemes[scheme][HUGEPAGE_1 as usize + i]` (the enum is
//! `#[repr(usize)]` with the C discriminants, so `HUGEPAGE_1 + i` addresses
//! `HUGEPAGE_1..=HUGEPAGE_4`, matching the class `HugePageMeter_attributes`).
//! `Meter_humanUnit(buffer, v, sizeof(buffer))` becomes the owned-`String`
//! [`Meter_humanUnit`] port.
//!
//! The file-scope `HugePageMeter_active_labels[4]` is a mutable C static
//! written by `HugePageMeter_updateValues` and read by
//! `HugePageMeter_display`, so it ports to a `Mutex<[Option<&'static str>;
//! 4]>` (the idiom for a global mutable C static that is neither a plain
//! counter nor a flag). `HugePageMeter_labels` is the immutable label table
//! `updateValues` selects from (retained for the eventual `updateValues`
//! port).
//!
//! Ported (self-contained: `RichString`, `CRT_colors`, and `Meter_humanUnit`
//! are ported):
//! - [`HugePageMeter_display`] (`HugePageMeter.c:76`) — writes `:<total>`
//! then, for each active label, `<label><value>`, coloring the total
//! `METER_VALUE`, each label `METER_TEXT`, and each value `HUGEPAGE_1 + i`.
//!
//! Stubbed (blocked on unported substrate — keeps its `todo!()`):
//! - `HugePageMeter_updateValues` (`HugePageMeter.c:39`) — reads the host via
//! `const LinuxMachine* host = (const LinuxMachine*) this->host;` and pulls
//! `host->totalHugePageMem` / `host->usedHugePageMem[i]`. The ported `Meter`
//! struct does not model the `host` field (documented as unmodeled
//! substrate in [`crate::ported::meter::Meter`]), so there is no faithful
//! `LinuxMachine` source to drive the totals — porting the arithmetic
//! without it would fabricate a data source, not translate the C.
use Mutex;
use crate;
use crate;
use crate;
/// Port of `static const char* HugePageMeter_active_labels[4]` from
/// `HugePageMeter.c:24`. A mutable file-scope C static (populated by
/// `HugePageMeter_updateValues`, read by [`HugePageMeter_display`]); modeled
/// as a `Mutex` guarding the four-slot table of `Option<&'static str>` labels
/// (`NULL` ⇒ `None`).
// keep the exact C static name (port convention)
static HugePageMeter_active_labels: =
new;
/// Port of `static const char* const HugePageMeter_labels[]` from
/// `HugePageMeter.c:33` — the `HTOP_HUGEPAGE_COUNT` label strings
/// `HugePageMeter_updateValues` selects the active ones from.
// keep the exact C static name (port convention)
static HugePageMeter_labels: = ;
/// TODO: port of `static void HugePageMeter_updateValues(Meter* this)` from
/// `HugePageMeter.c:39`. Blocked: the totals are sourced from the host via
/// `const LinuxMachine* host = (const LinuxMachine*) this->host;` and read
/// `host->totalHugePageMem` / `host->usedHugePageMem[i]`. The ported `Meter`
/// struct does not model the `host` field (unmodeled C substrate per
/// [`crate::ported::meter::Meter`]), so there is no faithful `LinuxMachine`
/// source to feed `this->total` / `this->values[]`.
/// Port of `static void HugePageMeter_display(const Object* cast, RichString*
/// out)` from `HugePageMeter.c:76`. Writes `:` then the human-readable
/// `this->total` (colored `METER_VALUE`), then walks the active-labels table:
/// for each non-`NULL` label it appends the label (`METER_TEXT`) followed by
/// the human-readable `this->values[i]` colored `CRT_colors[HUGEPAGE_1 + i]`,
/// stopping at the first empty slot. `CRT_colors[X]` is
/// `ColorElements::X.packed(scheme)`; the active scheme is read once (a
/// process-global that does not change mid-call), matching the C global
/// `CRT_colors`.