Commit c2479cad authored by Morten Welinder's avatar Morten Welinder Committed by Morten Welinder

Remove a number of evil fixed-length buffers.



2000-06-30  Morten Welinder  <terra@diku.dk>

	* src/solver-lp.c (write_constraint_str): Return an allocated
 	string instead of taking an unsized buffer.  Constify.  All
 	callers changed.
parent 264bc9c5
2000-06-30 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (write_constraint_str): Return an allocated
string instead of taking an unsized buffer. Constify. All
callers changed.
* plugins/Makefile.am (SUBDIRS): Delete text, ff-csv, and sample
plugins. Separate the remaining ones into file formats and
functions.
......
2000-06-30 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (write_constraint_str): Return an allocated
string instead of taking an unsized buffer. Constify. All
callers changed.
* plugins/Makefile.am (SUBDIRS): Delete text, ff-csv, and sample
plugins. Separate the remaining ones into file formats and
functions.
......
2000-06-30 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (write_constraint_str): Return an allocated
string instead of taking an unsized buffer. Constify. All
callers changed.
* plugins/Makefile.am (SUBDIRS): Delete text, ff-csv, and sample
plugins. Separate the remaining ones into file formats and
functions.
......
2000-06-30 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (write_constraint_str): Return an allocated
string instead of taking an unsized buffer. Constify. All
callers changed.
* plugins/Makefile.am (SUBDIRS): Delete text, ff-csv, and sample
plugins. Separate the remaining ones into file formats and
functions.
......
2000-06-30 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (write_constraint_str): Return an allocated
string instead of taking an unsized buffer. Constify. All
callers changed.
* plugins/Makefile.am (SUBDIRS): Delete text, ff-csv, and sample
plugins. Separate the remaining ones into file formats and
functions.
......
2000-06-30 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (write_constraint_str): Return an allocated
string instead of taking an unsized buffer. Constify. All
callers changed.
* plugins/Makefile.am (SUBDIRS): Delete text, ff-csv, and sample
plugins. Separate the remaining ones into file formats and
functions.
......
2000-06-30 Morten Welinder <terra@diku.dk>
* src/solver-lp.c (write_constraint_str): Return an allocated
string instead of taking an unsized buffer. Constify. All
callers changed.
* plugins/Makefile.am (SUBDIRS): Delete text, ff-csv, and sample
plugins. Separate the remaining ones into file formats and
functions.
......
......@@ -113,18 +113,14 @@ dialog_solver_options (Workbook *wb, Sheet *sheet)
}
static int
add_constraint(constraint_dialog_t *constraint_dialog,
int lhs_col, int lhs_row, int rhs_col, int rhs_row,
int cols, int rows, char *type_str)
add_constraint (constraint_dialog_t *constraint_dialog,
int lhs_col, int lhs_row, int rhs_col, int rhs_row,
int cols, int rows, const char *type_str)
{
SolverConstraint *constraint;
char constraint_buf[512];
char *constraint_str[2] = { constraint_buf, NULL };
char *constraint_str[2] = { NULL, NULL };
gint row;
write_constraint_str (constraint_buf, lhs_col, lhs_row, rhs_col,
rhs_row, type_str, cols, rows);
constraint = g_new (SolverConstraint, 1);
constraint->lhs.col = lhs_col;
constraint->lhs.row = lhs_row;
......@@ -132,12 +128,12 @@ add_constraint(constraint_dialog_t *constraint_dialog,
constraint->rhs.row = rhs_row;
constraint->cols = cols;
constraint->rows = rows;
constraint->str = constraint_str[0] =
write_constraint_str (lhs_col, lhs_row, rhs_col, rhs_row,
type_str, cols, rows);
constraint->type = g_strdup (type_str);
row = gtk_clist_append (constraint_dialog->clist, constraint_str);
constraint->type = g_malloc (strlen (type_str) + 1);
strcpy (constraint->type, type_str);
constraint->str = g_malloc (strlen (constraint_buf)+1);
strcpy (constraint->str, constraint_buf);
constraint_dialog->constraints =
g_slist_append(constraint_dialog->constraints,
(gpointer) constraint);
......@@ -380,8 +376,7 @@ loop:
v = gnumeric_dialog_run (data->wb, GNOME_DIALOG (dia));
if (v == 0) {
gchar buf[512];
gchar *constraint_str[2] = { buf, NULL };
gchar *constraint_str[2] = { NULL, NULL };
entry = gtk_entry_get_text (GTK_ENTRY (lhs_entry));
txt = (gchar *) cell_pos_name (&constraint->lhs);
if (strcmp (entry, txt) != 0) {
......@@ -449,13 +444,12 @@ loop:
constraint->cols = lhs_cols;
constraint->rows = lhs_rows;
write_constraint_str (buf, constraint->lhs.col,
constraint->lhs.row, constraint->rhs.col,
constraint->rhs.row, constraint->type,
constraint->cols, constraint->rows);
constraint->str = constraint_str[0] =
write_constraint_str (constraint->lhs.col, constraint->lhs.row,
constraint->rhs.col, constraint->rhs.row,
constraint->type,
constraint->cols, constraint->rows);
constraint->str = g_malloc (strlen (buf)+1);
strcpy (constraint->str, buf);
gtk_clist_remove (data->clist, selected_row);
gtk_clist_insert (data->clist, selected_row, constraint_str);
gtk_clist_set_row_data (data->clist, selected_row,
......@@ -792,15 +786,16 @@ dialog_solver (Workbook *wb, Sheet *sheet)
row = 0;
for (cur=constraint_dialog->constraints; cur != NULL; cur=cur->next) {
SolverConstraint *c = (SolverConstraint *) cur->data;
gchar buf[256];
gchar *tmp[] = { buf, NULL };
gchar *tmp[] = { NULL, NULL };
write_constraint_str (buf, c->lhs.col, c->lhs.row, c->rhs.col,
c->rhs.row, c->type, c->cols, c->rows);
tmp[0] = write_constraint_str (c->lhs.col, c->lhs.row,
c->rhs.col, c->rhs.row,
c->type, c->cols, c->rows);
gtk_clist_append (GTK_CLIST (constraint_list), tmp);
gtk_clist_set_row_data (GTK_CLIST (constraint_list), row++,
(gpointer) c);
g_free (tmp[0]);
}
gtk_widget_grab_focus (target_entry);
......
......@@ -267,8 +267,9 @@ simplex_copy_table (float_t *table, int cols, int rows)
return tbl;
}
int solver_simplex (Workbook *wb, Sheet *sheet, float_t **init_tbl,
float_t **final_tbl)
int
solver_simplex (Workbook *wb, Sheet *sheet, float_t **init_tbl,
float_t **final_tbl)
{
int i, n;
SolverParameters *param = &sheet->solver_parameters;
......@@ -537,9 +538,10 @@ make_solver_arrays (Sheet *sheet, SolverParameters *param, int n_variables,
return 0;
}
int solver_affine_scaling (Workbook *wb, Sheet *sheet,
float_t **x, /* the optimal solution */
float_t **sh_pr /* the shadow prizes */)
int
solver_affine_scaling (Workbook *wb, Sheet *sheet,
float_t **x, /* the optimal solution */
float_t **sh_pr /* the shadow prizes */)
{
SolverParameters *param = &sheet->solver_parameters;
GSList *constraints;
......@@ -626,30 +628,37 @@ int solver_affine_scaling (Workbook *wb, Sheet *sheet,
return SOLVER_LP_OPTIMAL;
}
void
write_constraint_str (char *buf, int lhs_col, int lhs_row, int rhs_col,
int rhs_row, char *type_str, int cols, int rows)
char *
write_constraint_str (int lhs_col, int lhs_row, int rhs_col,
int rhs_row, const char *type_str, int cols, int rows)
{
GString *buf = g_string_new ("");
char *result;
if (cols == 1 && rows == 1)
sprintf(buf, "%s %s ", cell_coord_name (lhs_col, lhs_row), type_str);
g_string_sprintfa (buf, "%s %s ", cell_coord_name (lhs_col, lhs_row), type_str);
else {
sprintf(buf, "%s", cell_coord_name (lhs_col, lhs_row));
strcat (buf, ":");
strcat (buf, cell_coord_name (lhs_col+cols-1, lhs_row+rows-1));
strcat (buf, " ");
strcat (buf, type_str);
strcat (buf, " ");
g_string_append (buf, cell_coord_name (lhs_col, lhs_row));
g_string_append_c (buf, ':');
g_string_append (buf, cell_coord_name (lhs_col + cols-1, lhs_row + rows - 1));
g_string_append_c (buf, ' ');
g_string_append (buf, type_str);
g_string_append_c (buf, ' ');
}
if (strcmp (type_str, "Int") != 0 && strcmp (type_str, "Bool") != 0) {
if (cols == 1 && rows == 1)
strcat(buf, cell_coord_name(rhs_col, rhs_row));
g_string_append (buf, cell_coord_name (rhs_col, rhs_row));
else {
strcat(buf, cell_coord_name(rhs_col, rhs_row));
strcat(buf, ":");
strcat(buf, cell_coord_name(rhs_col+cols-1, rhs_row+rows-1));
g_string_append (buf, cell_coord_name (rhs_col, rhs_row));
g_string_append_c (buf, ':');
g_string_append (buf, cell_coord_name (rhs_col + cols - 1, rhs_row + rows - 1));
}
}
result = buf->str;
g_string_free (buf, FALSE);
return result;
}
static void
......
......@@ -66,7 +66,7 @@ void solver_lp_reports (Workbook *wb, Sheet *sheet, GSList *ov,
gboolean answer, gboolean sensitivity,
gboolean limits);
void write_constraint_str (char *buf, int lhs_col, int lhs_row, int rhs_col,
int rhs_row, char *type_str, int cols, int rows);
char *write_constraint_str (int lhs_col, int lhs_row, int rhs_col, int rhs_row,
const char *type_str, int cols, int rows);
#endif
......@@ -2217,10 +2217,9 @@ xml_read_solver (Sheet *sheet, parse_xml_context_t *ctxt, xmlNodePtr tree,
c->type = "<=";
break;
}
write_constraint_str (buf, c->lhs.col, c->lhs.row, c->rhs.col,
c->rhs.row, c->type, c->cols, c->rows);
c->str = g_new (char, strlen (buf)+1);
strcpy (c->str, buf);
c->str = write_constraint_str (c->lhs.col, c->lhs.row,
c->rhs.col, c->rhs.row,
c->type, c->cols, c->rows);
param->constraints = g_slist_append (param->constraints, c);
child = xml_search_child (child, "Constr");
......@@ -3235,4 +3234,3 @@ xml_init (void)
file_format_register_save (".gnumeric", desc, FILE_FL_AUTO,
gnumeric_xml_write_workbook);
}
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