From: Ton v. O. <tvo...@us...> - 2007-09-28 01:23:32
|
Update of /cvsroot/easycalc/easycalc In directory sc8-pr-cvs17:/tmp/cvs-serv6359 Modified Files: Makefile.in calc.def solver.c Added Files: dbutil.c Log Message: Set backup attribute on calc_xxx.prc and all databases. Use a single function for opening the databases (dbutil.[ch]). Index: calc.def =================================================================== RCS file: /cvsroot/easycalc/easycalc/calc.def,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** calc.def 4 Oct 2006 00:39:17 -0000 1.7 --- calc.def 28 Sep 2007 01:23:25 -0000 1.8 *************** *** 1,2 **** ! application { "EasyCalc" OpCl stack=0x2000 } multiple code { "mlib" "basefunc" "iface" "specfun" "graph" "newfunc" "parser" "matfunc" } --- 1,2 ---- ! application { "EasyCalc" OpCl backup stack=0x2000 } multiple code { "mlib" "basefunc" "iface" "specfun" "graph" "newfunc" "parser" "matfunc" } Index: Makefile.in =================================================================== RCS file: /cvsroot/easycalc/easycalc/Makefile.in,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** Makefile.in 1 Oct 2006 22:38:12 -0000 1.35 --- Makefile.in 28 Sep 2007 01:23:25 -0000 1.36 *************** *** 36,40 **** ROFILE = $(TARGET).ro ! CALC_OBJS = calc.o about.o clie.o clie-util.o chkstack.o \ mlib/calcDB.o mlib/fl_num.o mlib/fp.o mlib/funcs.o \ mlib/guess.o mlib/konvert.o mlib/mathem.o mlib/stack.o prefs.o \ --- 36,40 ---- ROFILE = $(TARGET).ro ! CALC_OBJS = calc.o about.o clie.o clie-util.o chkstack.o dbutil.o \ mlib/calcDB.o mlib/fl_num.o mlib/fp.o mlib/funcs.o \ mlib/guess.o mlib/konvert.o mlib/mathem.o mlib/stack.o prefs.o \ --- NEW FILE: dbutil.c --- /* * $Id: dbutil.c,v 1.1 2007/09/28 01:23:25 tvoverbe Exp $ * * Scientific Calculator for Palms. * Copyright (C) 1999,2000,2007 Ondrej Palkovsky * * 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., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * * You can contact me at 'on...@pe...'. */ #include <PalmOS.h> #include "defuns.h" static Err db_open_byid(LocalID dbid, DmOpenRef *dbref) { *dbref = DmOpenDatabase(CARDNO, dbid, dmModeReadWrite); if (*dbref) return DmGetLastErr(); return 0; } /*********************************************************************** * * FUNCTION: open_db * * DESCRIPTION: Open a database for EasyCalc. Creates a new one, * if the database does not exist or if the old database * has the wrong version * * PARAMETERS: * * RETURN: 0 - on success * other - on error * ***********************************************************************/ Int16 open_db(const Char *name, UInt16 dbversion, UInt32 crid, UInt32 dbtype, DmOpenRef *dbref) { Err err; LocalID dbid; UInt16 version; UInt32 creator; UInt32 type; UInt16 attr = 0; dbid = DmFindDatabase(CARDNO, name); if (dbid) { /* Database exists */ DmDatabaseInfo(CARDNO, dbid, NULL, /* name */ &attr, /* attrib */ &version, /* version */ NULL, /* crDate */ NULL, /* modDate */ NULL, /* bckUpDate */ NULL, /* modNum */ NULL, /* appinfoID */ NULL, /* sortInfoID */ &type, /* Type */ &creator); /* Creator */ if (version == dbversion && creator == crid && type == dbtype) { if ((attr & dmHdrAttrBackup) == 0) { attr |= dmHdrAttrBackup; DmSetDatabaseInfo(CARDNO, dbid, NULL, /* name */ &attr, /* attrib */ NULL, /* version */ NULL, /* crDate */ NULL, /* modDate */ NULL, /* bckupDate */ NULL, /* modNum */ NULL, /* appinfoID */ NULL, /* sortInfoID */ NULL, /* Type */ NULL); /* Creator */ } return db_open_byid(dbid, dbref); } /* Database exists, but with incorrect version */ err = DmDeleteDatabase(CARDNO, dbid); if (err) return err; } /* Database doesn't exist or old version */ err = DmCreateDatabase(CARDNO, name, crid, dbtype, false); if (err) return err; dbid = DmFindDatabase(CARDNO, name); version = dbversion; attr |= dmHdrAttrBackup; DmSetDatabaseInfo(CARDNO, dbid, NULL, /* name */ &attr, /* attrib */ &version, /* version */ NULL, /* crDate */ NULL, /* modDate */ NULL, /* bckUpDate */ NULL, /* modNum */ NULL, /* appinfoID */ NULL, /* sortInfoID */ NULL, /* Type */ NULL); /* Creator */ return db_open_byid(dbid, dbref); } Index: solver.c =================================================================== RCS file: /cvsroot/easycalc/easycalc/solver.c,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** solver.c 16 Sep 2006 23:30:58 -0000 1.14 --- solver.c 28 Sep 2007 01:23:25 -0000 1.15 *************** *** 41,44 **** --- 41,45 ---- #include "mathem.h" #include "prefs.h" + #include "dbutil.h" #ifdef HANDERA_SDK *************** *** 551,565 **** } - - static Err slv_db_open_byid(LocalID dbid) IFACE; - static Err - slv_db_open_byid(LocalID dbid) - { - gDB=DmOpenDatabase(CARDNO,dbid,dmModeReadWrite); - if (gDB) - return DmGetLastErr(); - return 0; - } - /*********************************************************************** * --- 552,555 ---- *************** *** 577,632 **** slv_db_open() { ! Err err; ! LocalID dbid; ! UInt16 version; ! UInt32 creator; ! UInt32 type; ! ! dbid=DmFindDatabase(CARDNO,SOLVERDBNAME); ! if (dbid) { /* Database exists */ ! DmDatabaseInfo(CARDNO,dbid, ! NULL, /* name */ ! NULL, /* attrib */ ! &version, /* version */ ! NULL, /* crDate */ ! NULL, /* modDate */ ! NULL, /* bckUpDate */ ! NULL, /* modNum */ ! NULL, /* appinfoID */ ! NULL, /* sortInfoID */ ! &type, /* Type */ ! &creator); /* Creator */ ! ! if (version==SOLVER_DB_VERSION && creator==LIB_ID && \ ! type==SOLVERDBTYPE) ! return slv_db_open_byid(dbid); ! ! /* Database exists, but with uncorrect version */ ! err=DmDeleteDatabase(CARDNO,dbid); ! if (err) ! return err; ! } ! ! /* Database doesn't exist or old version */ ! err=DmCreateDatabase(CARDNO,SOLVERDBNAME,LIB_ID,SOLVERDBTYPE,false); ! if (err) ! return err; ! ! dbid=DmFindDatabase(CARDNO,SOLVERDBNAME); ! ! version=SOLVER_DB_VERSION; ! DmSetDatabaseInfo(CARDNO,dbid, ! NULL, /* name */ ! NULL, /* attrib */ ! &version, /* version */ ! NULL, /* crDate */ ! NULL, /* modDate */ ! NULL, /* bckUpDate */ ! NULL, /* modNum */ ! NULL, /* appinfoID */ ! NULL, /* sortInfoID */ ! NULL, /* Type */ ! NULL); /* Creator */ ! return slv_db_open_byid(dbid); } --- 567,572 ---- slv_db_open() { ! return open_db(SOLVERDBNAME, SOLVER_DB_VERSION, LIB_ID, SOLVERDBTYPE, ! &gDB); } |