home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
linuxmafia.com 2016
/
linuxmafia.com.tar
/
linuxmafia.com
/
pub
/
palmos
/
progect-src-0.20.tar.gz
/
progect-src-0.20.tar
/
progect-0.20
/
MemoDB.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-10-26
|
3KB
|
118 lines
/******************************************************************************
*
* Copyright (c) 1995-1999 Palm Computing, Inc. or its subsidiaries.
* All rights reserved.
*
* File: MemoDB.c
*
* Description:
* Memo Manager routines
*
* History:
* 1/3/95 rsf - Created
* 9/13/95 mlb - added MemoNewRecord for use by mbs shell command
* 10/02/99 jmp - Add MemoGetDatabase() routine.
*
*****************************************************************************/
#include <PalmOS.h>
#include "MemoDB.h"
#include "MemoMain.h"
#include "progect.h"
#include "progectRsc.h"
/************************************************************
*
* FUNCTION: MemoNewRecord
*
* DESCRIPTION: Create a new record
*
* PARAMETERS: database pointer
* database record
*
* RETURNS: zero if successful, errorcode if not
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* monty 9/13/95 Initial Revision
* lb 9/21/00 mod for progect
*
*************************************************************/
Err MemoNewRecord (DmOpenRef dbP, MemoItemPtr item, UInt16 *index)
{
Err result;
int size = 0;
UInt32 offset;
MemHandle recordH;
MemoDBRecordPtr recordP, nilP=0;
// Compute the size of the new memo record.
// lb : had to add 1 for \0
size = StrLen (item->note) + 1;
if (size > memoMaxLength)
{
DEBUG1("Memo too big");
return dmErrMemError;
}
// Allocate a chunk in the database for the new record.
recordH = (MemHandle)DmNewHandle(dbP, (UInt32) size);
if (recordH == NULL)
return dmErrMemError;
// Pack the the data into the new record.
recordP = MemHandleLock (recordH);
offset = (UInt32)&nilP->note;
DmStrCopy(recordP, offset, item->note);
MemPtrUnlock (recordP);
// Insert the record.
result = DmAttachRecord(dbP, index, recordH, 0);
if (result)
MemHandleFree(recordH);
return result;
}
/***********************************************************************
*
* FUNCTION: MemoGetDatabase
*
* DESCRIPTION: Get the application's database. Open the database if it
* exists, create it if neccessary.
*
* PARAMETERS: *dbPP - pointer to a database ref (DmOpenRef) to be set
* mode - how to open the database (dmModeReadWrite)
*
* RETURNED: Err - zero if no error, else the error
*
* REVISION HISTORY:
* Name Date Description
* ---- ---- -----------
* jmp 10/02/99 Initial Revision
*
***********************************************************************/
Err MemoGetDatabase (DmOpenRef *dbPP, UInt16 mode)
{
DmOpenRef dbP;
*dbPP = NULL;
// Find the application's data file.
dbP = DmOpenDatabaseByTypeCreator (memoDBType, sysFileCMemo, mode);
if (!dbP)
{
DEBUG1("Can't open Memo database");
return 1;
}
*dbPP = dbP;
return 0;
}