Fixed typos in comments.
[wine/multimedia.git] / misc / main.c
blob357db38041701788efe2a6346d8523937ed2c8ac
1 /*
2 * Main function.
4 * Copyright 1994 Alexandre Julliard
5 */
7 #include "config.h"
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
19 #include "windef.h"
20 #include "winbase.h"
21 #include "ntddk.h"
22 #include "winnls.h"
23 #include "winerror.h"
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"
33 DECLARE_DEBUG_CHANNEL(file);
36 #if 0
37 /***********************************************************************
38 * MAIN_ParseDebugOptions
40 * Turns specific debug messages on or off, according to "options".
42 void MAIN_ParseDebugOptions( const char *arg )
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;
51 int i;
52 int l, cls;
54 char *options = strdup(arg);
56 l = strlen(options);
57 if (l<2) goto error;
59 if (options[l-1]=='\n') options[l-1]='\0';
62 if ((*options!='+')&&(*options!='-')){
63 int j;
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;
75 else
76 cls = -1; /* all classes */
78 if (strchr(options,','))
79 l=strchr(options,',')-options;
80 else
81 l=strlen(options);
83 if (!strncasecmp(options+1,"all",l-1))
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=='+') );
91 else if (!strncasecmp(options+1, "relay=", 6) ||
92 !strncasecmp(options+1, "snoop=", 6))
94 int i, j;
95 char *s, *s2, ***output, c;
97 for (i=0; i<DEBUG_CHANNEL_COUNT; i++)
98 if (!strncasecmp( debug_channels[i] + 1, options + 1, 5))
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;
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++;
131 c = *(options + l);
132 *(options + l) = '\0';
133 *((*output)+i) = _strupr(strdup(s));
134 *(options + l) = c;
135 *((*output)+i+1) = NULL;
137 else
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])
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;
148 if (i==DEBUG_CHANNEL_COUNT)
149 goto error;
151 options+=l;
153 while((*options==',')&&(*(++options)));
155 if (!*options) return;
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");
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");
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);
181 #endif
183 /***********************************************************************
184 * MAIN_WineInit
186 * Wine initialisation
188 void MAIN_WineInit(void)
190 #ifdef MALLOC_DEBUGGING
191 char *trace;
193 mcheck(NULL);
194 if (!(trace = getenv("MALLOC_TRACE")))
196 MESSAGE( "MALLOC_TRACE not set. No trace generated\n" );
198 else
200 MESSAGE( "malloc trace goes to %s\n", trace );
201 mtrace();
203 #endif
205 setbuf(stdout,NULL);
206 setbuf(stderr,NULL);
207 setlocale(LC_CTYPE,"");
210 /***********************************************************************
211 * Beep (KERNEL32.11)
213 BOOL WINAPI Beep( DWORD dwFreq, DWORD dwDur )
215 static char beep = '\a';
216 /* dwFreq and dwDur are ignored by Win95 */
217 if (isatty(2)) write( 2, &beep, 1 );
218 return TRUE;
222 /***********************************************************************
223 * FileCDR (KERNEL.130)
225 FARPROC16 WINAPI FileCDR16(FARPROC16 x)
227 FIXME_(file)("(0x%8x): stub\n", (int) x);
228 return (FARPROC16)TRUE;
231 /***********************************************************************
232 * GetTickCount (USER.13) (KERNEL32.299)
234 * Returns the number of milliseconds, modulo 2^32, since the start
235 * of the wineserver.
237 DWORD WINAPI GetTickCount(void)
239 struct timeval t;
240 gettimeofday( &t, NULL );
241 return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - server_startticks;