Update year for documentation
[yazproxy-moved-to-github.git] / src / yaz-usemarcon.cpp
1 /* This file is part of YAZ proxy
2    Copyright (C) 1998-2011 Index Data
3
4 YAZ proxy is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17 */
18
19 #include <yaz/log.h>
20 #include "proxyp.h"
21
22 Yaz_usemarcon::Yaz_usemarcon()
23 {
24 #if HAVE_USEMARCON
25     m_stage1 = 0;
26     m_stage2 = 0;
27 #endif
28 }
29
30 Yaz_usemarcon::~Yaz_usemarcon()
31 {
32 #if HAVE_USEMARCON
33     delete m_stage1;
34     delete m_stage2;
35 #endif
36 }
37
38 int Yaz_usemarcon::convert(const char *stage1, const char *stage2,
39                            const char *input, int input_len,
40                            char **output, int *output_len)
41 {
42 #if HAVE_USEMARCON
43     if (stage1 && *stage1)
44     {
45         char *converted;
46 #if RULE_VERSION >= 314
47         size_t convlen;
48 #else
49         int convlen;
50 #endif
51         if (!m_stage1)
52         {
53             m_stage1 = new Usemarcon();
54         }
55         m_stage1->SetIniFileName(stage1);
56         m_stage1->SetMarcRecord((char*) input, input_len);
57         int res = m_stage1->Convert();
58         if (res == 0)
59         {
60             m_stage1->GetMarcRecord(converted, convlen);
61             if (stage2 && *stage2)
62             {
63                 if (!m_stage2)
64                 {
65                     m_stage2 = new Usemarcon();
66                 }
67                 m_stage2->SetIniFileName(stage2);
68                 m_stage2->SetMarcRecord(converted, convlen);
69                 res = m_stage2->Convert();
70                 if (res == 0)
71                 {
72                     free(converted);
73                     m_stage2->GetMarcRecord(converted, convlen);
74                 }
75                 else
76                 {
77                     yaz_log(YLOG_LOG, "USEMARCON stage 2 error %d", res);
78                     return 0;
79                 }
80             }
81             *output = converted;
82             *output_len = convlen;
83             return 1;
84         }
85         else
86         {
87             yaz_log(YLOG_LOG, "USEMARCON stage 1 error %d", res);
88         }
89     }
90 #endif
91     return 0;
92 }
93 /*
94  * Local variables:
95  * c-basic-offset: 4
96  * c-file-style: "Stroustrup"
97  * indent-tabs-mode: nil
98  * End:
99  * vim: shiftwidth=4 tabstop=8 expandtab
100  */
101