1997-11-01 01:39:32 +00:00
|
|
|
/********************************************************************\
|
|
|
|
|
* util.c -- utility functions that are used everywhere else for *
|
|
|
|
|
* xacc (X-Accountant) *
|
|
|
|
|
* Copyright (C) 1997 Robin D. Clark *
|
|
|
|
|
* *
|
|
|
|
|
* 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. *
|
|
|
|
|
* *
|
|
|
|
|
* Author: Rob Clark *
|
|
|
|
|
* Internet: rclark@cs.hmc.edu *
|
|
|
|
|
* Address: 609 8th Street *
|
|
|
|
|
* Huntington Beach, CA 92648-4632 *
|
|
|
|
|
\********************************************************************/
|
|
|
|
|
|
1997-11-30 02:39:58 +00:00
|
|
|
#include "config.h"
|
1997-12-06 02:59:44 +00:00
|
|
|
#include "main.h"
|
1997-11-01 01:39:32 +00:00
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
|
|
/** GLOBALS *********************************************************/
|
1997-11-22 03:41:59 +00:00
|
|
|
int loglevel = 1;
|
|
|
|
|
|
1997-11-01 01:39:32 +00:00
|
|
|
/********************************************************************\
|
|
|
|
|
* DEBUGGING MEMORY ALLOCATION STUFF *
|
|
|
|
|
\********************************************************************/
|
1997-11-30 02:39:58 +00:00
|
|
|
#if DEBUG_MEMORY
|
1997-11-01 01:39:32 +00:00
|
|
|
size_t core=0;
|
|
|
|
|
void
|
|
|
|
|
dfree( void *ptr )
|
|
|
|
|
{
|
|
|
|
|
core -= malloc_usable_size(ptr);
|
|
|
|
|
free(ptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void*
|
|
|
|
|
dmalloc( size_t size )
|
|
|
|
|
{
|
|
|
|
|
int i;
|
1997-11-22 03:41:59 +00:00
|
|
|
char *ptr;
|
|
|
|
|
ptr = (char *)malloc(size);
|
1997-11-01 01:39:32 +00:00
|
|
|
for( i=0; i<size; i++ )
|
|
|
|
|
ptr[i] = '.';
|
|
|
|
|
|
|
|
|
|
core += malloc_usable_size(ptr);
|
|
|
|
|
return (void *)ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t
|
|
|
|
|
dcoresize(void)
|
|
|
|
|
{
|
|
|
|
|
return core;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1997-12-06 02:59:44 +00:00
|
|
|
/********************************************************************\
|
|
|
|
|
* currency & locale related stuff.
|
|
|
|
|
* first attempt at internationalization i18n of currency amounts
|
1997-12-06 03:26:12 +00:00
|
|
|
* In the long run, amounts should be printed with punctuation
|
|
|
|
|
* returned from the localconv() subroutine
|
1997-12-06 02:59:44 +00:00
|
|
|
\********************************************************************/
|
|
|
|
|
|
|
|
|
|
char * xaccPrintAmount (double val, short shrs)
|
|
|
|
|
{
|
|
|
|
|
static char buf[BUFSIZE];
|
|
|
|
|
|
|
|
|
|
if (shrs & PRTSHR) {
|
|
|
|
|
if (shrs & PRTSYM) {
|
|
|
|
|
if (0.0 > val) {
|
|
|
|
|
sprintf( buf, "-%.3f shrs", DABS(val) );
|
|
|
|
|
} else {
|
|
|
|
|
sprintf( buf, " %.3f shrs", val );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (0.0 > val) {
|
|
|
|
|
sprintf( buf, "-%.3f", DABS(val) );
|
|
|
|
|
} else {
|
|
|
|
|
sprintf( buf, "%.3f", val );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
if (shrs & PRTSYM) {
|
|
|
|
|
if (0.0 > val) {
|
|
|
|
|
sprintf( buf, "-%s %.2f", CURRENCY_SYMBOL, DABS(val) );
|
|
|
|
|
} else {
|
|
|
|
|
sprintf( buf, "%s %.2f", CURRENCY_SYMBOL, val );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (0.0 > val) {
|
|
|
|
|
sprintf( buf, "-%.2f", DABS(val) );
|
|
|
|
|
} else {
|
|
|
|
|
sprintf( buf, "%.2f", val );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* its OK to reurn buf, since we declared it static */
|
|
|
|
|
return buf;
|
|
|
|
|
}
|
|
|
|
|
|
1997-11-22 10:42:02 +00:00
|
|
|
/************************* END OF FILE ******************************\
|
|
|
|
|
\********************************************************************/
|