ReactOS 0.4.16-dev-1948-gd260c1d
utils.c File Reference
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include "widl.h"
#include "utils.h"
#include "parser.h"
Include dependency graph for utils.c:

Go to the source code of this file.

Classes

struct  resource
 

Functions

void error_at (const struct location *where, const char *s,...)
 
void error (const char *s,...)
 
void warning (const char *s,...)
 
void warning_at (const struct location *where, const char *s,...)
 
void chat (const char *s,...)
 
size_t widl_getline (char **linep, size_t *lenp, FILE *fp)
 
size_t strappend (char **buf, size_t *len, size_t pos, const char *fmt,...)
 
static void put_resource_id (const char *str)
 
void add_output_to_resources (const char *type, const char *name)
 
void flush_output_resources (const char *name)
 
void put_pword (unsigned int val)
 
void put_str (int indent, const char *format,...)
 

Variables

unsigned charoutput_buffer
 
size_t output_buffer_pos
 
size_t output_buffer_size
 
static struct resource resources [16]
 
static unsigned int nb_resources
 

Function Documentation

◆ add_output_to_resources()

void add_output_to_resources ( const char type,
const char name 
)

Definition at line 192 of file utils.c.

193{
194 size_t data_size = output_buffer_pos;
195 size_t header_size = 5 * sizeof(unsigned int) + 2 * sizeof(unsigned short);
196
198
199 if (type[0] != '#') header_size += (strlen( type ) + 1) * sizeof(unsigned short);
200 else header_size += 2 * sizeof(unsigned short);
201 if (name[0] != '#') header_size += (strlen( name ) + 1) * sizeof(unsigned short);
202 else header_size += 2 * sizeof(unsigned short);
203
204 header_size = (header_size + 3) & ~3;
205 align_output( 4 );
206 check_output_buffer_space( header_size );
207 resources[nb_resources].size = header_size + output_buffer_pos;
209
211 put_dword( data_size ); /* ResSize */
212 put_dword( header_size ); /* HeaderSize */
213 put_resource_id( type ); /* ResType */
214 put_resource_id( name ); /* ResName */
215 align_output( 4 );
216 put_dword( 0 ); /* DataVersion */
217 put_word( 0 ); /* Memory options */
218 put_word( 0 ); /* Language */
219 put_dword( 0 ); /* Version */
220 put_dword( 0 ); /* Characteristics */
221
224}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define ARRAY_SIZE(A)
Definition: main.h:20
static void put_dword(struct bytecode_buffer *buffer, DWORD value)
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
unsigned short(__cdecl typeof(TIFFCurrentDirectory))(struct tiff *)
Definition: typeof.h:94
#define assert(x)
Definition: debug.h:53
FxCmResList * resources
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define memmove(s1, s2, n)
Definition: mkisofs.h:881
static void align_output(unsigned int align)
Definition: tools.h:833
static void init_output_buffer(void)
Definition: tools.h:791
static void check_output_buffer_space(size_t size)
Definition: tools.h:782
static void put_word(unsigned short val)
Definition: tools.h:811
size_t output_buffer_pos
Definition: utils.c:164
static void put_resource_id(const char *str)
Definition: utils.c:174
static unsigned int nb_resources
Definition: utils.c:172
unsigned char * output_buffer
Definition: utils.c:163
Definition: name.c:39

Referenced by output_typelib_regscript(), save_all_changes(), and write_regscript().

◆ chat()

void chat ( const char s,
  ... 
)

Definition at line 79 of file utils.c.

80{
82 {
83 va_list ap;
84 va_start(ap, s);
85 fprintf(stderr, "chat: ");
87 va_end(ap);
88 }
89}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
GLdouble s
Definition: gl.h:2039
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
int debuglevel
Definition: widl.c:94
#define DEBUGLEVEL_CHAT
Definition: widl.h:31
void int int ULONGLONG int va_list * ap
Definition: winesup.h:36

Referenced by add_block(), add_func_desc(), add_importlib(), add_index(), add_interface_typeinfo(), add_name(), add_structure_typeinfo(), add_type_typeinfo(), add_var_desc(), alloc_importinfo(), create_msft_typeinfo(), ctl2_alloc_guid(), dump_type(), dump_var_desc(), encode_type(), encode_var(), find_importinfo(), get_param_flags(), get_type_vt(), local_href(), save_all_changes(), sltg_add_typeinfo(), sltg_write_header(), sltg_write_helpstrings(), sltg_write_nametable(), sltg_write_typeinfo(), write_default_value(), and write_var_desc().

◆ error()

void error ( const char s,
  ... 
)

Definition at line 48 of file utils.c.

49{
50 va_list ap;
51 va_start(ap, s);
52 fprintf(stderr, "error: ");
54 va_end(ap);
55 exit(2);
56}
#define exit(n)
Definition: config.h:202

◆ error_at()

◆ flush_output_resources()

void flush_output_resources ( const char name)

Definition at line 226 of file utils.c.

227{
228 unsigned int i;
229
230 /* all output must have been saved with add_output_to_resources() first */
232
233 put_dword( 0 ); /* ResSize */
234 put_dword( 32 ); /* HeaderSize */
235 put_word( 0xffff ); /* ResType */
236 put_word( 0x0000 );
237 put_word( 0xffff ); /* ResName */
238 put_word( 0x0000 );
239 put_dword( 0 ); /* DataVersion */
240 put_word( 0 ); /* Memory options */
241 put_word( 0 ); /* Language */
242 put_dword( 0 ); /* Version */
243 put_dword( 0 ); /* Characteristics */
244
245 for (i = 0; i < nb_resources; i++)
246 {
248 free( resources[i].data );
249 }
251 nb_resources = 0;
252}
#define free
Definition: debug_ros.c:5
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static HRESULT flush_output_buffer(mxwriter *This)
Definition: mxwriter.c:661
static void put_data(const void *data, size_t size)
Definition: tools.h:798

Referenced by save_all_changes(), write_regscript(), and write_typelib_regscript().

◆ put_pword()

void put_pword ( unsigned int  val)

Definition at line 255 of file utils.c.

256{
257 if (pointer_size == 8) put_qword( val );
258 else put_dword( val );
259}
GLuint GLfloat * val
Definition: glext.h:7180
static void put_qword(unsigned int val)
Definition: tools.h:827
unsigned int pointer_size
Definition: widl.c:147

◆ put_resource_id()

static void put_resource_id ( const char str)
inlinestatic

Definition at line 174 of file utils.c.

175{
176 if (str[0] != '#')
177 {
178 while (*str)
179 {
180 unsigned char ch = *str++;
181 put_word( toupper(ch) );
182 }
183 put_word( 0 );
184 }
185 else
186 {
187 put_word( 0xffff );
188 put_word( atoi( str + 1 ));
189 }
190}
int toupper(int c)
Definition: utclib.c:881
const WCHAR * str
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)

Referenced by add_output_to_resources().

◆ put_str()

void put_str ( int  indent,
const char format,
  ... 
)

Definition at line 261 of file utils.c.

262{
263 int n;
265
269
270 for (;;)
271 {
273 va_start( args, format );
275 va_end( args );
276 if (n == -1) size *= 2;
277 else if ((size_t)n >= size) size = n + 1;
278 else
279 {
281 return;
282 }
284 }
285}
static const WCHAR indent[]
Definition: object.c:1156
GLdouble n
Definition: glext.h:7729
#define memset(x, y, z)
Definition: compat.h:39
#define args
Definition: format.c:66
size_t output_buffer_size
Definition: utils.c:165
Definition: match.c:390
Definition: format.c:58

Referenced by output_typelib_regscript(), write_coclass(), write_interface(), write_progid(), write_regscript(), write_runtimeclasses_registry(), and write_typelib_interface().

◆ strappend()

size_t strappend ( char **  buf,
size_t len,
size_t  pos,
const char fmt,
  ... 
)

Definition at line 120 of file utils.c.

121{
122 size_t size;
123 va_list ap;
124 char *ptr;
125 int n;
126
127 assert( buf && len );
128 assert( (*len == 0 && *buf == NULL) || (*len != 0 && *buf != NULL) );
129
130 if (*buf)
131 {
132 size = *len;
133 ptr = *buf;
134 }
135 else
136 {
137 size = 100;
138 ptr = xmalloc( size );
139 }
140
141 for (;;)
142 {
143 va_start( ap, fmt );
144 n = vsnprintf( ptr + pos, size - pos, fmt, ap );
145 va_end( ap );
146 if (n == -1) size *= 2;
147 else if (pos + (size_t)n >= size) size = pos + n + 1;
148 else break;
149 ptr = xrealloc( ptr, size );
150 }
151
152 *len = size;
153 *buf = ptr;
154 return n;
155}
void * xmalloc(int size)
Definition: uimain.c:747
void * xrealloc(void *oldmem, size_t size)
Definition: uimain.c:736
#define NULL
Definition: types.h:112
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum GLsizei len
Definition: glext.h:6722
static PVOID ptr
Definition: dispmode.c:27
Definition: dsound.c:943

Referenced by append_namespace(), append_namespaces(), append_pointer_stars(), append_type_signature(), append_var_list_signature(), format_parameterized_type_args(), format_parameterized_type_c_name(), format_parameterized_type_impl_name(), format_parameterized_type_name(), format_parameterized_type_short_name(), and format_parameterized_type_signature().

◆ warning()

void warning ( const char s,
  ... 
)

Definition at line 58 of file utils.c.

59{
60 va_list ap;
61 va_start(ap, s);
62 fprintf(stderr, "warning: ");
64 va_end(ap);
65}

◆ warning_at()

void warning_at ( const struct location where,
const char s,
  ... 
)

Definition at line 67 of file utils.c.

68{
69 char buffer[1024];
70
71 va_list ap;
72 va_start( ap, s );
73 vsnprintf( buffer, sizeof(buffer), s, ap );
74 va_end( ap );
75
76 parser_warning( where, buffer );
77}
void parser_warning(const struct location *where, const char *message)

Referenced by append_attr().

◆ widl_getline()

size_t widl_getline ( char **  linep,
size_t lenp,
FILE fp 
)

Definition at line 91 of file utils.c.

92{
93 char *line = *linep;
94 size_t len = *lenp;
95 size_t n = 0;
96
97 if (!line)
98 {
99 len = 64;
100 line = xmalloc(len);
101 }
102
103 while (fgets(&line[n], len - n, fp))
104 {
105 n += strlen(&line[n]);
106 if (line[n - 1] == '\n')
107 break;
108 else if (n == len - 1)
109 {
110 len *= 2;
111 line = xrealloc(line, len);
112 }
113 }
114
115 *linep = line;
116 *lenp = len;
117 return n;
118}
_Check_return_opt_ _CRTIMP char *__cdecl fgets(_Out_writes_z_(_MaxCount) char *_Buf, _In_ int _MaxCount, _Inout_ FILE *_File)
Definition: parser.c:49

Referenced by write_dlldata().

Variable Documentation

◆ nb_resources

unsigned int nb_resources
static

Definition at line 172 of file utils.c.

Referenced by add_output_to_resources(), and flush_output_resources().

◆ output_buffer

Definition at line 163 of file utils.c.

Referenced by add_output_to_resources().

◆ output_buffer_pos

◆ output_buffer_size

size_t output_buffer_size

Definition at line 165 of file utils.c.

Referenced by check_output_buffer_space(), init_output_buffer(), and put_str().

◆ resources

struct resource resources[16]
static