1 /******************************************************************************
2 *
3 * Copyright (C) 2009, The Gentee Group. All rights reserved.
4 * This file is part of the Gentee open source project - http://www.gentee.com.
5 *
6 * THIS FILE IS PROVIDED UNDER THE TERMS OF THE GENTEE LICENSE ("AGREEMENT").
7 * ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS FILE CONSTITUTES RECIPIENTS
8 * ACCEPTANCE OF THE AGREEMENT.
9 *
10 * Author: Alexey Krivonogov ( gentee )
11 *
12 ******************************************************************************/
13
14 #include "ged.h"
15
16 void ged_setuint( pgedfield pfield, pubyte ptr, uint ival )
17 {
18 pubyte offset = ptr + pfield->offset;
19 switch ( pfield->ftype )
20 {
21 case FT_BYTE:
22 case FT_UBYTE:
23 *offset = ( ubyte )ival;
24 break;
25 case FT_SHORT:
26 case FT_USHORT:
27 *( pushort )offset = ( ushort )ival;
28 break;
29 case FT_INT:
30 case FT_UINT:
31 *( puint )offset = ival;
32 break;
33 }
34 }
35
36 uint ged_append( pged pdb, puint ptr )
37 {
38 uint i, aoff = 0;
39 pubyte offset;
40 pubyte prec = buf_ptr( PRECORD );
41
42 // *prec = 0; // Delete mask
43 mem_zero( prec, pdb->fsize );
44
45 for ( i = 0; i < pdb->head->numfields; i++ )
46 {
47 offset = prec + pdb->fields[ i ].offset;
48 if ( !ptr )
49 continue;
50
51 switch ( pdb->fields[ i ].ftype )
52 {
53 case FT_BYTE:
54 case FT_UBYTE:
55 *offset = ( ubyte )*ptr;
56 break;
57 case FT_SHORT:
58 case FT_USHORT:
59 *( pushort )offset = ( ushort )*ptr;
60 break;
61 case FT_INT:
62 case FT_UINT:
63 *( puint )offset = *ptr;
64 break;
65 case FT_LONG:
66 case FT_ULONG:
67 *( plong64 )offset = *( plong64 )ptr;
68 ptr++;
69 break;
70 case FT_FLOAT:
71 *( puint )offset = *ptr;
72 break;
73 case FT_DOUBLE:
74 *( double* )offset = *( double* )ptr;
75 ptr++;
76 break;
77 case FT_STR:
78 if ( *ptr )
79 mem_copy( offset, ( pubyte )*ptr, min( pdb->fields[ i ].width,
80 (uint)lstrlen( ( pubyte )*ptr )));
81 break;
82 case FT_USTR:
83 if ( *ptr )
84 mem_copy( offset, ( pubyte )*ptr, min( pdb->fields[ i ].width,
85 (uint)lstrlenW( ( LPWSTR ) *ptr ) << 1 ));
86 break;
87 }
88 ptr++;
89 }
90 if ( pdb->head->autoid )
91 {
92 ged_setuint( pdb->fields + pdb->head->autoid - 1, prec, ++pdb->autoid );
93 *( puint )( prec + pdb->fsize ) = pdb->autoid;
94 pdb->gm->data.use -= sizeof( uint );
95 aoff = sizeof( uint );
96 }
97 ++pdb->reccount;
98 // ++pdb->reccount;
99 buf_append( PDATA, prec, pdb->fsize + aoff );
100 pdb->db = buf_ptr( PDATA ) + pdb->head->oversize;
101 ged_goto( pdb, pdb->reccount );
102 return ged_write( pdb, prec, -( long64 )aoff, pdb->fsize + aoff );
103 }
104
105 uint ged_isdel( pged pdb )
106 {
107 return *pdb->recptr;
108 }
109
110 /*BOOL ged_delete( pged pdb, uint recno )
111 {
112 return *pdb->recptr;
113 }*/