|
a/src/common/unacpp.cpp |
|
b/src/common/unacpp.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: unacpp.cpp,v 1.5 2006-01-05 16:37:26 dockes Exp $ (C) 2004 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: unacpp.cpp,v 1.6 2006-01-06 13:18:17 dockes Exp $ (C) 2004 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
|
4 |
|
5 |
#ifndef TEST_UNACPP
|
5 |
#ifndef TEST_UNACPP
|
6 |
#include <stdio.h>
|
6 |
#include <stdio.h>
|
7 |
|
7 |
|
|
... |
|
... |
15 |
|
15 |
|
16 |
#include "unacpp.h"
|
16 |
#include "unacpp.h"
|
17 |
#include "unac.h"
|
17 |
#include "unac.h"
|
18 |
|
18 |
|
19 |
|
19 |
|
20 |
bool unac_cpp(const std::string &in, std::string &out, const char *encoding)
|
20 |
bool unacmaybefold(const std::string &in, std::string &out,
|
|
|
21 |
const char *encoding, bool dofold)
|
21 |
{
|
22 |
{
|
22 |
char *cout = 0;
|
23 |
char *cout = 0;
|
23 |
size_t out_len;
|
24 |
size_t out_len;
|
24 |
|
25 |
int status;
|
|
|
26 |
status = dofold ?
|
|
|
27 |
unacfold_string(encoding, in.c_str(), in.length(), &cout, &out_len) :
|
25 |
if (unac_string(encoding, in.c_str(), in.length(), &cout, &out_len) < 0) {
|
28 |
unac_string(encoding, in.c_str(), in.length(), &cout, &out_len);
|
26 |
char cerrno[20];
|
29 |
if (status < 0) {
|
27 |
sprintf(cerrno, "%d", errno);
|
|
|
28 |
out = string("unac_string failed, errno : ") + cerrno;
|
|
|
29 |
return false;
|
|
|
30 |
}
|
|
|
31 |
out.assign(cout, out_len);
|
|
|
32 |
free(cout);
|
|
|
33 |
return true;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
bool unac_cpp_utf16be(const std::string &in, std::string &out)
|
|
|
37 |
{
|
|
|
38 |
char *cout = 0;
|
|
|
39 |
size_t out_len;
|
|
|
40 |
|
|
|
41 |
if (unac_string_utf16(in.c_str(), in.length(), &cout, &out_len) < 0) {
|
|
|
42 |
char cerrno[20];
|
30 |
char cerrno[20];
|
43 |
sprintf(cerrno, "%d", errno);
|
31 |
sprintf(cerrno, "%d", errno);
|
44 |
out = string("unac_string failed, errno : ") + cerrno;
|
32 |
out = string("unac_string failed, errno : ") + cerrno;
|
45 |
return false;
|
33 |
return false;
|
46 |
}
|
34 |
}
|
|
... |
|
... |
63 |
#include "unacpp.h"
|
51 |
#include "unacpp.h"
|
64 |
#include "readfile.h"
|
52 |
#include "readfile.h"
|
65 |
|
53 |
|
66 |
int main(int argc, char **argv)
|
54 |
int main(int argc, char **argv)
|
67 |
{
|
55 |
{
|
|
|
56 |
bool dofold = true;
|
68 |
if (argc != 4) {
|
57 |
if (argc != 4) {
|
69 |
cerr << "Usage: unacpp <encoding> <infile> <outfile>" << endl;
|
58 |
cerr << "Usage: unacpp <encoding> <infile> <outfile>" << endl;
|
70 |
exit(1);
|
59 |
exit(1);
|
71 |
}
|
60 |
}
|
72 |
const char *encoding = argv[1];
|
61 |
const char *encoding = argv[1];
|
|
... |
|
... |
77 |
if (!file_to_string(ifn, odata)) {
|
66 |
if (!file_to_string(ifn, odata)) {
|
78 |
cerr << "file_to_string: " << odata << endl;
|
67 |
cerr << "file_to_string: " << odata << endl;
|
79 |
exit(1);
|
68 |
exit(1);
|
80 |
}
|
69 |
}
|
81 |
string ndata;
|
70 |
string ndata;
|
82 |
if (!unac_cpp(odata, ndata, encoding)) {
|
71 |
if (!unacmaybefold(odata, ndata, encoding, dofold)) {
|
83 |
cerr << "unac: " << ndata << endl;
|
72 |
cerr << "unac: " << ndata << endl;
|
84 |
exit(1);
|
73 |
exit(1);
|
85 |
}
|
74 |
}
|
86 |
|
75 |
|
87 |
int fd = open(ofn, O_CREAT|O_EXCL|O_WRONLY, 0666);
|
76 |
int fd = open(ofn, O_CREAT|O_EXCL|O_WRONLY, 0666);
|