btm file command line augments comparing for string or math.

Mar 6, 2019
10
0
i've tried to research it especially in the help file but i'm not getting it.
i'm thinking somewhere between numerical and eval lies my answer but i'm still not getting it.
I get close..but not right.

I'd like to compare the command line augments to see if it's a mathematical equation and if so echo %@eval the augments
and if it's not mathematic do a google search on the string..

i'm sure it's simple for you programmers and those long experienced with tcc.. but i can't figure it out.
can someone show me how it should be done? hopefully i'll then pickit up and understand it once i see it done.
 
Here is one way of doing what you want;
Code:
@setlocal
@echo off
:: TCC  24.01.41 x64   Windows 7 [Version 6.1.7601]

iff %# gt 0 then
  set mycalc=%$
else
  set mycalc=2019-1956/(10-2)
endiff

set theLen=%@len[%mycalc]
set TPunct=%@tpunct[%mycalc]
set TDigit=%@tdigit[%mycalc]
echo TPunct+TDigit: %@eval[%TPunct+%TDigit]
echo theLen       : %theLen
iff %@eval[%TPunct+%TDigit] eq %theLen then
  echo %mycalc contains only Numeric Digits and punctuation characters
  echo This can be used as a math function
  echo %%@eval[%%mycalc] = %@eval[%mycalc]
else
  echo The %%mycalc variable cannot be used as a math function
  echo Doing a Google search of %mycalc
  https://www.google.ca/search?q="%mycalc"
endiff

Example runs;
Code:
c:\users\jlc\utils>test.btm 2+5*12
TPunct+TDigit: 6
theLen       : 6
2+5*12 contains only Numeric Digits and punctuation characters
This can be used as a math function
%@eval[%mycalc] = 62

Another example run;
Code:
c:\users\jlc\utils>test 2 + 5 * 12
TPunct+TDigit: 6
theLen       : 10
The %mycalc variable cannot be used as a math function

c:\users\jlc\utils>test "2 + 5 * 12"
TPunct+TDigit: 8
theLen       : 12
The %mycalc variable cannot be used as a math function

Joe
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
How about expressions containing letters?
Code:
set r=4
echo %@eval[pi * r * r]

Muddying the waters even further, @EVAL happily accepts nonexistent variables; they evaluate to zero:
Code:
echo %@eval[Oliver Cromwell]

I think the only way to determine whether a string is valid input to @EVAL is to try passing it to @EVAL....
Code:
set ans=
( set ans=%@eval[%$] ) >& nul:
if defined ans ....
 
May 20, 2008
11,437
99
Syracuse, NY, USA
I think the only way to determine whether a string is valid input to @EVAL is to try passing it to @EVAL....
Only if you're OK with zero meaning invalid. Even utter garbage evaluates to 0.
Code:
v:\> set answer=%@eval[utter garbage]

v:\> set answer
0

I wonder if @EVAL even knows when it was given a non-expression. If it does, returning something appropriate, like "N/A", would be more useful than 0.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
So, just pass everything to Google; let Google decide whether it's a math expression or not!

I've been messing with @URLENCODE. This function is fun to use because it can return percent signs. Have to use SETDOS to disable nested variable expansion:

Code:
@echo off
::   Google.btm
setlocal
setdos /x-4
start https://www.google.com/search?q=%@urlencode[%$]
endlocal
 
Mar 6, 2019
10
0
Wow. thanks for all the replies. Some is more complex than i expected... funny i had given up and also came up with the idea of giving it all to google but it wouldnt' pass the url correctly when i did 2+2 i guess the plus is some type of hypertext code and was unaware of the urlencode feature. I'm going to read some of this a few times. Thank you all very much.
 
Mar 6, 2019
10
0
So it looks like i'm going with joe's method and using urlencode.. that should do it perfectly i think. Thanks !

EDIT: yep works beautifully! and i learned a few things. also added that google.btm to my btm dir and aliased it with the letter g.
 
Last edited:
May 20, 2008
11,437
99
Syracuse, NY, USA
No, zero is valid. The expression is invalid if @EVAL fails, i.e. the command is not executed.
Huh? In my example,
Code:
set answer=%@eval[utter garbage]
the SET command was executed. Does that mean @EVAL succeeded ... that the expression is valid?

It's hard to get @EVAL to fail ... overflow ... divide by zero ... and those can come from expressions which are actually valid.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
Huh? In my example,
Code:
set answer=%@eval[utter garbage]
the SET command was executed. Does that mean @EVAL succeeded ... that the expression is valid?

I think UTTER is valid (evaluates to 0, unless you set it to something else) and GARBAGE is ignored. It does the same with numbers:
Code:
C:\>echo %@eval[42 1000]
42

C:\>

But if it finds an operator, @EVAL will carry on:
Code:
C:\>set utter=6765

C:\>set garbage=4181

C:\>echo %@eval[utter / garbage]
1.6180339632

C:\>
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
I suppose for proper algebra-ness, adjacent numbers without an operator between them ought to be multiplied. But the parser for @EVAL must be a... challenging piece of code already.
 
May 20, 2008
11,437
99
Syracuse, NY, USA
I suppose for proper algebra-ness, adjacent numbers without an operator between them ought to be multiplied. But the parser for @EVAL must be a... challenging piece of code already.
I think that is only for single letter variable names (possibly with coefficients, subscripts, exponents). x = 2, y = 3, xy = 6, 4x = 8, 4xy = 24. I've never thought of two numbers separated by whitespace as indicating multiplication (or anything). And, of course, if you don't separate two numbers with something, you get either one number or garbage. For multiplication ...
Code:
(2)(3) = 2x3 = 2∙3 = 2 x 3 = 2 ∙ 3 = 6

but not 2 3 = 6 or even (2) (3) = 6
 
Similar threads
Thread starter Title Forum Replies Date
A How to? Pass output from ffind to another command in a BTM file Support 5
D Get command line in btm file with equal sign? Support 1
Joe Caverly Embedding an .EXE (or other file) into a .BTM Support 8
P Kill all other instances of tcc from a btm batch file Support 2
Roedy How to? Understanding BTM file properties Support 0
Roedy BTM file encoding Support 13
R Unable to start any BTM file from Explorer Support 5
vefatica BTM file hoses logon session Support 12
T Calling a BTM-file from explorer stops at promt after updating to 14 Support 7
F Click a .btm file with "TCC Startup Options" in effect. Support 8
M A probably stupid question about .btm file argument parsing... Support 6
p.f.moore Best way of embedding data in a BTM file Support 12
B bdebugger doesn't load btm-file in window Support 1
MickeyF equivalent to TCSTART.btm for TCMD? Support 4
vefatica Console not redrawn in BTM or with multiple commands Support 4
Charles S. Roaten Problems with TCSTART.BTM Support 1
C TCC 26 BATCOMP BTM problems? Support 5
B IF command problem in tcexit.btm Support 9
vefatica WAD DIR.BTM? Support 11
vefatica BTM, elevated, console window caption? Support 4
I BTM slower than BAT? Support 14
D check for network tcstart.btm and load if newer Support 3
Craig Fitzgerald Problems using tcstart.btm Support 3
vefatica Installer sets BTM associations wrongly Support 4
O I cannot use links to .btm files Support 5
CWBillow Can't right-click a BTM Support 7
C NE1 have BTM to remove %appdata\JP Software\ etc... Support 0
C interesting TCStarts.btm Support 2
JohnQSmith ALIAS /R in TCSTART.BTM Support 9
Paul Berwanger BTM Bugs Support 2
M Drag and Drop for .BTM scripts Support 10
D WAD START /ELEVATED "Title" /PGM "job.btm" Support 6
C How to? run a BTM in elevated, inv tcc tab window Support 9
Fross GetOpt.btm Support 0
C How to? Add date/time to custom tpipe based BTM Support 1
thedave Problem chaining piped FIND commands in BTM Support 7
P Concatenating strings in a BTM Support 3
C Cmpr_Del.btm need help understanding UDF..... Support 2
G .BTM association doesn't work anymore Support 1
A 18.00.21 tries to cancel TCSTART.BTM Support 3
B How to? why does my BTM stop Support 2
redwdc btm won't run in ver. 17 but works in ver. 16 Support 11
I How to? Bat Works but BTM Doesn't Support 6
C Documentation .CMD .BAT .BTM Support 15
C TCMD17x64\tcchere.btm Support 3
T How to? sort history in tcexit.btm Support 22
Mezlo help with btm fragment Support 9
C REQ: tcmdhere.btm mod Support 11
vefatica Why isn't TCSTART.BTM run? Support 8
C move_all.btm Support 34

Similar threads