advapi: Improve SetEntriesInAclA stub.
[wine.git] / tools / winebuild / parser.c
blob9246fd2be776ba47fea29b006e498bc343f6a9f5
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 /* valid characters in ordinal names */
50 static const char valid_ordname_chars[] = "/$:-_@?abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
52 static const char * const TypeNames[TYPE_NBTYPES] =
54 "variable", /* TYPE_VARIABLE */
55 "pascal", /* TYPE_PASCAL */
56 "equate", /* TYPE_ABS */
57 "stub", /* TYPE_STUB */
58 "stdcall", /* TYPE_STDCALL */
59 "cdecl", /* TYPE_CDECL */
60 "varargs", /* TYPE_VARARGS */
61 "extern" /* TYPE_EXTERN */
64 static const char * const FlagNames[] =
66 "norelay", /* FLAG_NORELAY */
67 "noname", /* FLAG_NONAME */
68 "ret16", /* FLAG_RET16 */
69 "ret64", /* FLAG_RET64 */
70 "i386", /* FLAG_I386 */
71 "register", /* FLAG_REGISTER */
72 "private", /* FLAG_PRIVATE */
73 NULL
76 static int IsNumberString(const char *s)
78 while (*s) if (!isdigit(*s++)) return 0;
79 return 1;
82 static inline int is_token_separator( char ch )
84 return strchr( separator_chars, ch ) != NULL;
87 static inline int is_token_comment( char ch )
89 return strchr( comment_chars, ch ) != NULL;
92 /* get the next line from the input file, or return 0 if at eof */
93 static int get_next_line(void)
95 ParseNext = ParseBuffer;
96 current_line++;
97 return (fgets(ParseBuffer, sizeof(ParseBuffer), input_file) != NULL);
100 static const char * GetToken( int allow_eol )
102 char *p = ParseNext;
103 char *token = TokenBuffer;
105 for (;;)
107 /* remove initial white space */
108 p = ParseNext;
109 while (isspace(*p)) p++;
111 if (*p == '\\' && p[1] == '\n') /* line continuation */
113 if (!get_next_line())
115 if (!allow_eol) error( "Unexpected end of file\n" );
116 return NULL;
119 else break;
122 if ((*p == '\0') || is_token_comment(*p))
124 if (!allow_eol) error( "Declaration not terminated properly\n" );
125 return NULL;
129 * Find end of token.
131 if (is_token_separator(*p))
133 /* a separator is always a complete token */
134 *token++ = *p++;
136 else while (*p != '\0' && !is_token_separator(*p) && !isspace(*p))
138 if (*p == '\\') p++;
139 if (*p) *token++ = *p++;
141 *token = '\0';
142 ParseNext = p;
143 return TokenBuffer;
147 static ORDDEF *add_entry_point( DLLSPEC *spec )
149 if (spec->nb_entry_points == spec->alloc_entry_points)
151 spec->alloc_entry_points += 128;
152 spec->entry_points = xrealloc( spec->entry_points,
153 spec->alloc_entry_points * sizeof(*spec->entry_points) );
155 return &spec->entry_points[spec->nb_entry_points++];
158 /*******************************************************************
159 * parse_spec_variable
161 * Parse a variable definition in a .spec file.
163 static int parse_spec_variable( ORDDEF *odp, DLLSPEC *spec )
165 char *endptr;
166 int *value_array;
167 int n_values;
168 int value_array_size;
169 const char *token;
171 if (spec->type == SPEC_WIN32)
173 error( "'variable' not supported in Win32, use 'extern' instead\n" );
174 return 0;
177 if (!(token = GetToken(0))) return 0;
178 if (*token != '(')
180 error( "Expected '(' got '%s'\n", token );
181 return 0;
184 n_values = 0;
185 value_array_size = 25;
186 value_array = xmalloc(sizeof(*value_array) * value_array_size);
188 for (;;)
190 if (!(token = GetToken(0)))
192 free( value_array );
193 return 0;
195 if (*token == ')')
196 break;
198 value_array[n_values++] = strtol(token, &endptr, 0);
199 if (n_values == value_array_size)
201 value_array_size += 25;
202 value_array = xrealloc(value_array,
203 sizeof(*value_array) * value_array_size);
206 if (endptr == NULL || *endptr != '\0')
208 error( "Expected number value, got '%s'\n", token );
209 free( value_array );
210 return 0;
214 odp->u.var.n_values = n_values;
215 odp->u.var.values = xrealloc(value_array, sizeof(*value_array) * n_values);
216 return 1;
220 /*******************************************************************
221 * parse_spec_export
223 * Parse an exported function definition in a .spec file.
225 static int parse_spec_export( ORDDEF *odp, DLLSPEC *spec )
227 const char *token;
228 unsigned int i;
230 switch(spec->type)
232 case SPEC_WIN16:
233 if (odp->type == TYPE_STDCALL)
235 error( "'stdcall' not supported for Win16\n" );
236 return 0;
238 break;
239 case SPEC_WIN32:
240 if (odp->type == TYPE_PASCAL)
242 error( "'pascal' not supported for Win32\n" );
243 return 0;
245 break;
246 default:
247 break;
250 if (!(token = GetToken(0))) return 0;
251 if (*token != '(')
253 error( "Expected '(' got '%s'\n", token );
254 return 0;
257 for (i = 0; i < sizeof(odp->u.func.arg_types); i++)
259 if (!(token = GetToken(0))) return 0;
260 if (*token == ')')
261 break;
263 if (!strcmp(token, "word"))
264 odp->u.func.arg_types[i] = 'w';
265 else if (!strcmp(token, "s_word"))
266 odp->u.func.arg_types[i] = 's';
267 else if (!strcmp(token, "long") || !strcmp(token, "segptr"))
268 odp->u.func.arg_types[i] = 'l';
269 else if (!strcmp(token, "ptr"))
270 odp->u.func.arg_types[i] = 'p';
271 else if (!strcmp(token, "str"))
272 odp->u.func.arg_types[i] = 't';
273 else if (!strcmp(token, "wstr"))
274 odp->u.func.arg_types[i] = 'W';
275 else if (!strcmp(token, "segstr"))
276 odp->u.func.arg_types[i] = 'T';
277 else if (!strcmp(token, "double"))
279 odp->u.func.arg_types[i++] = 'l';
280 if (get_ptr_size() == 4 && i < sizeof(odp->u.func.arg_types))
281 odp->u.func.arg_types[i] = 'l';
283 else
285 error( "Unknown argument type '%s'\n", token );
286 return 0;
289 if (spec->type == SPEC_WIN32)
291 if (strcmp(token, "long") &&
292 strcmp(token, "ptr") &&
293 strcmp(token, "str") &&
294 strcmp(token, "wstr") &&
295 strcmp(token, "double"))
297 error( "Type '%s' not supported for Win32\n", token );
298 return 0;
302 if ((*token != ')') || (i >= sizeof(odp->u.func.arg_types)))
304 error( "Too many arguments\n" );
305 return 0;
308 odp->u.func.arg_types[i] = '\0';
309 if (odp->type == TYPE_VARARGS)
310 odp->flags |= FLAG_NORELAY; /* no relay debug possible for varags entry point */
312 if (!(token = GetToken(1)))
314 if (!strcmp( odp->name, "@" ))
316 error( "Missing handler name for anonymous function\n" );
317 return 0;
319 odp->link_name = xstrdup( odp->name );
321 else
323 odp->link_name = xstrdup( token );
324 if (strchr( odp->link_name, '.' ))
326 if (spec->type == SPEC_WIN16)
328 error( "Forwarded functions not supported for Win16\n" );
329 return 0;
331 odp->flags |= FLAG_FORWARD;
334 return 1;
338 /*******************************************************************
339 * parse_spec_equate
341 * Parse an 'equate' definition in a .spec file.
343 static int parse_spec_equate( ORDDEF *odp, DLLSPEC *spec )
345 char *endptr;
346 int value;
347 const char *token;
349 if (spec->type == SPEC_WIN32)
351 error( "'equate' not supported for Win32\n" );
352 return 0;
354 if (!(token = GetToken(0))) return 0;
355 value = strtol(token, &endptr, 0);
356 if (endptr == NULL || *endptr != '\0')
358 error( "Expected number value, got '%s'\n", token );
359 return 0;
361 if (value < -0x8000 || value > 0xffff)
363 error( "Value %d for absolute symbol doesn't fit in 16 bits\n", value );
364 value = 0;
366 odp->u.abs.value = value;
367 return 1;
371 /*******************************************************************
372 * parse_spec_stub
374 * Parse a 'stub' definition in a .spec file
376 static int parse_spec_stub( ORDDEF *odp, DLLSPEC *spec )
378 odp->u.func.arg_types[0] = '\0';
379 odp->link_name = xstrdup("");
380 odp->flags |= FLAG_I386; /* don't bother generating stubs for Winelib */
381 return 1;
385 /*******************************************************************
386 * parse_spec_extern
388 * Parse an 'extern' definition in a .spec file.
390 static int parse_spec_extern( ORDDEF *odp, DLLSPEC *spec )
392 const char *token;
394 if (spec->type == SPEC_WIN16)
396 error( "'extern' not supported for Win16, use 'variable' instead\n" );
397 return 0;
399 if (!(token = GetToken(1)))
401 if (!strcmp( odp->name, "@" ))
403 error( "Missing handler name for anonymous extern\n" );
404 return 0;
406 odp->link_name = xstrdup( odp->name );
408 else
410 odp->link_name = xstrdup( token );
411 if (strchr( odp->link_name, '.' )) odp->flags |= FLAG_FORWARD;
413 return 1;
417 /*******************************************************************
418 * parse_spec_flags
420 * Parse the optional flags for an entry point in a .spec file.
422 static const char *parse_spec_flags( ORDDEF *odp )
424 unsigned int i;
425 const char *token;
429 if (!(token = GetToken(0))) break;
430 for (i = 0; FlagNames[i]; i++)
431 if (!strcmp( FlagNames[i], token )) break;
432 if (!FlagNames[i])
434 error( "Unknown flag '%s'\n", token );
435 return NULL;
437 odp->flags |= 1 << i;
438 token = GetToken(0);
439 } while (token && *token == '-');
441 return token;
445 /*******************************************************************
446 * parse_spec_ordinal
448 * Parse an ordinal definition in a .spec file.
450 static int parse_spec_ordinal( int ordinal, DLLSPEC *spec )
452 const char *token;
453 size_t len;
455 ORDDEF *odp = add_entry_point( spec );
456 memset( odp, 0, sizeof(*odp) );
458 if (!(token = GetToken(0))) goto error;
460 for (odp->type = 0; odp->type < TYPE_NBTYPES; odp->type++)
461 if (TypeNames[odp->type] && !strcmp( token, TypeNames[odp->type] ))
462 break;
464 if (odp->type >= TYPE_NBTYPES)
466 error( "Expected type after ordinal, found '%s' instead\n", token );
467 goto error;
470 if (!(token = GetToken(0))) goto error;
471 if (*token == '-' && !(token = parse_spec_flags( odp ))) goto error;
473 odp->name = xstrdup( token );
474 odp->lineno = current_line;
475 odp->ordinal = ordinal;
477 len = strspn( odp->name, valid_ordname_chars );
478 if (len < strlen( odp->name ))
480 error( "Character '%c' is not allowed in exported name '%s'\n", odp->name[len], odp->name );
481 goto error;
484 switch(odp->type)
486 case TYPE_VARIABLE:
487 if (!parse_spec_variable( odp, spec )) goto error;
488 break;
489 case TYPE_PASCAL:
490 case TYPE_STDCALL:
491 case TYPE_VARARGS:
492 case TYPE_CDECL:
493 if (!parse_spec_export( odp, spec )) goto error;
494 break;
495 case TYPE_ABS:
496 if (!parse_spec_equate( odp, spec )) goto error;
497 break;
498 case TYPE_STUB:
499 if (!parse_spec_stub( odp, spec )) goto error;
500 break;
501 case TYPE_EXTERN:
502 if (!parse_spec_extern( odp, spec )) goto error;
503 break;
504 default:
505 assert( 0 );
508 if ((target_cpu != CPU_x86) && (odp->flags & FLAG_I386))
510 /* ignore this entry point on non-Intel archs */
511 spec->nb_entry_points--;
512 return 1;
515 if (ordinal != -1)
517 if (!ordinal)
519 error( "Ordinal 0 is not valid\n" );
520 goto error;
522 if (ordinal >= MAX_ORDINALS)
524 error( "Ordinal number %d too large\n", ordinal );
525 goto error;
527 if (ordinal > spec->limit) spec->limit = ordinal;
528 if (ordinal < spec->base) spec->base = ordinal;
529 odp->ordinal = ordinal;
532 if (odp->type == TYPE_STDCALL && !(odp->flags & FLAG_PRIVATE))
534 if (!strcmp( odp->name, "DllRegisterServer" ) ||
535 !strcmp( odp->name, "DllUnregisterServer" ) ||
536 !strcmp( odp->name, "DllGetClassObject" ) ||
537 !strcmp( odp->name, "DllGetVersion" ) ||
538 !strcmp( odp->name, "DllInstall" ) ||
539 !strcmp( odp->name, "DllCanUnloadNow" ))
541 warning( "Function %s should be marked private\n", odp->name );
542 if (strcmp( odp->name, odp->link_name ))
543 warning( "Function %s should not use a different internal name (%s)\n",
544 odp->name, odp->link_name );
548 if (!strcmp( odp->name, "@" ) || odp->flags & FLAG_NONAME)
550 if (ordinal == -1)
552 error( "Nameless function needs an explicit ordinal number\n" );
553 goto error;
555 if (spec->type != SPEC_WIN32)
557 error( "Nameless functions not supported for Win16\n" );
558 goto error;
560 if (!strcmp( odp->name, "@" )) free( odp->name );
561 else odp->export_name = odp->name;
562 odp->name = NULL;
564 return 1;
566 error:
567 spec->nb_entry_points--;
568 free( odp->name );
569 return 0;
573 static int name_compare( const void *ptr1, const void *ptr2 )
575 const ORDDEF *odp1 = *(const ORDDEF * const *)ptr1;
576 const ORDDEF *odp2 = *(const ORDDEF * const *)ptr2;
577 const char *name1 = odp1->name ? odp1->name : odp1->export_name;
578 const char *name2 = odp2->name ? odp2->name : odp2->export_name;
579 return strcmp( name1, name2 );
582 /*******************************************************************
583 * assign_names
585 * Build the name array and catch duplicates.
587 static void assign_names( DLLSPEC *spec )
589 int i, j, nb_exp_names = 0;
590 ORDDEF **all_names;
592 spec->nb_names = 0;
593 for (i = 0; i < spec->nb_entry_points; i++)
594 if (spec->entry_points[i].name) spec->nb_names++;
595 else if (spec->entry_points[i].export_name) nb_exp_names++;
597 if (!spec->nb_names && !nb_exp_names) return;
599 /* check for duplicates */
601 all_names = xmalloc( (spec->nb_names + nb_exp_names) * sizeof(all_names[0]) );
602 for (i = j = 0; i < spec->nb_entry_points; i++)
603 if (spec->entry_points[i].name || spec->entry_points[i].export_name)
604 all_names[j++] = &spec->entry_points[i];
606 qsort( all_names, j, sizeof(all_names[0]), name_compare );
608 for (i = 0; i < j - 1; i++)
610 const char *name1 = all_names[i]->name ? all_names[i]->name : all_names[i]->export_name;
611 const char *name2 = all_names[i+1]->name ? all_names[i+1]->name : all_names[i+1]->export_name;
612 if (!strcmp( name1, name2 ))
614 current_line = max( all_names[i]->lineno, all_names[i+1]->lineno );
615 error( "'%s' redefined\n%s:%d: First defined here\n",
616 name1, input_file_name,
617 min( all_names[i]->lineno, all_names[i+1]->lineno ) );
620 free( all_names );
622 if (spec->nb_names)
624 spec->names = xmalloc( spec->nb_names * sizeof(spec->names[0]) );
625 for (i = j = 0; i < spec->nb_entry_points; i++)
626 if (spec->entry_points[i].name) spec->names[j++] = &spec->entry_points[i];
628 /* sort the list of names */
629 qsort( spec->names, spec->nb_names, sizeof(spec->names[0]), name_compare );
633 /*******************************************************************
634 * assign_ordinals
636 * Build the ordinal array.
638 static void assign_ordinals( DLLSPEC *spec )
640 int i, count, ordinal;
642 /* start assigning from base, or from 1 if no ordinal defined yet */
644 spec->base = MAX_ORDINALS;
645 spec->limit = 0;
646 for (i = 0; i < spec->nb_entry_points; i++)
648 ordinal = spec->entry_points[i].ordinal;
649 if (ordinal == -1) continue;
650 if (ordinal > spec->limit) spec->limit = ordinal;
651 if (ordinal < spec->base) spec->base = ordinal;
653 if (spec->base == MAX_ORDINALS) spec->base = 1;
654 if (spec->limit < spec->base) spec->limit = spec->base;
656 count = max( spec->limit + 1, spec->base + spec->nb_entry_points );
657 spec->ordinals = xmalloc( count * sizeof(spec->ordinals[0]) );
658 memset( spec->ordinals, 0, count * sizeof(spec->ordinals[0]) );
660 /* fill in all explicitly specified ordinals */
661 for (i = 0; i < spec->nb_entry_points; i++)
663 ordinal = spec->entry_points[i].ordinal;
664 if (ordinal == -1) continue;
665 if (spec->ordinals[ordinal])
667 current_line = max( spec->entry_points[i].lineno, spec->ordinals[ordinal]->lineno );
668 error( "ordinal %d redefined\n%s:%d: First defined here\n",
669 ordinal, input_file_name,
670 min( spec->entry_points[i].lineno, spec->ordinals[ordinal]->lineno ) );
672 else spec->ordinals[ordinal] = &spec->entry_points[i];
675 /* now assign ordinals to the rest */
676 for (i = 0, ordinal = spec->base; i < spec->nb_entry_points; i++)
678 if (spec->entry_points[i].ordinal != -1) continue;
679 while (spec->ordinals[ordinal]) ordinal++;
680 if (ordinal >= MAX_ORDINALS)
682 current_line = spec->entry_points[i].lineno;
683 fatal_error( "Too many functions defined (max %d)\n", MAX_ORDINALS );
685 spec->entry_points[i].ordinal = ordinal;
686 spec->ordinals[ordinal] = &spec->entry_points[i];
688 if (ordinal > spec->limit) spec->limit = ordinal;
692 /*******************************************************************
693 * parse_spec_file
695 * Parse a .spec file.
697 int parse_spec_file( FILE *file, DLLSPEC *spec )
699 const char *token;
701 input_file = file;
702 current_line = 0;
704 comment_chars = "#;";
705 separator_chars = "()-";
707 while (get_next_line())
709 if (!(token = GetToken(1))) continue;
710 if (strcmp(token, "@") == 0)
712 if (spec->type != SPEC_WIN32)
714 error( "'@' ordinals not supported for Win16\n" );
715 continue;
717 if (!parse_spec_ordinal( -1, spec )) continue;
719 else if (IsNumberString(token))
721 if (!parse_spec_ordinal( atoi(token), spec )) continue;
723 else
725 error( "Expected ordinal declaration, got '%s'\n", token );
726 continue;
728 if ((token = GetToken(1))) error( "Syntax error near '%s'\n", token );
731 current_line = 0; /* no longer parsing the input file */
732 assign_names( spec );
733 assign_ordinals( spec );
734 return !nb_errors;
738 /*******************************************************************
739 * parse_def_library
741 * Parse a LIBRARY declaration in a .def file.
743 static int parse_def_library( DLLSPEC *spec )
745 const char *token = GetToken(1);
747 if (!token) return 1;
748 if (strcmp( token, "BASE" ))
750 free( spec->file_name );
751 spec->file_name = xstrdup( token );
752 if (!(token = GetToken(1))) return 1;
754 if (strcmp( token, "BASE" ))
756 error( "Expected library name or BASE= declaration, got '%s'\n", token );
757 return 0;
759 if (!(token = GetToken(0))) return 0;
760 if (strcmp( token, "=" ))
762 error( "Expected '=' after BASE, got '%s'\n", token );
763 return 0;
765 if (!(token = GetToken(0))) return 0;
766 /* FIXME: do something with base address */
768 return 1;
772 /*******************************************************************
773 * parse_def_stack_heap_size
775 * Parse a STACKSIZE or HEAPSIZE declaration in a .def file.
777 static int parse_def_stack_heap_size( int is_stack, DLLSPEC *spec )
779 const char *token = GetToken(0);
780 char *end;
781 unsigned long size;
783 if (!token) return 0;
784 size = strtoul( token, &end, 0 );
785 if (*end)
787 error( "Invalid number '%s'\n", token );
788 return 0;
790 if (is_stack) spec->stack_size = size / 1024;
791 else spec->heap_size = size / 1024;
792 if (!(token = GetToken(1))) return 1;
793 if (strcmp( token, "," ))
795 error( "Expected ',' after size, got '%s'\n", token );
796 return 0;
798 if (!(token = GetToken(0))) return 0;
799 /* FIXME: do something with reserve size */
800 return 1;
804 /*******************************************************************
805 * parse_def_export
807 * Parse an export declaration in a .def file.
809 static int parse_def_export( char *name, DLLSPEC *spec )
811 int i, args;
812 const char *token = GetToken(1);
814 ORDDEF *odp = add_entry_point( spec );
815 memset( odp, 0, sizeof(*odp) );
817 odp->lineno = current_line;
818 odp->ordinal = -1;
819 odp->name = name;
820 args = remove_stdcall_decoration( odp->name );
821 if (args == -1) odp->type = TYPE_CDECL;
822 else
824 odp->type = TYPE_STDCALL;
825 args /= get_ptr_size();
826 if (args >= sizeof(odp->u.func.arg_types))
828 error( "Too many arguments in stdcall function '%s'\n", odp->name );
829 return 0;
831 for (i = 0; i < args; i++) odp->u.func.arg_types[i] = 'l';
834 /* check for optional internal name */
836 if (token && !strcmp( token, "=" ))
838 if (!(token = GetToken(0))) goto error;
839 odp->link_name = xstrdup( token );
840 remove_stdcall_decoration( odp->link_name );
841 token = GetToken(1);
843 else
845 odp->link_name = xstrdup( name );
848 /* check for optional ordinal */
850 if (token && token[0] == '@')
852 int ordinal;
854 if (!IsNumberString( token+1 ))
856 error( "Expected number after '@', got '%s'\n", token+1 );
857 goto error;
859 ordinal = atoi( token+1 );
860 if (!ordinal)
862 error( "Ordinal 0 is not valid\n" );
863 goto error;
865 if (ordinal >= MAX_ORDINALS)
867 error( "Ordinal number %d too large\n", ordinal );
868 goto error;
870 odp->ordinal = ordinal;
871 token = GetToken(1);
874 /* check for other optional keywords */
876 if (token && !strcmp( token, "NONAME" ))
878 if (odp->ordinal == -1)
880 error( "NONAME requires an ordinal\n" );
881 goto error;
883 odp->export_name = odp->name;
884 odp->name = NULL;
885 odp->flags |= FLAG_NONAME;
886 token = GetToken(1);
888 if (token && !strcmp( token, "PRIVATE" ))
890 odp->flags |= FLAG_PRIVATE;
891 token = GetToken(1);
893 if (token && !strcmp( token, "DATA" ))
895 odp->type = TYPE_EXTERN;
896 token = GetToken(1);
898 if (token)
900 error( "Garbage text '%s' found at end of export declaration\n", token );
901 goto error;
903 return 1;
905 error:
906 spec->nb_entry_points--;
907 free( odp->name );
908 return 0;
912 /*******************************************************************
913 * parse_def_file
915 * Parse a .def file.
917 int parse_def_file( FILE *file, DLLSPEC *spec )
919 const char *token;
920 int in_exports = 0;
922 input_file = file;
923 current_line = 0;
925 comment_chars = ";";
926 separator_chars = ",=";
928 while (get_next_line())
930 if (!(token = GetToken(1))) continue;
932 if (!strcmp( token, "LIBRARY" ) || !strcmp( token, "NAME" ))
934 if (!parse_def_library( spec )) continue;
935 goto end_of_line;
937 else if (!strcmp( token, "STACKSIZE" ))
939 if (!parse_def_stack_heap_size( 1, spec )) continue;
940 goto end_of_line;
942 else if (!strcmp( token, "HEAPSIZE" ))
944 if (!parse_def_stack_heap_size( 0, spec )) continue;
945 goto end_of_line;
947 else if (!strcmp( token, "EXPORTS" ))
949 in_exports = 1;
950 if (!(token = GetToken(1))) continue;
952 else if (!strcmp( token, "IMPORTS" ))
954 in_exports = 0;
955 if (!(token = GetToken(1))) continue;
957 else if (!strcmp( token, "SECTIONS" ))
959 in_exports = 0;
960 if (!(token = GetToken(1))) continue;
963 if (!in_exports) continue; /* ignore this line */
964 if (!parse_def_export( xstrdup(token), spec )) continue;
966 end_of_line:
967 if ((token = GetToken(1))) error( "Syntax error near '%s'\n", token );
970 current_line = 0; /* no longer parsing the input file */
971 assign_names( spec );
972 assign_ordinals( spec );
973 return !nb_errors;