*** empty log message ***

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2100 57a11ea4-9604-0410-9ed3-97b8803252fd
zzzoldreleases/1.4
Dave Peticolas 27 years ago
parent 7a45d4f6a7
commit 2962e03ec9

@ -2,7 +2,7 @@
* util.c -- utility functions that are used everywhere else for *
* xacc (X-Accountant) *
* Copyright (C) 1997 Robin D. Clark *
* Copyright (C) 1997, 1998 Linas Vepstas *
* Copyright (C) 1997, 1998, 1999, 2000 Linas Vepstas *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@ -29,6 +29,8 @@
#include <string.h>
#include <locale.h>
/* #include <glib.h> */
#include "config.h"
#include "messages.h"
#include "gnc-common.h"
@ -72,14 +74,14 @@ size_t core=0;
void
dfree( void *ptr )
{
{
core -= malloc_usable_size(ptr);
free(ptr);
}
}
void*
dmalloc( size_t size )
{
{
int i;
char *ptr;
ptr = (char *)malloc(size);
@ -88,20 +90,21 @@ dmalloc( size_t size )
core += malloc_usable_size(ptr);
return (void *)ptr;
}
}
size_t
dcoresize(void)
{
{
return core;
}
}
#endif
/********************************************************************\
\********************************************************************/
int
safe_strcmp (const char * da, const char * db) {
safe_strcmp (const char * da, const char * db)
{
SAFE_STRCMP (da, db);
return 0;
}
@ -242,6 +245,8 @@ gnc_localeconv()
gnc_lconv_set(&lc.mon_thousands_sep, ",");
gnc_lconv_set(&lc.negative_sign, "-");
gnc_lconv_set_char(&lc.frac_digits, 2);
gnc_lconv_set_char(&lc.int_frac_digits, 2);
gnc_lconv_set_char(&lc.p_cs_precedes, 1);
gnc_lconv_set_char(&lc.p_sep_by_space, 0);
gnc_lconv_set_char(&lc.n_cs_precedes, 1);
@ -345,7 +350,7 @@ PrintAmt(char *buf, double val, int prec,
int
xaccSPrintAmountGeneral (char * bufp, double val, short shrs, int precision,
gncBoolean monetary, int min_trailing_zeros)
int min_trailing_zeros)
{
struct lconv *lc;
@ -429,8 +434,8 @@ xaccSPrintAmountGeneral (char * bufp, double val, short shrs, int precision,
bufp = stpcpy(bufp, "(");
/* Now print the value */
bufp += PrintAmt(bufp, DABS(val), precision,
shrs & PRTSEP, monetary, min_trailing_zeros);
bufp += PrintAmt(bufp, DABS(val), precision, shrs & PRTSEP,
!(shrs & PRTNMN), min_trailing_zeros);
/* Now see if we print parentheses */
if (print_sign && (sign_posn == 0))
@ -466,17 +471,24 @@ xaccSPrintAmountGeneral (char * bufp, double val, short shrs, int precision,
int
xaccSPrintAmount (char * bufp, double val, short shrs)
{
int precision = 2;
int min_trailing_zeros = 2;
int precision;
int min_trailing_zeros;
if (shrs & PRTSHR)
{
precision = 4;
min_trailing_zeros = 0;
}
else
{
struct lconv *lc = gnc_localeconv();
precision = lc->frac_digits;
min_trailing_zeros = lc->frac_digits;
}
return xaccSPrintAmountGeneral(bufp, val, shrs, precision,
GNC_T, min_trailing_zeros);
min_trailing_zeros);
}
char *

@ -2,7 +2,7 @@
* util.h -- utility functions that are used everywhere for *
* gnucash (ex-xacc (X-Accountant)) *
* Copyright (C) 1997 Robin D. Clark *
* Copyright (C) 1998, 1999 Linas Vepstas *
* Copyright (C) 1998, 1999, 2000 Linas Vepstas *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@ -151,8 +151,9 @@ struct lconv * gnc_localeconv();
*
* PRTSYM -- also print currency symbol.
* PRTSHR -- print four decimal places
* PRTSYM | PRTSHR -- prints three decimal places followed by string "shrs"
* PRTSYM | PRTSHR -- prints four decimal places followed by "shrs"
* PRTSEP -- print comma-separated K's
* PRTNMN -- print as non-monetary value
*
* The xaccPrintAmount() routine returns a pointer to a statically
* allocated buffer, and is therefore not thread-safe.
@ -160,11 +161,8 @@ struct lconv * gnc_localeconv();
* The xaccSPrintAmount() routine accepts a pointer to the buffer to be
* printed to. It returns the length of the printed string.
*
* The xaccSPrintAmountGeneral() routine is a generalization of
* xaccSPrintAmount that allows the precision and minimum
* number of trailing zeros to be set. You can also set
* whether the amount should be printed as monetary or
* non-monetary, which affects fomatting in locales.
* The xaccSPrintAmountGeneral() routine is a more general version that
* allows the user to set the precision and the minimum trailing zeros.
*
* The xaccPrintAmountArgs() routine is identical to xaccPrintAmount,
* except that the arguments are given as boolean values intead of
@ -174,12 +172,12 @@ struct lconv * gnc_localeconv();
#define PRTSYM 0x1
#define PRTSHR 0x2
#define PRTSEP 0x4
#define PRTNMN 0x8
char * xaccPrintAmount (double val, short shrs);
int xaccSPrintAmount (char *buf, double val, short shrs);
int xaccSPrintAmountGeneral (char * bufp, double val, short shrs,
int precision, gncBoolean monetary,
int min_trailing_zeros);
int precision, int min_trailing_zeros);
char * xaccPrintAmountArgs (double val,
gncBoolean print_currency_symbol,
gncBoolean print_separators,

@ -1,14 +1,3 @@
/*
* FILE:
* pricecell.c
*
* FUNCTION:
* Implements the price cell
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
*/
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
@ -25,6 +14,17 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
\********************************************************************/
/*
* FILE:
* pricecell.c
*
* FUNCTION:
* Implements the price cell
*
* HISTORY:
* Copyright (c) 1998, 1999, 2000 Linas Vepstas
*/
#include <ctype.h>
#include <string.h>
#include <locale.h>
@ -191,12 +191,11 @@ xaccInitPriceCell (PriceCell *cell)
xaccInitBasicCell( &(cell->cell));
cell->amount = 0.0;
cell->precision = 2;
cell->blank_zero = GNC_T;
cell->min_trail_zeros = 2;
cell->monetary = GNC_T;
cell->shares_value = GNC_F;
SET ( &(cell->cell), "");
SET (&(cell->cell), "");
cell->cell.use_fg_color = 1;
cell->cell.enter_cell = PriceEnter;
@ -212,7 +211,7 @@ void
xaccDestroyPriceCell (PriceCell *cell)
{
cell->amount = 0.0;
xaccDestroyBasicCell ( &(cell->cell));
xaccDestroyBasicCell (&(cell->cell));
}
/* ================================================ */
@ -221,14 +220,17 @@ static char *
xaccPriceCellPrintValue (PriceCell *cell)
{
static char buff[PRTBUF];
short flags = PRTSEP;
if (cell->blank_zero && DEQ(cell->amount, 0.0)) {
strcpy(buff, "");
return buff;
}
xaccSPrintAmountGeneral(buff, cell->amount, PRTSEP, cell->precision,
cell->monetary, cell->min_trail_zeros);
if (cell->shares_value)
flags |= PRTSHR;
xaccSPrintAmount(buff, cell->amount, flags);
return buff;
}
@ -258,11 +260,11 @@ void xaccSetPriceCellValue (PriceCell * cell, double amt)
/* ================================================ */
void
xaccSetPriceCellPrecision (PriceCell *cell, int precision)
xaccSetPriceCellSharesValue (PriceCell * cell, gncBoolean shares_value)
{
assert(cell != NULL);
cell->precision = precision;
cell->shares_value = shares_value;
}
/* ================================================ */
@ -277,16 +279,6 @@ xaccSetPriceCellMonetary (PriceCell * cell, gncBoolean monetary)
/* ================================================ */
void
xaccSetPriceCellMinTrailZeros (PriceCell * cell, int min_trail_zeros)
{
assert(cell != NULL);
cell->min_trail_zeros = min_trail_zeros;
}
/* ================================================ */
void
xaccSetPriceCellBlankZero (PriceCell *cell, gncBoolean blank_zero)
{

@ -1,3 +1,19 @@
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
\********************************************************************/
/*
* FILE:
* pricecell.h
@ -29,23 +45,8 @@
* dollars with penny accuracy.
*
* HISTORY:
* Copyright (c) 1998 Linas Vepstas
* Copyright (c) 1998, 1999, 2000 Linas Vepstas
*/
/********************************************************************\
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License as *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
\********************************************************************/
#ifndef __XACC_PRICE_CELL_C__
#define __XACC_PRICE_CELL_C__
@ -57,13 +58,11 @@ typedef struct _PriceCell
{
BasicCell cell;
double amount; /* the amount associated with this cell */
double amount; /* the amount associated with this cell */
int precision; /* precision of printed values */
int min_trail_zeros; /* minimum number of trailing zeros to print */
gncBoolean blank_zero; /* controls printing of zero values */
gncBoolean monetary; /* controls parsing of values */
gncBoolean blank_zero; /* controls printing of zero values */
gncBoolean monetary; /* controls parsing of values */
gncBoolean shares_value; /* true if a shares values */
} PriceCell;
/* installs a callback to handle price recording */
@ -77,13 +76,6 @@ double xaccGetPriceCellValue (PriceCell *cell);
/* updates amount, string format is three decimal places */
void xaccSetPriceCellValue (PriceCell *cell, double amount);
/* sets the precision of the printed value. Defaults to 2 */
void xaccSetPriceCellPrecision (PriceCell *cell, int precision);
/* Sets the mininum number of trailing decimal zeros that must
* be printed. Defaults to 2. */
void xaccSetPriceCellMinTrailZeros (PriceCell *cell, int);
/* determines whether 0 values are left blank or printed.
* defaults to true. */
void xaccSetPriceCellBlankZero (PriceCell *cell, gncBoolean);
@ -94,6 +86,10 @@ void xaccSetPriceCellBlankZero (PriceCell *cell, gncBoolean);
*/
void xaccSetPriceCellMonetary (PriceCell *, gncBoolean);
/* The xaccSetPriceCellSharesValue() sets a flag which determines
* whether the quantity is printed as a shares value or not. */
void xaccSetPriceCellSharesValue (PriceCell *, gncBoolean);
/* updates two cells; the deb cell if amt is negative,
* the credit cell if amount is positive, and makes the other cell
* blank. */

@ -125,8 +125,6 @@ static SplitRegisterColors reg_colors = {
#define SHRS_CELL_ALIGN ALIGN_RIGHT
#define BALN_CELL_ALIGN ALIGN_RIGHT
#define SHARES_PRECISION 4
/* ============================================== */
#define LABEL(NAME,label) \
@ -988,10 +986,8 @@ xaccInitSplitRegister (SplitRegister *reg, int type)
xaccSetPriceCellValue (reg->ndebitCell, 0.0);
xaccSetPriceCellValue (reg->ncreditCell, 0.0);
/* The format for share-related info is a printf-style
* format string for a double. */
xaccSetPriceCellMinTrailZeros (reg->shrsCell, 0);
xaccSetPriceCellPrecision (reg->shrsCell, SHARES_PRECISION);
/* Initialize shares cell */
xaccSetPriceCellSharesValue (reg->shrsCell, GNC_T);
/* The action cell should accept strings not in the list */
xaccComboCellSetStrict (reg->actionCell, GNC_F);
@ -1002,16 +998,10 @@ xaccInitSplitRegister (SplitRegister *reg, int type)
case STOCK_REGISTER:
case PORTFOLIO:
case CURRENCY_REGISTER:
xaccSetPriceCellMinTrailZeros (reg->debitCell, 0);
xaccSetPriceCellMinTrailZeros (reg->creditCell, 0);
xaccSetPriceCellMinTrailZeros (reg->ndebitCell, 0);
xaccSetPriceCellMinTrailZeros (reg->ncreditCell, 0);
xaccSetPriceCellPrecision (reg->debitCell, SHARES_PRECISION);
xaccSetPriceCellPrecision (reg->creditCell, SHARES_PRECISION);
xaccSetPriceCellPrecision (reg->ndebitCell, SHARES_PRECISION);
xaccSetPriceCellPrecision (reg->ncreditCell, SHARES_PRECISION);
xaccSetPriceCellPrecision (reg->priceCell, SHARES_PRECISION);
xaccSetPriceCellSharesValue (reg->debitCell, GNC_T);
xaccSetPriceCellSharesValue (reg->creditCell, GNC_T);
xaccSetPriceCellSharesValue (reg->ndebitCell, GNC_T);
xaccSetPriceCellSharesValue (reg->ncreditCell, GNC_T);
xaccSetBasicCellBlankHelp (&reg->priceCell->cell, PRICE_CELL_HELP);
xaccSetBasicCellBlankHelp (&reg->valueCell->cell, VALUE_CELL_HELP);

Loading…
Cancel
Save