-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsortenu.cpp
More file actions
102 lines (94 loc) · 2.25 KB
/
Copy pathsortenu.cpp
File metadata and controls
102 lines (94 loc) · 2.25 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#include <algorithm>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
using namespace std;
fstream fout;
map <string, pair <string, string> > entries;
void usage();
string getline(fstream &fin);
void sort(string filename);
int main(int argc, char**argv)
{
if(argc==0)
{
usage();
return 0;
}
string filename;
for(int i=1;i<argc;i++)
{
filename = argv[i];
if(filename[0] == '-')
{
usage();
return 0;
}
sort(filename);
}
map<string,pair<string,string> >::iterator i;
for(i=entries.begin();i!=entries.end();i++)
{
cout<<i->second.first<<endl;
cout<<i->second.second<<endl;
}
}
void usage()
{
cout<<"sorteng"<<endl;
cout<<endl;
cout<<"This is a small tool which is used as part of a larger system."<<endl;
cout<<"What this tool does is search through a file where odd lines are english glosses and even lines are ASL."<<endl;
cout<<"It then sorts them according to english order."<<endl;
cout<<"This tools job is to sort all inputs prior repackaging into a multi-lesson glossary."<<endl;
cout<<endl;
cout<<"If you really must know, it's expecting a list of files to do the sorting from."<<endl;
cout<<endl;
cout<<"Good Luck!"<<endl;
}
string getline(fstream &fin)
{
string result;
char c=0;
while(true)
{
if(fin.peek()==-1)
{
return result;
}
c = static_cast<char>(fin.get());
if(c==0xa)
{
if(fin.peek()==0xd)
{
fin.get();
}
return result;
}
if(c==0xd)
{
if(fin.peek()==0xa)
{
fin.peek();
}
return result;
}
result.push_back(c);
}
}
void sort(string filename)
{
fstream fin;
fin.open(filename, ios::in);
while(fin.peek()>-1)
{
string key,enu,asl;
key = enu = getline(fin);
asl = getline(fin);
transform(key.begin(), key.end(), key.begin(), ::tolower);
asl = asl.substr(0,asl.find('M')) + "B" + asl.substr(asl.find('M')+1);
entries[key]=make_pair(enu,asl);
}
fin.close();
}