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 >
C/C++ Source or Header  |  2000-10-26  |  3KB  |  118 lines

  1. /******************************************************************************
  2.  *
  3.  * Copyright (c) 1995-1999 Palm Computing, Inc. or its subsidiaries.
  4.  * All rights reserved.
  5.  *
  6.  * File: MemoDB.c
  7.  *
  8.  * Description:
  9.  *        Memo Manager routines
  10.  *
  11.  * History:
  12.  *       1/3/95    rsf - Created
  13.  *       9/13/95    mlb - added MemoNewRecord for use by mbs shell command
  14.  *        10/02/99 jmp - Add MemoGetDatabase() routine.
  15.  *
  16.  *****************************************************************************/
  17.  
  18. #include <PalmOS.h>
  19.  
  20. #include "MemoDB.h"
  21. #include "MemoMain.h"
  22. #include "progect.h"
  23. #include "progectRsc.h"
  24.  
  25.  
  26. /************************************************************
  27.  *
  28.  *  FUNCTION: MemoNewRecord
  29.  *
  30.  *  DESCRIPTION: Create a new record
  31.  *
  32.  *  PARAMETERS: database pointer
  33.  *                database record
  34.  *
  35.  *  RETURNS: zero if successful, errorcode if not
  36.  *
  37.  *  REVISION HISTORY:
  38.  *            Name    Date        Description
  39.  *            ----    ----        -----------
  40.  *            monty    9/13/95    Initial Revision
  41.  *            lb      9/21/00 mod for progect
  42.  *
  43.  *************************************************************/
  44. Err MemoNewRecord (DmOpenRef dbP, MemoItemPtr item, UInt16 *index)
  45. {
  46.     Err                     result;
  47.     int                    size = 0;
  48.     UInt32                offset;
  49.     MemHandle            recordH;    
  50.     MemoDBRecordPtr    recordP, nilP=0;
  51.  
  52.     // Compute the size of the new memo record.
  53.     // lb : had to add 1 for \0
  54.     size = StrLen (item->note) + 1;
  55.     if (size > memoMaxLength)
  56.     {
  57.         DEBUG1("Memo too big");
  58.         return dmErrMemError;
  59.     }
  60.  
  61.     //  Allocate a chunk in the database for the new record.
  62.     recordH = (MemHandle)DmNewHandle(dbP, (UInt32) size);
  63.     if (recordH == NULL)
  64.         return dmErrMemError;
  65.  
  66.     // Pack the the data into the new record.
  67.     recordP = MemHandleLock (recordH);
  68.     offset = (UInt32)&nilP->note;
  69.     DmStrCopy(recordP, offset, item->note);
  70.     
  71.     MemPtrUnlock (recordP);
  72.  
  73.     // Insert the record.
  74.     result = DmAttachRecord(dbP, index, recordH, 0);
  75.     if (result) 
  76.         MemHandleFree(recordH);
  77.     
  78.     return result;
  79. }
  80.  
  81.  
  82. /***********************************************************************
  83.  *
  84.  * FUNCTION:     MemoGetDatabase
  85.  *
  86.  * DESCRIPTION:  Get the application's database.  Open the database if it
  87.  * exists, create it if neccessary.
  88.  *
  89.  * PARAMETERS:   *dbPP - pointer to a database ref (DmOpenRef) to be set
  90.  *                      mode - how to open the database (dmModeReadWrite)
  91.  *
  92.  * RETURNED:     Err - zero if no error, else the error
  93.  *
  94.  * REVISION HISTORY:
  95.  *            Name        Date        Description
  96.  *            ----        ----        -----------
  97.  *            jmp        10/02/99    Initial Revision
  98.  *
  99.  ***********************************************************************/
  100. Err MemoGetDatabase (DmOpenRef *dbPP, UInt16 mode)
  101. {
  102.     DmOpenRef dbP;
  103.  
  104.     *dbPP = NULL;
  105.   
  106.   // Find the application's data file.
  107.     dbP = DmOpenDatabaseByTypeCreator (memoDBType, sysFileCMemo, mode);
  108.     if (!dbP)
  109.         {
  110.             DEBUG1("Can't open Memo database");
  111.             return 1;
  112.         }
  113.     
  114.     *dbPP = dbP;
  115.     return 0;
  116. }
  117.  
  118.