diff --git a/Makefile b/Makefile index 77239c671b..bcc0825c40 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,7 @@ CPU = @target_cpu@ default: @cd lib; $(MAKE) + @cd src/engine; $(MAKE) @cd src/register; $(MAKE) @cd src; $(MAKE) diff --git a/src/Makefile b/src/Makefile index ed50498b67..7e0c29a4b0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -58,9 +58,9 @@ LIBENG = libengine.a ###################################################################### SRCS = AccWindow.c AccountMenu.c AdjBWindow.c \ BuildMenu.c Destroy.c FileBox.c HelpWindow.c \ - Ledger.c LedgerUtils.c MainWindow.c \ + Ledger.c MainWindow.c \ RecnWindow.c RegWindow.c Reports.c TextBox.c \ - XferWindow.c main.c util.c xtutil.c + XferWindow.c main.c xtutil.c # OBJS = ${SRCS:.c=.o} $(LIBHTMLW) $(LIBXBAE) $(LIBCOMBO) OBJS = ${SRCS:.c=.o} $(LIBENG) $(LIBREG) $(LIBXMHTML) $(LIBXBAE) $(LIBCOMBO) ###################################################################### diff --git a/src/LedgerUtils.c b/src/engine/LedgerUtils.c similarity index 100% rename from src/LedgerUtils.c rename to src/engine/LedgerUtils.c diff --git a/src/engine/LedgerUtils.h b/src/engine/LedgerUtils.h new file mode 100644 index 0000000000..89f574ce78 --- /dev/null +++ b/src/engine/LedgerUtils.h @@ -0,0 +1,38 @@ +/*******************************************************************\ + * LedgerUtils.h -- utilities for the ledger window (X-Accountant) * + * Copyright (C) 1997 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_LEDGER_UTILS_H__ +#define __XACC_LEDGER_UTILS_H__ + +#include "config.h" + +#include "Account.h" + +/** PROTOTYPES ******************************************************/ + +int accListCount (Account **list); +Account ** accListCopy (Account **list); +Split ** accListGetSortedSplits (Account **list); +Account ** xaccGroupToList (Account *); + + +#endif /* __XACC_LEDGER_UTILS_H__ */ + +/************************** END OF FILE *************************/ diff --git a/src/engine/Makefile b/src/engine/Makefile index 08582bfee1..82fc27be6b 100644 --- a/src/engine/Makefile +++ b/src/engine/Makefile @@ -39,7 +39,8 @@ LIBPATH = -L/lib -L/usr/lib -L/usr/local/lib TARGET = ../libengine.a ###################################################################### -SRCS = Account.c FileIO.c Group.c QIFIO.c Transaction.c date.c +SRCS = Account.c FileIO.c Group.c LedgerUtils.c QIFIO.c \ + Transaction.c date.c util.c OBJS = ${SRCS:.c=.o} ###################################################################### diff --git a/src/engine/Makefile.in b/src/engine/Makefile.in index 35cd68090a..7161ef0469 100644 --- a/src/engine/Makefile.in +++ b/src/engine/Makefile.in @@ -38,7 +38,8 @@ LIBPATH = -L/lib -L/usr/lib -L/usr/local/lib TARGET = ../libengine.a ###################################################################### -SRCS = Account.c FileIO.c Group.c QIFIO.c Transaction.c date.c +SRCS = Account.c FileIO.c Group.c LedgerUtils.c QIFIO.c \ + Transaction.c date.c util.c OBJS = ${SRCS:.c=.o} ###################################################################### diff --git a/src/util.c b/src/engine/util.c similarity index 100% rename from src/util.c rename to src/engine/util.c diff --git a/src/engine/util.h b/src/engine/util.h new file mode 100644 index 0000000000..cdafa29320 --- /dev/null +++ b/src/engine/util.h @@ -0,0 +1,196 @@ +/********************************************************************\ + * util.h -- 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 * +\********************************************************************/ + +#ifndef __XACC_UTIL_H__ +#define __XACC_UTIL_H__ + +#include +#include "config.h" + +#define BUFSIZE 1024 + +extern int loglevel; + +/** DEBUGGING MACROS ************************************************/ +#include + +#define PERR(x) { if (0 <=loglevel) { \ + fprintf (stderr, "Error: "); \ + fprintf (stderr, x); }} + +#define WARN(x) { if (1 <=loglevel) { \ + fprintf (stderr, "Warning: "); \ + fprintf (stderr, x); }} + +#define INFO(x) { if (2 <=loglevel) { \ + fprintf (stderr, "Info: "); \ + fprintf (stderr, x); }} + +#define INFO_2(x,y) { if (2 <=loglevel) { \ + fprintf (stderr, "Info: "); \ + fprintf (stderr, x, y); }} + +#define DEBUG(x) { if (3 <=loglevel) { \ + fprintf (stderr, "Debug: "); \ + fprintf (stderr, x); }} + +#define ENTER(x) { if (3 <=loglevel) { \ + fprintf(stderr,"Entering: %s()\n", x); }} +#define LEAVE(x) { if (3 <=loglevel) { \ + fprintf(stderr,"Leaving: %s()\n", x); }} +#define DEBUGCMD(x) { if (3 <=loglevel) { x; }} + + +#include +#define ERROR() fprintf(stderr,"%s: Line %d, error = %s\n", \ + __FILE__, __LINE__, strerror(errno)); + +#ifdef DEBUGMEMORY +void *dmalloc( size_t size ); +void dfree( void *ptr ); +size_t dcoresize(); +# define _malloc(x) dmalloc(x) +# define _free(x) dfree(x) +# define _coresize() dcoresize() +#else +# define _malloc(x) malloc(x) +# define _free(x) free(x) +# define _coresize() 0 +#endif + +/** COOL MACROS *****************************************************/ +#define ABS(x) ((x)>=0) ? (x) : (-1*(x)) +#define DABS(x) ((x)>=0.0) ? (x) : (-1.0*(x)) +#define DMAX(x,y) ((x)>(y)) ? (x) : (y) +#define isNum(x) (((x)-0x30) < 0) ? 0 : (((x)-0x30) > 9) ? 0 : 1 + +#define EPS (1.0e-4) +#define DEQ(x,y) (((((x)+EPS)>(y)) ? 1 : 0) && ((((x)-EPS)<(y)) ? 1 : 0)) + +/** PROTOTYPES ******************************************************/ + +#define PRTSYM 0x1 +#define PRTSHR 0x2 +/* + * The xaccPrintAmount() subroutine converts a double amount + * to a printable string, depending on the argument shrs: + * 0 -- print two decimal places + * 1 -- print currency symbol & two decimal places + * 2 -- print three decimal places + * 3 -- prints three decimal places followed by string "shrs" + * shrs must be bitwise-OR of PRTSYM & PRTSHR + */ +char * xaccPrintAmount (double val, short shrs); + +/********************************************************************\ + * xaccParseUSAmount * + * parses U.S. style monetary strings * + * (strings of the form DDD,DDD,DDD.CC * + * * +\********************************************************************/ +double xaccParseUSAmount (const char * str); + + +/** TEMPLATES ******************************************************/ + +#define FIND_IN_LIST(Type,list,id,member,found) \ +{ \ + int i; \ + Type *elt; \ + \ + /* lets see if we have an */ \ + /* open window for this account */ \ + found = NULL; \ + if (id && list) { \ + i = 0; \ + elt = list[i]; \ + while (elt) { \ + if (id == elt->member) found = elt; \ + i++; \ + elt = list[i]; \ + } \ + } \ +} + +#define FETCH_FROM_LIST(Type,list,id,member,elt) \ +{ \ + int i; \ + Type **newlist; \ + if (!(id)) return 0x0; \ + \ + /* lets see if we already have an */ \ + /* open window for this account */ \ + i = 0; \ + if (list) { \ + elt = list[i]; \ + while (elt) { \ + if ((id) == elt->member) return elt; \ + i++; \ + elt = list[i]; \ + } \ + } \ + \ + /* if we are here, we didn't find it */ \ + newlist = (Type **) malloc ((i+2) * sizeof (Type *)); \ + i = 0; \ + if (list) { \ + elt = list[i]; \ + while (elt) { \ + newlist[i] = elt; \ + i++; \ + elt = list[i]; \ + } \ + free (list); \ + } \ + list = newlist; \ + \ + /* malloc a new one, add it to the list */ \ + elt = (Type *) malloc (sizeof (Type)); \ + elt->member = (id); \ + list [i] = elt; \ + list [i+1] = NULL; \ +} + +#define REMOVE_FROM_LIST(Type,list,id,member) \ +{ \ + int i,j; \ + Type *elt; \ + \ + /* find the item in the list, and remove it */ \ + if (list && id) { \ + i = j = 0; \ + elt = list[i]; \ + while (elt) { \ + list[j] = elt; \ + if (id == elt->member) j--; \ + i++; j++; \ + elt = list[i]; \ + } \ + list[j] = NULL; \ + } \ +} + + +#endif /* __XACC_UTIL_H__ */ diff --git a/src/register/Makefile b/src/register/Makefile index dfa37c19aa..fd8eff1461 100644 --- a/src/register/Makefile +++ b/src/register/Makefile @@ -5,6 +5,7 @@ RANLIB = ranlib INCLPATH = -I/usr/include \ -I/usr/X11R6/include/. \ -I./../../include \ + -I./../engine \ -I./../../lib/ComboBox-1.33 \ -I./../../lib/Xbae-4.6.2-linas