-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
74 lines (62 loc) · 1.92 KB
/
main.c
File metadata and controls
74 lines (62 loc) · 1.92 KB
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
#include <gio/gio.h>
#include <glib.h>
#include "tutorials/gio-example/notification-sender.h"
#include "tutorials/gobject-example/example-person.h"
#include "tutorials/gstreamer-example/screencast-webrtc.h"
#include "tutorials/gstreamer-example/screencast.h"
#include "tutorials/gstreamer-example/sound_exclusion.h"
#include "tutorials/timeout-example/timeout.h"
typedef void (*TutorialFunc)(gint, gchar**);
typedef struct {
const gchar* name; // command name
TutorialFunc func;
} Tutorial;
void screencast_webrtc_with_sound_exclusion(gint argc, gchar* argv[]) {
get_excluded_sound();
screencast_webrtc_tutorial(2, argv);
restore_system();
}
Tutorial tutorials[] = {
{"timeout", timeout_tutorial},
{"gobject-get-set", gobject_tutorial_get_set},
{"dbus-notification", send_notification},
{"screencast", screencast_tutorial},
{"screencast-webrtc", screencast_webrtc_tutorial},
{"screencast-webrtc-with-sound-exclusion",
screencast_webrtc_with_sound_exclusion},
{NULL, NULL} // end of the array
};
void print_help(const gchar* prog_name) {
g_print("Usage: %s <command>\n", prog_name);
g_print("Available commands:\n");
for (gint i = 0; tutorials[i].name != NULL; i++) {
g_print(" - %s\n", tutorials[i].name);
}
}
gint main(gint argc, gchar* argv[]) {
if (argc < 2) {
print_help(argv[0]);
return 1;
}
if (g_strcmp0(argv[1], "--list-commands") == 0) {
for (gint i = 0; tutorials[i].name != NULL; i++) {
g_print("%s\n", tutorials[i].name);
}
return 0;
}
gboolean found = FALSE;
for (gint i = 0; tutorials[i].name != NULL; i++) {
if (g_strcmp0(argv[1], tutorials[i].name) == 0) {
g_print("Running tutorial: %s\n", tutorials[i].name);
tutorials[i].func(argc - 1, argv + 1);
found = TRUE;
break;
}
}
if (!found) {
g_print("Error: Command '%s' not found.\n", argv[1]);
print_help(argv[0]);
return 1;
}
return 0;
}