Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
htop
Commits
20210238
Commit
20210238
authored
7 years ago
by
Hisham Muhammad
Browse files
Options
Download
Email Patches
Plain Diff
Read/write list of plugins in htoprc
parent
1807dde2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Settings.c
+26
-3
Settings.c
Settings.h
+3
-0
Settings.h
with
29 additions
and
3 deletions
+29
-3
Settings.c
View file @
20210238
...
...
@@ -34,6 +34,9 @@ typedef struct Settings_ {
MeterColumnSettings columns[2];
char** plugins;
int nPlugins;
ProcessField* fields;
int flags;
int colorScheme;
...
...
@@ -75,6 +78,7 @@ void Settings_delete(Settings* this) {
String_freeArray
(
this
->
columns
[
i
].
names
);
free
(
this
->
columns
[
i
].
modes
);
}
String_freeArray
(
this
->
plugins
);
free
(
this
);
}
...
...
@@ -86,6 +90,12 @@ static void Settings_readMeters(Settings* this, char* line, int column) {
this
->
columns
[
column
].
names
=
ids
;
}
static
void
Settings_readPlugins
(
Settings
*
this
,
char
*
line
)
{
char
*
trim
=
String_trim
(
line
);
this
->
plugins
=
String_split
(
trim
,
' '
,
&
(
this
->
nPlugins
));
free
(
trim
);
}
static
void
Settings_readMeterModes
(
Settings
*
this
,
char
*
line
,
int
column
)
{
char
*
trim
=
String_trim
(
line
);
int
nIds
;
...
...
@@ -242,6 +252,8 @@ static bool Settings_read(Settings* this, const char* fileName) {
}
else
if
(
String_eq
(
option
[
0
],
"right_meter_modes"
))
{
Settings_readMeterModes
(
this
,
option
[
1
],
1
);
readMeters
=
true
;
}
else
if
(
String_eq
(
option
[
0
],
"plugins"
))
{
Settings_readPlugins
(
this
,
option
[
1
]);
}
String_freeArray
(
option
);
}
...
...
@@ -263,15 +275,19 @@ static void writeFields(FILE* fd, ProcessField* fields, const char* name) {
fprintf
(
fd
,
"
\n
"
);
}
static
void
write
Meters
(
Settings
*
this
,
FILE
*
fd
,
int
colum
n
)
{
static
void
write
List
(
FILE
*
fd
,
char
**
list
,
int
le
n
)
{
const
char
*
sep
=
""
;
for
(
int
i
=
0
;
i
<
this
->
columns
[
column
].
len
;
i
++
)
{
fprintf
(
fd
,
"%s%s"
,
sep
,
this
->
columns
[
column
].
names
[
i
]);
for
(
int
i
=
0
;
i
<
len
;
i
++
)
{
fprintf
(
fd
,
"%s%s"
,
sep
,
list
[
i
]);
sep
=
" "
;
}
fprintf
(
fd
,
"
\n
"
);
}
static
void
writeMeters
(
Settings
*
this
,
FILE
*
fd
,
int
column
)
{
writeList
(
fd
,
this
->
columns
[
column
].
names
,
this
->
columns
[
column
].
len
);
}
static
void
writeMeterModes
(
Settings
*
this
,
FILE
*
fd
,
int
column
)
{
const
char
*
sep
=
""
;
for
(
int
i
=
0
;
i
<
this
->
columns
[
column
].
len
;
i
++
)
{
...
...
@@ -281,6 +297,10 @@ static void writeMeterModes(Settings* this, FILE* fd, int column) {
fprintf
(
fd
,
"
\n
"
);
}
static
void
writePlugins
(
Settings
*
this
,
FILE
*
fd
)
{
writeList
(
fd
,
this
->
plugins
,
this
->
nPlugins
);
}
bool
Settings_write
(
Settings
*
this
)
{
FILE
*
fd
;
...
...
@@ -318,6 +338,9 @@ bool Settings_write(Settings* this) {
fprintf
(
fd
,
"left_meter_modes="
);
writeMeterModes
(
this
,
fd
,
0
);
fprintf
(
fd
,
"right_meters="
);
writeMeters
(
this
,
fd
,
1
);
fprintf
(
fd
,
"right_meter_modes="
);
writeMeterModes
(
this
,
fd
,
1
);
if
(
this
->
nPlugins
>
0
)
{
fprintf
(
fd
,
"plugins="
);
writePlugins
(
this
,
fd
);
}
fclose
(
fd
);
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Settings.h
View file @
20210238
...
...
@@ -25,6 +25,9 @@ typedef struct Settings_ {
MeterColumnSettings
columns
[
2
];
char
**
plugins
;
int
nPlugins
;
ProcessField
*
fields
;
int
flags
;
int
colorScheme
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment