printf.exe: Arithmetic and Programming
Moderator: DosItHelp
Re: printf.exe: Show formatted output AND evaluate arithmetic expressions!
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..
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..
Re: printf.exe: Show formatted output AND evaluate arithmetic expressions!
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?
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?
Re: printf.exe: Show formatted output AND evaluate arithmetic expressions!
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
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
Re: printf.exe: Arithmetic and Programming
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:
![Image](https://i.imgur.com/SLEViRd.png)
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!!!
Antonio
- 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:
Data specification formats are %i for integers, %f for floats, %c for characters and %s for strings.
Code: Select all
printf "Hello, world!\n"
. - 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
- 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.
![Image](https://i.imgur.com/SLEViRd.png)
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!!!
![Very Happy :D](./images/smilies/icon_biggrin.gif)
Antonio
Re: printf.exe: Arithmetic and Programming
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?
Thank you so much!
![Sad :(](./images/smilies/icon_sad.gif)
Antonio
PS - Could you please confirm if the printf.exe program is running correctly on your computer?
![Rolling Eyes :roll:](./images/smilies/icon_rolleyes.gif)
Re: printf.exe: Arithmetic and Programming
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.
:\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.
Re: printf.exe: Arithmetic and Programming
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
Antonio
Re: printf.exe: Arithmetic and Programming
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..
Re: printf.exe: Arithmetic and Programming
A new release of printf.exe application is here!
The new printf.exe version 2.55 adds some new features:
![Image](https://tinypic.host/images/2024/05/12/MANDELBROT-SET---800x600x2500---1.0-1.125-2.0.png)
Enjoy it!
Antonio
The new printf.exe version 2.55 adds some new features:
- A couple small bugs were fixed
- A new set of very efficient FPU-only operations were added
- CURS new operation to control the cursor was added
- FMT{:r option to show text in color was added
![Image](https://tinypic.host/images/2024/05/12/MANDELBROT-SET---800x600x2500---1.0-1.125-2.0.png)
Enjoy it!
Antonio
Re: printf.exe: Arithmetic and Programming
I just released the new printf.exe version 2.80 with these new features:
![Image](https://tinypic.host/images/2024/09/02/Turtle-Graphics-Example.png)
Besides Turtle Graphics basic commands, there is another example program that implements the LABEL Turtle Graphics feature that allows you to show text messages. The printf.exe LABEL implementation is based on Font Definition Files that you can easily create in order to define your own fonts. The printf.exe package includes two font definition files; the image below show the standard ASCII characters 32-127 of one of such files.
![Image](https://tinypic.host/images/2024/09/02/Text-example-of-Label-Big-font.png)
Antonio
PS - I would like to invite you to register yourself as a printf.exe user. See the indications in the Register your copy of printf.exe.html file.
- CURS3..CURS9 change cursor size function added.
- SYSTEM function to execute cmd.exe commands added.
- CASE function that convert uppercase/lowercase letters from Code Page 850 added.
- A new set of Y vs X "reversed" comparison operators added.
- ]i++ ]i-- [i++ [i-- STOi++ STOi-- RCLi++ RCLi-- Post-increment/decrement in indirect addressing storage registers operations added.
![Image](https://tinypic.host/images/2024/09/02/Turtle-Graphics-Example.png)
Besides Turtle Graphics basic commands, there is another example program that implements the LABEL Turtle Graphics feature that allows you to show text messages. The printf.exe LABEL implementation is based on Font Definition Files that you can easily create in order to define your own fonts. The printf.exe package includes two font definition files; the image below show the standard ASCII characters 32-127 of one of such files.
![Image](https://tinypic.host/images/2024/09/02/Text-example-of-Label-Big-font.png)
Antonio
PS - I would like to invite you to register yourself as a printf.exe user. See the indications in the Register your copy of printf.exe.html file.
Re: printf.exe: Arithmetic and Programming
Nice. I wanted to use escape sequence DECDHL—Double-Width, Double-Height Line but it is not supported in Windows.
This:
Saso
This:
Code: Select all
ESC#3 Some text - displayed with double height and double width.
ESC#4 Some text - displayed with double height and double width.
Re: printf.exe: Arithmetic and Programming
Works for me, Saso.
Tested in the prompt of Windows Terminal. In a batch script you have to double the percent signs as always. And I think to make it also work in a console window, Antonio would have to set ENABLE_VIRTUAL_TERMINAL_PROCESSING for his application (https://learn.microsoft.com/en-us/windo ... onsolemode).
@Antonio, do you think supporting the non-standard \e sequence for an escape character would be reasonable? Some C and C++ compilers do (gcc and clang for example) as well as Linux shells. PowerShell 6.0+ supports it using its `e escape syntax.
Steffen
Code: Select all
printf "%c#3Double Height (implies Double Width)\n%c#4Double Height (implies Double Width)\n" 27 27
@Antonio, do you think supporting the non-standard \e sequence for an escape character would be reasonable? Some C and C++ compilers do (gcc and clang for example) as well as Linux shells. PowerShell 6.0+ supports it using its `e escape syntax.
Steffen
Re: printf.exe: Arithmetic and Programming
The inclusion of \e as an ESC character is very simple and it will be implemented in the next version of printf.exe.
About ENABLE_VIRTUAL_TERMINAL_PROCESSING: I understand that this mode must be implemented in order to use VT100 Terminal Sequences. What I have not decided yet is the way to do such implementation. I think of three possibilities:
1- Always enable VirtualProcessing when printf.exe starts and reset the original console mode when end.
2- Provide a simple printf.exe command that just enable/disable VirtualProcessing (I don't like this option: it looks like an ugly patch).
3- Provide an advanced command that gives full access to all modes of both input console and output buffer.
The first method is the simplest one, but I don't know if it would introduce some problems in certain programs that don't use VT100 sequences.
IMHO the third method is the "right way" to solve this problem. However, this option is somewhat difficult to use if you just want to enable VirtualProcessing. It also opens the possibility that users could damage the operation of the console if they don't know what they are doing...
What do you think?
Antonio
About ENABLE_VIRTUAL_TERMINAL_PROCESSING: I understand that this mode must be implemented in order to use VT100 Terminal Sequences. What I have not decided yet is the way to do such implementation. I think of three possibilities:
1- Always enable VirtualProcessing when printf.exe starts and reset the original console mode when end.
2- Provide a simple printf.exe command that just enable/disable VirtualProcessing (I don't like this option: it looks like an ugly patch).
3- Provide an advanced command that gives full access to all modes of both input console and output buffer.
The first method is the simplest one, but I don't know if it would introduce some problems in certain programs that don't use VT100 sequences.
IMHO the third method is the "right way" to solve this problem. However, this option is somewhat difficult to use if you just want to enable VirtualProcessing. It also opens the possibility that users could damage the operation of the console if they don't know what they are doing...
What do you think?
Antonio
Re: printf.exe: Arithmetic and Programming
Sorry Steffen for not being clear enough: I wanted to use Escape Sequences on their own (without printf) in the command prompt. Now printf would be useful.aGerman wrote: ↑02 Sep 2024 12:49Works for me, Saso.Tested in the prompt of Windows Terminal. In a batch script you have to double the percent signs as always. And I think to make it also work in a console window, Antonio would have to set ENABLE_VIRTUAL_TERMINAL_PROCESSING for his application (https://learn.microsoft.com/en-us/windo ... onsolemode).Code: Select all
printf "%c#3Double Height (implies Double Width)\n%c#4Double Height (implies Double Width)\n" 27 27
@Antonio, do you think supporting the non-standard \e sequence for an escape character would be reasonable? Some C and C++ compilers do (ggc and clang for example) as well as Linux shells. PowerShell 6.0+ supports it using its `e escape syntax.
Steffen
Saso
Re: printf.exe: Arithmetic and Programming
@Saso
I thought it was about printf as you asked in this thread.
However, no problem. Just create an escape character and assign it to a variable as you already know:
@Antonio
If you'd ask me, don't make it an option, just enable it. In fact I'm not aware of any tool where this is optional. Either it is enabled or not. The CMD, PowerShell and Linux Shells on Windows (via WSL) have it enabled. Also, if you run in Windows Terminal (which is the default on Win 11 already) you don't even need to enable it anymore. It's only required for applications running in the console. So this is rather an exception and I hope Microsoft has any good reason for that kind of inconsistency.
Since I don't speak ASM, I've been putting the code into the Compiler Explorer in the hope it's helpful for you:
https://godbolt.org/z/b4rb1f6Ys
Don't worry about the target. If it is anything else than a console (e.g. a redirection to a file or a pipe) Get/SetConsoleMode will just fail. So, let it fail...
EDIT Oh, I forgot to mention that you don't need to reset the mode.
Steffen
I thought it was about printf as you asked in this thread.
However, no problem. Just create an escape character and assign it to a variable as you already know:
Code: Select all
for /f %%i in ('echo prompt $E^|cmd') do set "ESC=%%i"
echo %ESC%#3 Some text - displayed with double height and double width.
echo %ESC%#4 Some text - displayed with double height and double width.
@Antonio
If you'd ask me, don't make it an option, just enable it. In fact I'm not aware of any tool where this is optional. Either it is enabled or not. The CMD, PowerShell and Linux Shells on Windows (via WSL) have it enabled. Also, if you run in Windows Terminal (which is the default on Win 11 already) you don't even need to enable it anymore. It's only required for applications running in the console. So this is rather an exception and I hope Microsoft has any good reason for that kind of inconsistency.
Since I don't speak ASM, I've been putting the code into the Compiler Explorer in the hope it's helpful for you:
https://godbolt.org/z/b4rb1f6Ys
Don't worry about the target. If it is anything else than a console (e.g. a redirection to a file or a pipe) Get/SetConsoleMode will just fail. So, let it fail...
![Wink :wink:](./images/smilies/icon_wink.gif)
EDIT Oh, I forgot to mention that you don't need to reset the mode.
Steffen