1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
....
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
....
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
....
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
....
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
|
allocate_cells (biff_workbook * workbook)
{
/* allocating the rows and cells for the active Worksheet */
unsigned int row;
unsigned int col;
biff_cell_value *p_cell;
/* allocating the cell values array */
workbook->active_sheet->cell_values =
malloc (sizeof (biff_cell_value) *
(workbook->active_sheet->rows *
workbook->active_sheet->columns));
if (workbook->active_sheet->cell_values == NULL)
return FREEXL_INSUFFICIENT_MEMORY;
................................................................................
{
/* main SST record [initializing] */
memcpy (n_strings.bytes, workbook->record + 4, 4);
if (swap)
swap32 (&n_strings);
p_string = workbook->record + 8;
workbook->shared_strings.string_count = n_strings.value;
workbook->shared_strings.utf8_strings =
malloc (sizeof (char **) * workbook->shared_strings.string_count);
for (i_string = 0; i_string < workbook->shared_strings.string_count;
i_string++)
*(workbook->shared_strings.utf8_strings + i_string) = NULL;
}
else
................................................................................
if (((workbook->p_in + workbook->record_size) - workbook->sector_buf) >
workbook->sector_end)
{
/* the current record spans on the following sector(s) */
unsigned int already_done;
unsigned int chunk =
workbook->sector_end - (workbook->p_in - workbook->sector_buf);
memcpy (workbook->record, workbook->p_in, chunk);
workbook->p_in += chunk;
already_done = chunk;
while (already_done < workbook->record_size)
{
/* reading a further sector */
................................................................................
/* BIG endian arch: swap required */
swap16 (&record_type);
swap16 (&record_size);
}
/* saving the current record */
workbook->record_type = record_type.value;
workbook->record_size = record_size.value;
memcpy (workbook->record, workbook->p_in, workbook->record_size);
workbook->p_in += record_size.value;
ret = parse_biff_record (workbook, swap);
if (ret != FREEXL_OK)
return 0;
................................................................................
{
/* setting Sheet dimensions */
int ret;
p_sheet->rows += 1;
p_sheet->columns += 1;
ret = allocate_cells (workbook);
if (ret != FREEXL_OK)
return ret;
p_sheet->valid_dimension = 1;
workbook->second_pass = 1;
}
else
p_sheet->already_done = 1;
p_sheet = p_sheet->next;
}
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
<
>
>
>
>
|
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
....
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
....
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
....
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
....
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
|
allocate_cells (biff_workbook * workbook)
{
/* allocating the rows and cells for the active Worksheet */
unsigned int row;
unsigned int col;
biff_cell_value *p_cell;
if (workbook == NULL)
return FREEXL_NULL_ARGUMENT;
if (workbook->active_sheet == NULL)
return FREEXL_NULL_ARGUMENT;
/* allocating the cell values array */
workbook->active_sheet->cell_values =
malloc (sizeof (biff_cell_value) *
(workbook->active_sheet->rows *
workbook->active_sheet->columns));
if (workbook->active_sheet->cell_values == NULL)
return FREEXL_INSUFFICIENT_MEMORY;
................................................................................
{
/* main SST record [initializing] */
memcpy (n_strings.bytes, workbook->record + 4, 4);
if (swap)
swap32 (&n_strings);
p_string = workbook->record + 8;
workbook->shared_strings.string_count = n_strings.value;
if (workbook->shared_strings.string_count > 1024 * 1024)
{
/* unexpected huge count ... cowardly giving up ... */
return FREEXL_INSUFFICIENT_MEMORY;
}
workbook->shared_strings.utf8_strings =
malloc (sizeof (char **) * workbook->shared_strings.string_count);
for (i_string = 0; i_string < workbook->shared_strings.string_count;
i_string++)
*(workbook->shared_strings.utf8_strings + i_string) = NULL;
}
else
................................................................................
if (((workbook->p_in + workbook->record_size) - workbook->sector_buf) >
workbook->sector_end)
{
/* the current record spans on the following sector(s) */
unsigned int already_done;
unsigned int chunk =
workbook->sector_end - (workbook->p_in - workbook->sector_buf);
if (workbook->sector_end <= (workbook->p_in - workbook->sector_buf))
return -1;
memcpy (workbook->record, workbook->p_in, chunk);
workbook->p_in += chunk;
already_done = chunk;
while (already_done < workbook->record_size)
{
/* reading a further sector */
................................................................................
/* BIG endian arch: swap required */
swap16 (&record_type);
swap16 (&record_size);
}
/* saving the current record */
workbook->record_type = record_type.value;
workbook->record_size = record_size.value;
if ((workbook->p_in - workbook->fat->miniStream) + workbook->record_size >
(int) workbook->size)
return 0; /* unexpected EOF */
memcpy (workbook->record, workbook->p_in, workbook->record_size);
workbook->p_in += record_size.value;
ret = parse_biff_record (workbook, swap);
if (ret != FREEXL_OK)
return 0;
................................................................................
{
/* setting Sheet dimensions */
int ret;
p_sheet->rows += 1;
p_sheet->columns += 1;
ret = allocate_cells (workbook);
if (ret != FREEXL_OK)
{
errcode = ret;
goto stop;
}
p_sheet->valid_dimension = 1;
workbook->second_pass = 1;
}
else
p_sheet->already_done = 1;
p_sheet = p_sheet->next;
}
|