从许多头文件中删除标头防护的随机部分

时间:2021-11-28 15:08:12

I've a program (an IDL compiler) that creates a bunch of header files. These header files have a header guard with a random part at the end, like this:

我有一个程序(一个IDL编译器),它创建了一堆头文件。这些头文件有一个头部保护,最后有一个随机部分,如下所示:

#ifndef AUTOMATEDGENERATEDCODEIMPL_H_U1CBCG
#define AUTOMATEDGENERATEDCODEIMPL_H_U1CBCG

// My code here

#endif /* AUTOMATEDGENERATEDCODEIMPL_H_U1CBCG */

These files are created every time that I build my solution and the random part changes even if the rest of the code is not changed. So in every commit that I do in git I commit these files that causes a lot of useless conflicts (I build the code, another one build the same code obtaining other headers and then in rebase/merge we have conflicts on these header guards).

每次构建我的解决方案时都会创建这些文件,即使其余代码没有更改,随机部分也会更改。因此,在我在git中进行的每次提交中,我提交这些文件会导致很多无用的冲突(我构建代码,另一个构建相同的代码获取其他头文件,然后在rebase / merge中,我们在这些头文件中存在冲突)。

So I want to create a PowerShell script that runs in the post-build event in Visual Studio, that removes the random part of all header guards in all header files in that project.

所以我想创建一个在Visual Studio中的后期构建事件中运行的PowerShell脚本,它删除该项目中所有头文件中所有头部保护的随机部分。

How can I replace in PowerShell the string *IMPL_H_(random part) with *IMPL_H_ in all .h files?

如何在PowerShell中用所有.h文件中的* IMPL_H_替换字符串* IMPL_H_(随机部分)?

1 个解决方案

#1


2  

Use a regular expression replacement:

使用正则表达式替换:

Get-ChildItem -Recurse -Filter *.h | ForEach-Object {
  $file = $_.FullName
  (Get-Content $file) -creplace '(_IMPL_H_)[A-Z0-9]*', '$1' | Set-Content $file
}

#1


2  

Use a regular expression replacement:

使用正则表达式替换:

Get-ChildItem -Recurse -Filter *.h | ForEach-Object {
  $file = $_.FullName
  (Get-Content $file) -creplace '(_IMPL_H_)[A-Z0-9]*', '$1' | Set-Content $file
}