Created dummy implementation of InternetSetOption function.
[wine] / library / debug.c
1 /*
2  * Management of the debugging channels
3  *
4  * Copyright 2000 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <ctype.h>
25
26 struct dll
27 {
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 */
32 };
33
34 static struct dll *first_dll;
35
36 struct debug_option
37 {
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" */
42 };
43
44 static struct debug_option *first_option;
45 static struct debug_option *last_option;
46
47
48 static int cmp_name( const void *p1, const void *p2 )
49 {
50     const char *name = p1;
51     const char * const *chan = p2;
52     return strcmp( name, *chan + 1 );
53 }
54
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 )
57 {
58     if (opt->name[0])
59     {
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;
63     }
64     else /* all */
65     {
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;
69     }
70 }
71
72 /* register a new set of channels for a dll */
73 void *__wine_dbg_register( char * const *channels, int nb )
74 {
75     struct debug_option *opt = first_option;
76     struct dll *dll = malloc( sizeof(*dll) );
77     if (dll)
78     {
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;
84
85         /* apply existing options to this dll */
86         while (opt)
87         {
88             apply_option( dll, opt );
89             opt = opt->next;
90         }
91     }
92     return dll;
93 }
94
95
96 /* unregister a set of channels; must pass the pointer obtained from wine_dbg_register */
97 void __wine_dbg_unregister( void *channel )
98 {
99     struct dll *dll = channel;
100     if (dll)
101     {
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 );
106     }
107 }
108
109
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 )
112 {
113     struct dll *dll = first_dll;
114     struct debug_option *opt;
115
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;
125
126     /* apply option to all existing dlls */
127     while (dll)
128     {
129         apply_option( dll, opt );
130         dll = dll->next;
131     }
132 }