- Create entries for ordinal only exports, use ordinals if non-standard.
[wine/hacks.git] / tools / specmaker / specmaker.h
blob8d952fc0782a242a78e1546e0946b2dd9a8e9c3a
1 /*
2 * Specmaker - A Wine DLL tool
4 * Copyright 2000 Jon Griffiths
6 * References:
7 * DLL symbol extraction based on file format from alib (anthonyw.cjb.net).
9 * Option processing shamelessly cadged from winebuild (www.winehq.com).
11 * All the cool functionality (prototyping, call tracing, forwarding)
12 * relies on Patrik Stridvall's 'function_grep.pl' script to work.
14 * http://msdn.microsoft.com/library/periodic/period96/msj/S330.htm
15 * This article provides both a description and freely downloadble
16 * implementation, in source code form, of how to extract symbols
17 * from Win32 PE executables/DLL's.
19 * http://www.kegel.com/mangle.html
20 * Gives information on the name mangling scheme used by MS compilers,
21 * used as the starting point for the code here. Contains a few
22 * mistakes and some incorrect assumptions, but the lists of types
23 * are pure gold.
25 #ifndef __WINE_SPECMAKER_H
26 #define __WINE_SPECMAKER_H
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <ctype.h>
32 #include <errno.h>
33 #include <assert.h>
34 #include <stdarg.h>
36 /* Argument type constants */
37 #define MAX_FUNCTION_ARGS 32
39 #define ARG_VOID 0x0
40 #define ARG_STRING 0x1
41 #define ARG_WIDE_STRING 0x2
42 #define ARG_POINTER 0x3
43 #define ARG_LONG 0x4
44 #define ARG_DOUBLE 0x5
45 #define ARG_STRUCT 0x6 /* By value */
46 #define ARG_FLOAT 0x7
47 #define ARG_VARARGS 0x8
49 /* Compound type flags */
50 #define CT_BY_REFERENCE 0x1
51 #define CT_VOLATILE 0x2
52 #define CT_CONST 0x4
53 #define CT_EXTENDED 0x8
55 /* symbol flags */
56 #define SYM_CDECL 0x1
57 #define SYM_STDCALL 0x2
58 #define SYM_THISCALL 0x4
59 #define SYM_DATA 0x8 /* Data, not a function */
61 /* Structure holding a parsed symbol */
62 typedef struct __parsed_symbol
64 char *symbol;
65 int ordinal;
66 char *return_text;
67 char return_type;
68 char *function_name;
69 unsigned int varargs;
70 unsigned int argc;
71 unsigned int flags;
72 char arg_type [MAX_FUNCTION_ARGS];
73 char arg_flag [MAX_FUNCTION_ARGS];
74 char *arg_text [MAX_FUNCTION_ARGS];
75 char *arg_name [MAX_FUNCTION_ARGS];
76 } parsed_symbol;
78 /* All globals */
79 typedef struct __globals
81 /* Options */
82 int do_code; /* -c, -t, -f */
83 int do_trace; /* -t, -f */
84 int do_cdecl; /* -C */
85 int do_quiet; /* -q */
86 int do_verbose; /* -v */
87 int do_documentation; /* -D */
88 int do_demangle; /* -S */
90 /* Option arguments */
91 int start_ordinal; /* -s */
92 int end_ordinal; /* -e */
93 const char *directory; /* -I */
94 const char *input_name; /* -d */
95 const char *forward_dll; /* -f */
96 const char *dll_name; /* -o */
97 char *uc_dll_name; /* -o */
98 int do_ordinals;
99 } _globals;
101 extern _globals globals;
103 /* Names to use for output DLL */
104 #define OUTPUT_DLL_NAME \
105 (globals.dll_name ? globals.dll_name : globals.input_name)
106 #define OUTPUT_UC_DLL_NAME globals.uc_dll_name
108 /* Verbosity levels */
109 #define QUIET (globals.do_quiet)
110 #define NORMAL (!QUIET)
111 #define VERBOSE (globals.do_verbose)
113 /* Default calling convention */
114 #define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
117 /* DLL functions */
118 void dll_open (const char *dll_name);
120 int dll_next_symbol (parsed_symbol * sym);
122 /* Symbol functions */
123 int symbol_demangle (parsed_symbol *symbol);
125 int symbol_search (parsed_symbol *symbol);
127 void symbol_clear(parsed_symbol *sym);
129 int symbol_is_valid_c(const parsed_symbol *sym);
131 const char *symbol_get_call_convention(const parsed_symbol *sym);
133 const char *symbol_get_spec_type (const parsed_symbol *sym, size_t arg);
135 void symbol_clean_string (const char *string);
137 int symbol_get_type (const char *string);
139 /* Output functions */
140 void output_spec_preamble (void);
142 void output_spec_symbol (const parsed_symbol *sym);
144 void output_header_preamble (void);
146 void output_header_symbol (const parsed_symbol *sym);
148 void output_c_preamble (void);
150 void output_c_symbol (const parsed_symbol *sym);
152 void output_prototype (FILE *file, const parsed_symbol *sym);
154 void output_makefile (void);
156 void output_install_script (void);
158 /* Misc functions */
159 char *str_create (size_t num_str, ...);
161 char *str_create_num (size_t num_str, int num, ...);
163 char *str_substring(const char *start, const char *end);
165 char *str_replace (char *str, const char *oldstr, const char *newstr);
167 const char *str_match (const char *str, const char *match, int *found);
169 const char *str_find_set (const char *str, const char *findset);
171 char *str_toupper (char *str);
173 FILE *open_file (const char *name, const char *ext, const char *mode);
175 #ifdef __GNUC__
176 void do_usage (void) __attribute__ ((noreturn));
177 #else
178 void do_usage (void);
179 #endif
181 void fatal (const char *message);
184 #endif /* __WINE_SPECMAKER_H */