*** empty log message ***

This commit is contained in:
dockes
2004-12-17 15:36:13 +00:00
parent ab473faa8c
commit 3c66f8e964
3 changed files with 142 additions and 21 deletions
+81
View File
@@ -0,0 +1,81 @@
#ifndef lint
static char rcsid[] = "@(#$Id: unacpp.cpp,v 1.1 2004-12-17 15:36:13 dockes Exp $ (C) 2004 J.F.Dockes";
#endif
#ifndef TEST_UNACPP
#include <errno.h>
#include <string>
using std::string;
#include "unacpp.h"
#include "unac.h"
bool unac_cpp(const std::string &in, std::string &out, const char *encoding)
{
char *cout = 0;
size_t out_len;
if (unac_string(encoding, in.c_str(), in.length(), &cout, &out_len) < 0) {
char cerrno[20];
sprintf(cerrno, "%d", errno);
out = string("unac_string failed, errno : ") + cerrno;
return false;
}
out.assign(cout, out_len);
return true;
}
#else // not testing
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <iostream>
using namespace std;
#include "unacpp.h"
#include "readfile.h"
int main(int argc, char **argv)
{
if (argc != 4) {
cerr << "Usage: unacpp <encoding> <infile> <outfile>" << endl;
exit(1);
}
const char *encoding = argv[1];
string ifn = argv[2];
const char *ofn = argv[3];
string odata;
if (!file_to_string(ifn, odata)) {
cerr << "file_to_string: " << odata << endl;
exit(1);
}
string ndata;
if (!unac_cpp(odata, ndata, encoding)) {
cerr << "unac: " << ndata << endl;
exit(1);
}
int fd = open(ofn, O_CREAT|O_EXCL|O_WRONLY, 0666);
if (fd < 0) {
cerr << "Open/Create " << ofn << " failed: " << strerror(errno)
<< endl;
exit(1);
}
if (write(fd, ndata.c_str(), ndata.length()) != (int)ndata.length()) {
cerr << "Write(2) failed: " << strerror(errno) << endl;
exit(1);
}
close(fd);
exit(0);
}
#endif
+11
View File
@@ -0,0 +1,11 @@
#ifndef _UNACPP_H_INCLUDED_
#define _UNACPP_H_INCLUDED_
/* @(#$Id: unacpp.h,v 1.1 2004-12-17 15:36:13 dockes Exp $ (C) 2004 J.F.Dockes */
#include <string>
// A small wrapper for unac.c
extern bool unac_cpp(const std::string &in, std::string &out,
const char *encoding = "UTF-8");
#endif /* _UNACPP_H_INCLUDED_ */