Implement NetBIOS resolution for UNC pathnames.
[wine/multimedia.git] / library / debug.c
blob0d9f7da0ae4e317183c3bc2accee7f05bf0bce64
1 /*
2 * Management of the debugging channels
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <ctype.h>
26 struct dll
28 struct dll *next; /* linked list of dlls */
29 struct dll *prev;
30 char * const *channels; /* array of channels */
31 int nb_channels; /* number of channels in array */
34 static struct dll *first_dll;
36 struct debug_option
38 struct debug_option *next; /* next option in list */
39 unsigned char set; /* bits to set */
40 unsigned char clear; /* bits to clear */
41 char name[14]; /* channel name, or empty for "all" */
44 static struct debug_option *first_option;
45 static struct debug_option *last_option;
48 static int cmp_name( const void *p1, const void *p2 )
50 const char *name = p1;
51 const char * const *chan = p2;
52 return strcmp( name, *chan + 1 );
55 /* apply a debug option to the channels of a given dll */
56 static void apply_option( struct dll *dll, const struct debug_option *opt )
58 if (opt->name[0])
60 char **dbch = bsearch( opt->name, dll->channels, dll->nb_channels,
61 sizeof(*dll->channels), cmp_name );
62 if (dbch) **dbch = (**dbch & ~opt->clear) | opt->set;
64 else /* all */
66 int i;
67 for (i = 0; i < dll->nb_channels; i++)
68 dll->channels[i][0] = (dll->channels[i][0] & ~opt->clear) | opt->set;
72 /* register a new set of channels for a dll */
73 void *__wine_dbg_register( char * const *channels, int nb )
75 struct debug_option *opt = first_option;
76 struct dll *dll = malloc( sizeof(*dll) );
77 if (dll)
79 dll->channels = channels;
80 dll->nb_channels = nb;
81 dll->prev = NULL;
82 if ((dll->next = first_dll)) dll->next->prev = dll;
83 first_dll = dll;
85 /* apply existing options to this dll */
86 while (opt)
88 apply_option( dll, opt );
89 opt = opt->next;
92 return dll;
96 /* unregister a set of channels; must pass the pointer obtained from wine_dbg_register */
97 void __wine_dbg_unregister( void *channel )
99 struct dll *dll = channel;
100 if (dll)
102 if (dll->next) dll->next->prev = dll->prev;
103 if (dll->prev) dll->prev->next = dll->next;
104 else first_dll = dll->next;
105 free( dll );
110 /* add a new debug option at the end of the option list */
111 void wine_dbg_add_option( const char *name, unsigned char set, unsigned char clear )
113 struct dll *dll = first_dll;
114 struct debug_option *opt;
116 if (!(opt = malloc( sizeof(*opt) ))) return;
117 opt->next = NULL;
118 opt->set = set;
119 opt->clear = clear;
120 strncpy( opt->name, name, sizeof(opt->name) );
121 opt->name[sizeof(opt->name)-1] = 0;
122 if (last_option) last_option->next = opt;
123 else first_option = opt;
124 last_option = opt;
126 /* apply option to all existing dlls */
127 while (dll)
129 apply_option( dll, opt );
130 dll = dll->next;