Get rid of the ThunkData stubs, these are not functions.
[wine/multimedia.git] / tools / winebuild / parser.c
blob4452b6cb100e384b8e58cbde50c328b0e9a7ca7e
1 /*
2 * Spec file parser
4 * Copyright 1993 Robert J. Amstadt
5 * Copyright 1995 Martin von Loewis
6 * Copyright 1995, 1996, 1997, 2004 Alexandre Julliard
7 * Copyright 1997 Eric Youngdale
8 * Copyright 1999 Ulrich Weigand
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "config.h"
26 #include "wine/port.h"
28 #include <assert.h>
29 #include <ctype.h>
30 #include <stdarg.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
35 #include "windef.h"
36 #include "winbase.h"
37 #include "build.h"
39 int current_line = 0;
41 static char ParseBuffer[512];
42 static char TokenBuffer[512];
43 static char *ParseNext = ParseBuffer;
44 static FILE *input_file;
46 static const char *separator_chars;
47 static const char *comment_chars;
49 static const char * const TypeNames[TYPE_NBTYPES] =
51 "variable", /* TYPE_VARIABLE */
52 "pascal", /* TYPE_PASCAL */
53 "equate", /* TYPE_ABS */
54 "stub", /* TYPE_STUB */
55 "stdcall", /* TYPE_STDCALL */
56 "cdecl", /* TYPE_CDECL */
57 "varargs", /* TYPE_VARARGS */
58 "extern" /* TYPE_EXTERN */
61 static const char * const FlagNames[] =
63 "norelay", /* FLAG_NORELAY */
64 "noname", /* FLAG_NONAME */
65 "ret16", /* FLAG_RET16 */
66 "ret64", /* FLAG_RET64 */
67 "i386", /* FLAG_I386 */
68 "register", /* FLAG_REGISTER */
69 "private", /* FLAG_PRIVATE */
70 NULL
73 static int IsNumberString(const char *s)
75 while (*s) if (!isdigit(*s++)) return 0;
76 return 1;
79 inline static int is_token_separator( char ch )
81 return strchr( separator_chars, ch ) != NULL;
84 inline static int is_token_comment( char ch )
86 return strchr( comment_chars, ch ) != NULL;
89 /* get the next line from the input file, or return 0 if at eof */
90 static int get_next_line(void)
92 ParseNext = ParseBuffer;
93 current_line++;
94 return (fgets(ParseBuffer, sizeof(ParseBuffer), input_file) != NULL);
97 static const char * GetToken( int allow_eol )
99 char *p = ParseNext;
100 char *token = TokenBuffer;
102 for (;;)
104 /* remove initial white space */
105 p = ParseNext;
106 while (isspace(*p)) p++;
108 if (*p == '\\' && p[1] == '\n') /* line continuation */
110 if (!get_next_line())
112 if (!allow_eol) error( "Unexpected end of file\n" );
113 return NULL;
116 else break;
119 if ((*p == '\0') || is_token_comment(*p))
121 if (!allow_eol) error( "Declaration not terminated properly\n" );
122 return NULL;
126 * Find end of token.
128 if (is_token_separator(*p))
130 /* a separator is always a complete token */
131 *token++ = *p++;
133 else while (*p != '\0' && !is_token_separator(*p) && !isspace(*p))
135 if (*p == '\\') p++;
136 if (*p) *token++ = *p++;
138 *token = '\0';
139 ParseNext = p;
140 return TokenBuffer;
144 static ORDDEF *add_entry_point( DLLSPEC *spec )
146 if (spec->nb_entry_points == spec->alloc_entry_points)
148 spec->alloc_entry_points += 128;
149 spec->entry_points = xrealloc( spec->entry_points,
150 spec->alloc_entry_points * sizeof(*spec->entry_points) );
152 return &spec->entry_points[spec->nb_entry_points++];
155 /*******************************************************************
156 * parse_spec_variable
158 * Parse a variable definition in a .spec file.
160 static int parse_spec_variable( ORDDEF *odp, DLLSPEC *spec )
162 char *endptr;
163 int *value_array;
164 int n_values;
165 int value_array_size;
166 const char *token;
168 if (spec->type == SPEC_WIN32)
170 error( "'variable' not supported in Win32, use 'extern' instead\n" );
171 return 0;
174 if (!(token = GetToken(0))) return 0;
175 if (*token != '(')
177 error( "Expected '(' got '%s'\n", token );
178 return 0;
181 n_values = 0;
182 value_array_size = 25;
183 value_array = xmalloc(sizeof(*value_array) * value_array_size);
185 for (;;)
187 if (!(token = GetToken(0)))
189 free( value_array );
190 return 0;
192 if (*token == ')')
193 break;
195 value_array[n_values++] = strtol(token, &endptr, 0);
196 if (n_values == value_array_size)
198 value_array_size += 25;
199 value_array = xrealloc(value_array,
200 sizeof(*value_array) * value_array_size);
203 if (endptr == NULL || *endptr != '\0')
205 error( "Expected number value, got '%s'\n", token );
206 free( value_array );
207 return 0;
211 odp->u.var.n_values = n_values;
212 odp->u.var.values = xrealloc(value_array, sizeof(*value_array) * n_values);
213 return 1;
217 /*******************************************************************
218 * parse_spec_export
220 * Parse an exported function definition in a .spec file.
222 static int parse_spec_export( ORDDEF *odp, DLLSPEC *spec )
224 const char *token;
225 unsigned int i;
227 switch(spec->type)
229 case SPEC_WIN16:
230 if (odp->type == TYPE_STDCALL)
232 error( "'stdcall' not supported for Win16\n" );
233 return 0;
235 break;
236 case SPEC_WIN32:
237 if (odp->type == TYPE_PASCAL)
239 error( "'pascal' not supported for Win32\n" );
240 return 0;
242 break;
243 default:
244 break;
247 if (!(token = GetToken(0))) return 0;
248 if (*token != '(')
250 error( "Expected '(' got '%s'\n", token );
251 return 0;
254 for (i = 0; i < sizeof(odp->u.func.arg_types); i++)
256 if (!(token = GetToken(0))) return 0;
257 if (*token == ')')
258 break;
260 if (!strcmp(token, "word"))
261 odp->u.func.arg_types[i] = 'w';
262 else if (!strcmp(token, "s_word"))
263 odp->u.func.arg_types[i] = 's';
264 else if (!strcmp(token, "long") || !strcmp(token, "segptr"))
265 odp->u.func.arg_types[i] = 'l';
266 else if (!strcmp(token, "ptr"))
267 odp->u.func.arg_types[i] = 'p';
268 else if (!strcmp(token, "str"))
269 odp->u.func.arg_types[i] = 't';
270 else if (!strcmp(token, "wstr"))
271 odp->u.func.arg_types[i] = 'W';
272 else if (!strcmp(token, "segstr"))
273 odp->u.func.arg_types[i] = 'T';
274 else if (!strcmp(token, "double"))
276 odp->u.func.arg_types[i++] = 'l';
277 if (i < sizeof(odp->u.func.arg_types)) odp->u.func.arg_types[i] = 'l';
279 else
281 error( "Unknown argument type '%s'\n", token );
282 return 0;
285 if (spec->type == SPEC_WIN32)
287 if (strcmp(token, "long") &&
288 strcmp(token, "ptr") &&
289 strcmp(token, "str") &&
290 strcmp(token, "wstr") &&
291 strcmp(token, "double"))
293 error( "Type '%s' not supported for Win32\n", token );
294 return 0;
298 if ((*token != ')') || (i >= sizeof(odp->u.func.arg_types)))
300 error( "Too many arguments\n" );
301 return 0;
304 odp->u.func.arg_types[i] = '\0';
305 if (odp->type == TYPE_VARARGS)
306 odp->flags |= FLAG_NORELAY; /* no relay debug possible for varags entry point */
308 if (!(token = GetToken(1)))
310 if (!strcmp( odp->name, "@" ))
312 error( "Missing handler name for anonymous function\n" );
313 return 0;
315 odp->link_name = xstrdup( odp->name );
317 else
319 odp->link_name = xstrdup( token );
320 if (strchr( odp->link_name, '.' ))
322 if (spec->type == SPEC_WIN16)
324 error( "Forwarded functions not supported for Win16\n" );
325 return 0;
327 odp->flags |= FLAG_FORWARD;
330 return 1;
334 /*******************************************************************
335 * parse_spec_equate
337 * Parse an 'equate' definition in a .spec file.
339 static int parse_spec_equate( ORDDEF *odp, DLLSPEC *spec )
341 char *endptr;
342 int value;
343 const char *token;
345 if (spec->type == SPEC_WIN32)
347 error( "'equate' not supported for Win32\n" );
348 return 0;
350 if (!(token = GetToken(0))) return 0;
351 value = strtol(token, &endptr, 0);
352 if (endptr == NULL || *endptr != '\0')
354 error( "Expected number value, got '%s'\n", token );
355 return 0;
357 odp->u.abs.value = value;
358 return 1;
362 /*******************************************************************
363 * parse_spec_stub
365 * Parse a 'stub' definition in a .spec file
367 static int parse_spec_stub( ORDDEF *odp, DLLSPEC *spec )
369 odp->u.func.arg_types[0] = '\0';
370 odp->link_name = xstrdup("");
371 return 1;
375 /*******************************************************************
376 * parse_spec_extern
378 * Parse an 'extern' definition in a .spec file.
380 static int parse_spec_extern( ORDDEF *odp, DLLSPEC *spec )
382 const char *token;
384 if (spec->type == SPEC_WIN16)
386 error( "'extern' not supported for Win16, use 'variable' instead\n" );
387 return 0;
389 if (!(token = GetToken(1)))
391 if (!strcmp( odp->name, "@" ))
393 error( "Missing handler name for anonymous extern\n" );
394 return 0;
396 odp->link_name = xstrdup( odp->name );
398 else
400 odp->link_name = xstrdup( token );
401 if (strchr( odp->link_name, '.' )) odp->flags |= FLAG_FORWARD;
403 return 1;
407 /*******************************************************************
408 * parse_spec_flags
410 * Parse the optional flags for an entry point in a .spec file.
412 static const char *parse_spec_flags( ORDDEF *odp )
414 unsigned int i;
415 const char *token;
419 if (!(token = GetToken(0))) break;
420 for (i = 0; FlagNames[i]; i++)
421 if (!strcmp( FlagNames[i], token )) break;
422 if (!FlagNames[i])
424 error( "Unknown flag '%s'\n", token );
425 return NULL;
427 odp->flags |= 1 << i;
428 token = GetToken(0);
429 } while (token && *token == '-');
431 return token;
435 /*******************************************************************
436 * parse_spec_ordinal
438 * Parse an ordinal definition in a .spec file.
440 static int parse_spec_ordinal( int ordinal, DLLSPEC *spec )
442 const char *token;
444 ORDDEF *odp = add_entry_point( spec );
445 memset( odp, 0, sizeof(*odp) );
447 if (!(token = GetToken(0))) goto error;
449 for (odp->type = 0; odp->type < TYPE_NBTYPES; odp->type++)
450 if (TypeNames[odp->type] && !strcmp( token, TypeNames[odp->type] ))
451 break;
453 if (odp->type >= TYPE_NBTYPES)
455 error( "Expected type after ordinal, found '%s' instead\n", token );
456 goto error;
459 if (!(token = GetToken(0))) goto error;
460 if (*token == '-' && !(token = parse_spec_flags( odp ))) goto error;
462 odp->name = xstrdup( token );
463 odp->lineno = current_line;
464 odp->ordinal = ordinal;
466 switch(odp->type)
468 case TYPE_VARIABLE:
469 if (!parse_spec_variable( odp, spec )) goto error;
470 break;
471 case TYPE_PASCAL:
472 case TYPE_STDCALL:
473 case TYPE_VARARGS:
474 case TYPE_CDECL:
475 if (!parse_spec_export( odp, spec )) goto error;
476 break;
477 case TYPE_ABS:
478 if (!parse_spec_equate( odp, spec )) goto error;
479 break;
480 case TYPE_STUB:
481 if (!parse_spec_stub( odp, spec )) goto error;
482 break;
483 case TYPE_EXTERN:
484 if (!parse_spec_extern( odp, spec )) goto error;
485 break;
486 default:
487 assert( 0 );
490 #ifndef __i386__
491 if (odp->flags & FLAG_I386)
493 /* ignore this entry point on non-Intel archs */
494 spec->nb_entry_points--;
495 return 1;
497 #endif
499 if (ordinal != -1)
501 if (!ordinal)
503 error( "Ordinal 0 is not valid\n" );
504 goto error;
506 if (ordinal >= MAX_ORDINALS)
508 error( "Ordinal number %d too large\n", ordinal );
509 goto error;
511 if (ordinal > spec->limit) spec->limit = ordinal;
512 if (ordinal < spec->base) spec->base = ordinal;
513 odp->ordinal = ordinal;
516 if (odp->type == TYPE_STDCALL && !(odp->flags & FLAG_PRIVATE))
518 if (!strcmp( odp->name, "DllRegisterServer" ) ||
519 !strcmp( odp->name, "DllUnregisterServer" ) ||
520 !strcmp( odp->name, "DllGetClassObject" ) ||
521 !strcmp( odp->name, "DllCanUnloadNow" ))
523 warning( "Function %s should be marked private\n", odp->name );
527 if (!strcmp( odp->name, "@" ) || odp->flags & FLAG_NONAME)
529 if (ordinal == -1)
531 error( "Nameless function needs an explicit ordinal number\n" );
532 goto error;
534 if (spec->type != SPEC_WIN32)
536 error( "Nameless functions not supported for Win16\n" );
537 goto error;
539 if (!strcmp( odp->name, "@" )) free( odp->name );
540 else odp->export_name = odp->name;
541 odp->name = NULL;
543 return 1;
545 error:
546 spec->nb_entry_points--;
547 free( odp->name );
548 return 0;
552 static int name_compare( const void *name1, const void *name2 )
554 const ORDDEF *odp1 = *(const ORDDEF * const *)name1;
555 const ORDDEF *odp2 = *(const ORDDEF * const *)name2;
556 return strcmp( odp1->name, odp2->name );
559 /*******************************************************************
560 * assign_names
562 * Build the name array and catch duplicates.
564 static void assign_names( DLLSPEC *spec )
566 int i, j;
568 spec->nb_names = 0;
569 for (i = 0; i < spec->nb_entry_points; i++)
570 if (spec->entry_points[i].name) spec->nb_names++;
571 if (!spec->nb_names) return;
573 spec->names = xmalloc( spec->nb_names * sizeof(spec->names[0]) );
574 for (i = j = 0; i < spec->nb_entry_points; i++)
575 if (spec->entry_points[i].name) spec->names[j++] = &spec->entry_points[i];
577 /* sort the list of names */
578 qsort( spec->names, spec->nb_names, sizeof(spec->names[0]), name_compare );
580 /* check for duplicate names */
581 for (i = 0; i < spec->nb_names - 1; i++)
583 if (!strcmp( spec->names[i]->name, spec->names[i+1]->name ))
585 current_line = max( spec->names[i]->lineno, spec->names[i+1]->lineno );
586 error( "'%s' redefined\n%s:%d: First defined here\n",
587 spec->names[i]->name, input_file_name,
588 min( spec->names[i]->lineno, spec->names[i+1]->lineno ) );
593 /*******************************************************************
594 * assign_ordinals
596 * Build the ordinal array.
598 static void assign_ordinals( DLLSPEC *spec )
600 int i, count, ordinal;
602 /* start assigning from base, or from 1 if no ordinal defined yet */
603 if (spec->base == MAX_ORDINALS) spec->base = 1;
604 if (spec->limit < spec->base) spec->limit = spec->base;
606 count = max( spec->limit + 1, spec->base + spec->nb_entry_points );
607 spec->ordinals = xmalloc( count * sizeof(spec->ordinals[0]) );
608 memset( spec->ordinals, 0, count * sizeof(spec->ordinals[0]) );
610 /* fill in all explicitly specified ordinals */
611 for (i = 0; i < spec->nb_entry_points; i++)
613 ordinal = spec->entry_points[i].ordinal;
614 if (ordinal == -1) continue;
615 if (spec->ordinals[ordinal])
617 current_line = max( spec->entry_points[i].lineno, spec->ordinals[ordinal]->lineno );
618 error( "ordinal %d redefined\n%s:%d: First defined here\n",
619 ordinal, input_file_name,
620 min( spec->entry_points[i].lineno, spec->ordinals[ordinal]->lineno ) );
622 else spec->ordinals[ordinal] = &spec->entry_points[i];
625 /* now assign ordinals to the rest */
626 for (i = 0, ordinal = spec->base; i < spec->nb_names; i++)
628 if (spec->names[i]->ordinal != -1) continue; /* already has an ordinal */
629 while (spec->ordinals[ordinal]) ordinal++;
630 if (ordinal >= MAX_ORDINALS)
632 current_line = spec->names[i]->lineno;
633 fatal_error( "Too many functions defined (max %d)\n", MAX_ORDINALS );
635 spec->names[i]->ordinal = ordinal;
636 spec->ordinals[ordinal] = spec->names[i];
638 if (ordinal > spec->limit) spec->limit = ordinal;
642 /*******************************************************************
643 * parse_spec_file
645 * Parse a .spec file.
647 int parse_spec_file( FILE *file, DLLSPEC *spec )
649 const char *token;
651 input_file = file;
652 current_line = 0;
654 comment_chars = "#;";
655 separator_chars = "()-";
657 while (get_next_line())
659 if (!(token = GetToken(1))) continue;
660 if (strcmp(token, "@") == 0)
662 if (spec->type != SPEC_WIN32)
664 error( "'@' ordinals not supported for Win16\n" );
665 continue;
667 if (!parse_spec_ordinal( -1, spec )) continue;
669 else if (IsNumberString(token))
671 if (!parse_spec_ordinal( atoi(token), spec )) continue;
673 else
675 error( "Expected ordinal declaration, got '%s'\n", token );
676 continue;
678 if ((token = GetToken(1))) error( "Syntax error near '%s'\n", token );
681 current_line = 0; /* no longer parsing the input file */
682 assign_names( spec );
683 assign_ordinals( spec );
684 return !nb_errors;
688 /*******************************************************************
689 * parse_def_library
691 * Parse a LIBRARY declaration in a .def file.
693 static int parse_def_library( DLLSPEC *spec )
695 const char *token = GetToken(1);
697 if (!token) return 1;
698 if (strcmp( token, "BASE" ))
700 free( spec->file_name );
701 spec->file_name = xstrdup( token );
702 if (!(token = GetToken(1))) return 1;
704 if (strcmp( token, "BASE" ))
706 error( "Expected library name or BASE= declaration, got '%s'\n", token );
707 return 0;
709 if (!(token = GetToken(0))) return 0;
710 if (strcmp( token, "=" ))
712 error( "Expected '=' after BASE, got '%s'\n", token );
713 return 0;
715 if (!(token = GetToken(0))) return 0;
716 /* FIXME: do something with base address */
718 return 1;
722 /*******************************************************************
723 * parse_def_stack_heap_size
725 * Parse a STACKSIZE or HEAPSIZE declaration in a .def file.
727 static int parse_def_stack_heap_size( int is_stack, DLLSPEC *spec )
729 const char *token = GetToken(0);
730 char *end;
731 unsigned long size;
733 if (!token) return 0;
734 size = strtoul( token, &end, 0 );
735 if (*end)
737 error( "Invalid number '%s'\n", token );
738 return 0;
740 if (is_stack) spec->stack_size = size / 1024;
741 else spec->heap_size = size / 1024;
742 if (!(token = GetToken(1))) return 1;
743 if (strcmp( token, "," ))
745 error( "Expected ',' after size, got '%s'\n", token );
746 return 0;
748 if (!(token = GetToken(0))) return 0;
749 /* FIXME: do something with reserve size */
750 return 1;
754 /*******************************************************************
755 * parse_def_export
757 * Parse an export declaration in a .def file.
759 static int parse_def_export( char *name, DLLSPEC *spec )
761 int i, args;
762 const char *token = GetToken(1);
764 ORDDEF *odp = add_entry_point( spec );
765 memset( odp, 0, sizeof(*odp) );
767 odp->lineno = current_line;
768 odp->ordinal = -1;
769 odp->name = name;
770 args = remove_stdcall_decoration( odp->name );
771 if (args == -1) odp->type = TYPE_CDECL;
772 else
774 odp->type = TYPE_STDCALL;
775 args /= sizeof(int);
776 if (args >= sizeof(odp->u.func.arg_types))
778 error( "Too many arguments in stdcall function '%s'\n", odp->name );
779 return 0;
781 for (i = 0; i < args; i++) odp->u.func.arg_types[i] = 'l';
784 /* check for optional internal name */
786 if (token && !strcmp( token, "=" ))
788 if (!(token = GetToken(0))) goto error;
789 odp->link_name = xstrdup( token );
790 remove_stdcall_decoration( odp->link_name );
791 token = GetToken(1);
793 else
795 odp->link_name = xstrdup( name );
798 /* check for optional ordinal */
800 if (token && token[0] == '@')
802 int ordinal;
804 if (!IsNumberString( token+1 ))
806 error( "Expected number after '@', got '%s'\n", token+1 );
807 goto error;
809 ordinal = atoi( token+1 );
810 if (!ordinal)
812 error( "Ordinal 0 is not valid\n" );
813 goto error;
815 if (ordinal >= MAX_ORDINALS)
817 error( "Ordinal number %d too large\n", ordinal );
818 goto error;
820 if (ordinal > spec->limit) spec->limit = ordinal;
821 if (ordinal < spec->base) spec->base = ordinal;
822 odp->ordinal = ordinal;
823 token = GetToken(1);
826 /* check for other optional keywords */
828 if (token && !strcmp( token, "NONAME" ))
830 if (odp->ordinal == -1)
832 error( "NONAME requires an ordinal\n" );
833 goto error;
835 odp->export_name = odp->name;
836 odp->name = NULL;
837 odp->flags |= FLAG_NONAME;
838 token = GetToken(1);
840 if (token && !strcmp( token, "PRIVATE" ))
842 odp->flags |= FLAG_PRIVATE;
843 token = GetToken(1);
845 if (token && !strcmp( token, "DATA" ))
847 odp->type = TYPE_EXTERN;
848 token = GetToken(1);
850 if (token)
852 error( "Garbage text '%s' found at end of export declaration\n", token );
853 goto error;
855 return 1;
857 error:
858 spec->nb_entry_points--;
859 free( odp->name );
860 return 0;
864 /*******************************************************************
865 * parse_def_file
867 * Parse a .def file.
869 int parse_def_file( FILE *file, DLLSPEC *spec )
871 const char *token;
872 int in_exports = 0;
874 input_file = file;
875 current_line = 0;
877 comment_chars = ";";
878 separator_chars = ",=";
880 while (get_next_line())
882 if (!(token = GetToken(1))) continue;
884 if (!strcmp( token, "LIBRARY" ) || !strcmp( token, "NAME" ))
886 if (!parse_def_library( spec )) continue;
887 goto end_of_line;
889 else if (!strcmp( token, "STACKSIZE" ))
891 if (!parse_def_stack_heap_size( 1, spec )) continue;
892 goto end_of_line;
894 else if (!strcmp( token, "HEAPSIZE" ))
896 if (!parse_def_stack_heap_size( 0, spec )) continue;
897 goto end_of_line;
899 else if (!strcmp( token, "EXPORTS" ))
901 in_exports = 1;
902 if (!(token = GetToken(1))) continue;
904 else if (!strcmp( token, "IMPORTS" ))
906 in_exports = 0;
907 if (!(token = GetToken(1))) continue;
909 else if (!strcmp( token, "SECTIONS" ))
911 in_exports = 0;
912 if (!(token = GetToken(1))) continue;
915 if (!in_exports) continue; /* ignore this line */
916 if (!parse_def_export( xstrdup(token), spec )) continue;
918 end_of_line:
919 if ((token = GetToken(1))) error( "Syntax error near '%s'\n", token );
922 current_line = 0; /* no longer parsing the input file */
923 assign_names( spec );
924 assign_ordinals( spec );
925 return !nb_errors;
929 /*******************************************************************
930 * add_debug_channel
932 static void add_debug_channel( const char *name )
934 int i;
936 for (i = 0; i < nb_debug_channels; i++)
937 if (!strcmp( debug_channels[i], name )) return;
939 debug_channels = xrealloc( debug_channels, (nb_debug_channels + 1) * sizeof(*debug_channels));
940 debug_channels[nb_debug_channels++] = xstrdup(name);
944 /*******************************************************************
945 * parse_debug_channels
947 * Parse a source file and extract the debug channel definitions.
949 int parse_debug_channels( const char *srcdir, const char *filename )
951 FILE *file;
952 int eol_seen = 1;
954 file = open_input_file( srcdir, filename );
955 while (fgets( ParseBuffer, sizeof(ParseBuffer), file ))
957 char *channel, *end, *p = ParseBuffer;
959 p = ParseBuffer + strlen(ParseBuffer) - 1;
960 if (!eol_seen) /* continuation line */
962 eol_seen = (*p == '\n');
963 continue;
965 if ((eol_seen = (*p == '\n'))) *p = 0;
967 p = ParseBuffer;
968 while (isspace(*p)) p++;
969 if (!memcmp( p, "WINE_DECLARE_DEBUG_CHANNEL", 26 ) ||
970 !memcmp( p, "WINE_DEFAULT_DEBUG_CHANNEL", 26 ))
972 p += 26;
973 while (isspace(*p)) p++;
974 if (*p != '(')
976 error( "invalid debug channel specification '%s'\n", ParseBuffer );
977 goto next;
979 p++;
980 while (isspace(*p)) p++;
981 if (!isalpha(*p))
983 error( "invalid debug channel specification '%s'\n", ParseBuffer );
984 goto next;
986 channel = p;
987 while (isalnum(*p) || *p == '_') p++;
988 end = p;
989 while (isspace(*p)) p++;
990 if (*p != ')')
992 error( "invalid debug channel specification '%s'\n", ParseBuffer );
993 goto next;
995 *end = 0;
996 add_debug_channel( channel );
998 next:
999 current_line++;
1001 close_input_file( file );
1002 return !nb_errors;