widl: Use the output buffer functions to write typelibs.
This commit is contained in:
parent
00dda6f687
commit
5d3b4fb6cb
|
@ -2408,24 +2408,9 @@ static void set_lib_flags(msft_typelib_t *typelib)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ctl2_write_chunk(int fd, void *segment, int length)
|
static void ctl2_write_segment(msft_typelib_t *typelib, int segment)
|
||||||
{
|
{
|
||||||
if (write(fd, segment, length) != length) {
|
put_data(typelib->typelib_segment_data[segment], typelib->typelib_segdir[segment].length);
|
||||||
close(fd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int ctl2_write_segment(msft_typelib_t *typelib, int fd, int segment)
|
|
||||||
{
|
|
||||||
if (write(fd, typelib->typelib_segment_data[segment], typelib->typelib_segdir[segment].length)
|
|
||||||
!= typelib->typelib_segdir[segment].length) {
|
|
||||||
close(fd);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ctl2_finalize_typeinfos(msft_typelib_t *typelib, int filesize)
|
static void ctl2_finalize_typeinfos(msft_typelib_t *typelib, int filesize)
|
||||||
|
@ -2455,7 +2440,7 @@ static int ctl2_finalize_segment(msft_typelib_t *typelib, int filepos, int segme
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void ctl2_write_typeinfos(msft_typelib_t *typelib, int fd)
|
static void ctl2_write_typeinfos(msft_typelib_t *typelib)
|
||||||
{
|
{
|
||||||
msft_typeinfo_t *typeinfo;
|
msft_typeinfo_t *typeinfo;
|
||||||
int typedata_size;
|
int typedata_size;
|
||||||
|
@ -2467,21 +2452,21 @@ static void ctl2_write_typeinfos(msft_typelib_t *typelib, int fd)
|
||||||
typedata_size = typeinfo->func_data[0];
|
typedata_size = typeinfo->func_data[0];
|
||||||
if (typeinfo->var_data)
|
if (typeinfo->var_data)
|
||||||
typedata_size += typeinfo->var_data[0];
|
typedata_size += typeinfo->var_data[0];
|
||||||
ctl2_write_chunk(fd, &typedata_size, sizeof(int));
|
put_data(&typedata_size, sizeof(int));
|
||||||
if (typeinfo->func_data)
|
if (typeinfo->func_data)
|
||||||
ctl2_write_chunk(fd, typeinfo->func_data + 1, typeinfo->func_data[0]);
|
put_data(typeinfo->func_data + 1, typeinfo->func_data[0]);
|
||||||
if (typeinfo->var_data)
|
if (typeinfo->var_data)
|
||||||
ctl2_write_chunk(fd, typeinfo->var_data + 1, typeinfo->var_data[0]);
|
put_data(typeinfo->var_data + 1, typeinfo->var_data[0]);
|
||||||
if (typeinfo->func_indices)
|
if (typeinfo->func_indices)
|
||||||
ctl2_write_chunk(fd, typeinfo->func_indices, (typeinfo->typeinfo->cElement & 0xffff) * 4);
|
put_data(typeinfo->func_indices, (typeinfo->typeinfo->cElement & 0xffff) * 4);
|
||||||
if (typeinfo->var_indices)
|
if (typeinfo->var_indices)
|
||||||
ctl2_write_chunk(fd, typeinfo->var_indices, (typeinfo->typeinfo->cElement >> 16) * 4);
|
put_data(typeinfo->var_indices, (typeinfo->typeinfo->cElement >> 16) * 4);
|
||||||
if (typeinfo->func_names)
|
if (typeinfo->func_names)
|
||||||
ctl2_write_chunk(fd, typeinfo->func_names, (typeinfo->typeinfo->cElement & 0xffff) * 4);
|
put_data(typeinfo->func_names, (typeinfo->typeinfo->cElement & 0xffff) * 4);
|
||||||
if (typeinfo->var_names)
|
if (typeinfo->var_names)
|
||||||
ctl2_write_chunk(fd, typeinfo->var_names, (typeinfo->typeinfo->cElement >> 16) * 4);
|
put_data(typeinfo->var_names, (typeinfo->typeinfo->cElement >> 16) * 4);
|
||||||
if (typeinfo->func_offsets)
|
if (typeinfo->func_offsets)
|
||||||
ctl2_write_chunk(fd, typeinfo->func_offsets, (typeinfo->typeinfo->cElement & 0xffff) * 4);
|
put_data(typeinfo->func_offsets, (typeinfo->typeinfo->cElement & 0xffff) * 4);
|
||||||
if (typeinfo->var_offsets) {
|
if (typeinfo->var_offsets) {
|
||||||
int add = 0, i, offset;
|
int add = 0, i, offset;
|
||||||
if(typeinfo->func_data)
|
if(typeinfo->func_data)
|
||||||
|
@ -2489,25 +2474,18 @@ static void ctl2_write_typeinfos(msft_typelib_t *typelib, int fd)
|
||||||
for(i = 0; i < (typeinfo->typeinfo->cElement >> 16); i++) {
|
for(i = 0; i < (typeinfo->typeinfo->cElement >> 16); i++) {
|
||||||
offset = typeinfo->var_offsets[i];
|
offset = typeinfo->var_offsets[i];
|
||||||
offset += add;
|
offset += add;
|
||||||
ctl2_write_chunk(fd, &offset, 4);
|
put_data(&offset, 4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int save_all_changes(msft_typelib_t *typelib)
|
static void save_all_changes(msft_typelib_t *typelib)
|
||||||
{
|
{
|
||||||
int retval;
|
|
||||||
int filepos;
|
int filepos;
|
||||||
int fd;
|
|
||||||
|
|
||||||
chat("save_all_changes(%p)\n", typelib);
|
chat("save_all_changes(%p)\n", typelib);
|
||||||
|
|
||||||
retval = TYPE_E_IOERROR;
|
|
||||||
|
|
||||||
fd = open(typelib->typelib->filename, O_CREAT | O_WRONLY | O_TRUNC | O_BINARY, 0666);
|
|
||||||
if (fd == -1) return retval;
|
|
||||||
|
|
||||||
filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
|
filepos = sizeof(MSFT_Header) + sizeof(MSFT_SegDir);
|
||||||
if(typelib->typelib_header.varflags & 0x100) filepos += 4; /* helpstringdll */
|
if(typelib->typelib_header.varflags & 0x100) filepos += 4; /* helpstringdll */
|
||||||
filepos += typelib->typelib_header.nrtypeinfos * 4;
|
filepos += typelib->typelib_header.nrtypeinfos * 4;
|
||||||
|
@ -2528,33 +2506,31 @@ static int save_all_changes(msft_typelib_t *typelib)
|
||||||
|
|
||||||
ctl2_finalize_typeinfos(typelib, filepos);
|
ctl2_finalize_typeinfos(typelib, filepos);
|
||||||
|
|
||||||
if (!ctl2_write_chunk(fd, &typelib->typelib_header, sizeof(typelib->typelib_header))) return retval;
|
byte_swapped = 0;
|
||||||
|
init_output_buffer();
|
||||||
|
|
||||||
|
put_data(&typelib->typelib_header, sizeof(typelib->typelib_header));
|
||||||
if(typelib->typelib_header.varflags & 0x100)
|
if(typelib->typelib_header.varflags & 0x100)
|
||||||
if (!ctl2_write_chunk(fd, &typelib->help_string_dll_offset, sizeof(typelib->help_string_dll_offset)))
|
put_data(&typelib->help_string_dll_offset, sizeof(typelib->help_string_dll_offset));
|
||||||
return retval;
|
|
||||||
|
|
||||||
if (!ctl2_write_chunk(fd, typelib->typelib_typeinfo_offsets, typelib->typelib_header.nrtypeinfos * 4)) return retval;
|
put_data(typelib->typelib_typeinfo_offsets, typelib->typelib_header.nrtypeinfos * 4);
|
||||||
if (!ctl2_write_chunk(fd, &typelib->typelib_segdir, sizeof(typelib->typelib_segdir))) return retval;
|
put_data(&typelib->typelib_segdir, sizeof(typelib->typelib_segdir));
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_TYPEINFO )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_TYPEINFO );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_GUIDHASH )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_GUIDHASH );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_GUID )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_GUID );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_REFERENCES )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_REFERENCES );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_IMPORTINFO )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_IMPORTINFO );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_IMPORTFILES )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_IMPORTFILES );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_NAMEHASH )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_NAMEHASH );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_NAME )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_NAME );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_STRING )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_STRING );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_TYPEDESC )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_TYPEDESC );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_ARRAYDESC )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_ARRAYDESC );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_CUSTDATA )) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_CUSTDATA );
|
||||||
if (!ctl2_write_segment(typelib, fd, MSFT_SEG_CUSTDATAGUID)) return retval;
|
ctl2_write_segment( typelib, MSFT_SEG_CUSTDATAGUID );
|
||||||
|
|
||||||
ctl2_write_typeinfos(typelib, fd);
|
ctl2_write_typeinfos(typelib);
|
||||||
|
flush_output_buffer( typelib->typelib->filename );
|
||||||
if (close(fd) == -1) return retval;
|
|
||||||
|
|
||||||
retval = S_OK;
|
|
||||||
return retval;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int create_msft_typelib(typelib_t *typelib)
|
int create_msft_typelib(typelib_t *typelib)
|
||||||
|
|
Loading…
Reference in New Issue