summaryrefslogtreecommitdiffstats
path: root/samples/split_phonebook.c
blob: 4ecc094c211cc9f803e51741221f662b08b93a86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/******************************************************************************

    (C) Nick Marley, 2001 -

    This software is distributed under the GNU Lesser General Public Licence.
    Please read and understand the comments at the top of vf_iface.h before use!

FILE
    $Workfile$
    $Revision: 1.3 $
    $Author: tilda $
         
ORIGINAL AUTHOR
    Nick Marley

DESCRIPTION
    Platform independant test harness for the vformat library functions.  This
    code runs various tests on the library, results are written to stdout.

REFERENCES
    (none)    

MODIFICATION HISTORY
 *  $Log: split_phonebook.c,v $
 *  Revision 1.3  2001/10/24 18:37:38  tilda
 *  BASE64 bugfixes.  Split reader/writer code. Start create/modify work.
 *
 *  Revision 1.2  2001/10/24 05:29:24  tilda
 *  Tidy up.
 *
 *  Revision 1.1.1.1  2001/10/16 05:49:57  tilda
 *  Initial Import to CVS.
 *
 *******************************************************************************/

#ifndef NORCSID
static const char split_phonebook_c_vss_id[] = "$Header: /cvsroot/vformat/build/samples/split_phonebook.c,v 1.3 2001/10/24 18:37:38 tilda Exp $";
#endif

/*=============================================================================*
 ANSI C & System-wide Header Files
 *=============================================================================*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

/*============================================================================*
 Interface Header Files
 *============================================================================*/

#include "vformat/vf_iface.h"

/*============================================================================*
 Local Header File
 *============================================================================*/

#include "split_phonebook.h"

/*============================================================================*
 Private Defines
 *============================================================================*/
/* None */

/*============================================================================*
 Private Data Types
 *============================================================================*/
/* None */

/*============================================================================*
 Private Function Prototypes
 *============================================================================*/
/* None */

/*============================================================================*
 Private Data
 *============================================================================*/
/* None */

/*============================================================================*
 Public Function Implementations
 *============================================================================*/


/*----------------------------------------------------------------------------*
 * NAME
 *      split_phonebook()
 * 
 * DESCRIPTION
 *      Read in the indicated file which is assumed to be a list of VCARDs.
 *      The component cards are written out to individual files.
 *
 * RETURNS
 *      TRUE <=> read / written OK.
 *----------------------------------------------------------------------------*/

bool_t split_phonebook(
    const char *p_filename,
    const char *p_outdir
    )
{
    VF_OBJECT_T *p_object = NULL;
    bool_t ret = FALSE;

    if (vf_read_file(&p_object, p_filename))
    {
        VF_OBJECT_T *p_tmp = p_object;

        ret = TRUE;

        do
        {
            VF_PROP_T *p_prop;
            char name[256];

            name[0] = '\0';

            if (vf_get_property(&p_prop, p_object, FALSE, NULL, VFP_NAME, NULL))
            {
                const char *p_givenname = vf_get_prop_value_string(p_prop, VFP_NAME_GIVEN);
                const char *p_familyname = vf_get_prop_value_string(p_prop, VFP_NAME_FAMILY);

                if (p_familyname && p_givenname)
                {
                    sprintf(name, "%s %s", p_givenname, p_familyname);
                }
                else
                if (p_familyname)
                {
                    strcpy(name, p_familyname);
                }
                else
                if (p_givenname)
                {
                    strcpy(name, p_givenname);
                }
            }
            else
            if (vf_get_property(&p_prop, p_object, FALSE, NULL, VFP_FULLNAME, NULL))
            {
                const char *p_fullname = vf_get_prop_value_string(p_prop, VFP_NAME_GIVEN);

                if (p_fullname)
                {
                    strcpy(name, p_fullname);
                }
            }

            if (name[0])
            {
                char filename[_MAX_PATH];

                sprintf(filename, "%s\\%s.vcf", p_outdir, name);

                ret &= vf_write_file(filename, p_object, FALSE);
            }
        }
        while (ret && vf_get_next_object(&p_object))
            ;

        vf_delete_object(p_tmp, TRUE);
    }

    return ret;
}



/*============================================================================*
 Private Function Implementations
 *============================================================================*/