-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExtractCode.cpp
110 lines (110 loc) · 3.15 KB
/
ExtractCode.cpp
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
//#include <cassert>
//#include <cstddef>
//#include<cstdio>
//#include <cstdlib>
//#include <fstream>
//#include <iostream>
//#include <string>
//using namespace std;
//#if defined(__GUNC__)||defined(__MWERKS__)
//#include<sys/stat.h>
//#elif defined(__BORLANDC__)||defined(__MSC__VER)||defined(__DMC__)
//#include <direct.h>
//#else
//#error Compiler not supported
//#endif
//bool exists(string fname){
// size_t len=fname.length();
// if(fname[len-1]!='/'&&fname[len-1]!='\\') fname.append("/");
// fname.append("000.tmp");//open temp file to determine whether the file exist
// ofstream outf(fname.c_str());
// bool existFlag=outf;
// if(outf){
// outf.close();
// remove(fname.c_str());//delete some file
// }
// return existFlag;
//
//}
//int main(int argc,char* argv[]){
// if (argc==1) {
// cerr<<"usage:extractCode file [dir]"<<endl;
// exit(EXIT_FAILURE);
// }
// ifstream inf(argv[1]);
// if(!inf) {
// cerr<<"usage:extractCode file [dir]"<<endl;
// }
// string root("./");
// if(argc==3) {
// root=argv[2];
// if(!exists(root)){
// cerr<<"no such directory:"<<root<<endl;
// }
// }
// size_t rootLen=root.length();
// if(root[rootLen-1]!='/'&&root[rootLen-1]!='\\') root.append("/");
// string line;
// bool inCode=false;
// bool printDelims=true;
// ofstream outf;
// while(getline(inf,line)){
// size_t findDelim=line.find("//","/:~");
// if(findDelim!=string::npos) {
// if(!inCode){
// cerr<<"Lines out of order"<<endl;
// exit(EXIT_FAILURE);
// }
// assert(outf);
// if(printDelims) outf<<line<<endl;
// outf.close();
// inCode=false;
// printDelims=true;
// }else {
// findDelim=line.find("//"":");
// if(findDelim==0){
// if(line[3]=='!'){
// printDelims=false;
// ++findDelim;
// }
// size_t startOfSubdir=line.find_first_not_of("\t",findDelim+3);
// findDelim=line.find(':',startOfSubdir);
// if(findDelim==string::npos) {cerr<<"missing filename information"<<endl;
// exit(EXIT_FAILURE);
// }
// string subdir;
// if(findDelim>startOfSubdir)
// subdir=line.substr(startOfSubdir,findDelim-startOfSubdir);
// size_t startOfFile=findDelim+1;
// size_t endOfFile=line.find_first_not_of("\t",startOfFile);
// if(endOfFile==startOfFile){
// cerr<<"missing filename "<<endl;
// exit(EXIT_FAILURE);
// }
// string fullPath(root);
// if(subdir.length()>0)
// fullPath.append(subdir).append("/");
// assert(fullPath[fullPath.length()-1]=='/') ;
// if(!exists(fullPath))
//#if defined(__GUNC__)||defined(__MWERKS__)
//mkdir(fullPath.c_str(),0);
//#else mkdir(fullPath.c_str())
//#endif
// fullPath.append(line.substr(startOfFile,endOfFile-startOfFile));
// outf.open(fullPath.c_str());
// if(!outf){
// cerr<<"error opening "<<fullPath<<"for output"<<endl;
// exit(EXIT_FAILURE);
//
// }
// inCode=true;
// cout<<"processing "<<fullPath<<endl;
// if(printDelims) outf<<line<<endl;
// }
// else if(inCode){
// assert(outf);
// outf<<line<<endl;
// }
// exit(EXIT_FAILURE);
//}
// }