FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
simplecpp/main.cpp at master · chmodawk/simplecpp · GitHub
chmodawk
/
simplecpp
Public
forked from
cppcheck-opensource/simplecpp
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
simplecpp
/
main.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
104 lines (95 loc) · 3.48 KB
Breadcrumbs
simplecpp
/
main.cpp
Copy path
File metadata and controls
104 lines (95 loc) · 3.48 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
simplecpp.h
"
#
include
<
fstream
>
#
include
<
iostream
>
#
include
<
cstring
>
int
main
(
int
argc,
char
**argv)
{
const
char
*filename =
NULL
;
//
Settings..
simplecpp::
DUI
dui;
for
(
int
i =
1
; i < argc; i++) {
const
char
*arg = argv[i];
if
(*arg ==
'
-
'
) {
char
c = arg[
1
];
if
(c !=
'
D
'
&& c !=
'
U
'
&& c !=
'
I
'
&& c !=
'
i
'
&& c !=
'
s
'
)
continue
;
//
Ignored
const
char
*value = arg[
2
] ? (argv[i] +
2
) : argv[++i];
switch
(c) {
case
'
D
'
:
//
define symbol
dui.
defines
.
push_back
(value);
break
;
case
'
U
'
:
//
undefine symbol
dui.
undefined
.
insert
(value);
break
;
case
'
I
'
:
//
include path
dui.
includePaths
.
push_back
(value);
break
;
case
'
i
'
:
if
(
std::strncmp
(arg,
"
-include=
"
,
9
)==
0
)
dui.
includes
.
push_back
(arg+
9
);
break
;
case
'
s
'
:
if
(
std::strncmp
(arg,
"
-std=
"
,
5
)==
0
)
dui.
std
= arg +
5
;
break
;
}
}
else
{
filename = arg;
}
}
if
(!filename) {
std::cout <<
"
Syntax:
"
<< std::endl;
std::cout <<
"
simplecpp [options] filename
"
<< std::endl;
std::cout <<
"
-DNAME Define NAME.
"
<< std::endl;
std::cout <<
"
-IPATH Include path.
"
<< std::endl;
std::cout <<
"
-include=FILE Include FILE.
"
<< std::endl;
std::cout <<
"
-UNAME Undefine NAME.
"
<< std::endl;
std::exit
(
0
);
}
//
Perform preprocessing
simplecpp::OutputList outputList;
std::vector<std::string> files;
std::ifstream
f
(filename);
simplecpp::TokenList
rawtokens
(f,files,filename,&outputList);
rawtokens.
removeComments
();
std::map<std::string, simplecpp::TokenList*> included =
simplecpp::load
(rawtokens, files, dui, &outputList);
for
(std::pair<std::string, simplecpp::TokenList *> i : included)
i.
second
->
removeComments
();
simplecpp::TokenList
outputTokens
(files);
simplecpp::preprocess
(outputTokens, rawtokens, files, included, dui, &outputList);
//
Output
std::cout << outputTokens.
stringify
() << std::endl;
for
(
const
simplecpp::Output &output : outputList) {
std::cerr << output.
location
.
file
() <<
'
:
'
<< output.
location
.
line
<<
"
:
"
;
switch
(output.
type
) {
case
simplecpp::Output::
ERROR
:
std::cerr <<
"
#error:
"
;
break
;
case
simplecpp::Output::
WARNING
:
std::cerr <<
"
#warning:
"
;
break
;
case
simplecpp::Output::
MISSING_HEADER
:
std::cerr <<
"
missing header:
"
;
break
;
case
simplecpp::Output::
INCLUDE_NESTED_TOO_DEEPLY
:
std::cerr <<
"
include nested too deeply:
"
;
break
;
case
simplecpp::Output::
SYNTAX_ERROR
:
std::cerr <<
"
syntax error:
"
;
break
;
case
simplecpp::Output::
PORTABILITY_BACKSLASH
:
std::cerr <<
"
portability:
"
;
break
;
case
simplecpp::Output::
UNHANDLED_CHAR_ERROR
:
std::cerr <<
"
unhandled char error:
"
;
break
;
case
simplecpp::Output::
EXPLICIT_INCLUDE_NOT_FOUND
:
std::cerr <<
"
explicit include not found:
"
;
break
;
}
std::cerr << output.
msg
<< std::endl;
}
//
cleanup included tokenlists
simplecpp::cleanup
(included);
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL