TCL syntax errors - if-statement

I have an automatically generated TCL proc, which has many if condition, some lines inside some if condition never gets executed for any possible combinations of proc inputs.
But I found some syntactical errors in those lines like extra ] or multiplication [1*1] instead of [expr 1*1]. I want to find out these TCL syntactical errors in all the lines. Is there any clever way to do achieve this?

You can use a tool like Nagelfar for syntax analysis; the website even has an online demo that you can try. It might not catch all the problems, but it could catch some.

Related

How do I Build a Regex Expression to Find String

I've been studying content on the regex topic, but am having trouble understanding how to make it work! I need to build a regex to locate a particular string, potentially in multiple places throughout numerous log files. If I were keying the search expression into a text editor, it would look like this...
*Failed to Install*
Following is a typical example of a line containing the string I would like to search for (exit code # will vary)
!!! Failed to install, with exit code 1603
I would really appreciate any help on how to build the regex for this. I suspect I might need the end of line character too?
I plan on using it in a variation of the script that was provided by https://stackoverflow.com/users/3142139/m-hassan in the following thread
Use PowerShell to Quickly Search Files for Regex and Output to CSV
I'm a newbie to powershell scripts, but I'd rather spend the time to figure this out, than pour over hundreds of log files!
Thanks,
Jim
You're in luck - You only require very simple regex for this. Assuming you want to capture the error code, this will work fine:
^.*Failed to install.*(exit code \d+)$
Try it online!
If you don't care about the error code, and just want to know if it failed or not, you can honestly get away with something as simple as:
^.*Failed to install.*$
Hope this helps.

How to I make gerrit query that spans across few specific projects?

I tried for few hours to find the right syntax for making a regex query that returns reviews from 2-3 different projects but I failed and decided to crowdsource the task ;)
The search is documented at https://review.openstack.org/Documentation/user-search.html and mentions possible use of REGEX,... but it just didn't work.
Task: return all CRs from openstack-infra/gerritlib and openstack-infra/git-review projects from https://review.openstack.org
Doing it for one project works well project:openstack-infra/gerritlib
Ideally I would like to look for somethign like ^openstack-infra\/(gerritlib|git-review), or at least this is the standard regex syntax.
Still, I found impossible to use parentheses so far, every time I used them it stopped it from returning any results.
1) You don't need to escape the "/" character.
2) You need to use double quotes to make the parentheses work.
So the following search should work for you:
project:"^openstack-infra/(gerritlib|git-review)"

If-Else conditions with APL?

So, I'm wondering/asking; Is it possible to do an If-Statement in APL? If so how?
Here's my code
'Please enter a number to count to: '
number ←⎕
⍳number
How do I get an if-statement to where if the user inputs a number over 100 it will print out "too high" and end; or if it's 100 or under then it will just continue?
Thanks!
In Dyalog APL you have this neat little thing called guards.
They can be used in dfns and evaluate code when a certain condition matches.
func ← {⍵>100 : 'too high' ⋄ 1 : 'number is ok'}
If your APL supports control structures then this should work:
∇ generateAll number
:If number>100
⎕←'Too high'
:else
⎕←⍳ number
:endif
∇
If it does NOT support control structures (like APL2) you will need to branch:
∇ generateAll number
→(number>100)/error
⎕←⍳ number
→0
error:
⎕←'Too high'
∇
You can also use tricks like execute but this is less readable.
A "classical" way of doing error handling* in APL2 is with the ⎕ES or ⎕EA.
Your code would look something like this:
⎕ES(NUMBER>100)/'Too high'
⍳NUMBER
What happens here is that IF the parentheses evaluate to true, THEN the ⎕ES will halt the execution and echo the quoted string.
If you don't want your THEN to terminate, have a look at ⎕EA in some APL documentation.
Please note that I'm on APL2 in a GreenOnBlack environment, so there are likely more neat ways of doing this in a more modern dialect like Dyalog.
*I know you're asking about conditionals and not error handling, but since you're example terminates execution, it might as well be error handling.
There is a crucial difference between this and what MBaas suggests: His solution will gracefully exit the current function which might return a value. Using ⎕ES or ⎕EA with terminate all execution.
Depends on the dialect you're using. Some APL-Implementations support control-strucures, so you could write something like
:If number>100
⎕←'Too high'
→0
:endif
⍳number
In "tradtional APL" you would probably do something like
⍎(number>100)/'⎕←''Too high'' ⋄ →0'
⍳number

Regular expression breakpoint in GDB

I am trying to set breakpoints on all functions that start with "dc_api" but I must exclude functions that start with "dc_api_port_counter" and "dc_api_send_reply".
Regarding the "dc_api_port_counter" exclusion, note that I do want to include functions that start with "dc_api_port_something".
I used regex online tester and came up with the following regex:
dc_api_(?!port_counter|send_reply).*
However, when using it, I get the following error:
(gdb) rbreak dc_api_(?!port_counter|send_reply).*
!port_counter|send_reply).*: event not found
(gdb)
Appreciate your help.
There's no simple, built-in way to do this. However, it can be done a couple of ways.
First, use rbreak to set "too many" breakpoints. Then, the trick is to find an automated way to delete the extra breakpoints.
A straightforward way to do this is to write a bit of code in Python that loops over all the gdb breakpoints. For each breakpoint it would examine the location attribute, and, if it should be excluded, call the breakpoint's delete method.

Replacement macros for Netbeans

Is it possible to write replacement macros for NetBeans?
I need to replace function is_active with function isActive. It seems that is not possible with short regex.
So I wonder is it possible to write such macros?
Crazy macros code....
We cannot use find properly, so I decieded to use find-selection
caret-begin
"function[^(]*_[a-z]"
selection-begin-line
find-selection
remove-selection
find
# there is no loop, so you need to repeat this lines many-many times (too many may hang your IDE)
caret-begin
find-next
caret-forward
caret-backward
delete-previous
to-upper-case
To use this macros you need to set the focus on a document and have turned on regex find option.
Warning, could spoil your code.