Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MojitOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sepia-pub
MojitOS
Commits
9537082d
Commit
9537082d
authored
3 months ago
by
Georges Da Costa
Browse files
Options
Downloads
Patches
Plain Diff
starts the cleanup
parent
c987fd80
No related branches found
No related tags found
1 merge request
!12
Libmoj
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/libmojitos.c
+3
-28
3 additions, 28 deletions
src/libmojitos.c
src/libmojitos.h
+0
-1
0 additions, 1 deletion
src/libmojitos.h
src/mojitos.c
+31
-22
31 additions, 22 deletions
src/mojitos.c
with
34 additions
and
51 deletions
src/libmojitos.c
+
3
−
28
View file @
9537082d
#include
<stdint.h>
#include
<stddef.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<assert.h>
...
...
@@ -25,18 +23,9 @@ struct Sensor {
typedef
struct
Sensor
Sensor
;
int
nb_defined_sensors
=
0
;
int
nb_defined_options
=
0
;
typedef
struct
optparse_long
Optparse
;
void
printopt
(
Optparse
*
opt
)
{
printf
(
"-%c"
,
opt
->
shortname
);
printf
(
"|--%s"
,
opt
->
longname
);
if
(
opt
->
usage_arg
!=
NULL
)
{
printf
(
" %s"
,
opt
->
usage_arg
);
}
printf
(
"
\n\t
%s
\n
"
,
opt
->
usage_msg
);
}
#include
"sensors.h"
...
...
@@ -83,7 +72,8 @@ void add_source(Sensor *cpt, char *arg)
int
moj_init
(
char
**
argv
)
{
init_sensors
(
_moj_opts
,
sensors
,
NB_SENSOR_OPT
,
0
,
&
nb_defined_sensors
);
nb_defined_options
=
NB_SENSOR_OPT
;
int
opt
;
struct
optparse
options
;
optparse_init
(
&
options
,
argv
);
...
...
@@ -139,18 +129,3 @@ uint64_t* moj_get_values() {
return
values
;
}
void
moj_usage
()
{
if
(
nb_defined_sensors
==
0
)
{
// no sensor to show
return
;
}
printf
(
"
\n
SENSORS:
\n
"
);
for
(
int
i
=
0
;
i
<
NB_SENSOR_OPT
;
i
++
)
{
printopt
(
&
_moj_opts
[
i
]);
}
}
This diff is collapsed.
Click to expand it.
src/libmojitos.h
+
0
−
1
View file @
9537082d
int
moj_init
(
char
**
argv
);
void
moj_usage
();
uint64_t
*
moj_get_values
();
void
moj_clean
();
char
**
moj_labels
();
This diff is collapsed.
Click to expand it.
src/mojitos.c
+
31
−
22
View file @
9537082d
...
...
@@ -18,7 +18,6 @@
*******************************************************/
#include
<assert.h>
#include
<inttypes.h>
#include
<signal.h>
#include
<stdio.h>
...
...
@@ -69,50 +68,58 @@ Optparse opts[NB_OPT + 1] = {
},
};
void
dumpopt
(
Optparse
*
opt
)
void
_
dumpopt
s
(
Optparse
*
opt
,
size_t
nb
)
{
printf
(
".It Fl %c | Fl
\\
-%s"
,
opt
->
shortname
,
opt
->
longname
);
if
(
opt
->
usage_arg
!=
NULL
)
{
printf
(
" Ar %s"
,
opt
->
usage_arg
);
for
(
size_t
i
=
0
;
i
<
nb
;
i
++
)
{
printf
(
".It Fl %c | Fl
\\
-%s"
,
opt
[
i
].
shortname
,
opt
[
i
].
longname
);
if
(
opt
[
i
].
usage_arg
!=
NULL
)
{
printf
(
" Ar %s"
,
opt
[
i
].
usage_arg
);
}
printf
(
"
\n
"
);
printf
(
"%s
\n
"
,
opt
->
usage_msg
);
printf
(
"%s
\n
"
,
opt
[
i
].
usage_msg
);
}
}
extern
Optparse
_moj_opts
[];
extern
int
nb_defined_
sensor
s
;
extern
int
nb_defined_
option
s
;
void
dumpopts
(
Optparse
*
opts
,
size_t
nb_opt
,
size_t
nb_sensor_opt
)
{
size_t
i
;
/* options */
printf
(
".Pp
\n
OPTIONS:
\n
.Bl -tag -width Ds
\n
"
);
for
(
i
=
0
;
i
<
nb_opt
;
i
++
)
{
dumpopt
(
&
opts
[
i
]);
}
_dumpopts
(
opts
,
nb_opt
);
printf
(
".El
\n
"
);
/* sensors */
printf
(
".Pp
\n
SENSORS:
\n
.Bl -tag -width Ds
\n
"
);
for
(
i
=
0
;
i
<
nb_sensor_opt
;
i
++
)
{
dumpopt
(
&
_moj_opts
[
i
]);
}
_dumpopts
(
_moj_opts
,
nb_sensor_opt
);
printf
(
".El
\n
"
);
}
void
printopt
(
Optparse
*
opt
);
void
printopts
(
Optparse
*
opt
,
size_t
nb
)
{
for
(
size_t
i
=
0
;
i
<
nb
;
i
++
)
{
printf
(
"-%c"
,
opt
[
i
].
shortname
);
printf
(
"|--%s"
,
opt
[
i
].
longname
);
if
(
opt
[
i
].
usage_arg
!=
NULL
)
{
printf
(
" %s"
,
opt
[
i
].
usage_arg
);
}
printf
(
"
\n\t
%s
\n
"
,
opt
[
i
].
usage_msg
);
}
}
void
usage
(
char
*
name
)
{
printf
(
"Usage : %s [OPTIONS] [SENSOR ...] [-e <cmd> ...]
\n
"
,
name
);
printf
(
"
\n
OPTIONS:
\n
"
);
for
(
int
i
=
0
;
i
<
NB_OPT
;
i
++
)
{
printopt
(
&
opts
[
i
]);
}
printopts
(
opts
,
NB_OPT
);
if
(
nb_defined_options
==
0
)
// no sensor to show
return
;
moj_usage
();
printf
(
"
\n
SENSORS:
\n
"
);
printopts
(
_moj_opts
,
nb_defined_options
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -192,15 +199,17 @@ int main(int argc, char **argv)
break
;
}
}
printf
(
"%s
\n
"
,
options
.
argv
[
options
.
optind
]);
int
nb_sensors
=
moj_init
(
save
);
free
(
save
);
if
(
argc
==
1
)
{
usage
(
argv
[
0
]);
}
if
(
argc
==
2
&&
strcmp
(
argv
[
1
],
"--dump-opts"
)
==
0
)
{
dumpopts
(
opts
,
NB_OPT
,
nb_defined_
sensor
s
);
dumpopts
(
opts
,
NB_OPT
,
nb_defined_
option
s
);
exit
(
EXIT_SUCCESS
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment