presage
0.9.2~beta
presage
src
tools
text2token.cpp
Go to the documentation of this file.
1
2
/******************************************************
3
* Presage, an extensible predictive text entry system
4
* ---------------------------------------------------
5
*
6
* Copyright (C) 2008 Matteo Vescovi <matteo.vescovi@yahoo.co.uk>
7
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 2 of the License, or
11
(at your option) any later version.
12
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
17
18
You should have received a copy of the GNU General Public License along
19
with this program; if not, write to the Free Software Foundation, Inc.,
20
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
*
22
**********(*)*/
23
24
25
#include <iostream>
26
#include <unistd.h>
27
#include <getopt.h>
28
#include <string>
29
#include <assert.h>
30
31
#include "
tokenizer.h
"
32
#include "
progress.h
"
33
34
std::string
program_name
;
35
36
void
printUsage
();
37
void
printVersion
();
38
39
40
41
int
main
(
int
argc,
char
* argv[] ) {
42
43
program_name
= argv[0];
44
int
next_option;
45
46
47
// getopt structures
48
const
char
*
const
short_options =
"hv"
;
49
50
const
struct
option long_options[] = {
51
{
"help"
, 0, NULL,
'h'
},
52
{
"version"
,0, NULL,
'v'
},
53
{ NULL, 0, NULL, 0 }
54
};
55
56
do
{
57
next_option = getopt_long( argc, argv,
58
short_options, long_options, NULL );
59
60
switch
( next_option ) {
61
case
'h'
:
// --help or -h option
62
printUsage
();
63
exit( 0 );
64
break
;
65
case
'v'
:
// --version or -v option
66
printVersion
();
67
exit( 0 );
68
break
;
69
case
'?'
:
// unknown option
70
printUsage
();
71
exit( 0 );
72
break
;
73
case
-1:
74
break
;
75
default
:
76
abort();
77
}
78
79
}
while
( next_option != -1 );
80
81
82
// check we have enough arguments
83
if
( argc - optind < 2 ) {
84
printUsage
();
85
exit(0);
86
}
87
88
89
// open outfile for output
90
std::ofstream outfile( argv[ optind ], std::ios::out );
91
assert( outfile );
92
93
94
// do the actual processing file by file
95
std::string token;
96
bool
done;
97
98
Tokenizer
* tokenizerPtr;
99
for
(
int
i = optind + 1; i < argc; i++ ) {
// optind + 1 because optind
100
// points to output file
101
// print out file information
102
std::cout <<
std::endl
103
<<
"Parsing file "
<< argv[i]
104
<<
std::endl
<<
std::endl
;
105
106
printProgressHeading();
107
108
// initialize escape variable done
109
done =
false
;
110
// create tokenizer object and open input file stream
111
tokenizerPtr =
new
Tokenizer
( argv[i] );
112
113
while
( !done ) {
114
115
// extract token from input stream
116
tokenizerPtr->tokenize( &token, &done );
117
118
// update progress bar
119
progressBar( tokenizerPtr->getProgress() );
120
121
// insert token into output stream
122
outfile << token <<
std::endl
;
123
}
124
125
delete
tokenizerPtr;
126
}
127
128
std::cout <<
std::endl
<<
std::endl
;
129
130
// close output file
131
outfile.close();
132
133
return
0;
134
}
135
136
137
138
139
140
141
void
printVersion
()
142
{
143
std::cout <<
"Version 0.1"
<<
std::endl
;
144
}
145
146
147
void
printUsage
()
148
{
149
std::cout <<
"Usage: "
<<
program_name
150
<<
" [OPTIONS] [OUTFILE] [INFILES]..."
151
<<
std::endl
<<
std::endl
152
<<
program_name
153
<<
" is free software distributed under the GPL."
154
<<
std::endl
155
<<
"Copyright by Matteo Vescovi"
<<
std::endl
;
156
}
157
158
Tokenizer
Definition:
tokenizer.h:64
progress.h
printVersion
void printVersion()
Definition:
text2token.cpp:141
tokenizer.h
program_name
std::string program_name
Definition:
text2token.cpp:34
main
int main(int argc, char *argv[])
Definition:
text2token.cpp:41
printUsage
void printUsage()
Definition:
text2token.cpp:147
endl
const Logger< _charT, _Traits > & endl(const Logger< _charT, _Traits > &lgr)
Definition:
logger.h:278
Generated on Wed Nov 28 2018 12:12:14 for presage by
1.8.14