]> code.delx.au - pulseaudio/blob - polyp/dumpmodules.c
a9c028258ca6187d64052f2927fd67bf058ec11e
[pulseaudio] / polyp / dumpmodules.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <string.h>
27 #include <getopt.h>
28 #include <assert.h>
29 #include <stdio.h>
30 #include <ltdl.h>
31
32 #include "dumpmodules.h"
33 #include "modinfo.h"
34
35 #define PREFIX "module-"
36
37 static void short_info(const char *name, const char *path, struct pa_modinfo *i) {
38 assert(name && i);
39 printf("%-40s%s\n", name, i->description ? i->description : "n/a");
40 }
41
42 static void long_info(const char *name, const char *path, struct pa_modinfo *i) {
43 static int nl = 0;
44 assert(name && i);
45
46 if (nl)
47 printf("\n");
48
49 nl = 1;
50
51 printf("Name: %s\n", name);
52
53 if (!i->description && !i->version && !i->author && !i->usage)
54 printf("No module information available\n");
55 else {
56 if (i->version)
57 printf("Version: %s\n", i->version);
58 if (i->description)
59 printf("Description: %s\n", i->description);
60 if (i->author)
61 printf("Author: %s\n", i->author);
62 if (i->usage)
63 printf("Usage: %s\n", i->usage);
64 }
65
66 if (path)
67 printf("Path: %s\n", path);
68 }
69
70 static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, struct pa_modinfo*i)) {
71 struct pa_modinfo *i;
72
73 if ((i = pa_modinfo_get_by_name(path ? path : name))) {
74 info(name, path, i);
75 pa_modinfo_free(i);
76 }
77 }
78
79 static int callback(const char *path, lt_ptr data) {
80 const char *e;
81 struct pa_daemon_conf *c = (data);
82
83 if ((e = (const char*) strrchr(path, '/')))
84 e++;
85 else
86 e = path;
87
88 if (strlen(e) > sizeof(PREFIX)-1 && !strncmp(e, PREFIX, sizeof(PREFIX)-1))
89 show_info(e, path, c->verbose ? long_info : short_info);
90
91 return 0;
92 }
93
94 void pa_dump_modules(struct pa_daemon_conf *c, int argc, char * const argv[]) {
95 if (argc > 0) {
96 int i;
97 for (i = 0; i < argc; i++)
98 show_info(argv[i], NULL, long_info);
99 } else
100 lt_dlforeachfile(NULL, callback, c);
101 }