File: conv.cxx

package info (click to toggle)
swath 0.3.0.cvs20030404
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,564 kB
  • ctags: 545
  • sloc: sh: 6,926; cpp: 3,643; makefile: 151
file content (62 lines) | stat: -rw-r--r-- 1,572 bytes parent folder | download | duplicates (2)
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
//
// conv.cc - Main Program for text converter program
// Created: 19 Jan 1999
// Author:  Theppitak Karoonboonyanan <thep@links.nectec.or.th>
//

#include <string>
#include <iostream>
#include <fstream>
#include "convfact.h"
#include "utf8.h"
#include "tis620.h"

//
// SYNOPSIS
//    conv ([-t|-u], [source], [target]);
// DESCRIPTION
//    'conv' converts text data from the file specified by 'source' and
//    writes the result to 'target' file. If either 'source' or 'target'
//    is omitted, standard input and standard output will be assumed.
// OPTIONS
//    -t  Converts UTF-8 to TIS-620
//    -u  Converts TIS-620 to UTF-8 (default)
//

int conv( char format, const char *inputFileName,const char *outputFileName)
{
    ETextFormat inputFormat = TIS620;
    ETextFormat outputFormat = UTF8;
    std::istream*    pInputFile = &std::cin;
    std::ostream*    pOutputFile = &std::cout;

	if (format=='t') {
		inputFormat = UTF8;
		outputFormat = TIS620;
	}else{
		inputFormat = TIS620;
		outputFormat = UTF8;
	}

    if (inputFileName) {
        pInputFile = new std::ifstream(inputFileName);
    }
    if (outputFileName) {
        pOutputFile = new std::ofstream(outputFileName);
    }

    TextReader* pReader = CreateTextReader(inputFormat, *pInputFile);
    TextWriter* pWriter = CreateTextWriter(outputFormat, *pOutputFile);

    if (pReader && pWriter) {
        TransferText(pReader, pWriter);
    }

    delete pReader;
    delete pWriter;
    if (inputFileName)  { delete pInputFile; }
    if (outputFileName) { delete pOutputFile; }

    return 0;
}