-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.cpp
More file actions
131 lines (124 loc) · 3.35 KB
/
Copy pathparser.cpp
File metadata and controls
131 lines (124 loc) · 3.35 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
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
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
using namespace std;
int main(int argc, char* argv[])
{
bool method;
int check=0;
string hello="";
if(argc!=2||!(strstr(argv[1],".rb\0")))
{
std::cout<<"Please include one Ruby file name please"<<std::endl;
}
else
{
int leng = strlen(argv[1]);
std::string str(argv[1]);
str=str.substr(0,leng-3);
str.append(".markdown");
std::ifstream ifile(argv[1]);
const char *out = str.c_str();
std::ofstream ofile(out);
char line[1000];
if(ifile.good())
{
while(ifile.getline(line,1000))
{
string stringent(line);
//initialized a string version of line to be used
if((strstr(line,"get \"")&&strstr(line,"do"))||(strstr(line,"put \"")&&strstr(line,"do")))
{
ofile<<"{% method "<<hello<<" %}"<<endl;
ofile<<line<<endl;
method=true;
}
else if((strstr(line,"if "))||strstr(line,"each do"))
{
//HOW TO MAKE SURE THAT THE STUPID IF IS AT THE VERY BEGINNING OF THE LINE
check++;
ofile<<check<<endl;
ofile<<"each or if"<<endl;
ofile<<line<<endl;
}
else if(strstr(line,"end")&&method)
{
//USED TO CLOSE LOOPS, IF,ELSE, WHILES, FORS... huh, I'll think of a more cleve rsooultion later
if(check==0)
{
ofile<<line<<endl;
ofile<<"{% endmethod %}"<<endl;
method=false;
}
//in the case that there is an if statememt or else or a loop... anything that could end in end...
else
{
ofile<<line<<endl;
ofile<<check<<endl;
check--;
}
}
else if(strstr(line,"#{"))
{
std::string aline(line);
aline=aline.substr(1,strlen(line));
/* stringstream ss;
ss<<aline.substr(1,strlen(line)-1);
string tagName;
ss>>tagName;
if(tagName=="class_name")
{
ofile<<"<div
}
*/
//HERE TRY A STRING STREAM TO CHECK IF THE FIRST WORD IS THE NAME OF A TAG YOU RECOGNIZE, just lots of if statements for each one??? O_O
ofile<<aline<<std::endl;
}
else if(strstr(line,"#")&&!strstr(line,"{%"))
{
ofile<<"{% comment %}"<<endl;
ofile<<line<<endl;
ofile<<"{% endcomment %}"<<endl;
}
else if(strstr(line,"class"))
{
ofile<<"{% class_name %}"<<endl;
ofile<<line<<endl;
ofile<<"{% endclass_name %}"<<endl;
}
else if(strstr(line,"resource"))
{
ofile<<"{% resource %}"<<endl;
//FIND INSTANCE OF FIRST SPACE AND 2ND SPACE, AND GET THE WORD IN BETWEEN THOSE TWO?
//int a,b;
//strchr
//HERE GET ONLY THE RESOURCE WORD OUT OF THIS
ofile<<line<<endl;
ofile<<"{% endresource %}"<<endl;
}
else
{
ofile<<line<<std::endl;
}
}
}
else
{
std::cout<<"File does not exist"<<std::endl;
}
//maybe if {class name then, write to file a certain way, make the custom tags in the parser.... just easier that way for me lol
//IFILE.GETLINE(LINE,1000);
/*IF(STRSTR(LINE.SUBSTR(0,2),"#/"))
{
LINE=LINE.SUBSTR(2,LINE.LENGTH)
THEN OFILE<<LINE<<ENDL;
on to the next on on to the next one
}
*/
}
}