Turning off optimization for all files in a folder - c++

Is there a way to turn off optimization in Visual Studio for all translation units in a folder?
For a specific file one can use something like mentioned here.
Some workarounds that come to my mind (all not perfect, i.e. too much manual work):
include a header in each cpp which can easily toggle optimization
use some script to prepend turning off optimization for each file

I used the power shell script to complete your requirements, you need to change the file path in the code to the path of .cpp in your project, the sample code is as follows
$cpps = (Get-ChildItem -Path "C:\Users\Admin\Desktop\asdasds\Project44\Project44" -Filter *.cpp).fullname
$line = '#pragma optimize( "", {off} )'
$cpps| ForEach-Object {
$line + "`n" + (Get-Content -path $_ -Raw) | Set-Content -Path $_
}
RESULT:
Hope it helps.

Related

can i include a file whose path is from a string variable?

i think in python:
i can use:
def include_something(s):
exec('import %s'%(s))
to import package dynamically
but in c++:
void include_something(const std::string& v) {
# include v.c_str();
}
seems doestnt work.
So, is there any methods can do this? and will the futures c++ support this kind of function?
Simple answer: No, You can't
Answer with details:
You can't do this with either include or import. As You can see on the picture below, include works on preprocess time, and import works on precompile time. While c_str is running at compile time (if it is constexpr), or at run time (if casual class or function), therefore, in any case, the import(or include) will be completed before the program learns the name of the module
source of image
There is no way in C/C++ to achieve dynamic header loading.
BUT
I'll do as the following:
Create a simple PowerShell script to create a master header file, that will contain all the headers from a given directory.
$source_dir = "C:\Program Files (x86)\Windows Kits\10\Include\10.0.14393.0\um\alljoyn_c\"
$master_headerfile = 'master.h'
Remove-Item $master_headerfile
New-Item $master_headerfile -ItemType File -Value "// Master header file`n"
Get-ChildItem $source_dir -Filter *.h |
Foreach-Object {
Add-Content $master_headerfile "#include `"$_`""
}
Output will be
Now just include this master.h in your source file.
I hope, it will help you.
Thanks :)

Search for string in all files in current drive using regex on windows

I am trying to search for an email address on my harddisk. I know that it should be something like:
b************m#e******.com
and this is why I came up with this regex:
b.{12}m#e.{6}.com
I found that findstr could be useful for this job and tried:
findstr /R b.{12}m#e.{6}\.com c:\*.*
but it doesn't find anything even if I added a file with an email that should match that regex of mine, this one for example: b8726ngs.poinm#e123456.com
You could try doing this with the following PowerShell command instead (note depending on where you start this could take a long time to run):
Get-ChildItem *.txt -Recurse -File | Where-Object { (Get-Content $_.FullName) -match "b.{12}m#e.{6}.com" }
You will get red error messages for areas of the disk that you don't have permission to access. Run PowerShell as Administrator for the widest possible search.
Add a file path to Get-ChildItem in order to set a base directory if you wish, otherwise it will start in the directory you are currently in.
Explanation of parameters:
-Recurse searches the current directory and all sub-directories.
-File returns only files (not directories).
Get-Content $_.FullName gets the contents of each file.
-match performs the regex comparison.
There are regex and then there are regex. Looks like findstr is not very powerful.
findstr /R "b............m#e......\.com" *.*
This is only on the findstr part not working.
Do this with appropriate precautions, e.g. inside a directory which only contains readable files.

grep through an explicit filelist

Stack,
We have many files in our library that were never used in subsequent projects. We are now at a development phase where we can do some good housekeeping and carefully remove unused library code. I am trying to optimize my grep command, it's current implementation is quite slow.
grep --include=*.cpp --recursive --files-with-matches <library function name> <network path to subsequent projects>
The main reason is that the projects path is expansive and the bulk of the time is spent just navigating the directory tree and applying the file mask. This grep command is called many times on the same set of project files.
Rather than navigating the directory tree every call, I would like to grep to reference a static filelist stored on my local disk.
Something akin to this:
grep --from-filelist=c:\MyProjectFileList.txt
The MyProjectFileList.txt would be:
\\server1\myproject1\main.cpp
\\server1\myproject1\func1.cpp
\\server1\myproject2\main.cpp
\\server1\myproject2\method.cpp
Grep would apply the pattern-expression to contents of each of those files. Grep output would be the fully qualified path of the project file that is uses a specific library function.
Grep commands for specific library functions that return no project files are extraneous and can be deleted.
How do you force grep to scan files from an external filelist stored in a text file?
(Thereby removing directory scanning.)
Try around a little using the 'xargs' command and pipes ("|").
Try the following:
while read line; do echo -e "$line"; done < list_of_files.txt | xargs -0 grep **YOUR_GREP_ARGS_HERE**
or in a Windows environment with Powershell installed try...
Get-Content List_of_files.txt | Foreach-Object {grep $_ GREP_ARGS_HERE}
I googled for windows args and found this:
FOR /F %k in (filelist.txt) DO grep yourgrepargs %k
(but I use linux, no idea if it works)

Cmd script to set the hintpath in .net projects

I am trying, withouth much luck, to create a bat or cmd file that would change a "corrupt" hintpath of my third party dll's so that it referes to my fixed dll path (the P-drive). The script would have to:
1) loop through all folders under my main projects folder finding all files with the .csproj ending
2) loop through each file and replace every instance of "< HintPath >c:\xx\yy\q.dll< /HintPath >" to "< HintPath >P:\q.dll< /HintPath >"
thanks,
regards,
styrmir
If possible, I would highly suggest to use PowerShell to perform this task. Here is what it would take to do what you are after:
Get-ChildItem -Recurse -Filter *.csproj -Path YOUR_TARGET_ROOT_DIRECTORY_HERE |
ForEach-Object {
(Get-Content $_.FullName) |
ForEach-Object {
$_.Replace('<HintPath>c:\xx\yy\q.dll</HintPath>', '<HintPath>P:\q.dll</HintPath>')
} |
Set-Content $_.FullName -WhatIf
}
Note: I have included a -WhatIf switch that prevents the script to make any change and just outputs the actions it would perform to the console window. Please remove it to make the script functional.
UPDATE
To replace every possible HintPath reference to q.dll within C:, at every possible directory depth, you may replace this line:
$_.Replace('<HintPath>c:\xx\yy\q.dll</HintPath>', '<HintPath>P:\q.dll</HintPath>')
with this one:
$_ -replace '\<HintPath\>C:\\.*\\q.dll\</HintPath\>', '<HintPath>P:\q.dll</HintPath>'

search and replace in entire project on linux/osx

How would I replace one pattern with another for every file with extension .cc and .h recursively? Not sure if I need to prevent it from going into .svn directories.
first attempt
#!/bin/bash
for file in `find . -name '*.cc' -or -name '*.h'`; do \
sed -e s/$1/$2/g -i temp $file
done
If your project is managed under linux platform, You can do sth like that inside the bash:
for file in `find . -name '*.cpp' -or -name '*.h'`; do \
cat $file | sed s/$1/$2/g > tmp
mv tmp $file
done
Each svn file has '*-base' extension so all of them will be unchanged. This script will only affect to *h and *cc files.
You can search and replace using regular expressions through certain files in Eclipse project explorer, for example. I'm sure there are lots of tools that can do this, but Elipse comes to mind first.
To do this you need to invoke the "Search" dialog, place your pattern in the search field, specify extensions with a wildcard and press "Replace",