home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
linuxmafia.com 2016
/
linuxmafia.com.tar
/
linuxmafia.com
/
pub
/
palmos
/
astro-src-2.1.0beta.tar.gz
/
astro-src-2.1.0beta.tar
/
astro-src-2.1.0beta
/
source
/
PalmUtil.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-09-26
|
5KB
|
190 lines
/*
* Astro Info - a an astronomical calculator/almanac for PalmOS devices.
*
* $Id: PalmUtil.c,v 1.2 2000/08/09 12:34:57 mheinz Exp $
* Copyright (C) 2000, Michael Heinz
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <PalmOS.h>
#include "PalmUtil.h"
#include "MathLib.h"
/*
* Returns true if the ROM version is at least
* minVersion.
*/
Boolean CheckMinRomVersion(UInt32 minVersion)
{
UInt32 romVersion;
FtrGet(sysFtrCreator,
sysFtrNumROMVersion,
&romVersion);
return (minVersion <= romVersion);
}
/* Retrieve the current value of a field. */
int GetNumField(FormPtr formPtr, UInt16 id)
{
FieldPtr fld = (FieldPtr)FrmGetObjectPtr(formPtr,
FrmGetObjectIndex(formPtr,
id));
char *s = FldGetTextPtr(fld);
return StrAToI(s);
}
/*
* Convert a double to a string.
* s = destination string
* d = number to convert
* p = # of digits to the right of the decimal.
* l = the maximum length of s.
*/
void
StrDToA(char *s,
double d,
int p,
int l)
{
int c;
double i,f;
c = 0;
if (d < 0.0)
s[c++] = '-';
d = fabs(d);
i = floor(d);
f = d - i;
StrIToA(&s[c],
i);
if (p == 0 || c >= l)
return;
c = StrLen(s);
s[c++] = '.';
while (p-- > 0 && c < l) {
f = f * 10.0;
i = floor(f);
f = f - i;
s[c++] = 48 + i;
}
s[c] = 0;
}
#define MAXDBRECORDS 16
DBRecord**
GetDBList(UInt32 type,
UInt32 creator,
int *count)
{
Err error;
Boolean newSearch = 1;
DmSearchStateType* state = (DmSearchStateType*)MemPtrNew(sizeof(DmSearchStateType));
DBRecord** recordList = (DBRecord**)MemPtrNew(sizeof(DBRecord*)*MAXDBRECORDS);
*count = 0;
while (*count < MAXDBRECORDS)
{
DBRecord* record = MemPtrNew(sizeof(DBRecord));
recordList[*count] = record;
error = DmGetNextDatabaseByTypeCreator(newSearch,
state,
type,
creator,
0,
&(record->cardNo),
&(record->dbID));
if (error)
{
MemPtrFree(record);
break;
}
error = DmDatabaseInfo(record->cardNo,
record->dbID,
record->name,
NULL, NULL, NULL,NULL,
NULL, NULL, NULL, NULL,
NULL, NULL);
if (error)
{
MemPtrFree(record);
break;
}
newSearch = 0;
(*count)++;
}
MemPtrFree(state);
if ((*count) == 0)
{
FreeDBList(recordList,0);
return NULL;
}
return recordList;
}
void
FreeDBList(DBRecord **recordList, int count)
{
int i;
for (i=0; i < count; i++)
{
DBRecord *record = recordList[i];
MemPtrFree(record);
}
MemPtrFree(recordList);
}
void
GotoApplication(UInt32 ApplId)
{
Err err;
UInt16 cardNo;
LocalID dbID;
DmSearchStateType dss;
/*
* Bounce the application
*/
err = DmGetNextDatabaseByTypeCreator(true,
&dss,
sysFileTApplication,
ApplId,
true,
&cardNo,
&dbID);
ErrFatalDisplayIf(err != errNone,"Failed to launch application!");
SysUIAppSwitch(cardNo,dbID,
sysAppLaunchCmdNormalLaunch,
NULL);
}