<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"><span style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">Hi All,</span></p>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
<br>
</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
I'm working on a project which given a C/C++ source code, I need to find the last #include and insert one additional #include right after that. For example, suppose I have a file called Test.c which looks like this:</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
<br>
</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
#include <stdio.h></div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
#include <stdlib.h></div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
int main(){</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
// some code here...</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
}</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
<br>
</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
I want to get the location of the #include <stdlib.h> and insert one extra #include, then the code should be like this:</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
<br>
</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
#include <stdio.h></div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
#include <stdlib.h></div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
#include "extraInclude.h"</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
int main(){</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
// some code here....</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
}</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
<br>
</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
I feel like the right class I need to use is clang::Preprocessor and clang::PPCallbacks, but I haven't figured out a way to implement this.</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
<br>
</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
Any help would be appreciated.</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
<br>
</div>
<div style="color: rgb(34, 34, 34); font-family: arial, sans-serif; font-size: small;">
Patrick</div>
<br>
<p></p>
</div>
</body>
</html>