Added spec generation tool specmaker.
[wine.git] / tools / specmaker / specmaker.h
blob0fc636771a6b604ec550be7981ef76d0f4eb6162
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
54 /* Structure holding a parsed symbol */
55 typedef struct __parsed_symbol
57 char *symbol;
58 char *return_text;
59 char return_type;
60 char *calling_convention;
61 char *function_name;
62 unsigned int varargs;
63 unsigned int argc;
64 char arg_type [MAX_FUNCTION_ARGS];
65 char arg_flag [MAX_FUNCTION_ARGS];
66 char *arg_text [MAX_FUNCTION_ARGS];
67 char *arg_name [MAX_FUNCTION_ARGS];
68 } parsed_symbol;
70 /* All globals */
71 typedef struct __globals
73 /* Options */
74 int do_code; /* -c, -t, -f */
75 int do_trace; /* -t, -f */
76 int do_cdecl; /* -C */
77 int do_quiet; /* -q */
78 int do_verbose; /* -v */
79 int do_documentation; /* -D */
81 /* Option arguments */
82 int start_ordinal; /* -s */
83 int end_ordinal; /* -e */
84 const char *directory; /* -I */
85 const char *input_name; /* -d */
86 const char *forward_dll; /* -f */
87 const char *dll_name; /* -o */
88 char *uc_dll_name; /* -o */
89 } _globals;
91 extern _globals globals;
93 /* Names to use for output DLL */
94 #define OUTPUT_DLL_NAME \
95 (globals.dll_name ? globals.dll_name : globals.input_name)
96 #define OUTPUT_UC_DLL_NAME globals.uc_dll_name
98 /* Verbosity levels */
99 #define QUIET (globals.do_quiet)
100 #define NORMAL (!QUIET)
101 #define VERBOSE (globals.do_verbose)
103 /* Default calling convention */
104 #define CALLING_CONVENTION (globals.do_cdecl ? "__cdecl" : "__stdcall")
107 /* DLL functions */
108 void dll_open (const char *dll_name);
110 char *dll_next_symbol (void);
112 /* Symbol functions */
113 int symbol_demangle (parsed_symbol *symbol);
115 int symbol_search (parsed_symbol *symbol);
117 void symbol_clear(parsed_symbol *sym);
119 int symbol_is_valid_c(const parsed_symbol *sym);
121 int symbol_is_cdecl(const parsed_symbol *sym);
123 const char *symbol_get_spec_type (const parsed_symbol *sym, size_t arg);
125 void symbol_clean_string (const char *string);
127 int symbol_get_type (const char *string);
129 /* Output functions */
130 void output_spec_preamble (void);
132 void output_spec_symbol (const parsed_symbol *sym);
134 void output_header_preamble (void);
136 void output_header_symbol (const parsed_symbol *sym);
138 void output_c_preamble (void);
140 void output_c_symbol (const parsed_symbol *sym);
142 void output_makefile (void);
144 void output_install_script (void);
146 /* Misc functions */
147 char *str_create (size_t num_str, ...);
149 char *str_create_num (size_t num_str, int num, ...);
151 char *str_substring(const char *start, const char *end);
153 char *str_replace (char *str, const char *oldstr, const char *newstr);
155 const char *str_match (const char *str, const char *match, int *found);
157 const char *str_find_set (const char *str, const char *findset);
159 char *str_toupper (char *str);
161 FILE *open_file (const char *name, const char *ext, const char *mode);
163 #ifdef __GNUC__
164 void do_usage (void) __attribute__ ((noreturn));
165 #else
166 void do_usage (void);
167 #endif
169 void fatal (const char *message);
172 #endif /* __WINE_SPECMAKER_H */