-
Notifications
You must be signed in to change notification settings - Fork 5
/
source.h
149 lines (140 loc) · 3.7 KB
/
source.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef SOURCE_H
#define SOURCE_H
#include<iostream>
#include<dirent.h>
#include<fstream>
#include<list>
#include<string>
#include"algo.h"
using namespace std;
class source{
public:
list<list<string> > lol;
string filename;
bool new_file();
bool open_file();
bool show_file();
bool write_file();
bool close_file();
bool list_dir();
bool open_editor();
};
bool source::new_file(){
ofstream file;
file.open("source/"+filename+".hyp");
return true;
}
bool source::list_dir(){
cout<<"\nsource codes\n````````````\n";
DIR *dir;
struct dirent *ent;
if ((dir = opendir ("source")) != NULL) {
int nxt_lin=0;
while ((ent = readdir (dir)) != NULL) {
string f_name=ent->d_name;
if(f_name[f_name.size()-1]=='p'){
f_name= f_name.substr(0, f_name.size()-4);
if(nxt_lin%5==0) cout<<endl;
cout<<f_name<<".hyp"<<"\t";
nxt_lin++;
}
}
closedir (dir);
} else {
perror ("");
}
cout<<"\n\nEnter a name from the above list to open OR Enter a new name to create one"<<endl;
}
bool source::open_editor(){
string topicName="source/"+filename+".hyp";
topicName = "subl \"" + topicName + "\"";
if(system(topicName.c_str())){
string topicName="source/"+filename+".hyp";
topicName = "notepad \"" + topicName + "\"";
system(topicName.c_str());
}
}
bool source::open_file(){
fstream file;
file.open("source/"+filename+".hyp");
if(file.fail()) return false;
string s="";
int cmt_flag=0;
while(file){
string p;
getline(file,p);
s+=p;
}
list<string> l;
string word="";
int str_flg=0;
int lineNo=2;
algo al;
l.push_back(al.int_to_string(1));
for(unsigned int i=0;i< s.length();i++){
if(s[i]!=' ' && s[i]!=';' && s[i]!=',' && s[i]!=':' && str_flg==0){
word+=s[i];
if(s[i]=='"') str_flg=1;
}
else if(str_flg==1){
word+=s[i];
if(s[i]=='"') str_flg=0;
continue;
}
else{
if(word!=""){
l.push_back(word);
}
word="";
}
if(s[i]==';' || s[i]==':'){
lol.push_back(l);
l.erase(l.begin(),l.end());
l.push_back(al.int_to_string(lineNo));
while(!isalpha(s[i])){
i++;
}
i--;
lineNo++;
}
}
return true;
}
bool source::show_file(){
cout<<filename<<".hyp\n````````````\n";
cout<<"please go to source/"<<filename<<".hyp and write the code in hyperbole\n\n\n";
for(int i=0;i<50;i++) cout<<"`"; cout<<endl;
list<list<string> >::iterator itr;
for (itr=lol.begin(); itr != lol.end(); itr++){
list<string>tl=*itr;
list<string>::iterator it;
int tab=0;
for(it=tl.begin();it!=tl.end();it++){
cout<<*it<<" ";
if(tab==0) cout<<"\t";;
tab++;
}
cout<<";"<<endl;
}
cout<<endl;
for(int i=0;i<50;i++) cout<<"`";
cout<<"\n\nPress 'R' to Refresh,'C' to Compile n Run OR 'Q' to close this file "<<endl;
}
bool source::write_file(){
ofstream file;
file.open("source/"+filename+".hyp");
list<list<string> >::iterator itr;
for (itr=lol.begin(); itr != lol.end(); itr++){
list<string>tl=*itr;
list<string>::iterator it;
cout<<"\t";
for(it=tl.begin();it!=tl.end();it++){
file<<*it<<" ";
}
file<<";"<<endl;
}
}
bool source::close_file(){
lol.erase(lol.begin(),lol.end());
}
#endif // SOURCE_H