]> code.delx.au - pulseaudio/blob - polyp/pamodinfo.c
6eb147f08df4ad6f811f344a6e1d903924d1ddcf
[pulseaudio] / polyp / pamodinfo.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 "modinfo.h"
33
34 #define PREFIX "module-"
35
36 static int verbose = 0;
37
38 static void short_info(const char *name, const char *path, struct pa_modinfo *i) {
39 assert(name && i);
40 printf("%-40s%s\n", name, i->description ? i->description : "n/a");
41 }
42
43 static void long_info(const char *name, const char *path, struct pa_modinfo *i) {
44 assert(name && i);
45 static int nl = 0;
46
47 if (nl)
48 printf("\n");
49
50 nl = 1;
51
52 printf("Name: %s\n", name);
53
54 if (!i->description && !i->version && !i->author && !i->usage)
55 printf("No module information available\n");
56 else {
57 if (i->version)
58 printf("Version: %s\n", i->version);
59 if (i->description)
60 printf("Description: %s\n", i->description);
61 if (i->author)
62 printf("Author: %s\n", i->author);
63 if (i->usage)
64 printf("Usage: %s\n", i->usage);
65 }
66
67 if (path)
68 printf("Path: %s\n", path);
69 }
70
71 static void show_info(const char *name, const char *path, void (*info)(const char *name, const char *path, struct pa_modinfo*i)) {
72 struct pa_modinfo *i;
73
74 if ((i = pa_modinfo_get_by_name(path ? path : name))) {
75 info(name, path, i);
76 pa_modinfo_free(i);
77 }
78 }
79
80 static int callback(const char *path, lt_ptr data) {
81 const char *e;
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, verbose ? long_info : short_info);
90
91 return 0;
92 }
93
94 int main(int argc, char *argv[]) {
95 int r = lt_dlinit();
96 char *path = NULL;
97 int c;
98 assert(r == 0);
99
100 while ((c = getopt(argc, argv, "p:v")) != -1) {
101 switch (c) {
102 case 'p':
103 path = optarg;
104 break;
105 case 'v':
106 verbose = 1;
107 break;
108 default:
109 return 1;
110 }
111 }
112
113 if (path)
114 lt_dlsetsearchpath(path);
115 #ifdef DLSEARCHPATH
116 else
117 lt_dlsetsearchpath(DLSEARCHPATH);
118 #endif
119
120 if (argc > optind)
121 show_info(argv[optind], NULL, long_info);
122 else
123 lt_dlforeachfile(NULL, callback, NULL);
124
125 lt_dlexit();
126 }