Pass a regex pattern to Perl Packer from Powershell - regex

How do I correctly write this in a Windows Powershell? Coming from macOS, I have some problems in understanding what it is wrong with this:
pp -u -g -o Executable -f Bleach="^(AAA_|BBB_|MainScript)" MainScript.pl
The regular expression to be passed to the option -f (filter) is not accepted and fires all sort of errors (command not recognized, and so on, no matter as I try to change it). On a Unix system it works just fine.

Escape character for Powershell is `.
Something like this could work:
pp -u -g -o Executable -f Bleach=`"`(AAA_`|BBB_`|MainScript`)`" MainScript.pl`

Related

Glob files except that including some expression

I want to write a command to build FooMain.cc among the following files:
$ ls src
FooMain.cc
FooMain2.cc
BarMain.cc
Helper.cc
Helper.h
FileToInclude.cc
FileToInclude.h
...
Each main file (those including Main) has main() function and they require all the other files without Main in filenames.
The straightforward way to build would be like:
clang++ [options] FooMain.cc Helper.cc FileToInclude.cc ...
Here the expression HelperOne.cc FileToInclude.cc ... includes all the files but those including Main.
What I want to do is rephrase this expression with glob expression
clang++ [options] FooMain.cc [Some clever glob expression]
I looked up for a while but could not find similar questions.
Appreciate any clues. Thank you!
Using ksh93, bash with the extglob option turned on (shopt -s extglob), or zsh with the ksh_glob option turned on (setopt ksh_glob):
$ clang++ [options] FooMain.cc !(*Main*).cc
Using zsh with the extended_glob option turned on (setopt extended_glob):
$ clang++ [options] FooMain.cc *.cc~*Main*

How can make my makefile overwrite a file?

descript: progam.cpp
g++ progam.cpp -o descript
./descript 2>output.txt | tee -a output.txt
From my understanding, first command compiles program.cpp and the second command sends the output to both terminal and a textfile.
Is there a way to adjust this so that I :
Use "make".Go through program prompts. Output is saved in output.txt
Use "./descript" or some command a second time and overwrite output.txt with new output
I'm fairly new to linux commands in general so anything would help.
It may be helpful to include a make clean function in your Makefile.
Example make clean function could include:
make clean:
rm -f output.txt
Then, insert the make clean at the beginning of your descript portion of the Makefile to auto-remove the previous output.

Using $1 in regexp within a Makefile [duplicate]

This question already has answers here:
Escaping in makefile
(2 answers)
Closed 6 years ago.
I try to do a replace with following perl command:
perl -C -p -i -e 's/([\?\.\!])\n/$1 /g' html/數14.html
The result is fine when I call it from the command line. When I call it from within a Makefile it doesn't work. Apparently the $1 is interpreted as shell variable.
In the Makefile it looks like this:
數14.html: 數14.adoc 40_2064_Im\ Strand-Appartment.adoc 41_2064_Ein\ Plan.adoc 42_1915_In\ einer\ Suppenküche.adoc
asciidoctor -D html parts/數14.adoc
perl -C -p -i -e 's/([\?\.\!])\n/$1 /g' html/數14.html
How can I have normal regexp behaviour here?
Makefiles always interpret $ sequences before executing commands, disregarding any quoting. In order to escape $ in a Makefile, write it as $$ - that will result in a single $ in the command.

Getting gdb to automatically load binary from core file

Can I get gdb to automatically load the binary that's specified in the core file?
Given a core file I now usually do:
gdb -c corefile
GNU gdb 6.8
...
Core was generated by `/path/to/binary'
Then i copy-paste that and run:
gdb -c corefile /path/to/binary
It seems like an unnecessary two-step process and yet I don't seen an obvious way of doing it based on the man page. Am I missing something?
You could just script it?
#!/bin/bash
gdb "`file "$1" | awk -F \' '{print $2}'`" "$1"
This is what I usually endup doing:
var=$(file corefile)
echo ${var##*from}
gdc() {
gdb -c "$1" "$(file "$1" | sed -r -e "s#.*execfn: '([^\']+)'.*#\1#")"
}
$ gdc corefile

Does g++ still generate an output file even if the program fails to compile/load?

I am compiling some C++ programs through a perl script using:
g++ -o out `find ./ -iname "*.h" -or -iname "*.cpp"`
This seems to generate an an out file every time, regardless of whether the program compiled successfully or not.
Whenever the script tries to run programs like this, it gets permission errors (weird since I'm running as root).
Is this accurate and if so, how can I prevent it?
Thanks.
The answer to your title's question ("Does g++ still generate an output file even if the program fails to compile/load?") is no:
% echo blah > test.cpp
% g++ -o out test.cpp
test.cpp:1: error: expected constructor, destructor, or type conversion at end of input
% ls *out*
/bin/ls: *out*: No such file or directory
%
I solved it as follows:
For some reason, trying to put the output executable using -o out seemed to force creating the file even after the compile failed (it seems to me).
g++ -o out.tmp `find ./ -iname "*.h" -or -iname "*.cpp"` && mv out.tmp out