Commit 0cdbae91 authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Handle larger number of columns.

2002-10-03  Morten Welinder  <terra@diku.dk>

	* src/parse-util.c (col_name_internal): Handle larger number of
	columns.

	* src/sheet-style.c (sheet_style_init): Warn if we have a conflict
	between column name TRUE and constant TRUE.
parent 10c2cd10
2002-10-03 Morten Welinder <terra@diku.dk>
* src/parse-util.c (col_name_internal): Handle larger number of
columns.
* src/sheet-style.c (sheet_style_init): Warn if we have a conflict
between column name TRUE and constant TRUE.
2002-10-03 Morten Welinder <terra@diku.dk>
* src/sheet-style.c (TILE_SIZE_COL, TILE_SIZE_ROW): Auto-size.
......
......@@ -13,6 +13,9 @@ Jody:
Morten:
* Port search center from gal's e-table to gtk's treeview.
* Fix parse-utils to handle large number of columns.
* Reduce the number of source places that need to be changed in
order to get more than 256 columns and/or 65536 rows.
--------------------------------------------------------------------------
Gnumeric 1.1.9
......
2002-10-03 Morten Welinder <terra@diku.dk>
* src/parse-util.c (col_name_internal): Handle larger number of
columns.
* src/sheet-style.c (sheet_style_init): Warn if we have a conflict
between column name TRUE and constant TRUE.
2002-10-03 Morten Welinder <terra@diku.dk>
* src/sheet-style.c (TILE_SIZE_COL, TILE_SIZE_ROW): Auto-size.
......
2002-10-03 Morten Welinder <terra@diku.dk>
* src/parse-util.c (col_name_internal): Handle larger number of
columns.
* src/sheet-style.c (sheet_style_init): Warn if we have a conflict
between column name TRUE and constant TRUE.
2002-10-03 Morten Welinder <terra@diku.dk>
* src/sheet-style.c (TILE_SIZE_COL, TILE_SIZE_ROW): Auto-size.
......
......@@ -3,8 +3,12 @@
#include <glib.h>
#define SHEET_MAX_ROWS (64 * 1024) /* 0 - 65535 inclusive */
#define SHEET_MAX_COLS 256 /* 0 - 255 inclusive */
#define SHEET_MAX_ROWS (64 * 1024) /* 0, 1, ... */
#define SHEET_MAX_COLS 256 /* 0, 1, ... */
/*
* Note: more than 364238 columns will introduce a column named TRUE.
*/
typedef struct _CommandContext CommandContext;
typedef struct _CommandContextStderr CommandContextStderr;
......
......@@ -45,25 +45,34 @@
inline static char *
col_name_internal (char *buf, int col)
{
g_return_val_if_fail (col < SHEET_MAX_COLS, buf);
g_return_val_if_fail (col >= 0, buf);
if (col <= 'Z'-'A') {
*buf++ = col + 'A';
} else {
int a = col / ('Z'-'A'+1);
int b = col % ('Z'-'A'+1);
*buf++ = a + 'A' - 1;
*buf++ = b + 'A';
}
return buf;
static const int steps[] = {
26,
26 * 26,
26 * 26 * 26,
26 * 26 * 26 * 26,
26 * 26 * 26 * 26 * 26,
26 * 26 * 26 * 26 * 26 * 26,
INT_MAX
};
int i;
char *res;
for (i = 0; col >= steps[i]; i++)
col -= steps[i];
res = buf + i + 1;
while (i >= 0) {
buf[i--] = 'A' + col % 26;
col /= 26;
}
return res;
}
char const *
col_name (int col)
{
static char buffer [3]; /* What if SHEET_MAX_COLS is changed ? */
static char buffer[8]; /* 26^7 > 2^32. */
char *res = col_name_internal (buffer, col);
*res = '\0';
return buffer;
......@@ -72,7 +81,7 @@ col_name (int col)
char const *
cols_name (int start_col, int end_col)
{
static char buffer [16]; /* Why is this 16 ? */
static char buffer[16]; /* See col_name. */
char *res = col_name_internal (buffer, start_col);
if (start_col != end_col) {
......@@ -110,14 +119,14 @@ col_parse (char const *str, int *res, unsigned char *relative)
inline static char *
row_name_internal (char *buf, int row)
{
int len = g_snprintf (buf, 6, "%d", row + 1); /* The 6 is hardcoded, see comments in row{s}_name */
int len = g_snprintf (buf, 4 * sizeof (int), "%d", row + 1);
return buf + len;
}
char const *
row_name (int row)
{
static char buffer [6]; /* What if SHEET_MAX_ROWS changes? */
static char buffer[4 * sizeof (int)];
char *res = row_name_internal (buffer, row);
*res = '\0';
return buffer;
......@@ -126,7 +135,7 @@ row_name (int row)
char const *
rows_name (int start_row, int end_row)
{
static char buffer [13]; /* What if SHEET_MAX_ROWS changes? */
static char buffer[2 * 4 * sizeof (int)];
char *res = row_name_internal (buffer, start_row);
if (start_row != end_row) {
......
......@@ -437,6 +437,14 @@ sheet_style_init (Sheet *sheet)
g_assert (SHEET_MAX_ROWS <= TILE_SIZE_ROW * TILE_SIZE_ROW * TILE_SIZE_ROW * TILE_SIZE_ROW);
g_return_if_fail (IS_SHEET (sheet));
if (SHEET_MAX_COLS > 364238) {
/* Oh, yeah? */
g_warning (_("This is a special version of Gnumeric. It has been compiled\n"
"with support for a very large number of rows. Access to the\n"
"column named TRUE may conflict with the constant of the same\n"
"name. Expect weirdness."));
}
sheet->style_data = g_new (SheetStyleData, 1);
sheet->style_data->style_hash =
g_hash_table_new (mstyle_hash, (GCompareFunc) mstyle_equal);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment