Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

supported cpp & c file #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README-EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ This is a tool for adding define macro definition to programming languages. It i
## Mode of use
### 1.Add macro comments to your code
```
// #ifdef WINDOWS
// ###ifdef WINDOWS
print("hello windows");
// #endif
// ###endif

// #ifdef WEB
// ###ifdef WEB
print("hello web");
// #endif
// ###endif
```
### 2.Run findtool in the directory where the code is located and define the macro: WINDOWS
This command can be operated directly on this project to view the effect
Expand All @@ -31,7 +31,7 @@ Do not use multiline comments for the content defined in the macro
-h View help

## Deficiencies and limitations
1. Do not use multiline comments /* */, between #define and #endif, and do not use # comments between #define and #endif in yaml files
1. Do not use multiline comments /* */, between ###ifdef and ###endif, and do not use # comments between ###ifdef and ###endif in yaml files
2. #Spaces cannot appear between and define
3. The code before replacement will be backed up as a .bak file, but it is recommended to back up the code before replacement

Expand Down
2 changes: 1 addition & 1 deletion README.html
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@
</style>
</head>
<body class='typora-export os-windows'>
<div id='write' class=''><h1><a name="宏替换工具" class="md-header-anchor"></a><span>宏替换工具</span></h1><p><span>这是一个为编程语言加入define宏定义的工具,用于实现对不同版本、不同平台进行区分,实现原理是利用宏注释不需要的代码,该工具理论上适用于任何编程语言。 </span></p><h2><a name="使用方式" class="md-header-anchor"></a><span>使用方式</span></h2><h3><a name="1在代码中加入宏注释" class="md-header-anchor"></a><span>1.在代码中加入宏注释</span></h3><pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang=""><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><span><span>​</span>x</span></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; // #ifdef WINDOWS</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; print("hello windows");</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; // #endif</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; // #ifdef WEB</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; print("hello web");</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; // #endif</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 140px;"></div><div class="CodeMirror-gutters" style="display: none; height: 140px;"></div></div></div></pre><h3><a name="2在代码所在目录运行findtool工具并定义宏windows" class="md-header-anchor"></a><span>2.在代码所在目录运行findtool工具,并定义宏:WINDOWS</span></h3><p><span>这个命令可直接在本项目上操作来查看效果</span></p><pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang=""><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; definetool -define WINDOWS </span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 20px;"></div><div class="CodeMirror-gutters" style="display: none; height: 20px;"></div></div></div></pre><p><span>在编译时若没有此宏,会将define与endif之间的内容进行/**/注释,若有宏,则进行解除注释。</span></p><p><span>宏内定义的内容不要使用多行注释</span></p><h2><a name="命令使用" class="md-header-anchor"></a><span>命令使用</span></h2><p><span>-define 定义宏</span><br/><span>-exdir 排除文件夹</span><br/><span>-h 查看帮助 </span></p><h2><a name="不足与限制" class="md-header-anchor"></a><span>不足与限制</span></h2><ol start='' ><li><span>在#define与#endif之间不要使用多行注释/**/,yaml文件中#define与#endif之间不要使用#注释</span></li><li><span>#与define之间不能出现空格</span></li><li><span>代码替换不会备份,若担心代码丢失请先备份代码</span></li></ol><p><span>//默认排除文件夹:</span><br/><span>bin build .git .svn debug release</span></p><h2><a name="打赏作者" class="md-header-anchor"></a><span>打赏作者</span></h2><p><span>打赏留言备注项目名+您的名字,您将出现在影子项目的赞助列表~</span>
<div id='write' class=''><h1><a name="宏替换工具" class="md-header-anchor"></a><span>宏替换工具</span></h1><p><span>这是一个为编程语言加入define宏定义的工具,用于实现对不同版本、不同平台进行区分,实现原理是利用宏注释不需要的代码,该工具理论上适用于任何编程语言。 </span></p><h2><a name="使用方式" class="md-header-anchor"></a><span>使用方式</span></h2><h3><a name="1在代码中加入宏注释" class="md-header-anchor"></a><span>1.在代码中加入宏注释</span></h3><pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang=""><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><span><span>​</span>x</span></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation" style=""><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; // ###ifdef WINDOWS</span></pre></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; print("hello windows");</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; // ###endif</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"><span cm-text="">​</span></span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; // ###ifdef WEB</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; print("hello web");</span></pre><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; // ###endif</span></pre></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 140px;"></div><div class="CodeMirror-gutters" style="display: none; height: 140px;"></div></div></div></pre><h3><a name="2在代码所在目录运行findtool工具并定义宏windows" class="md-header-anchor"></a><span>2.在代码所在目录运行findtool工具,并定义宏:WINDOWS</span></h3><p><span>这个命令可直接在本项目上操作来查看效果</span></p><pre spellcheck="false" class="md-fences md-end-block ty-contain-cm modeLoaded" lang=""><div class="CodeMirror cm-s-inner CodeMirror-wrap" lang=""><div style="overflow: hidden; position: relative; width: 3px; height: 0px; top: 0px; left: 8px;"><textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea></div><div class="CodeMirror-scrollbar-filler" cm-not-content="true"></div><div class="CodeMirror-gutter-filler" cm-not-content="true"></div><div class="CodeMirror-scroll" tabindex="-1"><div class="CodeMirror-sizer" style="margin-left: 0px; margin-bottom: 0px; border-right-width: 0px; padding-right: 0px; padding-bottom: 0px;"><div style="position: relative; top: 0px;"><div class="CodeMirror-lines" role="presentation"><div role="presentation" style="position: relative; outline: none;"><div class="CodeMirror-measure"><pre><span>xxxxxxxxxx</span></pre></div><div class="CodeMirror-measure"></div><div style="position: relative; z-index: 1;"></div><div class="CodeMirror-code" role="presentation"><div class="CodeMirror-activeline" style="position: relative;"><div class="CodeMirror-activeline-background CodeMirror-linebackground"></div><div class="CodeMirror-gutter-background CodeMirror-activeline-gutter" style="left: 0px; width: 0px;"></div><pre class=" CodeMirror-line " role="presentation"><span role="presentation" style="padding-right: 0.1px;"> &nbsp; definetool -define WINDOWS </span></pre></div></div></div></div></div></div><div style="position: absolute; height: 0px; width: 1px; border-bottom: 0px solid transparent; top: 20px;"></div><div class="CodeMirror-gutters" style="display: none; height: 20px;"></div></div></div></pre><p><span>在编译时若没有此宏,会将define与endif之间的内容进行/**/注释,若有宏,则进行解除注释。</span></p><p><span>宏内定义的内容不要使用多行注释</span></p><h2><a name="命令使用" class="md-header-anchor"></a><span>命令使用</span></h2><p><span>-define 定义宏</span><br/><span>-exdir 排除文件夹</span><br/><span>-h 查看帮助 </span></p><h2><a name="不足与限制" class="md-header-anchor"></a><span>不足与限制</span></h2><ol start='' ><li><span>在###ifdef与###endif之间不要使用多行注释/**/,yaml文件中###ifdef与###endif之间不要使用#注释</span></li><li><span>#与define之间不能出现空格</span></li><li><span>代码替换不会备份,若担心代码丢失请先备份代码</span></li></ol><p><span>//默认排除文件夹:</span><br/><span>bin build .git .svn debug release</span></p><h2><a name="打赏作者" class="md-header-anchor"></a><span>打赏作者</span></h2><p><span>打赏留言备注项目名+您的名字,您将出现在影子项目的赞助列表~</span>
<a href='https://afdian.net/@fengdeyingzi' target='_blank' class='url'>https://afdian.net/@fengdeyingzi</a></p></div>
</body>
</html>
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
这是一个为编程语言加入define宏定义的工具,用于实现对不同版本、不同平台进行区分,实现原理是利用宏注释不需要的代码,该工具理论上适用于任何编程语言。

## 使用方式
### 1.在代码中加入宏注释
### 1.在代码中加入宏注释(这里的宏注释的#必须是连续三个)
```
// #ifdef WINDOWS
// ###ifdef WINDOWS
print("hello windows");
// #endif
// ###endif

// #ifdef WEB
// ###ifdef WEB
print("hello web");
// #endif
// ###endif
```
### 2.在代码所在目录运行findtool工具,并定义宏:WINDOWS
这个命令可直接在本项目上操作来查看效果
Expand All @@ -31,7 +31,7 @@
-h 查看帮助

## 不足与限制
1. 在#define与#endif之间不要使用多行注释/**/,yaml文件中#define与#endif之间不要使用#注释
1. 在###ifdef与###endif之间不要使用多行注释/**/,yaml文件中###ifdef与###endif之间不要使用#注释
2. #与define之间不能出现空格
3. 替换前的代码会备份为.bak文件,不过还是建议在执行替换前备份代码

Expand Down
12 changes: 7 additions & 5 deletions bin/definetool.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import 'util/defineutil.dart';

*/
void main(List<String> arguments) {
// #ifdef WEB
/* print('Hello web!');*/
// #endif
// #ifdef WINDOWS
// ###ifdef WEB
/* print('Hello web!');
*/
// ###endif
// ###ifdef WINDOWS
print("Hello windows");
// #endif

// ###endif

print("宏定义替换工具");
print("风的影子 编写");
Expand Down
Loading