Use glib memory routines. Fix some memory leaks.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2647 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas
2000-08-08 04:05:38 +00:00
parent 94033d39ec
commit 474877730d
31 changed files with 423 additions and 392 deletions

View File

@@ -1,5 +1,10 @@
2000-08-07 Dave Peticolas <dave@krondo.com>
* src/register/*.c: Use glib memory allocation routines.
* src/register/cellblock.c: fix memory leaks and use glib memory
allocation routines.
* src/register/table-allgui.c: reimplement the Table code using
glib's dynamic arrays. Clean up the code and homogenize the
function naming convention.

View File

@@ -232,9 +232,7 @@ xaccSRInitRegisterData(SplitRegister *reg)
if (reg == NULL)
return;
/* calloc initializes to 0 */
info = calloc(1, sizeof(SRInfo));
assert(info != NULL);
info = g_new0(SRInfo, 1);
info->last_date_entered = time(NULL);
@@ -247,8 +245,7 @@ xaccSRDestroyRegisterData(SplitRegister *reg)
if (reg == NULL)
return;
if (reg->user_data != NULL)
free(reg->user_data);
g_free(reg->user_data);
reg->user_data = NULL;
}
@@ -261,7 +258,7 @@ xaccSRGetInfo(SplitRegister *reg)
if (reg->user_data == NULL)
xaccSRInitRegisterData(reg);
return (SRInfo *) reg->user_data;
return reg->user_data;
}
static gncUIWidget

View File

@@ -65,34 +65,39 @@ typedef struct {
} FoundationCBData;
static void
foundation_query_yes_cb(GtkWidget *w, gpointer data) {
foundation_query_yes_cb(GtkWidget *w, gpointer data)
{
int *result = (int *) data;
*result = GNC_QUERY_YES;
}
static void
foundation_query_no_cb(GtkWidget *w, gpointer data) {
foundation_query_no_cb(GtkWidget *w, gpointer data)
{
int *result = (int *) data;
*result = GNC_QUERY_NO;
}
static void
foundation_query_cancel_cb(GtkWidget *w, gpointer data) {
foundation_query_cancel_cb(GtkWidget *w, gpointer data)
{
int *result = (int *) data;
*result = GNC_QUERY_CANCEL;
}
static gboolean
foundation_query_delete_cb(GtkWidget *w, GdkEvent *event, gpointer data) {
foundation_query_delete_cb(GtkWidget *w, GdkEvent *event, gpointer data)
{
FoundationCBData * cb_data = (FoundationCBData *) data;
*(cb_data->dialog_result) = cb_data->delete_result;
return(FALSE);
}
static gint
foundation_query_close_cb(GtkWidget *w, gpointer data) {
free(data);
return(FALSE);
foundation_query_close_cb(GtkWidget *w, gpointer data)
{
g_free(data);
return FALSE;
}
GtkWidget *
@@ -157,14 +162,12 @@ gnc_foundation_query_dialog(gncUIWidget parent,
}
/* Allocate our resources */
cb_data = malloc(sizeof(FoundationCBData));
if (cb_data == NULL)
return NULL;
cb_data = g_new(FoundationCBData, 1);
query_dialog = gnome_dialog_newv(title, button_names);
if (query_dialog == NULL) {
free(cb_data);
g_free(cb_data);
return NULL;
}
@@ -185,12 +188,12 @@ gnc_foundation_query_dialog(gncUIWidget parent,
gtk_signal_connect(GTK_OBJECT(query_dialog),
"delete_event",
GTK_SIGNAL_FUNC(foundation_query_delete_cb),
(gpointer) cb_data);
cb_data);
gtk_signal_connect(GTK_OBJECT(query_dialog),
"close",
GTK_SIGNAL_FUNC(foundation_query_close_cb),
(gpointer) cb_data);
cb_data);
/* Setup window settings */
gtk_window_set_modal(GTK_WINDOW(query_dialog), GNC_T);
@@ -210,6 +213,7 @@ gnc_foundation_query_dialog(gncUIWidget parent,
return query_dialog;
}
/********************************************************************\
* gnc_ok_cancel_dialog_parented *
* display a message, and asks the user to press "Ok" or "Cancel" *
@@ -533,10 +537,7 @@ gnc_choose_item_from_list_dialog(const char *title, SCM list_items)
num_items = gh_length(list_items);
cb_data = (ChooseItemCBData *) malloc(sizeof(ChooseItemCBData) * num_items);
if(cb_data == NULL)
return SCM_BOOL_F;
cb_data = g_new(ChooseItemCBData, num_items);
/* Convert the scm data to C callback structs */
i = 0;
@@ -574,7 +575,7 @@ gnc_choose_item_from_list_dialog(const char *title, SCM list_items)
if(!status_ok) {
fprintf(stderr, "Dying after copy.\n");
free(cb_data);
g_free(cb_data);
return SCM_BOOL_F;
}
@@ -597,7 +598,7 @@ gnc_choose_item_from_list_dialog(const char *title, SCM list_items)
if(!status_ok) {
fprintf(stderr, "Dying after buttons.\n");
gtk_widget_unref(vbox);
free(cb_data);
g_free(cb_data);
return SCM_BOOL_F;
}
@@ -614,7 +615,7 @@ gnc_choose_item_from_list_dialog(const char *title, SCM list_items)
&dialog_result);
if(query_box == NULL) {
free(cb_data);
g_free(cb_data);
return SCM_BOOL_F;
}
@@ -639,9 +640,9 @@ gnc_choose_item_from_list_dialog(const char *title, SCM list_items)
break;
}
free(cb_data);
g_free(cb_data);
return(result);
return result;
}

View File

@@ -49,12 +49,14 @@ struct _AdjBWindow
GtkWidget * date_entry; /* Date field, the date for the balance */
};
/** GLOBALS *********************************************************/
static AdjBWindow **adjBList = NULL;
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_GUI;
/** Prototypes ******************************************************/
static void gnc_adjb_set_window_name(AdjBWindow *adjBData);

View File

@@ -97,14 +97,10 @@ gnc_html_data_new(const char *title, HTMLUserData user_data,
{
HTMLData *data;
data = malloc(sizeof(HTMLData));
assert(data != NULL);
data = g_new(HTMLData, 1);
if (title != NULL)
{
data->title = strdup(title);
assert(title != NULL);
}
data->title = g_strdup(title);
else
data->title = NULL;
@@ -114,8 +110,7 @@ gnc_html_data_new(const char *title, HTMLUserData user_data,
{
int i;
data->user_buttons = calloc(num_user_buttons, sizeof(GnomeUIInfo));
assert(data->user_buttons != NULL);
data->user_buttons = g_new0(GnomeUIInfo, num_user_buttons);
for (i = 0; i < num_user_buttons; i++)
data->user_buttons[i] = user_buttons[i];
@@ -135,12 +130,10 @@ html_data_destroy(HTMLData *data)
if (data == NULL)
return;
if (data->title != NULL)
free(data->title);
g_free(data->title);
data->title = NULL;
if (data->user_buttons != NULL)
free(data->user_buttons);
g_free(data->user_buttons);
data->user_buttons = NULL;
data->num_user_buttons = 0;
@@ -150,7 +143,7 @@ html_data_destroy(HTMLData *data)
data->destroy = NULL;
free(data);
g_free(data);
}
static HTMLHistoryNode *
@@ -158,8 +151,7 @@ history_node_new(HTMLData *data)
{
HTMLHistoryNode *new;
new = malloc(sizeof(HTMLHistoryNode));
assert(new != NULL);
new = g_new(HTMLHistoryNode, 1);
new->data = data;
new->last = NULL;
@@ -171,7 +163,7 @@ history_node_new(HTMLData *data)
/* Insert a history element into history. Return TRUE if this
* is the first element in the history. If not last element
* in history, all next pages are deleted */
static gncBoolean
static gboolean
historyInsert(HTMLHistory *history, HTMLData *data)
{
HTMLHistoryNode *new;
@@ -194,7 +186,7 @@ historyInsert(HTMLHistory *history, HTMLData *data)
history->current_node->next = temp->next;
html_data_destroy(temp->data);
temp->data = NULL;
free(temp);
g_free(temp);
temp = history->current_node->next;
}
@@ -257,13 +249,13 @@ historyClear(HTMLHistory *history)
history->current_node->next = temp->next;
html_data_destroy(temp->data);
temp->data = NULL;
free(temp);
g_free(temp);
}
/* delete current page: */
html_data_destroy(history->current_node->data);
history->current_node->data = NULL;
free(history->current_node);
g_free(history->current_node);
history->current_node = NULL;
}
@@ -295,8 +287,7 @@ historyNew()
{
HTMLHistory *history;
history = malloc(sizeof(HTMLHistory));
assert(history != NULL);
history = g_new(HTMLHistory, 1);
history->current_node = NULL;
@@ -310,7 +301,7 @@ historyDestroy(HTMLHistory *history)
return;
historyClear(history);
free(history);
g_free(history);
}
@@ -343,7 +334,7 @@ struct _HTMLWindow
/** PROTOTYPES ******************************************************/
static void htmlBackCB(GtkWidget *widget, gpointer data);
static void htmlBackCB(GtkWidget *widget, gpointer data);
static void htmlFwdCB(GtkWidget *widget, gpointer data);
static void htmlPrintCB(GtkWidget * widget, gpointer data);

View File

@@ -677,9 +677,7 @@ gnc_ui_reconcile_window_delete_cb(GtkButton *button, gpointer data)
* their register windows after the deletion. */
trans = xaccSplitGetParent(split);
num_splits = xaccTransCountSplits(trans);
affected_accounts = (Account **) malloc((num_splits + 1) *
sizeof(Account *));
assert(affected_accounts != NULL);
affected_accounts = g_new(Account *, num_splits + 1);
for (i = 0; i < num_splits; i++)
{
@@ -694,7 +692,7 @@ gnc_ui_reconcile_window_delete_cb(GtkButton *button, gpointer data)
gnc_account_list_ui_refresh(affected_accounts);
free(affected_accounts);
g_free(affected_accounts);
gnc_refresh_main_window ();
}

View File

@@ -1454,7 +1454,7 @@ gnc_register_record_cb(GnucashRegister *reg, gpointer data)
static void
gnc_register_destroy_cb(GtkWidget *widget, gpointer data)
{
RegWindow *regData = (RegWindow *) data;
RegWindow *regData = data;
closeRegWindow(widget, regData);
}
@@ -1554,9 +1554,9 @@ regWindowLedger(xaccLedgerDisplay *ledger)
if (regData != NULL)
return regData;
regData = (RegWindow *) malloc(sizeof (RegWindow));
regData = g_new(RegWindow, 1);
ledger->gui_hook = (void *) regData;
ledger->gui_hook = regData;
ledger->redraw = regRefresh;
ledger->destroy = regDestroy;
ledger->set_help = regSetHelp;
@@ -1882,7 +1882,7 @@ closeRegWindow(GtkWidget * widget, RegWindow *regData)
regData->date_window = NULL;
}
free(regData);
g_free(regData);
DEBUG("closed RegWindow\n");
}

View File

@@ -2,6 +2,7 @@
* QuickFill.h -- the quickfill tree data structure *
* Copyright (C) 1997 Robin D. Clark *
* Copyright (C) 1998 Linas Vepstas *
* Copyright (C) 2000 Dave Peticolas *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@@ -30,22 +31,19 @@
#include "QuickFill.h"
#include "util.h"
/** PROTOTYPES ******************************************************/
static void qfInsertTextRec( QuickFill *qf, const char * text, int depth,
QuickFillSort sort );
static void qfInsertTextRec(QuickFill *qf, const char * text, int depth,
QuickFillSort sort);
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_REGISTER;
/********************************************************************\
* Because I can't use C++ for this project, doesn't mean that I *
* can't pretend too! These functions perform actions on the *
* QuickFill tree structure, in order to encapsulate the knowledge *
* of the internals of QuickFill into one file. *
\********************************************************************/
/********************************************************************\
\********************************************************************/
static int
CHAR_TO_INDEX( char c )
CHAR_TO_INDEX(char c)
{
int index = toupper(c);
@@ -58,58 +56,61 @@ CHAR_TO_INDEX( char c )
/********************************************************************\
\********************************************************************/
QuickFill *
xaccMallocQuickFill( void )
xaccMallocQuickFill(void)
{
QuickFill *qf;
int i;
QuickFill *qf = (QuickFill *)malloc(sizeof(QuickFill));
for( i=0; i<QFNUM; i++ )
qf = g_new(QuickFill, 1);
for(i = 0; i < QFNUM; i++)
qf->qf[i] = NULL;
qf->text = NULL;
return qf;
}
/********************************************************************\
\********************************************************************/
void
xaccFreeQuickFill( QuickFill *qf )
xaccFreeQuickFill(QuickFill *qf)
{
int i;
if (qf == NULL )
return;
for( i=0; i<QFNUM; i++ )
for(i = 0; i < QFNUM; i++)
{
xaccFreeQuickFill( qf->qf[i] );
xaccFreeQuickFill(qf->qf[i]);
qf->qf[i] = NULL;
}
if (qf->text != NULL)
free(qf->text);
g_free(qf->text);
qf->text = NULL;
free(qf);
g_free(qf);
}
/********************************************************************\
\********************************************************************/
QuickFill *
xaccGetQuickFill( QuickFill *qf, char c )
xaccGetQuickFill(QuickFill *qf, char c)
{
if (qf == NULL)
return NULL;
DEBUG("xaccGetQuickFill(): index = %d\n",CHAR_TO_INDEX(c));
return qf->qf[CHAR_TO_INDEX(c)];
}
/********************************************************************\
\********************************************************************/
QuickFill *
xaccGetQuickFillStrLen( QuickFill *qf, const char *str, int len )
xaccGetQuickFillStrLen(QuickFill *qf, const char *str, int len)
{
if (str == NULL)
return NULL;
@@ -130,7 +131,7 @@ xaccGetQuickFillStrLen( QuickFill *qf, const char *str, int len )
/********************************************************************\
\********************************************************************/
QuickFill *
xaccGetQuickFillStr( QuickFill *qf, const char *str )
xaccGetQuickFillStr(QuickFill *qf, const char *str)
{
if (str == NULL)
return NULL;
@@ -155,7 +156,7 @@ xaccGetQuickFillUniqueLen( QuickFill *qf, int * length )
while (1)
{
count = 0;
for( i=0; i<QFNUM; i++ )
for(i = 0; i < QFNUM; i++)
{
if (qf->qf[i] != NULL)
{
@@ -178,9 +179,9 @@ xaccGetQuickFillUniqueLen( QuickFill *qf, int * length )
/********************************************************************\
\********************************************************************/
void
xaccQFInsertText( QuickFill *qf, const char * text, QuickFillSort sort )
xaccQFInsertText(QuickFill *qf, const char * text, QuickFillSort sort)
{
qfInsertTextRec( qf, text, 0, sort );
qfInsertTextRec(qf, text, 0, sort);
}
/********************************************************************\
@@ -195,7 +196,7 @@ qfInsertTextRec( QuickFill *qf, const char *text, int depth,
{
if( text[depth] != '\0' )
{
int index = CHAR_TO_INDEX( text[depth] );
int index = CHAR_TO_INDEX(text[depth]);
if( qf->qf[index] == NULL )
qf->qf[index] = xaccMallocQuickFill();
@@ -210,12 +211,13 @@ qfInsertTextRec( QuickFill *qf, const char *text, int depth,
default:
/* store text in LIFO order, recent
* stuff shows up before old stuff */
if (qf->qf[index]->text) free (qf->qf[index]->text);
qf->qf[index]->text = strdup (text);
if (qf->qf[index]->text)
g_free (qf->qf[index]->text);
qf->qf[index]->text = g_strdup (text);
break;
}
qfInsertTextRec( qf->qf[index], text, ++depth, sort );
qfInsertTextRec(qf->qf[index], text, ++depth, sort);
}
}
}

View File

@@ -2,6 +2,7 @@
* QuickFill.h -- the quickfill tree data structure *
* Copyright (C) 1997 Robin D. Clark *
* Copyright (C) 1998 Linas Vepstas *
* Copyright (C) 2000 Dave Peticolas *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@@ -22,8 +23,8 @@
* *
\********************************************************************/
#ifndef __XACC_QUICKFILL_H__
#define __XACC_QUICKFILL_H__
#ifndef __QUICKFILL_H__
#define __QUICKFILL_H__
#include "config.h"
@@ -59,6 +60,7 @@ typedef struct _quickfill {
struct _quickfill *qf[QFNUM]; /* array of children in the tree */
} QuickFill;
/** PROTOTYPES ******************************************************/
QuickFill *xaccMallocQuickFill( void );
@@ -69,6 +71,5 @@ QuickFill *xaccGetQuickFillStrLen( QuickFill *qf, const char *str, int len );
QuickFill *xaccGetQuickFillUniqueLen( QuickFill *qf, int *len );
void xaccQFInsertText( QuickFill *qf, const char *text, QuickFillSort );
/** GLOBALS *********************************************************/
#endif /* __XACC_QUICKFILL_H__ */
#endif /* __QUICKFILL_H__ */

View File

@@ -28,6 +28,7 @@
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas <dave@krondo.com>
*/
#include <stdlib.h>
@@ -35,13 +36,17 @@
#include "basiccell.h"
/* ===================================================== */
BasicCell * xaccMallocBasicCell (void)
{
BasicCell * cell;
cell = (BasicCell *) malloc (sizeof (BasicCell));
cell = g_new(BasicCell, 1);
xaccInitBasicCell (cell);
return cell;
}
@@ -51,10 +56,10 @@ static char *
BasicCellHelpValue(BasicCell *cell)
{
if ((cell->value != NULL) && (cell->value[0] != 0))
return strdup(cell->value);
return g_strdup(cell->value);
if (cell->blank_help != NULL)
return strdup(cell->blank_help);
return g_strdup(cell->blank_help);
return NULL;
}
@@ -64,13 +69,15 @@ BasicCellHelpValue(BasicCell *cell)
void xaccInitBasicCell (BasicCell *cell)
{
cell->input_output = XACC_CELL_ALLOW_ALL;
cell->changed = 0;
cell->bg_color = 0xffffff; /* white */
cell->fg_color = 0x0; /* black */
cell->use_bg_color = 0; /* ignore the color */
cell->use_fg_color = 0; /* ignore the color */
cell->value = NULL;
cell->blank_help = NULL;
cell->changed = 0;
cell->set_value = NULL;
cell->enter_cell = NULL;
cell->modify_verify = NULL;
@@ -80,6 +87,7 @@ void xaccInitBasicCell (BasicCell *cell)
cell->move = NULL;
cell->destroy = NULL;
cell->get_help_value = BasicCellHelpValue;
cell->gui_private = NULL;
}
@@ -88,46 +96,43 @@ void xaccInitBasicCell (BasicCell *cell)
void xaccDestroyBasicCell (BasicCell *cell)
{
/* give any gui elements a chance to clean up */
if (cell->destroy) {
(*(cell->destroy)) (cell);
}
if (cell->destroy)
(*(cell->destroy)) (cell);
/* free up data strings */
if (cell->value) {
free (cell->value);
}
g_free (cell->value);
cell->value = NULL;
if (cell->blank_help) {
free (cell->blank_help);
}
g_free (cell->blank_help);
cell->blank_help = NULL;
/* help prevent access to freed memory */
xaccInitBasicCell (cell);
/* free the object itself */
free (cell);
g_free (cell);
}
/* ===================================================== */
void xaccSetBasicCellValue (BasicCell *cell, const char *val)
{
void (*cb) (BasicCell *, const char *);
CellSetValueFunc cb;
cb = cell->set_value;
if (cb) {
/* avoid recursion by disabling the
* callback while it's being called. */
cell->set_value = NULL;
(*cb) (cell, val);
cb (cell, val);
cell->set_value = cb;
} else {
if (cell->value) free (cell->value);
if (val) {
cell->value = strdup (val);
} else {
cell->value = strdup("");
}
}
else {
g_free (cell->value);
if (val)
cell->value = g_strdup (val);
else
cell->value = g_strdup ("");
}
}
@@ -140,12 +145,12 @@ xaccSetBasicCellBlankHelp (BasicCell *cell, const char *blank_help)
return;
if (cell->blank_help != NULL)
free(cell->blank_help);
g_free(cell->blank_help);
if (blank_help == NULL)
cell->blank_help = NULL;
else
cell->blank_help = strdup(blank_help);
cell->blank_help = g_strdup(blank_help);
}
/* ===================================================== */

View File

@@ -180,10 +180,11 @@
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas <dave@krondo.com>
*/
#ifndef __XACC_BASIC_CELL_H__
#define __XACC_BASIC_CELL_H__
#ifndef __BASIC_CELL_H__
#define __BASIC_CELL_H__
#include <glib.h>
@@ -287,5 +288,5 @@ char * xaccBasicCellGetHelp (BasicCell *);
void xaccBasicCellSetChanged (BasicCell *, gncBoolean);
#endif /* __XACC_BASIC_CELL_H__ */
#endif /* __BASIC_CELL_H__ */
/* ------------------ end of file ---------------------- */

View File

@@ -28,6 +28,7 @@
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#include <stdlib.h>
@@ -35,7 +36,8 @@
/* =================================================== */
CellBlock * xaccMallocCellBlock (int numrows, int numcols)
CellBlock *
xaccMallocCellBlock (int numrows, int numcols)
{
CellBlock *cellblock;
@@ -69,60 +71,68 @@ CellBlock * xaccMallocCellBlock (int numrows, int numcols)
static void
FreeCellBlockMem (CellBlock *cellblock)
{
int i;
int oldrows, oldcols;
int i;
oldrows = cellblock->numRows;
oldcols = cellblock->numCols;
/* free cell array, if any */
if (cellblock->cells) {
for (i=0; i<oldrows; i++) {
if (cellblock->cells[i])
free (cellblock->cells[i]);
}
free (cellblock->cells);
if (cellblock->cells)
{
for (i = 0; i < oldrows; i++)
g_free (cellblock->cells[i]);
g_free (cellblock->cells);
cellblock->cells = NULL;
}
/* free label array, if any */
if (cellblock->cell_types) {
for (i=0; i<oldrows; i++) {
if (cellblock->cell_types[i])
free (cellblock->cell_types[i]);
}
/* free cell type array, if any */
if (cellblock->cell_types)
{
for (i = 0; i < oldrows; i++)
g_free (cellblock->cell_types[i]);
g_free (cellblock->cell_types);
cellblock->cell_types = NULL;
}
/* free right traversal chain */
if (cellblock->right_traverse_r) {
for (i=0; i<oldrows; i++) {
if (cellblock->right_traverse_r[i])
free (cellblock->right_traverse_r[i]);
}
if (cellblock->right_traverse_r)
{
for (i = 0; i < oldrows; i++)
g_free (cellblock->right_traverse_r[i]);
g_free(cellblock->right_traverse_r);
cellblock->right_traverse_r = NULL;
}
if (cellblock->right_traverse_c) {
for (i=0; i<oldrows; i++) {
if (cellblock->right_traverse_c[i])
free (cellblock->right_traverse_c[i]);
}
if (cellblock->right_traverse_c)
{
for (i = 0; i < oldrows; i++)
g_free (cellblock->right_traverse_c[i]);
g_free(cellblock->right_traverse_c);
cellblock->right_traverse_c = NULL;
}
/* free left traversal chain */
if (cellblock->left_traverse_r) {
for (i=0; i<oldrows; i++) {
if (cellblock->left_traverse_r[i])
free (cellblock->left_traverse_r[i]);
}
if (cellblock->left_traverse_r)
{
for (i = 0; i < oldrows; i++)
g_free (cellblock->left_traverse_r[i]);
g_free(cellblock->left_traverse_r);
cellblock->left_traverse_r = NULL;
}
if (cellblock->left_traverse_c) {
for (i=0; i<oldrows; i++) {
if (cellblock->left_traverse_c[i])
free (cellblock->left_traverse_c[i]);
}
if (cellblock->left_traverse_c)
{
for (i = 0; i < oldrows; i++)
g_free (cellblock->left_traverse_c[i]);
g_free(cellblock->left_traverse_c);
cellblock->left_traverse_c = NULL;
}
/* free widths, alignments */
if (cellblock->widths) free (cellblock->widths);
if (cellblock->alignments) free (cellblock->alignments);
g_free (cellblock->widths);
cellblock->widths = NULL;
g_free (cellblock->alignments);
cellblock->alignments = NULL;
}
/* =================================================== */
@@ -131,6 +141,7 @@ void
xaccInitCellBlock (CellBlock *cellblock, int numrows, int numcols)
{
int i, j;
if (!cellblock) return;
FreeCellBlockMem (cellblock);
@@ -140,11 +151,11 @@ xaccInitCellBlock (CellBlock *cellblock, int numrows, int numcols)
cellblock->numCols = numcols;
/* malloc new cell array */
cellblock->cells = malloc (numrows * sizeof (BasicCell **));
cellblock->cell_types = malloc (numrows * sizeof (short *));
for (i=0; i<numrows; i++) {
(cellblock->cells)[i] = malloc (numcols * sizeof (BasicCell *));
(cellblock->cell_types)[i] = malloc (numcols * sizeof (short));
cellblock->cells = g_new(BasicCell **, numrows);
cellblock->cell_types = g_new(short *, numrows);
for (i = 0; i < numrows; i++) {
(cellblock->cells)[i] = g_new(BasicCell *, numcols);
(cellblock->cell_types)[i] = g_new(short, numcols);
for (j=0; j<numcols; j++) {
(cellblock->cells)[i][j] = NULL;
(cellblock->cell_types)[i][j] = -1;
@@ -152,12 +163,12 @@ xaccInitCellBlock (CellBlock *cellblock, int numrows, int numcols)
}
/* malloc new right traversal arrays */
cellblock->right_traverse_r = malloc (numrows * sizeof (short *));
cellblock->right_traverse_c = malloc (numrows * sizeof (short *));
for (i=0; i<numrows; i++) {
(cellblock->right_traverse_r)[i] = malloc (numcols * sizeof (short));
(cellblock->right_traverse_c)[i] = malloc (numcols * sizeof (short));
for (j=0; j<numcols-1; j++) {
cellblock->right_traverse_r = g_new(short *, numrows);
cellblock->right_traverse_c = g_new(short *, numrows);
for (i = 0; i < numrows; i++) {
(cellblock->right_traverse_r)[i] = g_new(short, numcols);
(cellblock->right_traverse_c)[i] = g_new(short, numcols);
for (j = 0; j < numcols - 1; j++) {
/* default traversal is same row, next column */
(cellblock->right_traverse_r)[i][j] = i;
(cellblock->right_traverse_c)[i][j] = j+1;
@@ -171,16 +182,16 @@ xaccInitCellBlock (CellBlock *cellblock, int numrows, int numcols)
(cellblock->right_traverse_c)[numrows-1][numcols-1] = 0;
/* last is last ... */
cellblock->last_reenter_traverse_row = numrows-1;
cellblock->last_reenter_traverse_col = numcols-1;
cellblock->last_reenter_traverse_row = numrows - 1;
cellblock->last_reenter_traverse_col = numcols - 1;
/* malloc new left traversal arrays */
cellblock->left_traverse_r = malloc (numrows * sizeof (short *));
cellblock->left_traverse_c = malloc (numrows * sizeof (short *));
for (i=0; i<numrows; i++) {
(cellblock->left_traverse_r)[i] = malloc (numcols * sizeof (short));
(cellblock->left_traverse_c)[i] = malloc (numcols * sizeof (short));
for (j=0; j<numcols-1; j++) {
cellblock->left_traverse_r = g_new(short *, numrows);
cellblock->left_traverse_c = g_new(short *, numrows);
for (i = 0; i < numrows; i++) {
(cellblock->left_traverse_r)[i] = g_new(short, numcols);
(cellblock->left_traverse_c)[i] = g_new(short, numcols);
for (j = 0; j < numcols-1; j++) {
/* default traversal is same row, previous column */
(cellblock->left_traverse_r)[i][j] = i;
(cellblock->left_traverse_c)[i][j] = j-1;
@@ -196,11 +207,11 @@ xaccInitCellBlock (CellBlock *cellblock, int numrows, int numcols)
/* first is last ... */
cellblock->last_left_reenter_traverse_row = 0;
cellblock->last_left_reenter_traverse_col = 0;
cellblock->widths = malloc (numcols * sizeof(short));
cellblock->alignments = malloc (numcols * sizeof(Alignments));
for (j=0; j<numcols; j++) {
cellblock->widths = g_new(short, numcols);
cellblock->alignments = g_new(Alignments, numcols);
for (j = 0; j < numcols; j++) {
cellblock->widths[j] = 0;
cellblock->alignments[j] = ALIGN_RIGHT;
}
@@ -222,8 +233,9 @@ xaccDestroyCellBlock (CellBlock *cellblock)
/* =================================================== */
void
xaccNextRight (CellBlock *cellblock, int row, int col,
int next_row, int next_col)
xaccNextRight (CellBlock *cellblock,
int row, int col,
int next_row, int next_col)
{
if (!cellblock) return;

View File

@@ -53,6 +53,7 @@
*
* HISTORY:
* Copyright (c) 1988 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#ifndef __XACC_CELL_BLOCK_H__

View File

@@ -39,18 +39,21 @@
* HISTORY:
* Created Jan 1998 Linas Vepstas
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#ifndef __XACC_COMBO_CELL_H__
#define __XACC_COMBO_CELL_H__
#ifndef __COMBO_CELL_H__
#define __COMBO_CELL_H__
#include "basiccell.h"
#include "gnc-common.h"
typedef struct _ComboCell {
BasicCell cell;
} ComboCell;
ComboCell * xaccMallocComboCell (void);
void xaccInitComboCell (ComboCell *);
void xaccDestroyComboCell (ComboCell *);
@@ -62,7 +65,7 @@ void xaccAddComboCellMenuItem (ComboCell *, char * menustr);
/* Determines whether the cell will accept strings not in the
* menu. Defaults to strict, i.e., only menu items are accepted. */
void xaccComboCellSetStrict (ComboCell *, gncBoolean);
void xaccComboCellSetStrict (ComboCell *, gboolean);
/* Sets a character used for special completion processing. */
void xaccComboCellSetCompleteChar (ComboCell *, char);
@@ -78,8 +81,8 @@ void xaccComboCellSetIgnoreHelp (ComboCell *, const char *);
/* Determines whether combocells are automatically raised upon typing.
* Defaults to false. This is a 'class' method. */
void xaccComboCellSetAutoPop (gncBoolean auto_pop_combos);
void xaccComboCellSetAutoPop (gboolean auto_pop_combos);
#endif /* __XACC_COMBO_CELL_H__ */
#endif /* __COMBO_CELL_H__ */
/* --------------- end of file ---------------------- */

View File

@@ -28,6 +28,7 @@
* HISTORY:
* Copyright (C) 1997 Robin D. Clark
* Copyright (c) 1998, 1999, 2000 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#include <ctype.h>
@@ -42,26 +43,25 @@
#include "basiccell.h"
#include "datecell.h"
static void setDateCellValue (BasicCell *, const char *);
#define SET(cell,str) { \
if ((cell)->value) free ((cell)->value); \
(cell)->value = strdup (str); \
}
static void setDateCellValue (BasicCell *, const char *);
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_REGISTER;
/* ================================================ */
static void
xaccParseDate (struct tm *parsed, const char * datestr)
{
int iday, imonth, iyear;
if (!parsed) return;
if (!datestr) return;
scanDate(datestr, &iday, &imonth, &iyear);
parsed->tm_mday = iday;
parsed->tm_mon = imonth-1;
parsed->tm_year = iyear-1900;
@@ -95,11 +95,11 @@ DateCellHelpValue(BasicCell *bcell)
strftime(string, sizeof(string), "%A %d %B %Y", &time);
return strdup(string);
return g_strdup(string);
}
if (bcell->blank_help != NULL)
return strdup(bcell->blank_help);
return g_strdup(bcell->blank_help);
return NULL;
}
@@ -107,15 +107,16 @@ DateCellHelpValue(BasicCell *bcell)
/* ================================================ */
static const char *
DateEnter (BasicCell *_cell, const char * curr,
DateEnter (BasicCell *_cell,
const char * curr,
int *cursor_position,
int *start_selection,
int *end_selection)
{
DateCell *cell = (DateCell *) _cell;
/* OK, we just entered a new cell. Find out
* what date that cell thinks it has. */
/* OK, we just entered a new cell. Find out
* what date that cell thinks it has. */
xaccParseDate (&(cell->date), curr);
return curr;
@@ -134,10 +135,9 @@ DateMV (BasicCell *_cell,
int *end_selection)
{
DateCell *cell = (DateCell *) _cell;
gncBoolean accept = GNC_F;
gboolean accept = GNC_F;
struct tm *date;
char buff[30];
char *datestr;
/* if user hit backspace, accept the change */
if (change == NULL) accept = GNC_T;
@@ -146,9 +146,9 @@ DateMV (BasicCell *_cell,
{
int i, count = 0;
char separator = dateSeparator();
gncBoolean ok = GNC_T;
gncBoolean ok = TRUE;
for (i=0; 0 != change[i]; i++)
for (i = 0; 0 != change[i]; i++)
{
/* accept only numbers or a date separator. Note that the
* separator of '-' (for DATE_FORMAT_ISO) takes precedence
@@ -173,8 +173,8 @@ DateMV (BasicCell *_cell,
/* keep a copy of the new value */
if (accept) {
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (newval);
g_free (cell->cell.value);
cell->cell.value = g_strdup (newval);
xaccParseDate (&(cell->date), newval);
return newval;
}
@@ -259,12 +259,10 @@ DateMV (BasicCell *_cell,
printDate (buff, date->tm_mday, date->tm_mon+1, date->tm_year+1900);
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (buff);
g_free (cell->cell.value);
cell->cell.value = g_strdup (buff);
datestr = strdup (buff);
return datestr;
return g_strdup (buff);
}
/* ================================================ */
@@ -274,7 +272,6 @@ DateLeave (BasicCell *_cell, const char * curr)
{
DateCell *cell = (DateCell *) _cell;
char buff[30];
char * retval;
/* OK, we are leaving the cell. Find out
* what date that cell thinks it has. */
@@ -284,11 +281,10 @@ DateLeave (BasicCell *_cell, const char * curr)
cell->date.tm_mon+1,
cell->date.tm_year+1900);
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (buff);
g_free (cell->cell.value);
cell->cell.value = g_strdup (buff);
retval = strdup (buff);
return retval;
return g_strdup (buff);
}
/* ================================================ */
@@ -303,14 +299,17 @@ xaccCommitDateCell (DateCell *cell)
char buff[30];
if (!cell) return;
ENTER ("value is %s \n", cell->cell.value);
xaccParseDate (&(cell->date), cell->cell.value);
printDate (buff, cell->date.tm_mday,
cell->date.tm_mon+1,
cell->date.tm_year+1900);
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (buff);
g_free (cell->cell.value);
cell->cell.value = g_strdup (buff);
LEAVE ("value is %s \n", cell->cell.value);
}
@@ -333,8 +332,11 @@ DateCell *
xaccMallocDateCell (void)
{
DateCell *cell;
cell = (DateCell *) malloc (sizeof (DateCell));
cell = g_new(DateCell, 1);
xaccInitDateCell (cell);
return cell;
}
@@ -355,7 +357,8 @@ xaccInitDateCell (DateCell *cell)
cell->date = *now;
printDate (buff, now->tm_mday, now->tm_mon+1, now->tm_year+1900);
SET (&(cell->cell), buff);
g_free (cell->cell.value);
cell->cell.value = g_strdup (buff);
cell->cell.enter_cell = DateEnter;
cell->cell.modify_verify = DateMV;
@@ -372,7 +375,8 @@ xaccDestroyDateCell (DateCell *cell)
cell->date.tm_mday = 0;
cell->date.tm_mon = 0;
cell->date.tm_year = 0;
xaccDestroyBasicCell ( &(cell->cell));
xaccDestroyBasicCell (&(cell->cell));
}
/* ================================================ */
@@ -388,14 +392,15 @@ xaccSetDateCellValue (DateCell *cell, int day, int mon, int year)
dada.tm_year = year - 1900;
xaccValidateDate (&dada);
cell->date.tm_mday = dada.tm_mday;
cell->date.tm_mon = dada.tm_mon;
cell->date.tm_year = dada.tm_year;
printDate (buff, dada.tm_mday, dada.tm_mon+1, dada.tm_year+1900);
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (buff);
g_free (cell->cell.value);
cell->cell.value = g_strdup (buff);
}
/* ================================================ */
@@ -413,9 +418,8 @@ xaccSetDateCellValueSecs (DateCell *cell, time_t secs)
cell->date.tm_mon+1,
cell->date.tm_year+1900);
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (buff);
g_free (cell->cell.value);
cell->cell.value = g_strdup (buff);
}
/* ================================================ */
@@ -456,8 +460,8 @@ xaccSetDateCellValueSecsL (DateCell *cell, long long secs)
cell->date.tm_mon+1,
cell->date.tm_year+1900);
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (buff);
g_free (cell->cell.value);
cell->cell.value = g_strdup (buff);
}
@@ -475,8 +479,8 @@ setDateCellValue (BasicCell *_cell, const char *str)
cell->date.tm_mon+1,
cell->date.tm_year+1900);
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (buff);
g_free (cell->cell.value);
cell->cell.value = g_strdup (buff);
}
/* ============== END OF FILE ===================== */

View File

@@ -86,10 +86,11 @@
*
* HISTORY:
* Copyright (c) 1998, 1999, 2000 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#ifndef __XACC_DATE_CELL_C__
#define __XACC_DATE_CELL_C__
#ifndef __DATE_CELL_C__
#define __DATE_CELL_C__
#include <time.h>
@@ -115,6 +116,6 @@ void xaccCommitDateCell (DateCell *);
void xaccDateCellGetDate (DateCell *cell, Timespec *ts);
#endif /* __XACC_DATE_CELL_C__ */
#endif /* __DATE_CELL_C__ */
/* --------------- end of file ---------------------- */

View File

@@ -88,15 +88,16 @@ static const char * leaveCombo (BasicCell *bcell, const char *value);
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_GTK_REG;
static gncBoolean auto_pop_combos = GNC_F;
static gboolean auto_pop_combos = FALSE;
/* =============================================== */
ComboCell *xaccMallocComboCell (void)
{
ComboCell * cell = (ComboCell *) malloc (sizeof (ComboCell));
ComboCell * cell;
assert(cell != NULL);
cell = g_new(ComboCell, 1);
xaccInitComboCell(cell);
@@ -375,7 +376,7 @@ xaccClearComboCellMenu (ComboCell * cell)
static void
gnc_append_string_to_list(gpointer _string, gpointer _item_list)
{
char *string = (char *) _string;
char *string = _string;
GNCItemList *item_list = GNC_ITEM_LIST(_item_list);
gnc_item_list_append(item_list, string);
@@ -497,7 +498,7 @@ ComboMV (BasicCell *_cell,
return newval;
}
retval = strdup(match->text);
retval = g_strdup(match->text);
*start_selection = strlen(newval);
*end_selection = -1;
@@ -546,7 +547,7 @@ ComboDirect (BasicCell *bcell,
int length;
if (event->type != GDK_KEY_PRESS)
return GNC_F;
return FALSE;
length = strlen(oldval);
@@ -557,29 +558,30 @@ ComboDirect (BasicCell *bcell,
if (event->keyval == box->complete_char)
break;
return GNC_F;
return FALSE;
}
keep_on_going = TRUE;
/* Fall through */
case GDK_Tab:
case GDK_ISO_Left_Tab:
if (!(event->state & GDK_CONTROL_MASK) &&
!keep_on_going)
return GNC_F;
return FALSE;
match = xaccGetQuickFillStrLen(box->qf, oldval,
*cursor_position);
if (match == NULL)
return GNC_T;
return TRUE;
match = xaccGetQuickFillUniqueLen(match, &prefix_len);
if (match == NULL)
return GNC_T;
return TRUE;
if ((match->text != NULL) &&
(strncmp(match->text, oldval, length) == 0) &&
(strcmp(match->text, oldval) != 0))
{
*newval_ptr = strdup(match->text);
*newval_ptr = g_strdup(match->text);
assert(*newval_ptr != NULL);
xaccSetBasicCellValue(bcell, *newval_ptr);
@@ -595,27 +597,27 @@ ComboDirect (BasicCell *bcell,
*start_selection = *cursor_position;
*end_selection = -1;
return GNC_T;
return TRUE;
}
if (box->complete_char == 0)
return GNC_F;
return FALSE;
if (event->keyval != box->complete_char)
return GNC_F;
return FALSE;
if (event->state & (GDK_CONTROL_MASK | GDK_MOD1_MASK))
return GNC_F;
return FALSE;
if ((*cursor_position < length) &&
((*end_selection < length) ||
(*cursor_position < *start_selection)))
return GNC_F;
return FALSE;
if ((*cursor_position == length) &&
(*start_selection != *end_selection) &&
(*end_selection < length))
return GNC_F;
return FALSE;
search = NULL;
if (*cursor_position < length)
@@ -637,13 +639,13 @@ ComboDirect (BasicCell *bcell,
match = xaccGetQuickFillStrLen(box->qf, oldval, new_pos);
if (match == NULL)
return GNC_F;
return FALSE;
if (extra_colon)
{
match = xaccGetQuickFill(match, box->complete_char);
if (match == NULL)
return GNC_F;
return FALSE;
new_pos++;
}
@@ -652,7 +654,7 @@ ComboDirect (BasicCell *bcell,
(strncmp(match->text, oldval, length) == 0) &&
(strcmp(match->text, oldval) != 0))
{
*newval_ptr = strdup(match->text);
*newval_ptr = g_strdup(match->text);
assert(*newval_ptr != NULL);
xaccSetBasicCellValue(bcell, *newval_ptr);
@@ -666,7 +668,7 @@ ComboDirect (BasicCell *bcell,
*start_selection = new_pos;
*end_selection = -1;
return GNC_T;
return TRUE;
}
/* =============================================== */
@@ -682,13 +684,13 @@ ComboHelpValue(BasicCell *bcell)
if ((box->ignore_string != NULL) &&
(box->ignore_help != NULL) &&
(safe_strcmp(bcell->value, box->ignore_string) == 0))
return strdup(box->ignore_help);
return g_strdup(box->ignore_help);
return strdup(bcell->value);
return g_strdup(bcell->value);
}
if (bcell->blank_help != NULL)
return strdup(bcell->blank_help);
return g_strdup(bcell->blank_help);
return NULL;
}
@@ -753,7 +755,7 @@ enterCombo (BasicCell *bcell,
if ((box->ignore_string != NULL) &&
(safe_strcmp(value, box->ignore_string) == 0))
return strdup(value);
return g_strdup(value);
gnc_combo_sync_edit_list(box);
gnc_combo_sort_edit_list(box);
@@ -806,7 +808,7 @@ leaveCombo (BasicCell *bcell, const char *value)
(safe_strcmp(value, box->ignore_string) != 0)))
{
xaccSetBasicCellValue(bcell, "");
return strdup("");
return g_strdup("");
}
}
@@ -868,7 +870,7 @@ xaccComboCellSetIgnoreHelp (ComboCell *cell, const char *ignore_help)
if (cell == NULL)
return;
box = (PopBox *) cell->cell.gui_private;
box = cell->cell.gui_private;
box->ignore_help = g_strdup(ignore_help);
}

View File

@@ -878,9 +878,8 @@ gnucash_sheet_modify_current_cell(GnucashSheet *sheet, const gchar *new_text)
if (old_text == NULL)
old_text = "";
newval = strdup(new_text);
change = strdup(new_text);
assert((newval != NULL) && (change != NULL));
newval = g_strdup(new_text);
change = g_strdup(new_text);
editable = GTK_EDITABLE(sheet->entry);
@@ -913,15 +912,15 @@ gnucash_sheet_modify_current_cell(GnucashSheet *sheet, const gchar *new_text)
sheet->insert_signal);
if (retval != newval)
free (newval);
g_free (newval);
}
else
free(newval);
g_free(newval);
gtk_editable_set_position (editable, cursor_position);
gtk_entry_select_region(GTK_ENTRY(sheet->entry), start_sel, end_sel);
free(change);
g_free(change);
return retval;
}
@@ -964,8 +963,7 @@ gnucash_sheet_insert_cb (GtkWidget *widget, const gchar *new_text,
/* we set newval to what the entry contents would be if
the insert was processed */
newval = calloc (strlen(old_text) + new_text_length + 1, sizeof(char));
assert (newval != NULL);
newval = g_new0(char, strlen(old_text) + new_text_length + 1);
strncat (newval, old_text, *position);
strncat (newval, new_text, new_text_length);
@@ -1013,7 +1011,7 @@ gnucash_sheet_insert_cb (GtkWidget *widget, const gchar *new_text,
gtk_signal_emit_stop_by_name (GTK_OBJECT(sheet->entry),
"insert_text");
free (newval);
g_free (newval);
}
else if (!retval) {
if (*position < 0)
@@ -1022,7 +1020,7 @@ gnucash_sheet_insert_cb (GtkWidget *widget, const gchar *new_text,
/* the entry was disallowed, so we stop the insert signal */
gtk_signal_emit_stop_by_name (GTK_OBJECT(sheet->entry),
"insert_text");
free (newval);
g_free (newval);
}
else if (*position < 0)
*position = strlen(newval);
@@ -1068,9 +1066,7 @@ gnucash_sheet_delete_cb (GtkWidget *widget,
if (old_text == NULL)
old_text = "";
newval = calloc (strlen(old_text) - (end_pos - start_pos) + 1,
sizeof(char));
assert (newval != NULL);
newval = g_new0 (char, strlen(old_text) - (end_pos - start_pos) + 1);
strncat (newval, old_text, start_pos);
strcat (newval, &old_text[end_pos]);
@@ -1095,7 +1091,7 @@ gnucash_sheet_delete_cb (GtkWidget *widget,
would be after the delete is processed. So we synchronize
the entry contents, and stop the delete signal from
being processed further */
gtk_signal_handler_block (GTK_OBJECT (sheet->entry),
sheet->insert_signal);
@@ -1113,13 +1109,13 @@ gnucash_sheet_delete_cb (GtkWidget *widget,
gtk_signal_emit_stop_by_name (GTK_OBJECT(sheet->entry),
"delete_text");
free (newval);
g_free (newval);
}
else if (!retval) {
/* the entry was disallowed, so we stop the delete signal */
gtk_signal_emit_stop_by_name (GTK_OBJECT(sheet->entry),
"delete_text");
free (newval);
g_free (newval);
}
gtk_editable_set_position (editable, cursor_position);
@@ -1137,7 +1133,8 @@ gnucash_sheet_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
(*GTK_WIDGET_CLASS (sheet_parent_class)->size_allocate)
(widget, allocation);
if (allocation->height != sheet->window_height || allocation->width != sheet->window_width) {
if (allocation->height != sheet->window_height ||
allocation->width != sheet->window_width) {
sheet->window_height = allocation->height;
sheet->window_width = allocation->width;
@@ -1552,8 +1549,8 @@ gnucash_sheet_direct_event(GnucashSheet *sheet, GdkEvent *event)
Table *table = sheet->table;
int v_row, v_col, c_row, c_col;
int p_row, p_col;
gncBoolean result;
gboolean changed;
gboolean result;
const char *old_text;
char *new_text;

View File

@@ -33,7 +33,7 @@
#include "util.h"
static gncBoolean
static gboolean
QuickFillDirect (BasicCell *bcell,
const char *oldval,
char **newval_ptr,
@@ -48,20 +48,20 @@ QuickFillDirect (BasicCell *bcell,
int prefix_len;
if (event->type != GDK_KEY_PRESS)
return GNC_F;
return FALSE;
switch (event->keyval) {
case GDK_slash:
if (!(event->state & GDK_MOD1_MASK))
return GNC_F;
return FALSE;
break;
case GDK_Tab:
case GDK_ISO_Left_Tab:
if (!(event->state & GDK_CONTROL_MASK))
return GNC_F;
return FALSE;
break;
default:
return GNC_F;
return FALSE;
}
if ((*start_selection <= *cursor_position) &&
@@ -73,17 +73,17 @@ QuickFillDirect (BasicCell *bcell,
match = xaccGetQuickFillStrLen(cell->qfRoot, oldval, *cursor_position);
if (match == NULL)
return GNC_T;
return TRUE;
match = xaccGetQuickFillUniqueLen(match, &prefix_len);
if (match == NULL)
return GNC_T;
return TRUE;
if ((match->text != NULL) &&
(strncmp(match->text, oldval, strlen(oldval)) == 0) &&
(strcmp(match->text, oldval) != 0))
{
*newval_ptr = strdup(match->text);
*newval_ptr = g_strdup(match->text);
assert(*newval_ptr != NULL);
xaccSetBasicCellValue(bcell, *newval_ptr);
}
@@ -92,7 +92,7 @@ QuickFillDirect (BasicCell *bcell,
*start_selection = *cursor_position;
*end_selection = -1;
return GNC_T;
return TRUE;
}

View File

@@ -43,26 +43,26 @@
/* ================================================ */
/* Parses the string value and returns true if it is a
* number. In that case, *num is set to the value parsed. */
static gncBoolean
static gboolean
parse_num(const char *string, long int *num)
{
long int number;
if (string == NULL)
return GNC_F;
return FALSE;
if (!gnc_strisnum(string))
return GNC_F;
return FALSE;
number = strtol(string, NULL, 10);
if ((number == LONG_MIN) || (number == LONG_MAX))
return GNC_F;
return FALSE;
if (num != NULL)
*num = number;
return GNC_T;
return TRUE;
}
/* ================================================ */
@@ -97,7 +97,7 @@ NumMV (BasicCell *_cell,
int *end_selection)
{
NumCell *cell = (NumCell *) _cell;
gncBoolean accel = GNC_F;
gncBoolean accel = FALSE;
gncBoolean is_num;
long int number = 0;
@@ -105,8 +105,8 @@ NumMV (BasicCell *_cell,
(strlen(change) > 1)) /* or entering > 1 char */
/* then just accept the proposed change */
{
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (newval);
g_free (cell->cell.value);
cell->cell.value = g_strdup (newval);
return newval;
}
@@ -115,32 +115,32 @@ NumMV (BasicCell *_cell,
is_num = parse_num(oldval, &number);
if (is_num && (number < 0))
is_num = GNC_F;
is_num = FALSE;
switch (change[0])
{
case '+':
case '=':
number++;
accel = GNC_T;
accel = TRUE;
break;
case '_':
case '-':
number--;
accel = GNC_T;
accel = TRUE;
break;
case '}':
case ']':
number += 10;
accel = GNC_T;
accel = TRUE;
break;
case '{':
case '[':
number -= 10;
accel = GNC_T;
accel = TRUE;
break;
}
@@ -149,7 +149,7 @@ NumMV (BasicCell *_cell,
/* If there is already a non-number there, don't accelerate. */
if (accel && !is_num && (safe_strcmp(oldval, "") != 0))
accel = GNC_F;
accel = FALSE;
if (accel)
{
@@ -164,16 +164,16 @@ NumMV (BasicCell *_cell,
if (safe_strcmp(buff, "") == 0)
return NULL;
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (buff);
g_free (cell->cell.value);
cell->cell.value = g_strdup (buff);
*cursor_position = -1;
return strdup(buff);
return g_strdup(buff);
}
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (newval);
g_free (cell->cell.value);
cell->cell.value = g_strdup (newval);
return newval;
}
@@ -201,7 +201,8 @@ xaccMallocNumCell (void)
{
NumCell *cell;
cell = (NumCell *) malloc(sizeof(NumCell));
cell = g_new(NumCell, 1);
xaccInitNumCell (cell);
return cell;
@@ -228,8 +229,8 @@ setNumCellValue (BasicCell *_cell, const char *str)
cell->next_num = number + 1;
}
if (cell->cell.value) free (cell->cell.value);
cell->cell.value = strdup (str);
g_free (cell->cell.value);
cell->cell.value = g_strdup (str);
}
/* ================================================ */
@@ -248,7 +249,7 @@ xaccSetNumCellLastNum (NumCell *cell, const char *str)
if (parse_num(str, &number))
{
cell->next_num = number + 1;
cell->next_num_set = GNC_T;
cell->next_num_set = TRUE;
}
}
@@ -259,7 +260,7 @@ xaccInitNumCell (NumCell *cell)
xaccInitBasicCell (&(cell->cell));
cell->next_num = 0;
cell->next_num_set = GNC_F;
cell->next_num_set = FALSE;
cell->cell.enter_cell = NumEnter;
cell->cell.modify_verify = NumMV;

View File

@@ -30,8 +30,8 @@
* Copyright (c) 2000 Dave Peticolas <peticola@cs.ucdavis.edu>
*/
#ifndef __GNC_NUM_CELL_H__
#define __GNC_NUM_CELL_H__
#ifndef __NUM_CELL_H__
#define __NUM_CELL_H__
#include "basiccell.h"
@@ -39,7 +39,7 @@ typedef struct _NumCell
{
BasicCell cell;
long int next_num;
gncBoolean next_num_set;
gboolean next_num_set;
} NumCell;
NumCell * xaccMallocNumCell (void);
@@ -49,4 +49,4 @@ void xaccDestroyNumCell (NumCell *);
void xaccSetNumCellValue (NumCell *cell, const char *str);
void xaccSetNumCellLastNum (NumCell *cell, const char *str);
#endif /* __GNC_NUM_CELL_H__ */
#endif /* __NUM_CELL_H__ */

View File

@@ -27,6 +27,7 @@
*
* HISTORY:
* Copyright (c) 1998, 1999, 2000 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#include <ctype.h>
@@ -56,8 +57,8 @@ static char * xaccPriceCellPrintValue (PriceCell *cell);
}
#define SET(cell,str) { \
if ((cell)->value) free ((cell)->value); \
(cell)->value = strdup (str); \
g_free ((cell)->value); \
(cell)->value = g_strdup (str); \
}
#define PRTBUF 40
@@ -109,7 +110,7 @@ PriceMV (BasicCell *_cell,
/* accept the newval string if user action was delete, etc. */
if (change != NULL)
{
int i, count=0;
int i, count = 0;
for (i = 0; 0 != change[i]; i++)
{
@@ -152,13 +153,14 @@ PriceLeave (BasicCell *_cell, const char *val)
/* Otherwise, return the new one. */
SET ((&(cell->cell)), newval);
return strdup(newval);
return g_strdup(newval);
}
/* ================================================ */
static char *
PriceHelp(BasicCell *bcell)
PriceHelp (BasicCell *bcell)
{
PriceCell *cell = (PriceCell *) bcell;
@@ -168,11 +170,11 @@ PriceHelp(BasicCell *bcell)
help_str = xaccPriceCellPrintValue(cell);
return strdup(help_str);
return g_strdup(help_str);
}
if (bcell->blank_help != NULL)
return strdup(bcell->blank_help);
return g_strdup(bcell->blank_help);
return NULL;
}
@@ -183,8 +185,11 @@ PriceCell *
xaccMallocPriceCell (void)
{
PriceCell *cell;
cell = (PriceCell *) malloc (sizeof (PriceCell));
cell = g_new(PriceCell, 1);
xaccInitPriceCell (cell);
return cell;
}
@@ -193,7 +198,7 @@ xaccMallocPriceCell (void)
void
xaccInitPriceCell (PriceCell *cell)
{
xaccInitBasicCell( &(cell->cell));
xaccInitBasicCell (&(cell->cell));
cell->amount = 0.0;
cell->blank_zero = GNC_T;
@@ -267,7 +272,7 @@ xaccSetPriceCellValue (PriceCell * cell, double amount)
cell->amount = amount;
buff = xaccPriceCellPrintValue (cell);
SET ( &(cell->cell), buff);
SET (&(cell->cell), buff);
/* set the cell color to red if the value is negative */
COLORIZE (cell, amount);
@@ -281,7 +286,7 @@ xaccSetPriceCellBlank (PriceCell *cell)
cell->amount = 0.0;
SET ( &(cell->cell), "");
SET (&(cell->cell), "");
COLORIZE (cell, 0.0);
}

View File

@@ -50,10 +50,11 @@
*
* HISTORY:
* Copyright (c) 1998, 1999, 2000 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#ifndef __XACC_PRICE_CELL_C__
#define __XACC_PRICE_CELL_C__
#ifndef __PRICE_CELL_C__
#define __PRICE_CELL_C__
#include "basiccell.h"
#include "gnc-common.h"
@@ -62,12 +63,12 @@ typedef struct _PriceCell
{
BasicCell cell;
double amount; /* the amount associated with this cell */
double amount; /* the amount associated with this cell */
gncBoolean blank_zero; /* controls printing of zero values */
gncBoolean monetary; /* controls parsing of values */
gncBoolean is_currency; /* controls printint of values */
gncBoolean shares_value; /* true if a shares values */
gboolean blank_zero; /* controls printing of zero values */
gboolean monetary; /* controls parsing of values */
gboolean is_currency; /* controls printint of values */
gboolean shares_value; /* true if a shares values */
} PriceCell;
/* installs a callback to handle price recording */
@@ -86,20 +87,20 @@ void xaccSetPriceCellBlank (PriceCell *cell);
/* determines whether 0 values are left blank or printed.
* defaults to true. */
void xaccSetPriceCellBlankZero (PriceCell *cell, gncBoolean);
void xaccSetPriceCellBlankZero (PriceCell *cell, gboolean);
/* The xaccSetPriceCellMonetary() sets a flag which determines
* how string amounts are parsed, either as monetary or
* non-monetary amounts. The default is monetary. */
void xaccSetPriceCellMonetary (PriceCell *, gncBoolean);
void xaccSetPriceCellMonetary (PriceCell *, gboolean);
/* The xaccSetPriceCellCurrency() sets a flag which causes
* the amount to be printed as a currency price. */
void xaccSetPriceCellIsCurrency (PriceCell *, gncBoolean);
void xaccSetPriceCellIsCurrency (PriceCell *, gboolean);
/* The xaccSetPriceCellSharesValue() sets a flag which determines
* whether the quantity is printed as a shares value or not. */
void xaccSetPriceCellSharesValue (PriceCell *, gncBoolean);
void xaccSetPriceCellSharesValue (PriceCell *, gboolean);
/* updates two cells; the deb cell if amt is negative,
* the credit cell if amount is positive, and makes the other cell
@@ -107,6 +108,6 @@ void xaccSetPriceCellSharesValue (PriceCell *, gncBoolean);
void xaccSetDebCredCellValue (PriceCell *deb,
PriceCell *cred, double amount);
#endif /* __XACC_PRICE_CELL_C__ */
#endif /* __PRICE_CELL_C__ */
/* --------------- end of file ---------------------- */

View File

@@ -28,6 +28,7 @@
*
* HISTORY:
* Copyright (c) 1998-2000 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#include <stdlib.h>
@@ -38,9 +39,9 @@
#include "basiccell.h"
#include "quickfillcell.h"
#define SET(cell,str) { \
if ((cell)->value) free ((cell)->value); \
(cell)->value = strdup (str); \
#define SET(cell,str) { \
g_free ((cell)->value); \
(cell)->value = g_strdup (str); \
}
/* ================================================ */
@@ -137,7 +138,7 @@ quick_modify (BasicCell *_cell,
if ((match == NULL) || (match->text == NULL))
{
if (cell->original != NULL)
retval = strdup(cell->original);
retval = g_strdup(cell->original);
else
retval = newval;
@@ -147,7 +148,7 @@ quick_modify (BasicCell *_cell,
return retval;
}
retval = strdup(match->text);
retval = g_strdup(match->text);
*start_selection = strlen(newval);
*end_selection = -1;
@@ -176,9 +177,11 @@ QuickFillCell *
xaccMallocQuickFillCell (void)
{
QuickFillCell *cell;
cell = ( QuickFillCell *) malloc (sizeof (QuickFillCell));
cell = g_new(QuickFillCell, 1);
xaccInitQuickFillCell (cell);
return cell;
}

View File

@@ -39,10 +39,11 @@
*
* HISTORY:
* Copyright (c) 1997, 1998 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#ifndef __XACC_FILL_CELL_C__
#define __XACC_FILL_CELL_C__
#ifndef __QUICK_FILL_CELL_C__
#define __QUICK_FILL_CELL_C__
#include "basiccell.h"
#include "QuickFill.h"
@@ -71,6 +72,6 @@ void xaccSetQuickFillOriginal (QuickFillCell *, const char *);
/* GUI-dependent */
void xaccQuickFillGUIInit (QuickFillCell *);
#endif /* __XACC_FILL_CELL_C__ */
#endif /* __QUICK_FILL_CELL_C__ */
/* --------------- end of file ---------------------- */

View File

@@ -28,6 +28,7 @@
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#include <stdlib.h>
@@ -49,6 +50,7 @@
static RecnCellStringGetter string_getter = NULL;
/* ================================================ */
static const char *
@@ -85,14 +87,14 @@ ToggleRecn (BasicCell *_cell,
if (!gnc_verify_dialog(CHANGE_RECN_MSG, GNC_T))
return NULL;
if (cell->reconciled_flag == NREC) {
if (cell->reconciled_flag == NREC)
cell->reconciled_flag = CREC;
} else {
else
cell->reconciled_flag = NREC;
}
xaccRecnCellSetFlag (cell, cell->reconciled_flag);
return strdup (_cell->value);
return g_strdup (_cell->value);
}
/* ================================================ */
@@ -100,9 +102,10 @@ ToggleRecn (BasicCell *_cell,
RecnCell *
xaccMallocRecnCell (void)
{
RecnCell * cell = malloc(sizeof(RecnCell));
RecnCell * cell;
cell = g_new(RecnCell, 1);
assert(cell != NULL);
xaccInitRecnCell (cell);
return cell;

View File

@@ -32,10 +32,11 @@
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#ifndef __XACC_RECN_CELL_C__
#define __XACC_RECN_CELL_C__
#ifndef __RECN_CELL_C__
#define __RECN_CELL_C__
#include "basiccell.h"
@@ -58,6 +59,6 @@ char xaccRecnCellGetFlag (RecnCell *);
void xaccRecnCellSetStringGetter (RecnCellStringGetter getter);
#endif /* __XACC_RECN_CELL_C__ */
#endif /* __RECN_CELL_C__ */
/* --------------- end of file ---------------------- */

View File

@@ -48,6 +48,7 @@
#include "messages.h"
#include "util.h"
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_REGISTER;
@@ -817,7 +818,8 @@ xaccMallocSplitRegister (SplitRegisterType type, SplitRegisterStyle style)
{
SplitRegister * reg;
reg = malloc (sizeof (SplitRegister));
reg = g_new(SplitRegister, 1);
xaccInitSplitRegister (reg, type, style);
return reg;
@@ -1257,7 +1259,7 @@ xaccDestroySplitRegister (SplitRegister *reg)
reg->ndebitCell = NULL;
/* free the memory itself */
free (reg);
g_free (reg);
}
/* ============================================== */

View File

@@ -357,7 +357,7 @@ gnc_physical_cell_new (void)
pcell = &tcell->phys_cell;
pcell->entry = strdup("");
pcell->entry = g_strdup("");
assert(pcell->entry != NULL);
pcell->fg_color = 0x000000; /* black */
@@ -376,9 +376,7 @@ gnc_physical_cell_free (TableCell *tcell)
if (tcell == NULL)
return;
if (tcell->phys_cell.entry != NULL)
free(tcell->phys_cell.entry);
g_free(tcell->phys_cell.entry);
tcell->phys_cell.entry = NULL;
g_mem_chunk_free(cell_mem_chunk, tcell);
@@ -810,9 +808,8 @@ gnc_table_commit_cursor (Table *table)
phys_row_origin + cell_row,
phys_col_origin + cell_col);
if (pcell->entry)
free (pcell->entry);
pcell->entry = strdup (cell->value);
g_free (pcell->entry);
pcell->entry = g_strdup (cell->value);
if (cell->use_bg_color)
pcell->bg_color = cell->bg_color;
if (cell->use_fg_color)
@@ -850,15 +847,14 @@ gnc_table_refresh_header (Table *table)
/* Assumes header starts at physical (0, 0) */
pcell = gnc_table_get_physical_cell (table, cell_row, cell_col);
if (pcell->entry)
free(pcell->entry);
g_free(pcell->entry);
cell = cb->cells[cell_row][cell_col];
if (cell && cell->value)
pcell->entry = strdup (cell->value);
pcell->entry = g_strdup (cell->value);
else
pcell->entry = strdup ("");
pcell->entry = g_strdup ("");
}
}
@@ -1165,8 +1161,7 @@ gnc_table_enter_update(Table *table,
{
if (safe_strcmp(retval, val) != 0)
(cb->cells[cell_row][cell_col])->changed = GNC_CELL_CHANGED;
if (pcell->entry)
free (pcell->entry);
g_free (pcell->entry);
pcell->entry = (char *) retval;
}
else
@@ -1183,8 +1178,7 @@ gnc_table_enter_update(Table *table,
table->set_help(table, help_str);
if (help_str != NULL)
free(help_str);
g_free(help_str);
}
/* record this position as the cell that will be
@@ -1243,7 +1237,7 @@ gnc_table_leave_update(Table *table,
}
if (!retval)
retval = strdup (callback_text);
retval = g_strdup (callback_text);
/* save whatever was returned; but lets check for
* changes to avoid roiling the cells too much. */
@@ -1251,14 +1245,14 @@ gnc_table_leave_update(Table *table,
{
if (safe_strcmp (pcell->entry, retval))
{
free (pcell->entry);
g_free (pcell->entry);
pcell->entry = (char *) retval;
(cb->cells[cell_row][cell_col])->changed = GNC_CELL_CHANGED;
}
else
{
/* leave() allocated memory, which we will not be using */
free ((char *) retval);
g_free ((char *) retval);
retval = NULL;
}
}
@@ -1326,8 +1320,7 @@ gnc_table_modify_update(Table *table,
if (retval)
{
/* update data. bounds check done earlier */
if (pcell->entry)
free (pcell->entry);
g_free (pcell->entry);
pcell->entry = (char *) retval;
(cb->cells[cell_row][cell_col])->changed = GNC_CELL_CHANGED;
}
@@ -1335,8 +1328,7 @@ gnc_table_modify_update(Table *table,
else
{
/* update data. bounds check done earlier */
if (pcell->entry)
free (pcell->entry);
g_free (pcell->entry);
pcell->entry = newval;
retval = newval;
(cb->cells[cell_row][cell_col])->changed = GNC_CELL_CHANGED;
@@ -1352,8 +1344,7 @@ gnc_table_modify_update(Table *table,
table->set_help(table, help_str);
if (help_str != NULL)
free(help_str);
g_free(help_str);
}
LEAVE ("change %d %d (relrow=%d relcol=%d) cell=%p val=%s\n",
@@ -1405,8 +1396,7 @@ gnc_table_direct_update(Table *table,
start_selection, end_selection, gui_data);
if ((*newval_ptr != oldval) && (*newval_ptr != NULL)) {
if (pcell->entry)
free (pcell->entry);
g_free (pcell->entry);
pcell->entry = *newval_ptr;
cell->changed = GNC_CELL_CHANGED;
}
@@ -1419,8 +1409,7 @@ gnc_table_direct_update(Table *table,
table->set_help(table, help_str);
if (help_str != NULL)
free(help_str);
g_free(help_str);
}
return result;

View File

@@ -27,6 +27,7 @@
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#include <stdlib.h>
@@ -72,8 +73,8 @@ xaccInitTextCell (BasicCell *cell)
{
xaccInitBasicCell (cell);
if (cell->value) free (cell->value);
cell->value = strdup ("");
g_free (cell->value);
cell->value = g_strdup ("");
cell->modify_verify = TextMV;
}

View File

@@ -29,18 +29,19 @@
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 2000 Dave Peticolas
*/
#ifndef __XACC_TEXT_CELL_H__
#define __XACC_TEXT_CELL_H__
#ifndef __TEXT_CELL_H__
#define __TEXT_CELL_H__
#include "basiccell.h"
/* installs a callback to handle text recording */
BasicCell * xaccMallocTextCell (void);
void xaccInitTextCell (BasicCell *);
void xaccDestroyTextCell (BasicCell *);
void xaccInitTextCell (BasicCell *);
void xaccDestroyTextCell (BasicCell *);
#endif /* __XACC_TEXT_CELL_H__ */
#endif /* __TEXT_CELL_H__ */
/* --------------- end of file ---------------------- */