Added an unknown VxD error code.
[wine] / tools / specmaker / specmaker.h
1 /*
2  *  Specmaker - A Wine DLL tool
3  *
4  *  Copyright 2000 Jon Griffiths
5  *
6  *  References:
7  *  DLL symbol extraction based on file format from alib (anthonyw.cjb.net).
8  *
9  *  Option processing shamelessly cadged from winebuild (www.winehq.com).
10  *
11  *  All the cool functionality (prototyping, call tracing, forwarding)
12  *  relies on Patrik Stridvall's 'function_grep.pl' script to work.
13  *
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.
18  *
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.
24  */
25 #ifndef __WINE_SPECMAKER_H
26 #define __WINE_SPECMAKER_H
27
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>
35
36 /* Argument type constants */
37 #define MAX_FUNCTION_ARGS   32
38
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
48
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
54
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 */
60
61 /* Structure holding a parsed symbol */
62 typedef struct __parsed_symbol
63 {
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;
77
78 /* All globals */
79 typedef struct __globals
80 {
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 */
89
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;
100
101 extern _globals globals;
102
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
107
108 /* Verbosity levels */
109 #define QUIET   (globals.do_quiet)
110 #define NORMAL  (!QUIET)
111 #define VERBOSE (globals.do_verbose)
112
113 /* Default calling convention */
114 #define CALLING_CONVENTION (globals.do_cdecl ? SYM_CDECL : SYM_STDCALL)
115
116
117 /* DLL functions */
118 void  dll_open (const char *dll_name);
119
120 int dll_next_symbol (parsed_symbol * sym);
121
122 /* Symbol functions */
123 int   symbol_demangle (parsed_symbol *symbol);
124
125 int   symbol_search (parsed_symbol *symbol);
126
127 void  symbol_clear(parsed_symbol *sym);
128
129 int   symbol_is_valid_c(const parsed_symbol *sym);
130
131 const char *symbol_get_call_convention(const parsed_symbol *sym);
132
133 const char *symbol_get_spec_type (const parsed_symbol *sym, size_t arg);
134
135 void  symbol_clean_string (const char *string);
136
137 int   symbol_get_type (const char *string);
138
139 /* Output functions */
140 void  output_spec_preamble (void);
141
142 void  output_spec_symbol (const parsed_symbol *sym);
143
144 void  output_header_preamble (void);
145
146 void  output_header_symbol (const parsed_symbol *sym);
147
148 void  output_c_preamble (void);
149
150 void  output_c_symbol (const parsed_symbol *sym);
151
152 void  output_prototype (FILE *file, const parsed_symbol *sym);
153
154 void  output_makefile (void);
155
156 void  output_install_script (void);
157
158 /* Misc functions */
159 char *str_create (size_t num_str, ...);
160
161 char *str_create_num (size_t num_str, int num, ...);
162
163 char *str_substring(const char *start, const char *end);
164
165 char *str_replace (char *str, const char *oldstr, const char *newstr);
166
167 const char *str_match (const char *str, const char *match, int *found);
168
169 const char *str_find_set (const char *str, const char *findset);
170
171 char *str_toupper (char *str);
172
173 FILE *open_file (const char *name, const char *ext, const char *mode);
174
175 #ifdef __GNUC__
176 void  do_usage (void) __attribute__ ((noreturn));
177 #else
178 void  do_usage (void);
179 #endif
180
181 void  fatal (const char *message);
182
183
184 #endif /* __WINE_SPECMAKER_H */