2e64c71313bece04fac2e12fb3d9d9b325ab474a
[yazproxy-moved-to-github.git] / src / yaz-usemarcon.cpp
1 /* $Id: yaz-usemarcon.cpp,v 1.2 2005-06-25 15:58:34 adam Exp $
2    Copyright (c) 1998-2004, Index Data.
3
4 This file is part of the yaz-proxy.
5
6 YAZ proxy is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2, or (at your option) any later
9 version.
10
11 YAZ proxy is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with YAZ proxy; see the file LICENSE.  If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
19 02111-1307, USA.
20  */
21
22 #include "proxyp.h"
23
24 Yaz_usemarcon::Yaz_usemarcon()
25 {
26 #if HAVE_USEMARCON
27     m_stage1 = 0;
28     m_stage2 = 0;
29 #endif
30 }
31
32 Yaz_usemarcon::~Yaz_usemarcon()
33 {
34 #if HAVE_USEMARCON
35     delete m_stage1;
36     delete m_stage2;
37 #endif
38 }
39
40 int Yaz_usemarcon::convert(const char *stage1, const char *stage2,
41                            const char *input, int input_len,
42                            char **output, int *output_len)
43 {
44 #if HAVE_USEMARCON
45     if (stage1 && *stage1)
46     {
47         char *converted;
48         int convlen;
49         if (!m_stage1)
50         {
51             m_stage1 = new CDetails();
52         }
53         m_stage1->SetIniFileName(stage1);
54         m_stage1->SetMarcRecord((char*) input, input_len);
55         int res = m_stage1->Start();
56         if (res == 0)
57         {
58             m_stage1->GetMarcRecord(converted, convlen);
59             if (stage2 && *stage2)
60             {
61                 if (!m_stage2)
62                 {
63                     m_stage2 = new CDetails();
64                 }
65                 m_stage2->SetIniFileName(stage2);
66                 m_stage2->SetMarcRecord(converted, convlen);
67                 res = m_stage2->Start();
68                 if (res == 0)
69                 {
70                     free(converted);
71                     m_stage2->GetMarcRecord(converted, convlen);
72                 }
73                 else
74                     return 0;
75             }
76             *output = converted;
77             *output_len = convlen;
78             return 1;
79         }
80     }
81 #endif
82     return 0;
83 }
84 /*
85  * Local variables:
86  * c-basic-offset: 4
87  * indent-tabs-mode: nil
88  * End:
89  * vim: shiftwidth=4 tabstop=8 expandtab
90  */
91