printf.exe: Arithmetic and Programming

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
lazna
Posts: 53
Joined: 27 Dec 2012 10:54

Re: printf.exe: Show formatted output AND evaluate arithmetic expressions!

#16 Post by lazna » 05 Aug 2022 13:08

Each data source (DS) in RRD file is represented by each column of `rrdtool fetch`output. There could be #IND string only in SOME columns on some line, not on ALL of them. Number of DS may differ across various RRD database files. So never could expect how many columns will be on fprint.exe input, but fprint translating expression MUST be aware of input format.

Therefor prior translating, querying RRD file by `rrdtool info` for list of its data sources, counting them and then assemble fprint translating expression accordingly. There are fixed 10 parameters with untranslated numbers at the and of fprint line, because batch scripts replace non-existing variable by nothing and i am trying keep it simple.

NOTE: Not only professional programmers dealing with windows shell scripts, but uneducated people sometimes too. For those `scientific notation`could be something like chinese chars or hieroglyphs. If I wrote human readable, I mean ALL HUMAN READABLE, not only enough educated ones...

BTW: for same reason is for me very hard to read documentation writen by higly educated people. No excuses, just sidenote..

lazna
Posts: 53
Joined: 27 Dec 2012 10:54

Re: printf.exe: Show formatted output AND evaluate arithmetic expressions!

#17 Post by lazna » 06 Aug 2022 02:41

Problem solved!

IN the for loop definition "tokens=1-5" remains from previous version, but now it process more tokens. This cause by later variable expansion the non existent tokens was replaced by its names instead it remain empty. It working now

Final version published in Cacti forum https://forums.cacti.net/viewtopic.php?t=62271#p288538

Thanks to Antonio for its patientce.

BTW: One more question: Why printf in case of problem does not report error message (plus set errorlevel) and terminate liek other consoel programs, but crash so windows display GUI msg it must be clicked by mouse?

lazna
Posts: 53
Joined: 27 Dec 2012 10:54

Re: printf.exe: Show formatted output AND evaluate arithmetic expressions!

#18 Post by lazna » 07 Aug 2022 04:17

One more note:

It seem to me, first use of fprint.exe on windows batch file somehow 'stop interpreting' ANSI sequences. All sequences after first run (it looping multiple time in my script) are not interpreted, but just displayed on screen. Could someone verify its not a problem only on my machine, please?

EDIT: It does work when prepend "cmd /C" just before printf command, so this could be a workaround

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: printf.exe: Arithmetic and Programming

#19 Post by Aacini » 21 Aug 2023 20:06

I have just released a new version of the printf.exe application. The new version 2.11 of printf.exe includes many new features. Firstly, this is a list of the original printf.exe features as implemented in the current version 2.11:
  • All output is performed via the printf C standard function in the usual way. Allowed control characters in the format string are: \n New line, \r CR, \t TAB, \b BS and \a BELL. For example:

    Code: Select all

    printf "Hello, world!\n"
    
    Data specification formats are %i for integers, %f for floats, %c for characters and %s for strings.
    .
  • The 64-bits integer numbers of previous version were removed; this point allows to write correct arithmetic expressions in a simpler way. Current data types are: 32-bits integer number (with no decimal point), 64-bits floating point number (with decimal point or Exponent of ten), a character enclosed in apostrophes ('C') and a string enclosed "between quotes". A Batch (environment) variable also works as string value. A simple example:

    Code: Select all

    printf "A character: %c\tA string: %s\tAn integer: %i\tA floating point: %f\n"  'X'  "ABC"  1  1.
    
    .
  • Arithmetic operations are evaluated in Reverse Polish Notation. Integer operations. One operand: ! BoolNot, ~ BitNot, _ ChS, $ Sign, ] Sto, [ Rcl, > Dup, < Drop, ++ Inc, -- Dec. Two operands: + Add, - Sub, * Mul, / Div, % Mod, ** Power. << BitSHL, >> BitSHR, & BitAnd, | BitOr, ^ BitXor, <> Exchan. # Random, . Float.
    .
  • Floating Point operations. One operand: CHS, ABS, SIGN, FRAC, INV, SQR, SQRT; LN, LOG, EXP, EXPT; STO, RCL, DUP, DROP. SIN, COS, TAN, ASIN, ACOS, ATAN (rad); DEG, RAD. Special: ZERO, ONE, PI, INT. Two operands: ADD, SUB, MUL, DIV, MOD, POW, XCHG. For example:

    Code: Select all

    printf "The sum of 3 plus 4 is %i\nThe sum of 3. plus 4. is %f\n"  3 4 +  3. 4. ADD
    
The new printf version 2.11 have a lot of new and amazing features. This is a brief list:
  • A few extended operations for stack management, storage registers and arithmetic operations have been added.
  • A new rich set of string management functions: atoi(string), atof(string), len(string), getc(str,pos), putc(str,pos,C), xchc(str,pos,C), dupc(character,N), dups(string,N), revc(string), revs(s1,..,sn,N), gets(str,pos,len), index(str,subs), split(string), join(s1,..,sn,N), shift(s1,..,sn,N), repl(str,s1,s2).
  • An entirely new set of basic and advanced Input/Output operations: OUT, FMT{, FMT}, GETK, GETK?, GETK?:r, maxlen IN, "command" CMD, maxlen IN?, "file" IN{?:n, "file" IN{+?:n, maxlen IN?:n, "file" OUT{:n, "file" OUT{+:n, OUT:n, OUT}:n, OUT}+:n, SEEK#:n:p.
However, the most important feature of the new printf.exe version 2.11 is its programming capabilities. The printf.exe programming scheme is not the very high-level one of modern programming languages; it is a much simpler one that was designed based on a technology that arose together with the Lisp programming language, which established the principles of Structured Programming. The program writing method used in printf.exe is based on only four control elements (Begin, Repeat, Quit and End) and a couple of simple rules about evaluating conditions (Tests), but this method still allows the same constructs of modern structured programming languages ​​to be assembled and used. The scheme below summarizes all operation rules on printf.exe programming:

Image

This programming paradigm makes it possible for non-technical people to understand and practice the process of writing programs; they just need a little interest in math.

All these features are described with detail in the new printf.exe 2.11 User's Manual (now in both English and Spanish) that include a lot of examples on several levels.

I encourage you to download the printf.exe 2.11 package, review the User's Manual, and try each of the included sample programs at least once. You may be surprised!!! :D

printf.exe version 2.11.zip
printf.exe 2.11 with examples, user's manuals and support files
(192.6 KiB) Downloaded 395 times

Antonio

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: printf.exe: Arithmetic and Programming

#20 Post by Aacini » 24 Aug 2023 06:19

Ops! I just realized that I forgot a couple of images in the printf.zip file 2.11 previously released. :( I added the missing files to the .zip, so please download the file again.

Antonio

PS - Could you please confirm if the printf.exe program is running correctly on your computer? :roll: Thank you so much!

lazna
Posts: 53
Joined: 27 Dec 2012 10:54

Re: printf.exe: Arithmetic and Programming

#21 Post by lazna » 22 Oct 2023 04:30

Just download zip file, extract printf.exe and run it:

:\Users\user>\utils\printf.exe
printf.exe Version 1.0 Copyright (C) 2016-2020, Antonio Perez Ayala

'printfHelp.bat' is not recognized as an internal or external command,
operable program or batch file.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: printf.exe: Arithmetic and Programming

#22 Post by Aacini » 22 Oct 2023 20:28

lazna wrote:
22 Oct 2023 04:30
Just download zip file, extract printf.exe and run it:

:\Users\user>\utils\printf.exe
printf.exe Version 1.0 Copyright (C) 2016-2020, Antonio Perez Ayala

'printfHelp.bat' is not recognized as an internal or external command,
operable program or batch file.

I am afraid the description of your problem is incomplete...

I assumed that you downloaded the .zip file and extracted just printf.exe file from it. The .zip file contains 27 files. Why just download printf.exe?

The Appendix 1: "printf.exe installation and support" of printf.exe User's Manual clearly specify: "download the printf.zip file and extract its contents in a given folder". Then a list of the included files follows. In such a list, this file appears:

Code: Select all

printfHelp.bat			printf.exe on-screen help
I hope this information helps you solve your problem. If not, please describe your situation in more detail...

Antonio

lazna
Posts: 53
Joined: 27 Dec 2012 10:54

Re: printf.exe: Arithmetic and Programming

#23 Post by lazna » 23 Oct 2023 02:18

Aacini wrote:
22 Oct 2023 20:28
I assumed that you downloaded the .zip file and extracted just printf.exe file from it. The .zip file contains 27 files. Why just download printf.exe?
Because I am using it in redistributable package which including many other files, and want to minimize files number to keep whole package better maintained. And because previous version of printf.exe work fine as a single file.

Now I have exctracted whole package and program start normally. Sorry for my ignorance..

Post Reply