- README update
[wine] / misc / main.c
1 /*
2  * Main function.
3  *
4  * Copyright 1994 Alexandre Julliard
5  */
6
7 #include "config.h"
8
9 #include <locale.h>
10 #include <ctype.h>
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
14 #include <unistd.h>
15 #ifdef MALLOC_DEBUGGING
16 # include <malloc.h>
17 #endif
18
19 #include "windef.h"
20 #include "winbase.h"
21 #include "ntddk.h"
22 #include "winnls.h"
23 #include "winerror.h"
24
25 #include "winsock.h"
26 #include "heap.h"
27 #include "msdos.h"
28 #include "options.h"
29 #include "debugtools.h"
30 #include "module.h"
31 #include "tweak.h"
32
33 DECLARE_DEBUG_CHANNEL(file);
34
35
36 #if 0
37 /***********************************************************************
38  *          MAIN_ParseDebugOptions
39  *
40  *  Turns specific debug messages on or off, according to "options".
41  */
42 void MAIN_ParseDebugOptions( const char *arg )
43 {
44   /* defined in relay32/relay386.c */
45   extern char **debug_relay_includelist;
46   extern char **debug_relay_excludelist;
47   /* defined in relay32/snoop.c */
48   extern char **debug_snoop_includelist;
49   extern char **debug_snoop_excludelist;
50
51   int i;
52   int l, cls;
53
54   char *options = strdup(arg);
55
56   l = strlen(options);
57   if (l<2) goto error;
58
59   if (options[l-1]=='\n') options[l-1]='\0';
60   do
61   {
62     if ((*options!='+')&&(*options!='-')){
63       int j;
64
65       for(j=0; j<DEBUG_CLASS_COUNT; j++)
66         if(!strncasecmp(options, debug_cl_name[j], strlen(debug_cl_name[j])))
67           break;
68       if(j==DEBUG_CLASS_COUNT)
69         goto error;
70       options += strlen(debug_cl_name[j]);
71       if ((*options!='+')&&(*options!='-'))
72         goto error;
73       cls = j;
74     }
75     else
76       cls = -1; /* all classes */
77
78     if (strchr(options,','))
79       l=strchr(options,',')-options;
80     else
81       l=strlen(options);
82
83     if (!strncasecmp(options+1,"all",l-1))
84       {
85         int i, j;
86         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
87           for(j=0; j<DEBUG_CLASS_COUNT; j++)
88             if(cls == -1 || cls == j)
89                 __SET_DEBUGGING( j, debug_channels[i], (*options=='+') );
90       }
91     else if (!strncasecmp(options+1, "relay=", 6) ||
92              !strncasecmp(options+1, "snoop=", 6))
93       {
94         int i, j;
95         char *s, *s2, ***output, c;
96
97         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
98           if (!strncasecmp( debug_channels[i] + 1, options + 1, 5))
99           {
100             for(j=0; j<DEBUG_CLASS_COUNT; j++)
101               if(cls == -1 || cls == j)
102                   __SET_DEBUGGING( j, debug_channels[i], 1 );
103             break;
104           }
105         /* should never happen, maybe assert(i!=DEBUG_CHANNEL_COUNT)? */
106         if (i==DEBUG_CHANNEL_COUNT)
107           goto error;
108         output = (*options == '+') ?
109                         ((*(options+1) == 'r') ?
110                                 &debug_relay_includelist :
111                                 &debug_snoop_includelist) :
112                         ((*(options+1) == 'r') ?
113                                 &debug_relay_excludelist :
114                                 &debug_snoop_excludelist);
115         s = options + 7;
116         /* if there are n ':', there are n+1 modules, and we need n+2 slots
117          * last one being for the sentinel (NULL) */
118         i = 2;  
119         while((s = strchr(s, ':'))) i++, s++;
120         *output = malloc(sizeof(char **) * i);
121         i = 0;
122         s = options + 7;
123         while((s2 = strchr(s, ':'))) {
124           c = *s2;
125           *s2 = '\0';
126           *((*output)+i) = _strupr(strdup(s));
127           *s2 = c;
128           s = s2 + 1;
129           i++;
130         }
131         c = *(options + l);
132         *(options + l) = '\0';
133         *((*output)+i) = _strupr(strdup(s));
134         *(options + l) = c;
135         *((*output)+i+1) = NULL;
136       }
137     else
138       {
139         int i, j;
140         for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
141           if (!strncasecmp( debug_channels[i] + 1, options + 1, l - 1) && !debug_channels[i][l])
142           {
143             for(j=0; j<DEBUG_CLASS_COUNT; j++)
144               if(cls == -1 || cls == j)
145                   __SET_DEBUGGING( j, debug_channels[i], (*options=='+') );
146             break;
147           }
148         if (i==DEBUG_CHANNEL_COUNT)
149           goto error;
150       }
151     options+=l;
152   }
153   while((*options==',')&&(*(++options)));
154
155   if (!*options) return;
156
157  error:  
158   MESSAGE("%s: Syntax: --debugmsg [class]+xxx,...  or "
159       "--debugmsg [class]-xxx,...\n",argv0);
160   MESSAGE("Example: --debugmsg +all,warn-heap\n"
161       "  turn on all messages except warning heap messages\n");
162   MESSAGE("Special case: --debugmsg +relay=DLL:DLL.###:FuncName\n"
163       "  turn on --debugmsg +relay only as specified\n"
164       "Special case: --debugmsg -relay=DLL:DLL.###:FuncName\n"
165       "  turn on --debugmsg +relay except as specified\n"
166       "Also permitted, +snoop=..., -snoop=... as with relay.\n\n");
167   
168   MESSAGE("Available message classes:\n");
169   for(i=0;i<DEBUG_CLASS_COUNT;i++)
170     MESSAGE( "%-9s", debug_cl_name[i]);
171   MESSAGE("\n\n");
172   
173   MESSAGE("Available message types:\n");
174   MESSAGE("%-9s ","all");
175   for(i=0;i<DEBUG_CHANNEL_COUNT;i++)
176       MESSAGE("%-9s%c",debug_channels[i] + 1,
177           (((i+2)%8==0)?'\n':' '));
178   MESSAGE("\n\n");
179   ExitProcess(1);
180 }
181 #endif
182
183 /***********************************************************************
184  *           MAIN_WineInit
185  *
186  * Wine initialisation
187  */
188 void MAIN_WineInit(void)
189 {
190 #ifdef MALLOC_DEBUGGING
191     char *trace;
192
193     mcheck(NULL);
194     if (!(trace = getenv("MALLOC_TRACE")))
195     {       
196         MESSAGE( "MALLOC_TRACE not set. No trace generated\n" );
197     }
198     else
199     {
200         MESSAGE( "malloc trace goes to %s\n", trace );
201         mtrace();
202     }
203 #endif
204
205     setbuf(stdout,NULL);
206     setbuf(stderr,NULL);
207     setlocale(LC_CTYPE,"");
208 }
209
210 /***********************************************************************
211  *           Beep   (KERNEL32.11)
212  */
213 BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
214 {
215     static char beep = '\a';
216     /* dwFreq and dwDur are ignored by Win95 */
217     if (isatty(2)) write( 2, &beep, 1 );
218     return TRUE;
219 }
220
221
222 /***********************************************************************
223 *       FileCDR (KERNEL.130)
224 */
225 FARPROC16 WINAPI FileCDR16(FARPROC16 x)
226 {
227         FIXME_(file)("(0x%8x): stub\n", (int) x);
228         return (FARPROC16)TRUE;
229 }
230
231 /***********************************************************************
232  *           GetTickCount   (USER.13) (KERNEL32.299)
233  *
234  * Returns the number of milliseconds, modulo 2^32, since the start
235  * of the wineserver.
236  */
237 DWORD WINAPI GetTickCount(void)
238 {
239     struct timeval t;
240     gettimeofday( &t, NULL );
241     return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - server_startticks;
242 }